Skip to content

Commit

Permalink
chore: Small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
michalJur committed Oct 20, 2024
1 parent ff9a54e commit 625c69c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 19 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
"program": "${workspaceFolder}/examples/draft_examples.py",
"justMyCode": false
},
{
"name": "Draft presentation",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/examples/draft_presentation.py",
"justMyCode": false
},
{
"name": "Train graph",
"type": "python",
Expand Down
2 changes: 1 addition & 1 deletion conmech/helpers/cmh.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ def find_files_by_name(directory, name):


def get_base_for_comarison():
print("USING BASE FOR COMPARISON")
all_paths = glob(
"output/**/scenarios/*skinning_backwards*.scenes_comparer", recursive=True
)
assert len(all_paths) == 1
print("USING BASE FOR COMPARISON")
return all_paths[0]


Expand Down
2 changes: 1 addition & 1 deletion conmech/helpers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Config:
shell: bool = False
timestamp_skip: int = 10000
run_timestamp: float = int(time.time() * timestamp_skip)
current_time: str = datetime.now().strftime("%m.%d-%H.%M.%S")
current_time: str = datetime.now().strftime("%y.%m.%d-%H.%M.%S")
verbose: bool = True

animation_backend: str = "three" # "matplotlib blender three"
Expand Down
2 changes: 1 addition & 1 deletion conmech/plotting/plotter_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def save_results_three(file_path, json_dict):


def plot_using_blender(output: bool = True):
path = "~/Desktop/Blender/blender-3.2.0-linux-x64/blender" # TODO: Move to configuration
path = "~/Desktop/Blender/blender-4.1.1-linux-x64/blender" # TODO: Move to configuration
args = " --background --python ~/Desktop/conmech3d/blender/load.py --render"
print("Plotting using Blender...")
stdout = sys.stdout if output else subprocess.DEVNULL
Expand Down
4 changes: 2 additions & 2 deletions conmech/simulations/simulation_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_solve_function(simulation_config):
if simulation_config.mode == "normal":
return Calculator.solve
if simulation_config.mode == "pca":
return Calculator.solve_skinning_backwards ### solve
return Calculator.solve_skinning_backwards_base
if simulation_config.mode == "compare_reduced":
return Calculator.solve_compare_reduced
if simulation_config.mode == "skinning":
Expand Down Expand Up @@ -186,7 +186,7 @@ def save_scene(scene: Scene, scenes_path: str, save_animation: bool):
pkh.append_data(data=blender_data, data_path=blender_data_path, lock=None)

# Comparer
if hasattr(scene, 'reduced'):
if hasattr(scene, "reduced"):
comparer_data_path = scenes_path + "_comparer"

comparer_data = {
Expand Down
27 changes: 22 additions & 5 deletions conmech/solvers/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,24 @@ def solve_skinning_backwards(
initial_a,
initial_t=None,
timer=Timer(),
):
return Calculator.solve_skinning_backwards_base(
scene=scene,
energy_functions=energy_functions,
initial_a=initial_a,
initial_t=initial_t,
timer=timer,
with_base_for_comparison=False,
)

@staticmethod
def solve_skinning_backwards_base(
scene: Scene,
energy_functions: EnergyFunctions,
initial_a,
initial_t=None,
timer=Timer(),
with_base_for_comparison=True,
):
_ = initial_a, initial_t
energy_functions = (
Expand All @@ -230,21 +248,20 @@ def solve_skinning_backwards(
else energy_functions
)

dense_path = cmh.get_base_for_comarison()

with timer["reduced_solver"]:
scene.lifted_acceleration, _ = Calculator.solve(
scene=scene,
energy_functions=energy_functions,
initial_a=scene.exact_acceleration,
timer=timer,
)
if dense_path is None:
exact_acceleration = scene.lifted_acceleration
else:
if with_base_for_comparison:
dense_path = cmh.get_base_for_comarison()
exact_acceleration, _ = cmh.get_exact_acceleration(
scene=scene, path=dense_path
)
else:
exact_acceleration = scene.lifted_acceleration
with timer["lift_data"]:
scene.reduced.exact_acceleration = scene.lift_acceleration_from_position(
exact_acceleration
Expand Down
7 changes: 3 additions & 4 deletions examples/draft_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def main():
"skinning",
"net",
"pca",
] # , "pca"] # Do not use "normal" - does not contain reduced
# run_all_simulations(modes=modes)
] # Do not use "normal" - does not contain reduced
run_all_simulations(modes=modes)
compare_latest(modes=modes)
input("Press Enter to continue...")

Expand All @@ -41,8 +41,7 @@ def run_simulation(mode):
config = get_train_config(shell=False, mode=mode)

all_scenarios = scenarios.all_validation(config.td, config.sc)
all_scenarios = all_scenarios[-1]

all_scenarios = all_scenarios[-1] #-1]
# all_scenarios[0].schedule.final_time = 1.

simulation_runner.run_examples(
Expand Down
10 changes: 5 additions & 5 deletions examples/draft_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
use_lhs_preconditioner=False,
with_self_collisions=False,
)
name = "linear_16"
simulation_config.use_green_strain = False
simulation_config.use_linear_solver = True
simulation_config.use_constant_contact_integral = True
name = "test_green"
# simulation_config.use_green_strain = False
# simulation_config.use_linear_solver = True
# simulation_config.use_constant_contact_integral = True

animation_backend = "three" # None


def main(mesh_density=16, final_time=3, plot_animation=True): # 100
def main(mesh_density=16, final_time=2, plot_animation=True): # 100
schedule = Schedule(final_time=final_time, time_step=0.01)
body_prop = TimeDependentBodyProperties(
mu=8,
Expand Down

0 comments on commit 625c69c

Please sign in to comment.