13 #include "gretl/data_store.hpp"
14 #include "gretl/state.hpp"
15 #include "gretl/create_state.hpp"
21 using FEDualPtr = std::shared_ptr<FiniteElementDual>;
24 using FieldVecState = gretl::State<std::vector<FEFieldPtr>, std::vector<FEDualPtr>>;
33 return std::make_shared<smith::FiniteElementDual>(f->space(), f->name() +
"_dual");
43 return std::make_shared<smith::FiniteElementState>(f->space(), f->name() +
"_undual");
54 template <
typename function_space>
56 const std::string& mesh_tag)
69 template <
typename function_space>
71 const std::string& mesh_tag)
95 return axpby(weight, a, 1.0 - weight, b);
112 double initial_scaling)
198 inline mfem::ParFiniteElementSpace&
space(
FieldState field) {
return field.get()->space(); }
201 inline std::vector<const mfem::ParFiniteElementSpace*>
spaces(
const std::vector<FieldState>& states,
202 const std::vector<FieldState>& params = {})
204 std::vector<const mfem::ParFiniteElementSpace*>
spaces;
205 for (
auto s : states) {
206 spaces.push_back(&s.get()->space());
208 for (
auto s : params) {
209 spaces.push_back(&s.get()->space());
216 std::vector<FieldState> params = {})
218 std::vector<FiniteElementState*> pointers;
219 for (
auto& t : states) {
220 pointers.push_back(t.get().get());
222 for (
auto& p : params) {
223 pointers.push_back(p.get().get());
230 const std::vector<FieldState>& params = {})
232 std::vector<const FiniteElementState*> pointers;
233 for (
auto& t : states) {
234 pointers.push_back(t.get().get());
236 for (
auto& p : params) {
237 pointers.push_back(p.get().get());
static FiniteElementDual newDual(FunctionSpace space, const std::string &dual_name, const std::string &mesh_tag)
Factory method for creating a new FEDual object.
static FiniteElementState newState(FunctionSpace space, const std::string &state_name, const std::string &mesh_tag)
Factory method for creating a new FEState object.
Accelerator functionality.
gretl::State< FEDualPtr, FEFieldPtr > ReactionState
typedef
std::vector< const mfem::ParFiniteElementSpace * > spaces(const std::vector< FieldState > &states, const std::vector< FieldState > ¶ms={})
Get the spaces from the primal fields of a vector of field states.
gretl::State< double, double > DoubleState
typedef
std::shared_ptr< FiniteElementState > FEFieldPtr
typedef
gretl::State< std::vector< FEFieldPtr >, std::vector< FEDualPtr > > FieldVecState
typedef
FieldStateWeightedSum operator+(const FieldState &x, const FieldState &y)
add two FieldState
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 createFieldState(gretl::DataStore &dataStore, const smith::FEFieldPtr &s)
initialize on the gretl::DataStore a FieldState with values from s
constexpr SMITH_HOST_DEVICE int size(const tensor< T, n... > &)
returns the total number of stored values in a tensor
ReactionState createReactionState(gretl::DataStore &dataStore, const smith::FEDualPtr &s)
initialize on the gretl::DataStore a ReactionState with values from s
FieldState axpby(double a, const FieldState &x, double b, const FieldState &y)
gretl-function to compute a*x + b*y
std::shared_ptr< FiniteElementDual > FEDualPtr
typedef
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 square(const FieldState &state)
gretl-function to square (x^2) every component of the Field
gretl::State< double > innerProduct(const FieldState &a, const FieldState &b)
gretl-function to compute the inner product (vector l2-norm) of a and b
FieldStateWeightedSum operator*(double a, const FieldState &b)
multiply scalar by a FieldState to get a temporary FieldStateWeightedSum which can cast back to a Fie...
FieldState zeroCopy(const FieldState &x)
gretl-function to make a deep-copy of a FieldState and initialize it to 0.
mfem::ParFiniteElementSpace & space(FieldState field)
Get the space from the primal field of a field states.
FieldStateWeightedSum operator-(const FieldState &x, const FieldState &y)
subtract two FieldState
FieldState weighted_average(const FieldState &a, const FieldState &b, double weight)
gretl-function to compute the weighted average a * weight + b * (1-weight)
This file contains the declaration of the StateManager class.
temporary object to register the multiplication of a gretl::State<double> with a FieldState....
FieldStateWeightedSum operator-() const
negate
FieldStateWeightedSum & operator*=(double weight)
mulitply by a fixed scalar
FieldStateWeightedSum(const std::vector< double > &w, const std::vector< FieldState > &f)
construct from double weights, and fields
std::vector< double > weights_
non-differentiable weights
FieldStateWeightedSum & operator+=(const FieldStateWeightedSum &b)
add another weighted sum in place
FieldStateWeightedSum & operator=(const FieldStateWeightedSum &old)=default
default assignment
std::vector< FieldState > weighted_fields_
fields to weight by non-differentiable weights
FieldStateWeightedSum(const FieldStateWeightedSum &old)=default
default copy
FieldStateWeightedSum(const std::vector< gretl::State< double >> &w, const std::vector< FieldState > &f, double initial_scaling)
construct from State<double> weights, and fields
std::vector< double > differentiable_scale_factors_
flag differentiable weights to be negated
std::vector< FieldState > differentiably_weighted_fields_
fields to weight by differentiable weights
FieldStateWeightedSum & operator-=(const FieldStateWeightedSum &b)
subtract another weighted sum in place
std::vector< gretl::State< double > > differentiable_weights_
differentiable weights
functor which takes a std::shared_ptr<FiniteElementState>, and returns a zero-valued std::shared_ptr<...
auto operator()(const smith::FEFieldPtr &f) const
functor operator
functor which takes a std::shared_ptr<FiniteElementDual>, and returns a zero-valued std::shared_ptr<F...
auto operator()(const smith::FEDualPtr &f) const
functor operator