14 #include "smith/differentiable_numerics/field_store.hpp"
17 #include "smith/differentiable_numerics/multiphysics_time_integrator.hpp"
39 typename... parameter_space>
41 static_assert(TemperatureTimeRule::num_states == 2,
"ThermalSystem requires a 2-state time integration rule");
101 template <
typename MaterialType>
102 void setMaterial(
const MaterialType& material,
const std::string& domain_name)
107 domain_name, [=](
auto t_info,
auto ,
auto temperature,
auto temperature_old,
auto... params) {
108 auto [T_current, T_dot] = captured_temp_rule->interpolate(t_info, temperature, temperature_old);
109 auto [heat_capacity, heat_flux] = material(get<VALUE>(T_current), get<DERIVATIVE>(T_current), params...);
110 return smith::tuple{heat_capacity * get<VALUE>(T_dot), -heat_flux};
120 template <
int... active_parameters,
typename HeatSourceType>
122 HeatSourceType source_function)
127 [=](
auto t_info,
auto X,
auto temperature,
auto temperature_old,
auto... params) {
128 auto T = captured_temp_rule->value(t_info, temperature, temperature_old);
129 return source_function(t_info.time(), X, T, params...);
138 template <
typename HeatSourceType>
139 void addHeatSource(
const std::string& domain_name, HeatSourceType source_function)
141 addHeatSourceAllParams(domain_name, source_function, std::make_index_sequence<2 +
sizeof...(parameter_space)>{});
150 template <
int... active_parameters,
typename HeatFluxType>
152 HeatFluxType flux_function)
157 depends_on, boundary_name,
158 [=](
auto t_info,
auto X,
auto n,
auto temperature,
auto temperature_old,
auto... params) {
159 auto T = captured_temp_rule->value(t_info, temperature, temperature_old);
160 return -flux_function(t_info.time(), X, n, T, params...);
169 template <
typename HeatFluxType>
170 void addHeatFlux(
const std::string& boundary_name, HeatFluxType flux_function)
172 addHeatFluxAllParams(boundary_name, flux_function, std::make_index_sequence<2 +
sizeof...(parameter_space)>{});
176 template <
typename HeatSourceType, std::size_t... Is>
177 void addHeatSourceAllParams(
const std::string& domain_name, HeatSourceType f, std::index_sequence<Is...>)
182 template <
typename HeatFluxType, std::size_t... Is>
183 void addHeatFluxAllParams(
const std::string& boundary_name, HeatFluxType f, std::index_sequence<Is...>)
185 addHeatFlux(DependsOn<
static_cast<int>(Is)...>{}, boundary_name, f);
202 template <
int dim,
int temp_order,
typename TemperatureTimeRule,
typename... parameter_space>
204 std::shared_ptr<Mesh> mesh, std::shared_ptr<CoupledSystemSolver> solver, TemperatureTimeRule temp_rule,
207 auto field_store = std::make_shared<FieldStore>(mesh, 100);
209 auto prefix = [&](
const std::string& name) {
210 if (prepend_name.empty()) {
213 return prepend_name +
"_" + name;
217 field_store->addShapeDisp(shape_disp_type);
219 auto temperature_time_rule = std::make_shared<TemperatureTimeRule>(temp_rule);
221 auto temperature_bc = field_store->addIndependent(temperature_type, temperature_time_rule);
222 auto temperature_old_type =
223 field_store->addDependent(temperature_type, FieldStore::TimeDerivative::VAL, prefix(
"temperature"));
225 std::vector<FieldState> parameter_fields;
227 (parameter_fields.push_back(field_store->getField(prefix(
"param_" + parameter_types.
name))), ...);
229 std::string thermal_flux_name = prefix(
"thermal_flux");
230 auto thermal_weak_form = std::make_shared<
231 typename ThermalSystem<dim, temp_order, TemperatureTimeRule, parameter_space...>::ThermalWeakFormType>(
232 thermal_flux_name, field_store->getMesh(), field_store->getField(temperature_type.
name).get()->space(),
233 field_store->createSpaces(thermal_flux_name, temperature_type.
name, temperature_type, temperature_old_type,
236 std::vector<std::shared_ptr<WeakForm>> weak_forms{thermal_weak_form};
237 auto advancer = std::make_shared<MultiphysicsTimeIntegrator>(field_store, weak_forms, solver);
239 return ThermalSystem<dim, temp_order, TemperatureTimeRule, parameter_space...>{
240 {field_store, solver, advancer, parameter_fields, prepend_name},
243 temperature_time_rule};
249 template <
int dim,
int temp_order,
typename... parameter_space>
encodes rules for time discretizing first order odes (involving first time derivatives)....
Defines a BasePhysics implementation backed by FieldState objects and a gretl computational graph.
Contains DirichletBoundaryConditions class for interaction with the differentiable solve interfaces.
Accelerator functionality.
ThermalSystem< dim, temp_order, TemperatureTimeRule, parameter_space... > buildThermalSystem(std::shared_ptr< Mesh > mesh, std::shared_ptr< CoupledSystemSolver > solver, TemperatureTimeRule temp_rule, std::string prepend_name="", FieldType< parameter_space >... parameter_types)
Factory function to build a thermal system.
BackwardEulerFirstOrderTimeIntegrationRule QuasiStaticFirstOrderTimeIntegrationRule
Alias for BackwardEulerFirstOrderTimeIntegrationRule for convenience. Quasi-static still should compu...
mfem::future::tuple< T... > tuple
Expose MFEM tuple in the Smith namespace.
decltype(detail::time_rule_params_impl< Space, Tail... >(std::make_index_sequence< Rule::num_states >{})) TimeRuleParams
Generate a Parameters<...> type with Rule::num_states copies of Space followed by additional Tail typ...
This file contains nonlinear block solver interfaces and helpers.
Representation of a field type with a name and an optional unknown index.
std::string name
Name of the field.
Base struct for physics systems containing common members and helper functions.
std::string prefix(const std::string &name) const
Helper function to prepend the physics name to a string.
std::shared_ptr< StateAdvancer > advancer
The state advancer.
std::shared_ptr< FieldStore > field_store
Field store managing the system's fields.
const std::vector< FieldState > & getParameterFields() const
Get the list of all parameter fields.
Container for a thermal system with configurable time integration.
std::shared_ptr< ThermalWeakFormType > thermal_weak_form
Thermal weak form.
std::shared_ptr< DirichletBoundaryConditions > temperature_bc
Temperature boundary conditions.
std::vector< FieldState > getStateFields() const
Get the list of all state fields (temperature_solve_state, temperature).
std::unique_ptr< DifferentiablePhysics > createDifferentiablePhysics(std::string physics_name)
Create a DifferentiablePhysics object for this system.
void addHeatFlux(const std::string &boundary_name, HeatFluxType flux_function)
Add a boundary heat flux that depends on all state and parameter fields.
void addHeatFlux(DependsOn< active_parameters... > depends_on, const std::string &boundary_name, HeatFluxType flux_function)
Add a boundary heat flux to the thermal system (with DependsOn).
void addHeatSource(const std::string &domain_name, HeatSourceType source_function)
Add a body heat source that depends on all state and parameter fields.
std::vector< ReactionInfo > getReactionInfos() const
Get information about reaction fields for this system.
void addHeatSource(DependsOn< active_parameters... > depends_on, const std::string &domain_name, HeatSourceType source_function)
Add a body heat source to the thermal system (with DependsOn).
std::vector< FieldState > getOutputFieldStates() const
Get the list of physical, non-solve state fields.
std::shared_ptr< TemperatureTimeRule > temperature_time_rule
Time integration for temperature.
void setMaterial(const MaterialType &material, const std::string &domain_name)
Set the thermal material model for a domain.
Defines the SystemBase struct for common system functionality.
Provides templated implementations for discretizing values, velocities and accelerations from current...