23 template <
int spatial_dim,
typename parameters = Parameters<>,
24 typename parameter_indices = std::make_
integer_sequence<
int, parameters::n>>
30 template <
int spatial_dim,
typename... InputSpaces,
int... parameter_indices>
34 using SpacesT = std::vector<const mfem::ParFiniteElementSpace*>;
46 std::array<
const mfem::ParFiniteElementSpace*,
sizeof...(InputSpaces)> mfem_spaces;
49 sizeof...(InputSpaces) != input_mfem_spaces.size(),
50 std::format(
"{} parameter spaces given in the template argument but {} parameter names were supplied.",
51 sizeof...(InputSpaces), input_mfem_spaces.size()));
53 if constexpr (
sizeof...(InputSpaces) > 0) {
54 for_constexpr<
sizeof...(InputSpaces)>([&](
auto i) { mfem_spaces[i] = input_mfem_spaces[i]; });
57 const auto& shape_disp_space = mesh_->shapeDisplacementSpace();
60 std::make_unique<ShapeAwareFunctional<
ShapeDispSpace, double(InputSpaces...)>>(&shape_disp_space, mfem_spaces);
70 template <
int... active_parameters,
typename FuncOfTimeSpaceAndParams>
72 const FuncOfTimeSpaceAndParams& qfunction)
75 mesh_->domain(body_name));
80 const std::vector<ConstFieldPtr>& fields)
const override
83 cycle_ = time_info.
cycle();
85 return evaluateObjective(std::make_integer_sequence<
int,
sizeof...(parameter_indices)>{}, time_info.
time(),
91 size_t field_ordinal)
const override
94 cycle_ = time_info.
cycle();
96 auto grads = gradientEvaluators(std::make_integer_sequence<
int,
sizeof...(parameter_indices)>{}, time_info.
time(),
98 auto g = smith::get<DERIVATIVE>(grads[field_ordinal](time_info.
time(), shape_disp, fields));
104 const std::vector<ConstFieldPtr>& fields)
const override
106 dt_ = time_info.
dt();
107 cycle_ = time_info.
cycle();
109 auto g = smith::get<DERIVATIVE>(
118 const std::vector<ConstFieldPtr>& fs)
const
120 return (*objective_)(time, *shape_disp, *fs[i]...);
125 auto gradientEvaluators(std::integer_sequence<int, i...>,
double time,
ConstFieldPtr shape_disp,
126 const std::vector<ConstFieldPtr>& fs)
const
128 using JacFuncType = std::function<decltype((*objective_)(DifferentiateWRT<1>{}, time, *shape_disp, *fs[i]...))(
130 return std::array<JacFuncType,
sizeof...(i)>{
131 [
this](
double _time,
ConstFieldPtr _shape_disp,
const std::vector<ConstFieldPtr>& _fs) {
132 return (*objective_)(DifferentiateWRT<i + 1>{}, _time, *_shape_disp, *_fs[i]...);
140 mutable size_t cycle_ = 0;
143 std::shared_ptr<Mesh> mesh_;
146 std::unique_ptr<ShapeAwareFunctional<ShapeDispSpace, double(InputSpaces...)>> objective_;
This contains a class that represents the dual of a finite element vector space, i....
This file contains the declaration of structure that manages the MFEM objects that make up the state ...
Smith mesh class which assists in constructing the appropriate parallel mfem meshes and registering a...
Accelerator functionality.
DoubleState evaluateObjective(const ScalarObjective &objective, const FieldState &shape_disp, const std::vector< FieldState > &inputs, const TimeInfo &time_info)
Evaluates a DoubleState using a provided ScalarObjective reference, and the input arguments to that o...
SMITH_HOST_DEVICE auto max(dual< gradient_type > a, double b)
Implementation of max for dual numbers.
FiniteElementState const * ConstFieldPtr
using
Specifies interface for evaluating scalar objective from fields and their field gradients.
Wrapper of smith::Functional for evaluating integrals and derivatives of quantities with shape displa...
Compile-time alias for a dimension.
a struct that is used in the physics modules to clarify which template arguments are user-controlled ...
struct storing time and timestep information
double dt() const
accessor for dt
size_t cycle() const
accessor for cycle
double time() const
accessor for the current time