Skip to content

Commit

Permalink
fixed brocken test
Browse files Browse the repository at this point in the history
  • Loading branch information
aradermacher committed Feb 15, 2024
1 parent 8ace758 commit 9172d28
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
27 changes: 26 additions & 1 deletion amworkflow/simulation/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
38 changes: 19 additions & 19 deletions amworkflow/simulation/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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":
Expand Down
6 changes: 3 additions & 3 deletions examples/Wall/.doit.db.bak
Original file line number Diff line number Diff line change
@@ -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)
Binary file modified examples/Wall/.doit.db.dat
Binary file not shown.
6 changes: 3 additions & 3 deletions examples/Wall/.doit.db.dir
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions examples/Wall/dodo_wall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 9172d28

Please sign in to comment.