Skip to content

Commit

Permalink
Merge pull request #285 from pyiron/refactor_integration_tests
Browse files Browse the repository at this point in the history
[minor] Refactor integration tests
  • Loading branch information
samwaseda committed Apr 26, 2024
2 parents e9e248c + b375b38 commit 9fcc98a
Showing 1 changed file with 84 additions and 213 deletions.
297 changes: 84 additions & 213 deletions tests/integration/damask/test_backward_compatibility.py
Expand Up @@ -15,22 +15,48 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.project.remove(enable=True)

def test_damask_tutorial(self):
grains = 8
grids = 16
job = self.project.create.job.DAMASK("tutorial")
homogenization = self.project.create.DAMASK.homogenization(
method="SX",
parameters={"N_constituents": 1, "mechanical": {"type": "pass"}},
def _get_load_step(self):
return [
{
"mech_bc_dict": {
"dot_F": [1e-3, 0, 0, 0, "x", 0, 0, 0, "x"],
"P": ["x", "x", "x", "x", 0, "x", "x", "x", 0],
},
"discretization": {"t": 10.0, "N": 40},
"additional": {"f_out": 4},
},
{
"mech_bc_dict": {
"dot_F": [1e-3, 0, 0, 0, "x", 0, 0, 0, "x"],
"P": ["x", "x", "x", "x", 0, "x", "x", "x", 0],
},
"discretization": {"t": 60.0, "N": 60},
"additional": {"f_out": 4},
},
]

def _get_grid(self, sd=16, n=4):
return self.project.continuum.damask.Grid.via_voronoi_tessellation(
box_size=1.0e-5, spatial_discretization=sd, num_grains=n
)
homogenization = self.project.continuum.damask.Homogenization(

def _get_homogenization(self):
return self.project.continuum.damask.Homogenization(
method="SX",
parameters={"N_constituents": 1, "mechanical": {"type": "pass"}},
)
elasticity = self.project.continuum.damask.Elasticity(
type="Hooke", C_11=106.75e9, C_12=60.41e9, C_44=28.34e9

def test_creator(self):
self.assertEqual(
self.project.create.DAMASK.homogenization(
method="SX",
parameters={"N_constituents": 1, "mechanical": {"type": "pass"}},
),
self._get_homogenization(),
)
plasticity = self.project.continuum.damask.Plasticity(

def get_plasticity_phenopowerlaw(self):
return self.project.continuum.damask.Plasticity(
type="phenopowerlaw",
N_sl=[12],
a_sl=[2.25],
Expand All @@ -43,43 +69,35 @@ def test_damask_tutorial(self):
xi_0_sl=[31.0e6],
xi_inf_sl=[63.0e6],
)
phase = self.project.continuum.damask.Phase(

def _get_elasticity(self):
return self.project.continuum.damask.Elasticity(
type="Hooke", C_11=106.75e9, C_12=60.41e9, C_44=28.34e9
)

def get_phase_aluminum(self, elasticity, plasticity):
return self.project.continuum.damask.Phase(
composition="Aluminum",
lattice="cF",
output_list=["F", "P", "F_e", "F_p", "L_p", "O"],
elasticity=elasticity,
plasticity=plasticity,
)

def test_damask_tutorial(self):
grains = 8
job = self.project.create.job.DAMASK("tutorial")
plasticity = self.get_plasticity_phenopowerlaw()
phase = self.get_phase_aluminum(self._get_elasticity(), plasticity)
rotation = self.project.continuum.damask.Rotation(shape=grains)
material = self.project.continuum.damask.Material(
[rotation], ["Aluminum"], phase, homogenization
[rotation], ["Aluminum"], phase, self._get_homogenization()
)
job.material = material
grid = self.project.continuum.damask.Grid.via_voronoi_tessellation(
box_size=1.0e-5, spatial_discretization=grids, num_grains=grains
)
job.grid = grid
load_step = [
{
"mech_bc_dict": {
"dot_F": [1e-3, 0, 0, 0, "x", 0, 0, 0, "x"],
"P": ["x", "x", "x", "x", 0, "x", "x", "x", 0],
},
"discretization": {"t": 10.0, "N": 40},
"additional": {"f_out": 4},
},
{
"mech_bc_dict": {
"dot_F": [1e-3, 0, 0, 0, "x", 0, 0, 0, "x"],
"P": ["x", "x", "x", "x", 0, "x", "x", "x", 0],
},
"discretization": {"t": 60.0, "N": 60},
"additional": {"f_out": 4},
},
]
job.grid = self._get_grid(n=grains)
solver = job.list_solvers()[0]
job.loading = self.project.continuum.damask.Loading(
solver=solver, load_steps=load_step
solver=solver, load_steps=self._get_load_step()
)
job.run()
job.plot_stress_strain(component="zz")
Expand All @@ -90,30 +108,19 @@ def test_damask_tutorial(self):
def test_linear_elastic(self):
job = self.project.create.job.DAMASK("linear_elastic")
grains = 8
grids = 16
elasticity = self.project.continuum.damask.Elasticity(
type="Hooke", C_11=106.75e9, C_12=60.41e9, C_44=28.34e9
)
phase = self.project.continuum.damask.Phase(
composition="Aluminum",
lattice="cF",
output_list=["F", "P", "F_e"],
elasticity=elasticity,
elasticity=self._get_elasticity(),
plasticity=None,
)
rotation = self.project.continuum.damask.Rotation(shape=grains)
homogenization = self.project.continuum.damask.Homogenization(
method="SX",
parameters={"N_constituents": 1, "mechanical": {"type": "pass"}},
)
material = self.project.continuum.damask.Material(
[rotation], ["Aluminum"], phase, homogenization
[rotation], ["Aluminum"], phase, self._get_homogenization()
)
job.material = material
grid = self.project.continuum.damask.Grid.via_voronoi_tessellation(
box_size=1.0e-5, spatial_discretization=grids, num_grains=grains
)
job.grid = grid
job.grid = self._get_grid(n=grains)
load_step = [
{
"mech_bc_dict": {
Expand All @@ -134,9 +141,6 @@ def test_linear_elastic(self):

def test_elastoplasticity_isotropic(self):
job = self.project.create.job.DAMASK("elastoplasticity_isotropic")
elasticity = self.project.continuum.damask.Elasticity(
type="Hooke", C_11=106.75e9, C_12=60.41e9, C_44=28.34e9
)
plasticity = self.project.continuum.damask.Plasticity(
type="isotropic",
dot_gamma_0=0.001,
Expand All @@ -148,156 +152,49 @@ def test_elastoplasticity_isotropic(self):
M=1.0,
h=1.0,
)
phase = self.project.continuum.damask.Phase(
composition="Aluminum",
lattice="cF",
output_list=["F", "P", "F_e", "F_p", "L_p", "O"],
elasticity=elasticity,
plasticity=plasticity,
)
phase = self.get_phase_aluminum(self._get_elasticity(), plasticity)
rotation = self.project.continuum.damask.Rotation(Rotation.from_random, 4)
homogenization = self.project.continuum.damask.Homogenization(
method="SX",
parameters={"N_constituents": 1, "mechanical": {"type": "pass"}},
)
material = self.project.continuum.damask.Material(
[rotation], ["Aluminum"], phase, homogenization
[rotation], ["Aluminum"], phase, self._get_homogenization()
)
job.material = material
grid = self.project.continuum.damask.Grid.via_voronoi_tessellation(
box_size=1.0e-5, spatial_discretization=16, num_grains=4
)
job.grid = grid
load_step = [
{
"mech_bc_dict": {
"dot_F": [1e-3, 0, 0, 0, "x", 0, 0, 0, "x"],
"P": ["x", "x", "x", "x", 0, "x", "x", "x", 0],
},
"discretization": {"t": 10.0, "N": 40},
"additional": {"f_out": 4},
},
{
"mech_bc_dict": {
"dot_F": [1e-2, 0, 0, 0, "x", 0, 0, 0, "x"],
"P": ["x", "x", "x", "x", 0, "x", "x", "x", 0],
},
"discretization": {"t": 60.0, "N": 60},
"additional": {"f_out": 4},
},
]
job.grid = self._get_grid()
solver = job.list_solvers()[0] # choose the mechanis solver
job.loading = self.project.continuum.damask.Loading(
solver=solver, load_steps=load_step
solver=solver, load_steps=self._get_load_step()
)
job.run() # running your job, if you want the parallelization you can modify your 'pyiron/damask/bin/run_damask_3.0.0.sh file'
job.run()

def test_elastoplasticity_powerlaw(self):
job = self.project.create.job.DAMASK("elastoplasticity_powerlaw")
grains = 4
grids = 16
elasticity = self.project.continuum.damask.Elasticity(
type="Hooke", C_11=106.75e9, C_12=60.41e9, C_44=28.34e9
)
plasticity = self.project.continuum.damask.Plasticity(
type="phenopowerlaw",
N_sl=[12],
a_sl=[2.25],
atol_xi=1.0,
dot_gamma_0_sl=[0.001],
h_0_sl_sl=[75.0e6],
h_sl_sl=[1, 1, 1.4, 1.4, 1.4, 1.4, 1.4],
n_sl=[20],
output=["xi_sl"],
xi_0_sl=[31.0e6],
xi_inf_sl=[63.0e6],
)
phase = self.project.continuum.damask.Phase(
composition="Aluminum",
lattice="cF",
output_list=["F", "P", "F_e", "F_p", "L_p", "O"],
elasticity=elasticity,
plasticity=plasticity,
)
plasticity = self.get_plasticity_phenopowerlaw()
phase = self.get_phase_aluminum(self._get_elasticity(), plasticity)
rotation = self.project.continuum.damask.Rotation(shape=grains)
homogenization = self.project.continuum.damask.Homogenization(
method="SX",
parameters={"N_constituents": 1, "mechanical": {"type": "pass"}},
)
material = self.project.continuum.damask.Material(
[rotation], ["Aluminum"], phase, homogenization
[rotation], ["Aluminum"], phase, self._get_homogenization()
)
job.material = material
grid = self.project.continuum.damask.Grid.via_voronoi_tessellation(
box_size=1.0e-5, spatial_discretization=grids, num_grains=grains
)
job.grid = grid
load_step = [
{
"mech_bc_dict": {
"dot_F": [1e-3, 0, 0, 0, "x", 0, 0, 0, "x"],
"P": ["x", "x", "x", "x", 0, "x", "x", "x", 0],
},
"discretization": {"t": 10.0, "N": 40},
"additional": {"f_out": 4},
},
{
"mech_bc_dict": {
"dot_F": [1e-3, 0, 0, 0, "x", 0, 0, 0, "x"],
"P": ["x", "x", "x", "x", 0, "x", "x", "x", 0],
},
"discretization": {"t": 60.0, "N": 60},
"additional": {"f_out": 4},
},
]
job.grid = self._get_grid()
solver = job.list_solvers()[0] # choose the mechanis solver
job.loading = self.project.continuum.damask.Loading(
solver=solver, load_steps=load_step
solver=solver, load_steps=self._get_load_step()
)
job.run() # running your job, if you want the parallelization you can modify your 'pyiron/damask/bin/run_damask_3.0.0.sh file'
job.run()
job.plot_stress_strain(component="zz")
job.plot_stress_strain(von_mises=True)

def test_multiple_rolling(self):
job = self.project.create.job.ROLLING("multiple_rolling")
elasticity = self.project.continuum.damask.Elasticity(
type="Hooke", C_11=106.75e9, C_12=60.41e9, C_44=28.34e9
)
plasticity = self.project.continuum.damask.Plasticity(
type="phenopowerlaw",
N_sl=[12],
a_sl=[2.25],
atol_xi=1.0,
dot_gamma_0_sl=[0.001],
h_0_sl_sl=[75.0e6],
h_sl_sl=[1, 1, 1.4, 1.4, 1.4, 1.4, 1.4],
n_sl=[20],
output=["xi_sl"],
xi_0_sl=[31.0e6],
xi_inf_sl=[63.0e6],
)
plasticity = self.get_plasticity_phenopowerlaw()
grains = 4
grids = 4
phase = self.project.continuum.damask.Phase(
composition="Aluminum",
lattice="cF",
output_list=["F", "P", "F_e", "F_p", "L_p", "O"],
elasticity=elasticity,
plasticity=plasticity,
)
phase = self.get_phase_aluminum(self._get_elasticity(), plasticity)
rotation = self.project.continuum.damask.Rotation(shape=grains)
homogenization = self.project.continuum.damask.Homogenization(
method="SX",
parameters={"N_constituents": 1, "mechanical": {"type": "pass"}},
)
material = self.project.continuum.damask.Material(
[rotation], ["Aluminum"], phase, homogenization
[rotation], ["Aluminum"], phase, self._get_homogenization()
)
job.material = material
grid = self.project.continuum.damask.Grid.via_voronoi_tessellation(
box_size=1.0e-5, spatial_discretization=grids, num_grains=grains
)
job.grid = grid
job.grid = self._get_grid(4, grains)
reduction_height = 0.05
reduction_speed = 5.0e-2
reduction_outputs = 250
Expand All @@ -312,46 +209,20 @@ def test_multiple_rolling(self):
)
job.postProcess() # do the postprocess
job.plotStressStrainCurve(0.0, 0.60, 0.0, 1.7e8) # xmin,xmax, ymin,ymax
reduction_height = 0.1
reduction_speed = 4.5e-2
reduction_outputs = 300
regrid_flag = True
job.executeRolling(
reduction_height,
reduction_speed,
reduction_outputs,
regrid_flag,
damask_exe,
)
job.postProcess() # do the postprocess
job.plotStressStrainCurve(0.0, 0.60, 0.0, 1.7e8) # xmin,xmax, ymin,ymax
reduction_height = 0.1
reduction_speed = 4.5e-2
reduction_outputs = 350
regrid_flag = True
job.executeRolling(
reduction_height,
reduction_speed,
reduction_outputs,
regrid_flag,
damask_exe,
)
job.postProcess() # do the postprocess
job.plotStressStrainCurve(0.0, 0.60, 0.0, 1.7e8) # xmin,xmax, ymin,ymax
reduction_height = 0.12
reduction_speed = 4.25e-2
reduction_outputs = 300
regrid_flag = True # enable the regridding
job.executeRolling(
reduction_height,
reduction_speed,
reduction_outputs,
regrid_flag,
damask_exe,
)
job.postProcess() # do the postprocess
job.plotStressStrainCurve(0.0, 0.60, 0.0, 1.7e8) # xmin,xmax, ymin,ymax
print(job.ResultsFile)
for reduction_height, reduction_outputs in zip(
[0.1, 0.1, 0.12], [300, 350, 300]
):
job.executeRolling(
reduction_height,
reduction_speed,
reduction_outputs,
regrid_flag,
damask_exe,
)
job.postProcess() # do the postprocess
job.plotStressStrainCurve(0.0, 0.60, 0.0, 1.7e8) # xmin,xmax, ymin,ymax


if __name__ == "__main__":
Expand Down

0 comments on commit 9fcc98a

Please sign in to comment.