31 #include "smith/differentiable_numerics/field_store.hpp"
35 #include "smith/differentiable_numerics/multiphysics_time_integrator.hpp"
57 template <
int dim,
typename StateSpace,
typename InternalVarTimeRule = BackwardEulerFirstOrderTimeIntegrationRule,
58 typename Coupling = std::tuple<>>
62 static_assert(InternalVarTimeRule::num_states == 2,
63 "InternalVariableSystem requires a 2-state time integration rule");
84 template <
typename EvolutionType>
85 void addEvolution(
const std::string& domain_name, EvolutionType evolution_law)
91 *captured_time_rule, *captured_coupling, t_info,
92 [&](
auto alpha_current,
auto alpha_dot,
auto... interpolated_params) {
94 evolution_law(t_info, get<VALUE>(alpha_current), get<VALUE>(alpha_dot), interpolated_params...);
115 template <
int dim,
typename StateSpace,
typename InternalVarTimeRule,
typename... parameter_space>
119 auto internal_variable_time_rule = std::make_shared<InternalVarTimeRule>();
121 field_store->addIndependent(state_type, internal_variable_time_rule);
122 field_store->addDependent(state_type, FieldStore::TimeDerivative::VAL,
"state");
124 if constexpr (
sizeof...(parameter_space) > 0) {
125 auto prefix_param = [&](
auto& pt) {
126 pt.name =
"param_" + pt.name;
127 field_store->addParameter(pt);
129 (prefix_param(parameter_types), ...);
137 template <
int dim,
typename StateSpace,
typename InternalVarTimeRule,
typename... parameter_space>
141 return registerInternalVariableFields<dim, StateSpace, InternalVarTimeRule>(field_store, parameter_types...);
156 template <
int dim,
typename StateSpace,
typename InternalVarTimeRule,
typename Coupling>
157 requires detail::is_coupling_packs_v<Coupling>
159 std::shared_ptr<SystemSolver> solver)
161 auto internal_variable_time_rule = std::make_shared<InternalVarTimeRule>();
166 auto internal_variable_bc = field_store->getBoundaryConditions(state_type.
name);
170 std::string internal_variable_residual_name = field_store->prefix(
"state_residual");
171 auto internal_variable_weak_form =
172 detail::buildWeakFormWithCoupling<typename SystemType::InternalVariableWeakFormType>(
173 field_store, internal_variable_residual_name, state_type.
name, state_type, state_old_type,
176 auto sys = std::make_shared<SystemType>(field_store, solver,
177 std::vector<std::shared_ptr<WeakForm>>{internal_variable_weak_form});
178 sys->internal_variable_bc = internal_variable_bc;
179 sys->internal_variable_time_rule = internal_variable_time_rule;
180 sys->coupling = std::make_shared<Coupling>(coupling);
181 sys->internal_variable_weak_form = internal_variable_weak_form;
193 template <
typename SelfFields>
194 requires(detail::has_time_rule_v<SelfFields>)
195 auto buildInternalVariableSystem(std::shared_ptr<SystemSolver> solver,
const SelfFields& self_fields)
197 constexpr
int dim = SelfFields::dim;
198 using StateSpace =
typename std::tuple_element_t<0, decltype(self_fields.fields)>::space_type;
199 using InternalVarTimeRule =
typename std::decay_t<SelfFields>::time_rule_type;
200 auto field_store = self_fields.field_store;
202 return detail::buildInternalVariableSystemImpl<dim, StateSpace, InternalVarTimeRule>(field_store, coupling, solver);
208 template <
typename SelfFields,
typename... PFs>
209 requires(detail::has_time_rule_v<SelfFields>)
210 auto buildInternalVariableSystem(std::shared_ptr<SystemSolver> solver,
const SelfFields& self_fields,
211 const CouplingFields<PFs...>& coupled)
213 constexpr
int dim = SelfFields::dim;
214 using StateSpace =
typename std::tuple_element_t<0, decltype(self_fields.fields)>::space_type;
215 using InternalVarTimeRule =
typename std::decay_t<SelfFields>::time_rule_type;
216 auto field_store = self_fields.field_store;
218 return detail::buildInternalVariableSystemImpl<dim, StateSpace, InternalVarTimeRule>(field_store, coupling, solver);
224 template <
typename SelfFields,
typename... ParamSpaces>
225 requires(detail::has_time_rule_v<SelfFields>)
226 auto buildInternalVariableSystem(std::shared_ptr<SystemSolver> solver,
const SelfFields& self_fields,
227 const ParamFields<ParamSpaces...>& params)
229 constexpr
int dim = SelfFields::dim;
230 using StateSpace =
typename std::tuple_element_t<0, decltype(self_fields.fields)>::space_type;
231 using InternalVarTimeRule =
typename std::decay_t<SelfFields>::time_rule_type;
232 auto field_store = self_fields.field_store;
234 return detail::buildInternalVariableSystemImpl<dim, StateSpace, InternalVarTimeRule>(field_store, coupling, solver);
240 template <
typename SelfFields,
typename... PFs,
typename... ParamSpaces>
241 requires(detail::has_time_rule_v<SelfFields>)
242 auto buildInternalVariableSystem(std::shared_ptr<SystemSolver> solver,
const SelfFields& self_fields,
243 const CouplingFields<PFs...>& coupled,
const ParamFields<ParamSpaces...>& params)
245 constexpr
int dim = SelfFields::dim;
246 using StateSpace =
typename std::tuple_element_t<0, decltype(self_fields.fields)>::space_type;
247 using InternalVarTimeRule =
typename std::decay_t<SelfFields>::time_rule_type;
248 auto field_store = self_fields.field_store;
250 return detail::buildInternalVariableSystemImpl<dim, StateSpace, InternalVarTimeRule>(field_store, coupling, solver);
Coupling pack types and helpers for injecting explicit coupled-physics fields into weak form paramete...
Defines a BasePhysics implementation backed by FieldState objects and a gretl computational graph.
Contains DirichletBoundaryConditions class for interaction with the differentiable solve interfaces.
decltype(auto) applyTimeRuleAndCoupling(const Rule &rule, const Coupling &coupling, const TimeInfoT &t_info, Callback &&callback, const RawArgs &... raw_args)
Interpolate self time-rule states then coupling segments, then invoke callback.
auto collectCouplingFields()
Collect no coupling or parameter packs.
auto flattenCouplingFields(const PacksTuple &packs)
Concatenate each pack's .fields tuple — used to derive trailing weak-form parameter spaces.
requires detail::is_coupling_packs_v< Coupling > auto buildInternalVariableSystemImpl(std::shared_ptr< FieldStore > field_store, const Coupling &coupling, std::shared_ptr< SystemSolver > solver)
Internal builder for an internal-variable system after public registration and coupling collection.
Accelerator functionality.
auto registerStateVariableFields(std::shared_ptr< FieldStore > field_store, FieldType< parameter_space >... parameter_types)
Backward-compatible alias for registerInternalVariableFields.
requires(detail::has_time_rule_v< SelfFields >) auto buildSolidMechanicsSystem(std
Build a SolidMechanicsSystem from already-registered field packs.
mfem::future::tuple< T... > tuple
Expose MFEM tuple in the Smith namespace.
auto registerInternalVariableFields(std::shared_ptr< FieldStore > field_store, FieldType< parameter_space >... parameter_types)
Register state variable fields into a FieldStore.
This file contains nonlinear block solver interfaces and helpers.
Interface and implementations for advancing from one step to the next. Typically these are time integ...
Representation of a field type with a name and a flag indicating whether it is an active Jacobian unk...
std::string name
Name of the field.
System for a single internal variable using a two-state first-order rule.
void addEvolution(const std::string &domain_name, EvolutionType evolution_law)
Register an ODE evolution law for the internal variable.
std::shared_ptr< InternalVarTimeRule > internal_variable_time_rule
Time integration rule.
std::shared_ptr< DirichletBoundaryConditions > internal_variable_bc
Internal variable BCs.
std::shared_ptr< InternalVariableWeakFormType > internal_variable_weak_form
Internal variable weak form.
std::shared_ptr< const Coupling > coupling
Coupling metadata.
Fields returned by a physics register function, carrying time rule type information.
Base struct for physics systems containing common members and helper functions.
SystemBase()=default
Construct an empty system shell.
Defines the SystemBase struct for common system functionality.
Provides templated implementations for discretizing values, velocities and accelerations from current...