diff --git a/amworkflow/simulation/experiment.py b/amworkflow/simulation/experiment.py index 02fbccb..cf200a0 100644 --- a/amworkflow/simulation/experiment.py +++ b/amworkflow/simulation/experiment.py @@ -176,6 +176,18 @@ def create_body_force_am( return L + def compute_volume(self) -> float: + """Computes the volume of the structure + + Returns: + volume of the structure + + """ + dx = ufl.Measure("dx", domain=self.mesh, metadata={"quadrature_degree": 2}) + volume = df.fem.assemble_scalar(df.fem.form(1.0 * dx)) + + return volume + class ExperimentStructure(Experiment): """Experiment class for AM structure simulation in the end (after printing). @@ -279,6 +291,7 @@ def create_displacement_boundary( # Attention: # normally geometries are defined as x/y and z in height due to AM production z is the direction perpendicular to the layers with is not usually the loading direction + # for each defined case please also define the bottom boundary for the reaction force sensor if self.p["bc_setting"] == "fixed_y": # loading displacement controlled in y direction at max_y surface, whereas y-z surface at min_y is full fixed @@ -473,7 +486,7 @@ def boundary_bottom(self): Returns: fct defining if dof is at boundary """ - if self.p["bc_setting"] == "compr_disp_y": + if self.p["bc_setting"] == "compr_disp_y" or self.p["bc_setting"] == "fixed_y": if self.p["dim"] == 3: # get mesh_points to define boundaries mesh_points = self.mesh.geometry.x @@ -492,6 +505,18 @@ def boundary_bottom(self): else: raise ValueError(f"Wrong boundary setting: {self.p['bc_setting']}") + def compute_volume(self) -> float: + """Computes the volume of the structure + + Returns: + volume of the structure + + """ + dx = ufl.Measure("dx", domain=self.mesh, metadata={"quadrature_degree": 2}) + volume = df.fem.assemble_scalar(df.fem.form(1.0 * dx)) + + return volume + # def create_body_force(self, v: ufl.argument.Argument) -> ufl.form.Form: # """defines body force diff --git a/amworkflow/simulation/simulation.py b/amworkflow/simulation/simulation.py index c8af0bb..088fc66 100644 --- a/amworkflow/simulation/simulation.py +++ b/amworkflow/simulation/simulation.py @@ -99,6 +99,7 @@ def run(self, mesh_file: Path, out_xdmf: Path) -> None: if self.pint_parameters["experiment_type"].magnitude == "structure": experiment = ExperimentStructure(self.pint_parameters) + print('Volume of design', experiment.compute_volume()) if self.pint_parameters["material_type"].magnitude == "linear": self.problem = LinearElasticity( @@ -114,11 +115,10 @@ def run(self, mesh_file: Path, out_xdmf: Path) -> None: # set sensors self.problem.add_sensor(ReactionForceSensor()) - self.problem.add_sensor(StressSensor(where=experiment.sensor_location_middle_endge, name="stress sensor")) - self.problem.add_sensor(StrainSensor(where=experiment.sensor_location_middle_endge, name="strain sensor")) - self.problem.add_sensor(DisplacementSensor(where=experiment.sensor_location_corner_top, name="disp top")) - - + if experiment.p["bc_setting"] == "compr_disp_x" or experiment.p["bc_setting"] == "compr_disp_y": + self.problem.add_sensor(StressSensor(where=experiment.sensor_location_middle_endge, name="stress sensor")) + self.problem.add_sensor(StrainSensor(where=experiment.sensor_location_middle_endge, name="strain sensor")) + self.problem.add_sensor(DisplacementSensor(where=experiment.sensor_location_corner_top, name="disp top")) for i in range(0,self.pint_parameters["number_steps"].magnitude): d_disp = 0 + (i+1) * self.pint_parameters["top_displacement"] / self.pint_parameters["number_steps"].magnitude @@ -133,29 +133,29 @@ def run(self, mesh_file: Path, out_xdmf: Path) -> None: "force_x_y_z", np.array(self.problem.sensors["ReactionForceSensor"].data),self.problem.sensors["ReactionForceSensor"].units ) - print("disp sensor", np.array(self.problem.sensors["disp top"].data)) - print("stress sensor", np.array(self.problem.sensors["stress sensor"].data)) - print("strain sensor", np.array(self.problem.sensors["strain sensor"].data)) + ## temporary solution to get equivalent modulus TO BE DELTED if self.pint_parameters["bc_setting"].magnitude == "compr_disp_y": - force_y = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 1].max() + force_y = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 1].min() u_max = d_disp print('equivalent modulus', force_y/(u_max*0.15)) elif self.pint_parameters["bc_setting"].magnitude == "compr_disp_x": - force_y = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 0].max() + force_y = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 0].min() u_max = d_disp print('equivalent modulus', force_y/(u_max*0.15)) # save sensor output as csv file for postprocessing - sensor_dict = {} - sensor_dict["disp_x"] = np.array(self.problem.sensors["disp top"].data)[:, 0] - sensor_dict["disp_y"] = np.array(self.problem.sensors["disp top"].data)[:, 1] - sensor_dict["disp_z"] = np.array(self.problem.sensors["disp top"].data)[:, 2] - sensor_dict["force_x"] = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 0] - sensor_dict["force_y"] = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 1] - sensor_dict["force_z"] = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 2] - df_sensor = pd.DataFrame(sensor_dict) - df_sensor.to_csv(out_xdmf.parent / f"{out_xdmf.stem}.csv", index=False) + if experiment.p["bc_setting"] == "compr_disp_x" or experiment.p["bc_setting"] == "compr_disp_y": + sensor_dict = {} + sensor_dict["disp_x"] = np.array(self.problem.sensors["disp top"].data)[:, 0] + sensor_dict["disp_y"] = np.array(self.problem.sensors["disp top"].data)[:, 1] + sensor_dict["disp_z"] = np.array(self.problem.sensors["disp top"].data)[:, 2] + sensor_dict["force_x"] = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 0] + sensor_dict["force_y"] = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 1] + sensor_dict["force_z"] = np.array(self.problem.sensors["ReactionForceSensor"].data)[:, 2] + df_sensor = pd.DataFrame(sensor_dict) + print(df_sensor) + df_sensor.to_csv(out_xdmf.parent / f"{out_xdmf.stem}.csv", index=False) elif self.pint_parameters["experiment_type"].magnitude == "process": diff --git a/examples/Wall/.doit.db.bak b/examples/Wall/.doit.db.bak index f1bf9f8..ca10fa2 100644 --- a/examples/Wall/.doit.db.bak +++ b/examples/Wall/.doit.db.bak @@ -1,4 +1,4 @@ 'create_design', (1024, 109) -'structure_simulation_disp_x', (6144, 1245) -'meshing', (9216, 1169) -'structure_simulation_disp_y', (11264, 307) +'structure_simulation_disp_x', (6144, 1401) +'meshing', (9216, 1325) +'structure_simulation_disp_y', (12288, 624) diff --git a/examples/Wall/.doit.db.dat b/examples/Wall/.doit.db.dat index 7f37ea0..e2703f9 100644 Binary files a/examples/Wall/.doit.db.dat and b/examples/Wall/.doit.db.dat differ diff --git a/examples/Wall/.doit.db.dir b/examples/Wall/.doit.db.dir index 3a73b5d..4932088 100644 --- a/examples/Wall/.doit.db.dir +++ b/examples/Wall/.doit.db.dir @@ -1,4 +1,4 @@ 'create_design', (1024, 109) -'structure_simulation_disp_x', (6144, 1245) -'meshing', (9216, 1169) -'structure_simulation_disp_y', (11264, 465) +'structure_simulation_disp_x', (6144, 1402) +'meshing', (9216, 1326) +'structure_simulation_disp_y', (12288, 625) diff --git a/examples/Wall/dodo_wall.py b/examples/Wall/dodo_wall.py index c473974..29c6659 100644 --- a/examples/Wall/dodo_wall.py +++ b/examples/Wall/dodo_wall.py @@ -28,7 +28,7 @@ "radius": None, # mm "infill": get_var('infill',"zigzag"), # default infill changeable via command line doit -f dodo_wall.py infill=zigzag or solid or honeycomb # mesh parameters (meshing by layer height) - "line_width": 10, # mm + "line_width": float(get_var('line_width', 11)), # mm # 11 for zigzag 10 for honeycomb to get same volume reduction "mesh_size_factor": float(get_var('mesh_size',4)), # default mesh size factor changeable via command line doit -f dodo_wall.py mesh_size=4 "layer_height": 10, # mm } @@ -45,7 +45,7 @@ "rho": 0 * ureg("kg/m^3"), # density of the material -> no body force in the moment! "E": 33000 * ureg("MPa"), # Young's modulus "nu": 0.2 * ureg(""), # Poisson's ratio - "bc_setting": "compr_disp_y" * ureg(""), # bc setting for structure simulation + #"bc_setting": "compr_disp_y" * ureg(""), # bc setting for structure simulation -> defined in task_structure_simulation_... "top_displacement": -1.5 * ureg("mm"), # max displacement of top surface "number_steps": 3 * ureg(""), # number of steps for simulation "material_type": "linear" * ureg(""), # material type