https://mooseframework.inl.gov
NEML2FEInterpolation.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include <vector>
13 #ifdef NEML2_ENABLED
14 
15 // system includes
16 #include <unordered_map>
17 
18 // libmesh includes
19 #include "MooseTypes.h"
20 #include "libmesh/fe_type.h"
21 #include "libmesh/id_types.h"
22 
23 // MOOSE includes
24 #include "ElementUserObject.h"
25 #include "NEML2Assembly.h"
26 #include "MooseVariableFE.h"
27 
28 // NEML2 includes
29 #include "neml2/tensors/Tensor.h"
30 
38 {
39 public:
41 
43 
52  const neml2::Tensor & getValue(const std::string & var_name);
53 
63  const neml2::Tensor & getGradient(const std::string & var_name);
64 
74  const neml2::Tensor & getPhi(const std::string & var_name);
75 
85  const neml2::Tensor & getPhiGradient(const std::string & var_name);
86 
96  const neml2::Tensor & getDofMap(const std::string & var_name);
97 
99  const std::vector<dof_id_type> & getGlobalDofMap(const std::string & var_name);
100 
101  int64_t local_ndof() const;
102 
104  bool contextUpToDate() const { return _fem_context_up_to_date; }
105 
107  void invalidateFEMContext();
108 
111 
112  void initialSetup() override;
113  void meshChanged() override;
114 
115  void initialize() override;
116  void execute() override;
117  void finalize() override;
118  void threadJoin(const UserObject &) override;
119 
120 protected:
121  virtual void syncWithMainThread();
122  virtual void updateFEMContext();
123  virtual void updateDofMap();
124  virtual void updatePhi();
125  virtual void updateGradPhi();
126  virtual void updateInterpolations();
127 
130 
133 
135  bool _interp_up_to_date = false;
136 
138  std::unordered_map<std::string, neml2::Tensor> _vars;
139 
141  std::unordered_map<std::string, neml2::Tensor> _grad_vars;
142 
144  std::unordered_map<std::string, const MooseVariableFE<Real> *> _moose_vars;
145 
148  std::unordered_map<FEType, int64_t> _ndofe;
149  std::unordered_map<FEType, const VariablePhiValue *> _phis;
150  std::unordered_map<FEType, const VariablePhiGradient *> _grad_phis;
151 
152  std::unordered_map<std::string, std::vector<int64_t>> _moose_dof_map;
153  std::unordered_map<std::string, std::vector<dof_id_type>> _moose_dof_map_global;
154  std::unordered_map<FEType, std::vector<Real>> _moose_phi;
155  std::unordered_map<FEType, std::vector<Real>> _moose_grad_phi;
156 
157  std::unordered_map<std::string, neml2::Tensor> _neml2_dof_map;
158  std::unordered_map<FEType, neml2::Tensor> _neml2_phi;
159  std::unordered_map<FEType, neml2::Tensor> _neml2_grad_phi;
161 
163  const PetscVector<Real> * _petsc_solution;
164 
165 private:
167  const MooseVariableFE<Real> * getMOOSEVariable(const std::string & var_name) const;
168 
170  std::vector<dof_id_type> _dof_indices;
171 
173  int64_t _local_ndof;
174 };
175 
176 #endif
This user object serves as the "interface" for interpolating MOOSE variable values and gradients from...
const neml2::Tensor & getPhiGradient(const std::string &var_name)
Get the shape function gradient associated with a MOOSE variable.
const std::vector< dof_id_type > & getGlobalDofMap(const std::string &var_name)
Similar to getDofMap, but returns the global dof map (as a flattened vector of dof_id_type) ...
virtual void updateInterpolations()
const neml2::Tensor & getGradient(const std::string &var_name)
Get the variable gradient of a MOOSE nonlinear variable converted to a NEML2 tensor.
std::unordered_map< FEType, const VariablePhiGradient * > _grad_phis
void initialize() override
Called before execute() is ever called so that data can be cleared.
bool _fem_context_up_to_date
Whether the current FEM context is up to date.
bool _interp_up_to_date
Whether the current interpolations are up to date.
const NEML2Assembly & _neml2_assembly
Assembly.
const neml2::Tensor & getValue(const std::string &var_name)
Get the variable value of a MOOSE nonlinear variable converted to a NEML2 tensor. ...
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
std::unordered_map< std::string, neml2::Tensor > _vars
coupled variables (by value) requested by other objects
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
NEML2FEInterpolation(const InputParameters &parameters)
const PetscVector< Real > * _petsc_solution
PETSc solution vector.
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
void threadJoin(const UserObject &) override
Must override.
virtual void syncWithMainThread()
int64_t _local_ndof
Number of local dofs (including ghost dofs)
virtual void updateFEMContext()
std::unordered_map< std::string, neml2::Tensor > _neml2_dof_map
std::unordered_map< std::string, neml2::Tensor > _grad_vars
coupled variables (by gradient) requested by other objects
void invalidateInterpolations()
Invalidate the cached interpolations.
void execute() override
Execute method.
std::unordered_map< FEType, neml2::Tensor > _neml2_phi
static InputParameters validParams()
const neml2::Tensor & getPhi(const std::string &var_name)
Get the shape function associated with a MOOSE variable.
std::unordered_map< FEType, int64_t > _ndofe
cached information on the requested function spaces
bool contextUpToDate() const
Whether the current FEM context is up to date.
void finalize() override
Finalize.
This user object caches assembly information from MOOSE.
Definition: NEML2Assembly.h:20
std::unordered_map< FEType, std::vector< Real > > _moose_phi
std::unordered_map< FEType, neml2::Tensor > _neml2_grad_phi
const neml2::Tensor & getDofMap(const std::string &var_name)
Get the local dof map associated with a MOOSE variable.
std::unordered_map< FEType, std::vector< Real > > _moose_grad_phi
const MooseVariableFE< Real > * getMOOSEVariable(const std::string &var_name) const
Helper to get the MOOSE variable and check for common restrictions.
std::unordered_map< FEType, const VariablePhiValue * > _phis
void meshChanged() override
Called on this object when the mesh changes.
std::unordered_map< std::string, std::vector< dof_id_type > > _moose_dof_map_global
std::unordered_map< std::string, const MooseVariableFE< Real > * > _moose_vars
moose variables that have been coupled
void invalidateFEMContext()
Invalidate the cached FEM context such as dof map, shape functions, etc.
Base class for user-specific data.
Definition: UserObject.h:19
std::vector< dof_id_type > _dof_indices
Helper vector to store local dof indices.
std::unordered_map< std::string, std::vector< int64_t > > _moose_dof_map