Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
Classes | Public Types | Public Member Functions | List of all members
smith::FieldStore Struct Reference

Manages storage and metadata for fields, parameters, and weak forms. More...

#include <field_store.hpp>

Classes

struct  TimeIntegrationMapping
 Mapping between primary and history/derivative fields for time integration. More...
 

Public Types

enum class  TimeDerivative { VAL , DOT , DDOT , DDDOT }
 Enum for different types of time derivatives. More...
 

Public Member Functions

 FieldStore (std::shared_ptr< Mesh > mesh, size_t storage_size=50, std::string prepend_name="")
 Construct a new FieldStore object. More...
 
std::string prefix (const std::string &base) const
 Apply this store's namespace prefix to a base name. More...
 
template<typename Space >
void addShapeDisp (FieldType< Space > &type)
 Add a shape displacement field to the store. More...
 
template<typename Space >
void addParameter (FieldType< Space > &type)
 Add a parameter field to the store. More...
 
template<typename Space >
std::shared_ptr< DirichletBoundaryConditionsaddIndependent (FieldType< Space > &type, std::shared_ptr< TimeIntegrationRule > time_rule)
 Add an independent field (a solver unknown) to the store. More...
 
template<typename Space >
auto addDependent (FieldType< Space > independent_field, TimeDerivative derivative, std::string name_override="")
 Add a dependent field (history value, velocity, or acceleration) to the store. More...
 
void addWeakFormUnknownArg (std::string weak_form_name, std::string argument_name, size_t argument_index)
 Register an argument to a weak form as an unknown. More...
 
void addWeakFormArg (std::string weak_form_name, std::string argument_name, size_t argument_index)
 Register an argument to a weak form. More...
 
void addWeakFormReaction (std::string weak_form_name, std::string field_name)
 Register the reaction (test) field for a weak form. More...
 
void markWeakFormInternal (const std::string &weak_form_name)
 Mark a weak form as internal so it is excluded from getReactionInfos(). More...
 
std::string getWeakFormReaction (const std::string &weak_form_name) const
 Get the name of the reaction (test) field for a weak form. More...
 
template<typename... FieldTypes>
std::vector< const mfem::ParFiniteElementSpace * > createSpaces (const std::string &weak_form_name, const std::string &reaction_field_name, FieldTypes... types)
 Register all input fields for a weak form and return their FE spaces. More...
 
const std::vector< std::pair< std::shared_ptr< TimeIntegrationRule >, TimeIntegrationMapping > > & getTimeIntegrationRules () const
 Get all registered time integration rules and their mappings. More...
 
void printMap ()
 Print the internal field maps for debugging.
 
std::vector< std::vector< size_t > > indexMap (const std::vector< std::string > &residual_names) const
 Generate an index map for the residuals. More...
 
std::vector< const BoundaryConditionManager * > getBoundaryConditionManagers (const std::vector< std::string > &weak_form_names) const
 Get the boundary condition managers for the given weak forms, one per residual row. More...
 
std::vector< const BoundaryConditionManager * > getBoundaryConditionManagersForFields (const std::vector< std::string > &field_names) const
 Get ordered boundary condition managers corresponding to an ordered list of fields.
 
bool hasField (const std::string &field_name) const
 Check whether a field exists. More...
 
size_t getFieldIndex (const std::string &field_name) const
 Get the internal index of a field by name. More...
 
FieldState getField (const std::string &field_name) const
 Get a FieldState by name. More...
 
FieldState getParameter (const std::string &param_name) const
 Get a parameter field by name. More...
 
void setField (const std::string &field_name, FieldState updated_field)
 Update a field in the store by name. More...
 
void setField (size_t index, FieldState updated_field)
 Update a field in the store by index. More...
 
FieldState getShapeDisp () const
 Get the shape displacement field. More...
 
const std::vector< FieldState > & getAllFields () const
 Get all fields stored in the FieldStore. More...
 
std::vector< FieldStategetStates (const std::string &weak_form_name) const
 Get the state fields associated with a weak form. More...
 
std::vector< FieldStategetStatesFromVectors (const std::string &weak_form_name, const std::vector< FieldState > &state_fields, const std::vector< FieldState > &param_fields) const
 Extract state fields for a weak form from provided state and parameter vectors. More...
 
const std::vector< FieldState > & getParameterFields () const
 Get the list of all parameter fields.
 
