Skip to content

Commit

Permalink
Merge pull request sandialabs#70 from btalamini/main
Browse files Browse the repository at this point in the history
Pu time increment call back into energy functions
  • Loading branch information
cmhamel authored Nov 14, 2023
2 parents 395fc48 + ff3ae32 commit d00ffd1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions examples/uniaxial/UniaxialCycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self):
materialModel = Material.create_material_model_functions(props)

self.mechanicsFunctions = Mechanics.create_mechanics_functions(
self.fs, "plane strain", materialModel, dt=dt
self.fs, "plane strain", materialModel
)

self.outputForce = []
Expand All @@ -99,14 +99,14 @@ def assemble_sparse(self, Uu, p):
def energy_function(self, Uu, p):
U = self.create_field(Uu, p)
internalVariables = p[1]
return self.mechanicsFunctions.compute_strain_energy(U, internalVariables)
return self.mechanicsFunctions.compute_strain_energy(U, internalVariables, dt)


@partial(jax.jit, static_argnums=0)
@partial(jax.value_and_grad, argnums=2)
def compute_reactions_from_bcs(self, Uu, Ubc, internalVariables):
U = self.dofManager.create_field(Uu, Ubc)
return self.mechanicsFunctions.compute_strain_energy(U, internalVariables)
return self.mechanicsFunctions.compute_strain_energy(U, internalVariables, dt)


def create_field(self, Uu, p):
Expand Down Expand Up @@ -193,7 +193,7 @@ def run(self):
Uu = EqSolver.nonlinear_equation_solve(objective, Uu, p, settings)

state = self.mechanicsFunctions.\
compute_updated_internal_variables(self.create_field(Uu, p), p[1])
compute_updated_internal_variables(self.create_field(Uu, p), p[1], dt)
p = Objective.param_index_update(p, 1, state)

self.write_output(Uu, p, i)
Expand Down Expand Up @@ -239,7 +239,7 @@ def make_FD_plot(self):
materialModel = Neohookean.create_material_model_functions(props)

app.mechanicsFunctions = Mechanics.create_mechanics_functions(
app.fs, "plane strain", materialModel, dt=0.0
app.fs, "plane strain", materialModel
)

app.run()
Expand Down
11 changes: 5 additions & 6 deletions optimism/Mechanics.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ def compute_initial_state():


def create_mechanics_functions(functionSpace, mode2D, materialModel,
pressureProjectionDegree=None,
dt=0.0):
pressureProjectionDegree=None):
fs = functionSpace

if mode2D == 'plane strain':
Expand All @@ -269,23 +268,23 @@ def modify_element_gradient(elemGrads, elemShapes, elemVols, elemNodalDisps, ele
return grad_2D_to_3D(elemGrads, elemShapes, elemVols, elemNodalDisps, elemNodalCoords)


def compute_strain_energy(U, stateVariables, dt=dt):
def compute_strain_energy(U, stateVariables, dt=0.0):
return _compute_strain_energy(fs, U, stateVariables, dt, materialModel.compute_energy_density, modify_element_gradient)


def compute_updated_internal_variables(U, stateVariables, dt=dt):
def compute_updated_internal_variables(U, stateVariables, dt=0.0):
return _compute_updated_internal_variables(fs, U, stateVariables, dt, materialModel.compute_state_new, modify_element_gradient)


def compute_element_stiffnesses(U, stateVariables, dt=dt):
def compute_element_stiffnesses(U, stateVariables, dt=0.0):
return _compute_element_stiffnesses(U, stateVariables, dt, fs, materialModel.compute_energy_density, modify_element_gradient)


output_lagrangian = strain_energy_density_to_lagrangian_density(materialModel.compute_energy_density)
output_constitutive = value_and_grad(output_lagrangian, 1)


def compute_output_energy_densities_and_stresses(U, stateVariables, dt=dt):
def compute_output_energy_densities_and_stresses(U, stateVariables, dt=0.0):
return FunctionSpace.evaluate_on_block(fs, U, stateVariables, dt, output_constitutive, slice(None), modify_element_gradient=modify_element_gradient)


Expand Down

0 comments on commit d00ffd1

Please sign in to comment.