15 #include "gretl/data_store.hpp"
19 #include "smith/differentiable_numerics/multiphysics_time_integrator.hpp"
28 class TimestepEstimator;
47 const FieldState& shape_disp,
const std::vector<FieldState>& states,
48 const std::vector<FieldState>& params, std::shared_ptr<StateAdvancer> advancer,
49 std::string physics_name,
const std::vector<ReactionInfo>& reaction_infos = {});
63 std::vector<std::string>
stateNames()
const override;
69 std::vector<std::string>
dualNames()
const override;
110 void setAdjointLoad(std::unordered_map<std::string, const smith::FiniteElementDual&> string_to_dual)
override;
113 void setDualAdjointBcs(std::unordered_map<std::string, const smith::FiniteElementState&> string_to_bc)
override;
175 void initializeReactionStates();
177 std::shared_ptr<gretl::DataStore> checkpointer_;
178 std::shared_ptr<StateAdvancer> advancer_;
180 std::vector<FieldState> initial_field_states_;
182 std::vector<FieldState> field_states_;
183 std::vector<FieldState> field_params_;
184 std::unique_ptr<FieldState>
185 field_shape_displacement_;
187 std::map<std::string, size_t> state_name_to_field_index_;
188 std::map<std::string, size_t> param_name_to_field_index_;
189 std::vector<std::string> state_names_;
190 std::vector<std::string> param_names_;
192 std::vector<ReactionInfo> reaction_infos_;
193 mutable std::vector<ReactionState> reaction_states_;
194 std::map<std::string, size_t> reaction_name_to_reaction_index_;
195 std::vector<std::string> reaction_names_;
197 std::vector<gretl::Int> milestones_;
210 template <
typename SystemType>
219 std::shared_ptr<StateAdvancer> advancer,
220 const std::string& physics_name)
222 return std::make_unique<DifferentiablePhysics>(
223 system->field_store->getMesh(), system->field_store->graph(), system->field_store->getShapeDisp(),
224 system->field_store->getStateFields(), system->field_store->getParameterFields(), std::move(advancer),
225 physics_name, system->field_store->getReactionInfos());
228 template <
typename SystemType>
238 const std::string& physics_name)
The base interface class for a generic PDE solver.
This is the abstract base class for a generic forward solver.
virtual double time() const
Get the current forward-solution time.
const smith::Mesh & mesh() const
Returns a reference to the mesh object.
virtual int cycle() const
Get the current forward-solution cycle iteration number.
BasePhysics implementation that stores differentiable states in gretl for checkpointed reverse solves...
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 sha...
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 ...
FieldState getFieldParam(const std::string ¶m_name) const
Get a tracked parameter field by name.
void reverseAdjointTimestep() override
Reverse one recorded timestep through the gretl graph.
void completeSetup() override
Complete the setup and allocate the necessary data structures.
std::vector< FieldState > getFieldStates() const
Get the current primal state fields.
std::vector< std::string > parameterNames() const override
Get a vector of the finite element state parameter names.
std::vector< FieldState > getInitialFieldStates() const
Get the initial state fields captured before any timesteps were advanced.
FieldState getFieldState(const std::string &state_name) const
Get a tracked current state field by name.
void setShapeDisplacement(const FiniteElementState &shape_displacement) override
Set the current shape displacement for the underlying mesh.
std::vector< FieldState > getFieldParams() const
Get all the parameter FieldStates.
FieldState getShapeDispFieldState() const
Get the tracked shape displacement field.
const FiniteElementState & adjoint(const std::string &adjoint_name) const override
Accessor for getting named finite element state adjoint solution from the physics modules.
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 afte...
std::vector< std::string > dualNames() const override
Get a vector of the finite element state dual (reaction) solution names.
FiniteElementDual computeTimestepSensitivity(size_t parameter_index) override
Compute the implicit sensitivity of the quantity of interest used in defining the adjoint load with r...
virtual void resetAdjointStates() override
Base method to reset physics states back to the end of time to start adjoint calculations again....
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.
void setAdjointLoad(std::unordered_map< std::string, const smith::FiniteElementDual & > string_to_dual) override
Set the loads for the adjoint reverse timestep solve.
const FiniteElementDual & computeTimestepShapeSensitivity() override
Compute the implicit sensitivity of the quantity of interest used in defining the adjoint load with r...
const FiniteElementState & parameter(std::size_t parameter_index) const override
Accessor for getting indexed finite element state parameter fields from the physics modules.
void setState(const std::string &state_name, const FiniteElementState &s) override
Set the primal solution field values of the underlying physics solver.
FieldState getInitialFieldState(const std::string &state_name) const
Get a tracked initial state field by name.
const FiniteElementState & shapeDisplacement() const override
Accessor for getting the shape displacement field from the physics modules.
~DifferentiablePhysics()
Destructor.
FiniteElementState loadCheckpointedState(const std::string &state_name, int cycle) override
Return a state for a stored checkpoint cycle.
std::vector< FieldState > getFieldStatesAndParamStates() const
Get the tracked state fields followed by the tracked parameter fields.
virtual void advanceTimestep(double dt) override
Advance the state variables according to the chosen time integrator.
const FiniteElementState & state(const std::string &state_name) const override
Accessor for getting named finite element state primal solution from the physics modules.
std::shared_ptr< StateAdvancer > getStateAdvancer() const
Get the state advancer used for forward solves.
std::vector< ReactionState > getReactionStates() const
Get the current differentiable reaction outputs.
std::vector< std::string > stateNames() const override
Get a vector of the finite element state primal solution names.
const FiniteElementDual & dual(const std::string &dual_name) const override
Accessor for getting named finite element state dual (reaction) solution from the physics modules.
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 fi...
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.
Class for encapsulating the dual vector space of a finite element space (i.e. the space of linear for...
Class for encapsulating the critical MFEM components of a primal finite element field.
Accelerator functionality.
gretl::State< FEFieldPtr, FEDualPtr > FieldState
typedef
std::unique_ptr< DifferentiablePhysics > makeDifferentiablePhysics(std::shared_ptr< SystemType > system, std::shared_ptr< StateAdvancer > advancer, const std::string &physics_name)
Build a DifferentiablePhysics from a preconfigured system and advancer.
std::shared_ptr< MultiphysicsTimeIntegrator > makeAdvancer(std::shared_ptr< SystemBase > system)
Build a MultiphysicsTimeIntegrator using the system's own auxiliary systems.
Defines the SystemBase struct for common system functionality.