const std::vector< FieldState > & getStateFields () const
 Get the list of all state fields.
 
std::vector< FieldStategetOutputFieldStates () const
 Get the list of physical, non-solve state fields suitable for output.
 
std::vector< ReactionInfogetReactionInfos () const
 Get information about reaction fields.
 
const std::shared_ptr< smith::Mesh > & getMesh () const
 Get associated mesh shared by all registered fields.
 
std::shared_ptr< DirichletBoundaryConditionsgetBoundaryConditions (const std::string &field_name) const
 Get the boundary conditions for a given field name.
 
const std::shared_ptr< gretl::DataStore > & graph () const
 Get the associated data store graph. More...
 

Detailed Description

Manages storage and metadata for fields, parameters, and weak forms.

Definition at line 63 of file field_store.hpp.

Member Enumeration Documentation

◆ TimeDerivative

Enum for different types of time derivatives.

Enumerator
DOT 

The first time derivative.

DDOT 

The second time derivative.

DDDOT 

The third time derivative.

Definition at line 84 of file field_store.hpp.

Constructor & Destructor Documentation

◆ FieldStore()

smith::FieldStore::FieldStore ( std::shared_ptr< Mesh mesh,
size_t  storage_size = 50,
std::string  prepend_name = "" 
)

Construct a new FieldStore object.

Parameters
meshThe mesh associated with the fields.
storage_sizeInitial storage size for fields (default: 50).
prepend_nameNamespace prefix applied by prefix(). Empty means no prefix.

Definition at line 14 of file field_store.cpp.

Member Function Documentation

◆ addDependent()

template<typename Space >
auto smith::FieldStore::addDependent ( FieldType< Space >  independent_field,
TimeDerivative  derivative,
std::string  name_override = "" 
)
inline

Add a dependent field (history value, velocity, or acceleration) to the store.

Creates and registers a new field that carries the previous time-step value of a particular time derivative of an independent field. The relationship is recorded in the TimeIntegrationMapping for the parent independent field so that, at evaluation time, the time integration rule can reconstruct the current rate from the pair (predicted_value, stored_old_value).

Return value: a FieldType<Space> whose name is the name of the newly registered field and is_unknown is false. This object is intentionally returned (rather than discarded) so that callers can pass it directly to createSpaces when assembling the weak-form argument list. To make it the Jacobian variable for a specific weak form (e.g. the cycle-zero acceleration solve), copy the returned object and set is_unknown = true before passing to createSpaces.

Template Parameters
SpaceThe finite element space type (must match the independent field).
Parameters
independent_fieldThe FieldType of the independent (predicted) field.
derivativeWhich time-derivative level this history field stores.
name_overrideIf non-empty, use this as the field name instead of the auto-generated one.
Returns
FieldType<Space> Type descriptor for the newly created dependent field.

Definition at line 187 of file field_store.hpp.

◆ addIndependent()

template<typename Space >
std::shared_ptr<DirichletBoundaryConditions> smith::FieldStore::addIndependent ( FieldType< Space > &  type,
std::shared_ptr< TimeIntegrationRule time_rule 
)
inline

Add an independent field (a solver unknown) to the store.

Registers the field as an unknown by setting type.is_unknown = true, so the same FieldType<Space> object can later be passed to createSpaces to mark this argument as an active Jacobian variable. Also creates a boundary-condition slot keyed by field name that callers can populate after this call returns.

Template Parameters
SpaceThe finite element space type.
Parameters
typeThe field type specification; type.is_unknown is set to true on return.
time_ruleThe time integration rule governing how this unknown and its dependents are related across time steps.
Returns
std::shared_ptr<DirichletBoundaryConditions> The boundary conditions for this field.

Definition at line 142 of file field_store.hpp.

◆ addParameter()

template<typename Space >
void smith::FieldStore::addParameter ( FieldType< Space > &  type)
inline

Add a parameter field to the store.

Template Parameters
SpaceThe finite element space type.
Parameters
typeThe field type specification.

Definition at line 110 of file field_store.hpp.

◆ addShapeDisp()

template<typename Space >
void smith::FieldStore::addShapeDisp ( FieldType< Space > &  type)
inline

Add a shape displacement field to the store.

Template Parameters
SpaceThe finite element space type.
Parameters
typeThe field type specification.

Definition at line 98 of file field_store.hpp.

◆ addWeakFormArg()

