28 std::vector<gretl::StateBase> inputs{shape_u, rho, lumped_field};
32 z.set_eval([=](
const gretl::UpstreamStates& upstreams, gretl::DownstreamState& downstream) {
37 FEFieldPtr Z = std::make_shared<FiniteElementState>(
38 LumpedOutputFieldForSizing->space(),
41 auto m_diagonal = mass_residual_eval->
residual(
49 z.set_vjp([=](gretl::UpstreamStates& upstreams,
const gretl::DownstreamState& downstream) {
57 Z_dual_state = *Z_dual;
69 auto z = x.clone({x});
70 z.set_eval([](
const gretl::UpstreamStates& upstreams, gretl::DownstreamState& downstream) {
72 FEFieldPtr Z = std::make_shared<FiniteElementState>(X->space(),
"diag_inverse");
76 for (
int index = 0; index < sz; index++) {
77 Z_[index] = 1 / X_[index];
83 z.set_vjp([](gretl::UpstreamStates& upstreams,
const gretl::DownstreamState& downstream) {
88 for (
int index = 0; index < sz; index++) {
89 X_dual[index] -= Z_dual[index] / (
std::pow(X_[index], 2));
100 const std::vector<FieldState>& states,
const std::vector<FieldState>& params,
101 TimeInfo time_info,
size_t inertial_index)
103 std::vector<gretl::StateBase> allStateBases;
104 for (
auto& s : states) allStateBases.push_back(s);
105 for (
auto& p : params) allStateBases.push_back(p);
106 allStateBases.push_back(shape_disp);
107 auto z = states[inertial_index].clone(allStateBases);
109 z.set_eval([=](
const gretl::UpstreamStates& inputs, gretl::DownstreamState& output) {
112 size_t num_fields = inputs.size() - 1;
113 std::vector<ConstFieldPtr> fields(num_fields);
117 for (
size_t field_index = 0; field_index < num_fields; ++field_index) {
118 fields[field_index] = inputs[field_index].get<
FEFieldPtr>().
get();
122 std::make_shared<FiniteElementState>(fields[inertial_index]->
space(),
"residual");
127 fields[inertial_index] = &zero_accel;
130 *R = residual_eval->
residual(time_info, inputs[num_fields].get<FEFieldPtr>().
get(), fields);
135 z.set_vjp([=](gretl::UpstreamStates& inputs,
const gretl::DownstreamState& output) {
141 Z_dual_state = *Z_dual;
144 size_t num_fields = inputs.size() - 1;
145 std::vector<ConstFieldPtr> fields(num_fields);
146 for (
size_t field_index = 0; field_index < num_fields; ++field_index) {
147 fields[field_index] = inputs[field_index].get<
FEFieldPtr>().
get();
153 fields[inertial_index] = &zero_accel;
155 std::vector<DualFieldPtr> field_sensitivities(num_fields);
156 for (
size_t field_index = 0; field_index < num_fields; ++field_index) {
160 field_sensitivities[inertial_index] =
nullptr;
162 auto shape_disp_ptr = inputs[num_fields].get<
FEFieldPtr>();
166 residual_eval->
vjp(time_info, shape_disp_ptr.get(), fields, {}, &Z_dual_state, shape_disp_sensitivity_ptr.get(),
167 field_sensitivities, {});
178 SLIC_ERROR_IF(x.get()->Size() != y.get()->Size(),
"Trying to component wise multiple vectors with different sizes");
179 auto z = x.clone({x, y});
181 z.set_eval([=](
const gretl::UpstreamStates& upstreams, gretl::DownstreamState& downstream) {
183 FEFieldPtr Z = std::make_shared<FiniteElementState>(X->space(),
"ComponentMult");
189 for (
int index = 0; index < sz; index++) {
190 Z_[index] = X_[index] * Y_[index];
203 z.set_vjp([=](gretl::UpstreamStates& upstreams,
const gretl::DownstreamState& downstream) {
216 for (
int index = 0; index < sz; index++) {
217 X_dual[index] += Z_dual[index] * Y[index];
218 Y_dual[index] += Z_dual[index] * X[index];
232 SLIC_ERROR_IF(x.get()->Size() != y.get()->Size(),
"Trying to component wise multiple vectors with different sizes");
233 auto z = x.clone({x, y});
235 z.set_eval([=](
const gretl::UpstreamStates& upstreams, gretl::DownstreamState& downstream) {
237 FEFieldPtr Z = std::make_shared<FiniteElementState>(X->space(),
"ComponentMult");
243 for (
int index = 0; index < sz; index++) {
244 Z_[index] = -X_[index] * Y_[index];
257 z.set_vjp([=](gretl::UpstreamStates& upstreams,
const gretl::DownstreamState& downstream) {
270 for (
int index = 0; index < sz; index++) {
271 X_dual[index] -= Z_dual[index] * Y[index];
272 Y_dual[index] -= Z_dual[index] * X[index];
This file contains the declaration of the boundary condition manager class.
A container for the boundary condition information relating to a specific physics module.
const mfem::Array< int > & allEssentialTrueDofs() const
Returns all the true degrees of freedom associated with all the essential BCs.
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.
FieldState diagInverse(const FieldState &x)
gretl-function implementation to compute invert the values for every entry in a FieldState.
FieldState evalResidual(const WeakForm *residual_eval, FieldState shape_disp, const std::vector< FieldState > &states, const std::vector< FieldState > ¶ms, TimeInfo time_info, size_t inertial_index)
gretl-function implementation which evaluates the residual force (which is minus the mechanical force...
constexpr T & get(variant< T0, T1 > &v)
Returns the variant member of specified type.
std::shared_ptr< FiniteElementState > FEFieldPtr
typedef
std::vector< FiniteElementState * > getFieldPointers(std::vector< FieldState > &states, std::vector< FieldState > params={})
Get a vector of FieldPtr or DualFieldPtr from a vector of FieldState.
gretl::State< FEFieldPtr, FEDualPtr > FieldState
typedef
FieldState componentWiseMult(const FieldState &x, const FieldState &y, const BoundaryConditionManager *bc_manager)
gretl-function implementation which multiplies x and y component-wise to create a new FieldState....
FieldState computeLumpedMass(const WeakForm *mass_residual_eval, const FieldState &shape_u, const FieldState &lumped_field, const FieldState &rho)
gretl-function implementation to compute lumped mass vectors from shape_displacements FieldState and ...
std::shared_ptr< FiniteElementDual > FEDualPtr
typedef
SMITH_HOST_DEVICE auto pow(dual< gradient_type > a, dual< gradient_type > b)
implementation of a (dual) raised to the b (dual) power
std::vector< const FiniteElementState * > getConstFieldPointers(const std::vector< FieldState > &states, const std::vector< FieldState > ¶ms={})
Get a vector of ConstFieldPtr or ConstDualFieldPtr from a vector of FieldState.
FieldState negativeComponentWiseMult(const FieldState &x, const FieldState &y, const BoundaryConditionManager *bc_manager)
gretl-function implementation which multiplies and then negates x and y component-wise to create a ne...
mfem::ParFiniteElementSpace & space(FieldState field)
Get the space from the primal field of a field states.
#define SMITH_MARK_FUNCTION
struct storing time and timestep information