|
Smith
0.1
Smith is an implicit thermal structural mechanics simulation code.
|
BasePhysics implementation that stores differentiable states in gretl for checkpointed reverse solves.
More...
#include <differentiable_physics.hpp>

Public Member Functions | |
| DifferentiablePhysics (std::shared_ptr< Mesh > mesh, std::shared_ptr< gretl::DataStore > graph, const FieldState &shape_disp, const std::vector< FieldState > &states, const std::vector< FieldState > ¶ms, std::shared_ptr< StateAdvancer > advancer, std::string physics_name, const std::vector< ReactionInfo > &reaction_infos={}) | |
| Construct a differentiable physics wrapper around a state advancer and its tracked fields. More... | |
| ~DifferentiablePhysics () | |
| Destructor. | |
| void | resetStates (int cycle=0, double time=0.0) override |
| Base method to reset physics states to the initial time. This does not reset design parameters or shape. More... | |
| virtual void | resetAdjointStates () override |
| Base method to reset physics states back to the end of time to start adjoint calculations again. This does not reset design parameters or shape. More... | |
| void | completeSetup () override |
| Complete the setup and allocate the necessary data structures. More... | |
| std::vector< std::string > | stateNames () const override |
| Get a vector of the finite element state primal solution names. More... | |
| std::vector< std::string > | parameterNames () const override |
| Get a vector of the finite element state parameter names. More... | |
| std::vector< std::string > | dualNames () const override |
| Get a vector of the finite element state dual (reaction) solution names. More... | |
| const FiniteElementState & | state (const std::string &state_name) const override |
| Accessor for getting named finite element state primal solution from the physics modules. More... | |
| const FiniteElementDual & | dual (const std::string &dual_name) const override |
| Accessor for getting named finite element state dual (reaction) solution from the physics modules. More... | |
| const FiniteElementState & | shapeDisplacement () const override |
| Accessor for getting the shape displacement field from the physics modules. More... | |
| const FiniteElementState & | parameter (std::size_t parameter_index) const override |
| Accessor for getting indexed finite element state parameter fields from the physics modules. More... | |
| const FiniteElementState & | parameter (const std::string ¶meter_name) const override |
| Accessor for getting named finite element state parameter fields from the physics modules. More... | |
| FiniteElementState | loadCheckpointedState (const std::string &state_name, int cycle) override |
| Return a state for a stored checkpoint cycle. More... | |
| FiniteElementDual | loadCheckpointedDual (const std::string &state_name, int cycle) override |
| Accessor for getting a single named finite element dual solution from the physics modules at a given checkpointed cycle index. More... | |
| void | setState (const std::string &state_name, const FiniteElementState &s) override |
| Set the primal solution field values of the underlying physics solver. More... | |
| void | setShapeDisplacement (const FiniteElementState &shape_displacement) override |
| Set the current shape displacement for the underlying mesh. More... | |
| void | setParameter (const size_t parameter_index, const FiniteElementState ¶meter_state) override |
| Deep copy a parameter field into the internally-owned parameter used for simulations. More... | |
| void | setAdjointLoad (std::unordered_map< std::string, const smith::FiniteElementDual & > string_to_dual) override |
| Set the loads for the adjoint reverse timestep solve. More... | |
| void | setDualAdjointBcs (std::unordered_map< std::string, const smith::FiniteElementState & > string_to_bc) override |
| Set the dual loads (dirichlet values) for the adjoint reverse timestep solve This must be called after setAdjointLoad. More... | |
| const FiniteElementState & | adjoint (const std::string &adjoint_name) const override |
| Accessor for getting named finite element state adjoint solution from the physics modules. More... | |
| virtual void | advanceTimestep (double dt) override |
| Advance the state variables according to the chosen time integrator. More... | |
| void | reverseAdjointTimestep () override |
| Reverse one recorded timestep through the gretl graph. More... | |
| FiniteElementDual | computeTimestepSensitivity (size_t parameter_index) override |
| Compute the implicit sensitivity of the quantity of interest used in defining the adjoint load with respect to the parameter field (d QOI/d state * d state/d parameter). More... | |
| const FiniteElementDual & | computeTimestepShapeSensitivity () override |
| Compute the implicit sensitivity of the quantity of interest used in defining the adjoint load with respect to the shape displacement field (d QOI/d state * d state/d shape displacement). More... | |
| const std::unordered_map< std::string, const smith::FiniteElementDual & > | computeInitialConditionSensitivity () const override |
| Compute the implicit sensitivity of the quantity of interest with respect to the initial condition fields. More... | |
| std::vector< FieldState > | getInitialFieldStates () const |
| Get the initial state fields captured before any timesteps were advanced. More... | |
| std::vector< FieldState > | getFieldStates () const |
| Get the current primal state fields. More... | |
| std::vector< FieldState > | getFieldParams () const |
| Get all the parameter FieldStates. | |
| std::vector< FieldState > | getFieldStatesAndParamStates () const |
| Get the tracked state fields followed by the tracked parameter fields. More... | |
| FieldState | getShapeDispFieldState () const |
| Get the tracked shape displacement field. More... | |
| std::vector< ReactionState > | getReactionStates () const |
| Get the current differentiable reaction outputs. More... | |
| std::shared_ptr< StateAdvancer > | getStateAdvancer () const |
| Get the state advancer used for forward solves. More... | |
Public Member Functions inherited from smith::BasePhysics | |
| BasePhysics (std::string physics_name, std::shared_ptr< smith::Mesh > mesh, int cycle=0, double time=0.0, bool checkpoint_to_disk=false) | |
| Empty constructor. More... | |
| BasePhysics (BasePhysics &&other)=default | |
| Construct a new Base Physics object (copy constructor) More... | |
| virtual double | time () const |
| Get the current forward-solution time. More... | |
| virtual int | cycle () const |
| Get the current forward-solution cycle iteration number. More... | |
| virtual double | maxTime () const |
| Get the maximum time reached by the forward solver. More... | |
| virtual double | minTime () const |
| Get the initial time used by the forward solver. More... | |
| virtual int | maxCycle () const |
| The maximum cycle (timestep iteration number) reached by the forward solver. More... | |
| virtual int | minCycle () const |
| Get the initial cycle (timestep iteration number) used by the forward solver. More... | |
| bool | isQuasistatic () const |
| Check if the physics is setup as quasistatic. More... | |
| virtual const std::vector< double > & | timesteps () const |
| Get a vector of the timestep sizes (i.e. \(\Delta t\)s) taken by the forward solver. More... | |
| virtual std::vector< std::string > | adjointNames () const |
| Get a vector of the finite element state adjoint solution names. More... | |
| virtual const FiniteElementState & | dualAdjoint (const std::string &dual_name) const |
| Accessor for getting named finite element state dual adjoint (reaction adjoint load) from the physics modules. More... | |
| virtual void | outputStateToDisk (std::optional< std::string > paraview_output_dir={}) const |
Output the current state of the PDE fields in Sidre format and optionally in Paraview format if paraview_output_dir is given. More... | |
| void | loadCheckpointedStatesFromDisk (int cycle) |
| load checkpointed states from disk into states array More... | |
| virtual FiniteElementDual | loadCheckpointedDual ([[maybe_unused]] const std::string &state_name, [[maybe_unused]] int cycle) |
| Accessor for getting a single named finite element dual solution from the physics modules at a given checkpointed cycle index. More... | |
| virtual double | getCheckpointedTimestep (int cycle) const |
| Get a timestep increment which has been previously checkpointed at the give cycle. More... | |
| virtual void | initializeSummary (axom::sidre::DataStore &datastore, const double t_final, const double dt) const |
| Initializes the Sidre structure for simulation summary data. More... | |
| virtual void | saveSummary (axom::sidre::DataStore &datastore, const double t) const |
| Saves the summary data to the Sidre Datastore. More... | |
| virtual | ~BasePhysics ()=default |
| Destroy the Base Solver object. | |
| const smith::Mesh & | mesh () const |
| Returns a reference to the mesh object. | |
| const mfem::ParMesh & | mfemParMesh () const |
| Returns a reference to the mfem ParMesh object. | |
| mfem::ParMesh & | mfemParMesh () |
| Returns a reference to the mfem ParMesh object. | |
| std::string | name () const |
| Return the name of the physics. | |
Additional Inherited Members | |
Protected Member Functions inherited from smith::BasePhysics | |
| const FiniteElementDual & | shapeDisplacementSensitivity () const |
| Internally used accessor for getting the shape displacement sensitivity from the physics modules. More... | |
| void | CreateParaviewDataCollection () const |
| Create a paraview data collection for the physics package if requested. | |
| void | UpdateParaviewDataCollection (const std::string ¶view_output_dir) const |
| Update the paraview states, duals, parameters, and metadata (cycle, time) in preparation for output. More... | |
| void | initializeBasePhysicsStates (int cycle, double time) |
| Protected, non-virtual method to reset physics states to zero. This does not reset design parameters or shape. More... | |
| std::unordered_map< std::string, FiniteElementState > | getCheckpointedStates (int cycle) |
| Accessor for getting all of the primal solutions from the physics modules at a given checkpointed cycle index. More... | |
Protected Attributes inherited from smith::BasePhysics | |
| std::string | name_ = {} |
| Name of the physics module. | |
| std::shared_ptr< smith::Mesh > | mesh_ |
| The primary mesh. | |
| MPI_Comm | comm_ |
| The MPI communicator. | |
| std::vector< const smith::FiniteElementState * > | states_ |
| List of finite element primal states associated with this physics module. | |
| std::vector< const smith::FiniteElementState * > | adjoints_ |
| List of finite element adjoint states associated with this physics module. | |
| std::vector< const smith::FiniteElementDual * > | duals_ |
| List of finite element duals associated with this physics module. | |
| std::vector< const smith::FiniteElementState * > | dual_adjoints_ |
| List of adjoint finite element duals associated with this physics module. | |
| std::vector< ParameterInfo > | parameters_ |
| A vector of the parameters associated with this physics module. | |
| std::unordered_map< std::string, std::vector< smith::FiniteElementState > > | checkpoint_states_ |
| A map containing optionally in-memory checkpointed primal states for transient adjoint solvers. | |
| std::unordered_map< std::string, smith::FiniteElementState > | cached_checkpoint_states_ |
| A container relating a checkpointed cycle and the associated finite element state fields. More... | |
| std::optional< int > | cached_checkpoint_cycle_ |
| An optional int for disk-based checkpointing containing the cycle number of the last retrieved checkpoint. | |
| bool | is_quasistatic_ = true |
| Whether the simulation is time-independent. | |
| double | time_ |
| Current time for the forward pass. | |
| double | dt_ |
| Current time step. | |
| double | max_time_ |
| The maximum time reached for the forward solver. | |
| double | min_time_ |
| The time the forward solver was initialized to. | |
| std::vector< double > | timesteps_ |
| A vector of the timestep sizes (i.e. \(\Delta t\)) taken by the forward solver. | |
| int | cycle_ |
| Current cycle (forward pass time iteration count) | |
| int | max_cycle_ |
| The maximum cycle (forward pass iteration count) reached by the forward solver. | |
| int | min_cycle_ |
| The cycle the forward solver was initialized to. | |
| double | ode_time_point_ |
| The value of time at which the ODE solver wants to evaluate the residual. | |
| int | mpi_rank_ |
| MPI rank. | |
| int | mpi_size_ |
| MPI size. | |
| std::unique_ptr< mfem::ParaViewDataCollection > | paraview_dc_ |
| DataCollection pointer for optional paraview output. | |
| std::unordered_map< std::string, std::unique_ptr< mfem::ParGridFunction > > | paraview_dual_grid_functions_ |
| A optional map of the dual names and duals in grid function form for paraview output. | |
| std::unique_ptr< mfem::ParGridFunction > | shape_sensitivity_grid_function_ |
| A optional view of the shape sensitivity in grid function form for paraview output. | |
| smith::FiniteElementState | shape_displacement_ |
| The shape displacement field. | |
| smith::FiniteElementDual | shape_displacement_dual_ |
| The shape displacement field sensitivity. | |
| BoundaryConditionManager | bcs_ |
| Boundary condition manager instance. | |
| bool | checkpoint_to_disk_ |
| A flag denoting whether to save the state to disk or memory as needed for dynamic adjoint solves. | |
Static Protected Attributes inherited from smith::BasePhysics | |
| static constexpr int | FLOAT_PRECISION_ = 8 |
| Number of significant figures to output for floating-point. | |
BasePhysics implementation that stores differentiable states in gretl for checkpointed reverse solves.
Definition at line 31 of file differentiable_physics.hpp.
| smith::DifferentiablePhysics::DifferentiablePhysics | ( | std::shared_ptr< Mesh > | mesh, |
| std::shared_ptr< gretl::DataStore > | graph, | ||
| const FieldState & | shape_disp, | ||
| const std::vector< FieldState > & | states, | ||
| const std::vector< FieldState > & | params, | ||
| std::shared_ptr< StateAdvancer > | advancer, | ||
| std::string | physics_name, | ||
| const std::vector< ReactionInfo > & | reaction_infos = {} |
||
| ) |
Construct a differentiable physics wrapper around a state advancer and its tracked fields.
| mesh | The mesh shared by all tracked fields. |
| graph | The gretl data store used to record forward operations and replay them in reverse. |
| shape_disp | The shape displacement field held fixed during a forward solve. |
| states | The primal state fields advanced by advancer. |
| params | The parameter fields treated as differentiable inputs. |
| advancer | The algorithm that advances the tracked state fields by one timestep. |
| physics_name | The BasePhysics name for this module. |
| reaction_infos | Metadata for differentiable dual outputs produced during advanceTimestep. |
Definition at line 41 of file differentiable_physics.cpp.
|
overridevirtual |
Accessor for getting named finite element state adjoint solution from the physics modules.
| adjoint_name | The name of the Finite Element State adjoint solution to retrieve |
Implements smith::BasePhysics.
Definition at line 227 of file differentiable_physics.cpp.
|
overridevirtual |
Advance the state variables according to the chosen time integrator.
Advance the underlying ODE with the requested time integration scheme using the previously set timestep.
| dt | The increment of simulation time to advance the underlying physical system |
Implements smith::BasePhysics.
Definition at line 234 of file differentiable_physics.cpp.
|
overridevirtual |
Complete the setup and allocate the necessary data structures.
This finializes the underlying data structures in a solver and enables it to be run through a timestepping loop.
Implements smith::BasePhysics.
Definition at line 80 of file differentiable_physics.cpp.
|
overridevirtual |
Compute the implicit sensitivity of the quantity of interest with respect to the initial condition fields.
reverseAdjointTimestep with an appropriate adjoint load must be called prior to this method as many times as the forward advance is called. Reimplemented from smith::BasePhysics.
Definition at line 301 of file differentiable_physics.cpp.
|
overridevirtual |
Compute the implicit sensitivity of the quantity of interest used in defining the adjoint load with respect to the parameter field (d QOI/d state * d state/d parameter).
| parameter_index | the index of the parameter |
Reimplemented from smith::BasePhysics.
Definition at line 290 of file differentiable_physics.cpp.
|
overridevirtual |
Compute the implicit sensitivity of the quantity of interest used in defining the adjoint load with respect to the shape displacement field (d QOI/d state * d state/d shape displacement).
Reimplemented from smith::BasePhysics.
Definition at line 295 of file differentiable_physics.cpp.
|
overridevirtual |
Accessor for getting named finite element state dual (reaction) solution from the physics modules.
| dual_name | The name of the Finite Element State dual solution to retrieve |
Reimplemented from smith::BasePhysics.
Definition at line 120 of file differentiable_physics.cpp.
|
overridevirtual |
Get a vector of the finite element state dual (reaction) solution names.
Reimplemented from smith::BasePhysics.
Definition at line 109 of file differentiable_physics.cpp.
|
inline |
Get the current primal state fields.
Definition at line 143 of file differentiable_physics.hpp.
| std::vector< FieldState > smith::DifferentiablePhysics::getFieldStatesAndParamStates | ( | ) | const |
Get the tracked state fields followed by the tracked parameter fields.
Definition at line 311 of file differentiable_physics.cpp.
|
inline |
Get the initial state fields captured before any timesteps were advanced.
Definition at line 139 of file differentiable_physics.hpp.
|
inline |
Get the current differentiable reaction outputs.
Definition at line 158 of file differentiable_physics.hpp.
| FieldState smith::DifferentiablePhysics::getShapeDispFieldState | ( | ) | const |
Get the tracked shape displacement field.
FieldState. Definition at line 319 of file differentiable_physics.cpp.
|
inline |
Get the state advancer used for forward solves.
Definition at line 162 of file differentiable_physics.hpp.
|
override |
Accessor for getting a single named finite element dual solution from the physics modules at a given checkpointed cycle index.
| state_name | The name of the state to retrieve (e.g. "reaction") |
| cycle | The cycle to retrieve state from |
Definition at line 137 of file differentiable_physics.cpp.
|
overridevirtual |
Return a state for a stored checkpoint cycle.
| state_name | Name of the state to retrieve. |
| cycle | Cycle index to load. |
Reimplemented from smith::BasePhysics.
Definition at line 147 of file differentiable_physics.cpp.
|
overridevirtual |
Accessor for getting named finite element state parameter fields from the physics modules.
| parameter_name | The name of the Finite Element State parameter to retrieve |
Reimplemented from smith::BasePhysics.
Definition at line 166 of file differentiable_physics.cpp.
|
overridevirtual |
Accessor for getting indexed finite element state parameter fields from the physics modules.
| parameter_index | The index of the Finite Element State parameter to retrieve |
Reimplemented from smith::BasePhysics.
Definition at line 158 of file differentiable_physics.cpp.
|
overridevirtual |
Get a vector of the finite element state parameter names.
Reimplemented from smith::BasePhysics.
Definition at line 107 of file differentiable_physics.cpp.
|
overridevirtual |
Base method to reset physics states back to the end of time to start adjoint calculations again. This does not reset design parameters or shape.
Reimplemented from smith::BasePhysics.
Definition at line 98 of file differentiable_physics.cpp.
|
overridevirtual |
Base method to reset physics states to the initial time. This does not reset design parameters or shape.
| [in] | cycle | The simulation cycle (i.e. timestep iteration) to intialize the physics module to |
| [in] | time | The simulation time to initialize the physics module to |
Implements smith::BasePhysics.
Definition at line 86 of file differentiable_physics.cpp.
|
overridevirtual |
Reverse one recorded timestep through the gretl graph.
Restores the primal state values and adjoint values at the start of the just-reversed step.
Reimplemented from smith::BasePhysics.
Definition at line 256 of file differentiable_physics.cpp.
|
overridevirtual |
Set the loads for the adjoint reverse timestep solve.
| string_to_dual | An unorder map from the state field name string to the finite element adjoint/dual load The adjoint load is d(qoi)/d(state) |
Reimplemented from smith::BasePhysics.
Definition at line 198 of file differentiable_physics.cpp.
|
overridevirtual |
Set the dual loads (dirichlet values) for the adjoint reverse timestep solve This must be called after setAdjointLoad.
| string_to_bc | An unorder map from dual name string to finite element adjoint/state boundary condition The adjoint bc is d(qoi)/d(dual) |
Reimplemented from smith::BasePhysics.
Definition at line 212 of file differentiable_physics.cpp.
|
overridevirtual |
Deep copy a parameter field into the internally-owned parameter used for simulations.
| parameter_index | the index of the parameter |
| parameter_state | the values to use for the specified parameter |
The physics module constructs its own parameter FiniteElementState in the physics module constructor. This call sets the internally-owned parameter object by value (i.e. deep copies) from the given argument.
Reimplemented from smith::BasePhysics.
Definition at line 175 of file differentiable_physics.cpp.
|
overridevirtual |
Set the current shape displacement for the underlying mesh.
| shape_displacement | The shape displacement to copy for use in the physics module |
This updates the shape displacement field associated with the underlying mesh. Note that the input FiniteElementState is deep copied into the shape displacement object owned by the StateManager.
Reimplemented from smith::BasePhysics.
Definition at line 183 of file differentiable_physics.cpp.
|
overridevirtual |
Set the primal solution field values of the underlying physics solver.
Implements smith::BasePhysics.
Definition at line 188 of file differentiable_physics.cpp.
|
overridevirtual |
Accessor for getting the shape displacement field from the physics modules.
Reimplemented from smith::BasePhysics.
Definition at line 156 of file differentiable_physics.cpp.
|
overridevirtual |
Accessor for getting named finite element state primal solution from the physics modules.
| state_name | The name of the Finite Element State primal solution to retrieve |
Implements smith::BasePhysics.
Definition at line 111 of file differentiable_physics.cpp.
|
overridevirtual |
Get a vector of the finite element state primal solution names.
Implements smith::BasePhysics.
Definition at line 105 of file differentiable_physics.cpp.