void smith::FieldStore::addWeakFormArg ( std::string  weak_form_name,
std::string  argument_name,
size_t  argument_index 
)

Register an argument to a weak form.

Parameters
weak_form_nameName of the weak form.
argument_nameName of the argument field.
argument_indexIndex of the argument in the weak form's argument list.

Definition at line 44 of file field_store.cpp.

◆ addWeakFormReaction()

void smith::FieldStore::addWeakFormReaction ( std::string  weak_form_name,
std::string  field_name 
)

Register the reaction (test) field for a weak form.

The reaction field is the field whose test function space the weak form integrates against. It determines which field's degrees of freedom the assembled residual is "returned to" (i.e. the field whose force/flux vector is populated).

Parameters
weak_form_nameName of the weak form.
field_nameName of the reaction field.

Definition at line 362 of file field_store.cpp.

◆ addWeakFormUnknownArg()

void smith::FieldStore::addWeakFormUnknownArg ( std::string  weak_form_name,
std::string  argument_name,
size_t  argument_index 
)

Register an argument to a weak form as an unknown.

Parameters
weak_form_nameName of the weak form.
argument_nameName of the argument field.
argument_indexIndex of the argument in the weak form's argument list.

Definition at line 34 of file field_store.cpp.

◆ createSpaces()

template<typename... FieldTypes>
std::vector<const mfem::ParFiniteElementSpace*> smith::FieldStore::createSpaces ( const std::string &  weak_form_name,
const std::string &  reaction_field_name,
FieldTypes...  types 
)
inline

Register all input fields for a weak form and return their FE spaces.

This is the primary setup method for constructing a weak form. It:

  1. Registers reaction_field_name as the reaction/test field via addWeakFormReaction.
  2. Iterates over every FieldType in types (in order), registering each as an input argument. If type.is_unknown is true, the field is also registered as an active Jacobian unknown for this weak form.
  3. Returns the ordered vector of finite element spaces.

A field may have is_unknown = true in one weak form and false in another (e.g. displacement is a Jacobian variable in the main solid solve but a fixed input in the stress projection). Callers control this by passing the FieldType returned from addIndependent (has is_unknown = true) or a plain copy constructed from the field name (has is_unknown = false). Similarly, a dependent field can be made the Jacobian variable for a specific weak form (e.g. acceleration in the cycle-zero solve) by copying the returned FieldType and setting is_unknown = true.

Parameters
weak_form_nameName of the weak form being constructed.
reaction_field_nameName of the test/reaction field (may differ from the first input).
typesOrdered list of FieldType descriptors for every input argument.
Returns
std::vector<const mfem::ParFiniteElementSpace*> Ordered input FE spaces.

Definition at line 290 of file field_store.hpp.

◆ getAllFields()

const std::vector< FieldState > & smith::FieldStore::getAllFields ( ) const

Get all fields stored in the FieldStore.

Returns
const std::vector<FieldState>& List of all fields.

Definition at line 275 of file field_store.cpp.

◆ getBoundaryConditionManagers()

std::vector< const BoundaryConditionManager * > smith::FieldStore::getBoundaryConditionManagers ( const std::vector< std::string > &  weak_form_names) const

Get the boundary condition managers for the given weak forms, one per residual row.

For each weak form in weak_form_names the reaction (test) field name is looked up. The returned manager is selected by consulting the registered TimeIntegrationMapping s:

  • reaction = primary or history slot -> value-level BC manager
  • reaction = second-derivative (ddot) slot -> second-derivative BC manager
  • reaction has its own DBC entry not tied to a mapping -> that DBC's value manager
  • otherwise -> nullptr (solver skips null entries)

The second-derivative manager is rebuilt on each call, so late value-BC additions are reflected.

Parameters
weak_form_namesOrdered list of weak form names whose BCs are needed.
Returns
std::vector<const BoundaryConditionManager*> One entry per weak form, in order.

Definition at line 129 of file field_store.cpp.

◆ getField()

FieldState smith::FieldStore::getField ( const std::string &  field_name) const

Get a FieldState by name.

Parameters
field_nameFully-qualified or unprefixed field name.
Returns
FieldState The field state.

Definition at line 209 of file field_store.cpp.

◆ getFieldIndex()

size_t smith::FieldStore::getFieldIndex ( const std::string &  field_name) const

Get the internal index of a field by name.

Parameters
field_nameFully-qualified or unprefixed field name.
Returns
size_t Index of the field.

