Skip to content

Commit

Permalink
Merge pull request #100 from sandialabs/chamel/equinox-mechanics
Browse files Browse the repository at this point in the history
moving mechanics to equinox modules. Again, seeing no performance reg…
  • Loading branch information
cmhamel authored Nov 6, 2024
2 parents 4f154bf + 5420731 commit d215c9f
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions optimism/Mechanics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,48 @@
from optimism.TensorMath import tensor_2D_to_3D
from optimism import QuadratureRule
from optimism import Interpolants

MechanicsFunctions = namedtuple('MechanicsFunctions',
['compute_strain_energy',
'compute_updated_internal_variables',
'compute_element_stiffnesses',
'compute_output_energy_densities_and_stresses',
'compute_initial_state',
'integrated_material_qoi',
'compute_output_material_qoi'])


DynamicsFunctions = namedtuple('DynamicsFunctions',
['compute_algorithmic_energy',
'compute_updated_internal_variables',
'compute_element_hessians',
'compute_output_energy_densities_and_stresses',
'compute_output_kinetic_energy',
'compute_output_strain_energy',
'compute_initial_state',
'compute_element_masses', # not used for time integration, provided for convenience (spectral analysis, eg)
'predict',
'correct'])

NewmarkParameters = namedtuple('NewmarkParameters', ['gamma', 'beta'], defaults=[0.5, 0.25])
from typing import Callable

import equinox as eqx


# TODO
# eventually let's move to some kind of class hierarchy like below
# that we can derive off of with shared behavior
#
# normal python inheritance rules apply to equinox Modules
# class BaseFunctions(eqx.Module):
# compute_output_energy_densities_and_stresses: Callable
# compute_initial_state: Callable


# TODO further type below so Callable refelcts the actual called arguments and returns
class MechanicsFunctions(eqx.Module):
compute_strain_energy: Callable
compute_updated_internal_variables: Callable
compute_element_stiffnesses: Callable
compute_output_energy_densities_and_stresses: Callable
compute_initial_state: Callable
integrated_material_qoi: Callable
compute_output_material_qoi: Callable


class DynamicsFunctions(eqx.Module):
compute_algorithmic_energy: Callable
compute_updated_internal_variables: Callable
compute_element_hessians: Callable
compute_output_energy_densities_and_stresses: Callable
compute_output_kinetic_energy: Callable
compute_output_strain_energy: Callable
compute_initial_state: Callable
compute_element_masses: Callable # not used for time integration, provided for convenience (spectral analysis, eg)
predict: Callable
correct: Callable


class NewmarkParameters(eqx.Module):
gamma: float = 0.5
beta: float = 0.25


def plane_strain_gradient_transformation(elemDispGrads, elemShapes, elemVols, elemNodalDisps, elemNodalCoords):
Expand Down

0 comments on commit d215c9f

Please sign in to comment.