Definition at line 196 of file field_store.cpp.

◆ getParameter()

FieldState smith::FieldStore::getParameter ( const std::string &  param_name) const

Get a parameter field by name.

Parameters
param_nameFully-qualified or unprefixed parameter name.
Returns
FieldState The parameter field state.

Definition at line 226 of file field_store.cpp.

◆ getShapeDisp()

FieldState smith::FieldStore::getShapeDisp ( ) const

Get the shape displacement field.

Returns
FieldState The shape displacement field.

Definition at line 273 of file field_store.cpp.

◆ getStates()

std::vector< FieldState > smith::FieldStore::getStates ( const std::string &  weak_form_name) const

Get the state fields associated with a weak form.

Parameters
weak_form_nameName of the weak form.
Returns
std::vector<FieldState> List of state fields.

Definition at line 277 of file field_store.cpp.

◆ getStatesFromVectors()

std::vector< FieldState > smith::FieldStore::getStatesFromVectors ( const std::string &  weak_form_name,
const std::vector< FieldState > &  state_fields,
const std::vector< FieldState > &  param_fields 
) const

Extract state fields for a weak form from provided state and parameter vectors.

Parameters
weak_form_nameName of the weak form.
state_fieldsVector of all state fields.
param_fieldsVector of all parameter fields.
Returns
std::vector<FieldState> Subset of fields relevant to the weak form.

Definition at line 301 of file field_store.cpp.

◆ getTimeIntegrationRules()

const std::vector< std::pair< std::shared_ptr< TimeIntegrationRule >, FieldStore::TimeIntegrationMapping > > & smith::FieldStore::getTimeIntegrationRules ( ) const

Get all registered time integration rules and their mappings.

Returns
const std::vector<std::pair<std::shared_ptr<TimeIntegrationRule>, TimeIntegrationMapping>>& List of rules and mappings.

Definition at line 350 of file field_store.cpp.

◆ getWeakFormReaction()

std::string smith::FieldStore::getWeakFormReaction ( const std::string &  weak_form_name) const

Get the name of the reaction (test) field for a weak form.

Parameters
weak_form_nameName of the weak form.
Returns
std::string Name of the reaction field.

Definition at line 373 of file field_store.cpp.

◆ graph()

const std::shared_ptr< gretl::DataStore > & smith::FieldStore::graph ( ) const

Get the associated data store graph.

Returns
const std::shared_ptr<gretl::DataStore>& The graph.

Definition at line 347 of file field_store.cpp.

◆ hasField()

bool smith::FieldStore::hasField ( const std::string &  field_name) const

Check whether a field exists.

Accepts either a fully-qualified field name or an unprefixed base name.

Definition at line 187 of file field_store.cpp.

◆ indexMap()

std::vector< std::vector< size_t > > smith::FieldStore::indexMap ( const std::vector< std::string > &  residual_names) const

Generate an index map for the residuals.

Parameters
residual_namesNames of the residuals.
Returns
std::vector<std::vector<size_t>> The index map.

Definition at line 67 of file field_store.cpp.

◆ markWeakFormInternal()

void smith::FieldStore::markWeakFormInternal ( const std::string &  weak_form_name)

Mark a weak form as internal so it is excluded from getReactionInfos().

Use this for subsystem forms (e.g. cycle-zero acceleration solve) that should not be exposed as user-visible reactions in DifferentiablePhysics.

Definition at line 357 of file field_store.cpp.

◆ prefix()

std::string smith::FieldStore::prefix ( const std::string &  base) const

Apply this store's namespace prefix to a base name.

Returns base unchanged when the store was constructed with an empty prepend name, otherwise returns prepend_name_ + "_" + base. Factories use this to namespace weak form, field, and parameter names consistently without re-implementing the rule.

Definition at line 21 of file field_store.cpp.

◆ setField() [1/2]

void smith::FieldStore::setField ( const std::string &  field_name,
FieldState  updated_field 
)

Update a field in the store by name.

Parameters
field_nameFully-qualified or unprefixed field name.
updated_fieldThe new field state.

Definition at line 233 of file field_store.cpp.

◆ setField() [2/2]

void smith::FieldStore::setField ( size_t  index,
FieldState  updated_field 
)

Update a field in the store by index.

Parameters
indexIndex of the field.
updated_fieldThe new field state.

Definition at line 355 of file field_store.cpp.


The documentation for this struct was generated from the following files: