https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
NEML2CentralDifference Class Reference

#include <NEML2CentralDifference.h>

Inheritance diagram for NEML2CentralDifference:
[legend]

Public Types

enum  TimeOrder { FIRST, SECOND }
 
typedef DataFileName DataFileParameterType
 

Public Member Functions

 NEML2CentralDifference (const InputParameters &parameters)
 
void initialSetup () override
 
void meshChanged () override
 
void postSolve () override
 
virtual int order () override
 
virtual void computeTimeDerivatives () override
 
virtual void solve () override
 
virtual void postResidual (NumericVector< Number > &residual) override
 
virtual bool overridesSolve () const override
 
virtual bool advancesProblemState () const override
 
virtual bool performExplicitSolve (SparseMatrix< Number > &mass_matrix) override
 
void computeADTimeDerivatives (ADReal &, const dof_id_type &, ADReal &) const override
 
virtual void init () override
 
TimeOrder findVariableTimeOrder (unsigned int var_num) const
 Retrieve the order of the highest time derivative of a variable. More...
 
virtual void preSolve () override
 
virtual bool isExplicit () const override
 
virtual void preStep ()
 
virtual void postStep ()
 
virtual unsigned int getNumNonlinearIterations () const
 
virtual unsigned int getNumLinearIterations () const
 
const Realdt () const
 
virtual unsigned int numStatesRequired () const
 
virtual const bool & isLumped () const
 
bool integratesVar (const unsigned int var_num) const
 
void setNumIterationsLastSolve ()
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool haveParameter (const std::string &name) const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
TagID uDotFactorTag () const
 
TagID uDotDotFactorTag () const
 
virtual Real timeDerivativeRHSContribution (dof_id_type dof_id, const std::vector< Real > &factors={}) const
 
virtual Real timeDerivativeMatrixContribution (const Real factor) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Types

enum  SolveType
 

Protected Member Functions

void evaluateRHSResidual () override
 Evaluate the RHS residual. More...
 
void rebuildBoundaryElementList ()
 
void updateDOFIndices ()
 compile the dof indices for first and second order in time variables More...
 
virtual TagID massMatrixTagID () const override
 
template<typename T , typename T2 , typename T3 , typename T4 >
void computeTimeDerivativeHelper (T &u_dot, T2 &u_dotdot, const T3 &u_old, const T4 &u_older) const
 Helper function that actually does the math for computing the time derivative. More...
 
void computeICs ()
 
void setupSolver ()
 
bool solveLinearSystem (SparseMatrix< Number > &mass_matrix)
 
bool checkLinearConvergence ()
 
unsigned int getNumNonlinearIterationsLastSolve () const
 
unsigned int getNumLinearIterationsLastSolve () const
 
void copyVector (const NumericVector< Number > &from, NumericVector< Number > &to)
 
virtual Real duDotDuCoeff () const
 
void computeDuDotDu ()
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
TdeclareRestartableData (const std::string &data_name, Args &&... args)
 
ManagedValue< TdeclareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
const TgetRestartableData (const std::string &data_name) const
 
TdeclareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
TdeclareRecoverableData (const std::string &data_name, Args &&... args)
 
TdeclareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 
TdeclareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 
std::string restartableName (const std::string &data_name) const
 
NumericVector< Number > * addVector (const std::string &name, const bool project, const libMesh::ParallelType type)
 

Protected Attributes

NEML2Assembly_neml2_assembly = nullptr
 The assembly object with cached assembly information. More...
 
NEML2FEInterpolation_fe = nullptr
 The FE interface for getting variable values/gradients interpolated onto the finite element space. More...
 
const bool & _constant_mass
 Whether we are reusing the mass matrix. More...
 
const bool & _recompute_mass_matrix_on_mesh_change
 Must be set to true to use adaptivity with a constant mass matrix. More...
 
bool _mesh_changed
 Whether the mesh changed just before the current solve. More...
 
const TagName & _mass_matrix_name
 Mass matrix name. More...
 
NumericVector< Real > * _mass_matrix_lumped
 Lumped mass matrix. More...
 
const NumericVector< Number > & _solution_older
 The older solution. More...
 
std::unordered_set< unsigned int > & _vars_first
 
std::vector< dof_id_type > & _local_first_order_indices
 
std::unordered_set< unsigned int > & _vars_second
 
std::vector< dof_id_type > & _local_second_order_indices
 
 CONSISTENT
 
 LUMPED
 
 LUMP_PRECONDITIONED
 
MooseEnum _solve_type
 
NumericVector< Real > * _explicit_residual
 
NumericVector< Real > * _solution_update
 
NumericVector< Real > * _mass_matrix_diag_inverted
 
NumericVector< Real > * _ones
 
TagID _Ke_time_tag
 
std::unique_ptr< libMesh::LinearSolver< Number > > _linear_solver
 
std::unique_ptr< LumpedPreconditioner_preconditioner
 
Real _current_time
 
FEProblemBase_fe_problem
 
SystemBase_sys
 
std::vector< Real > & _du_dot_du
 
int_t_step
 
Real_dt
 
Real_dt_old
 
unsigned int _n_nonlinear_iterations
 
unsigned int _n_linear_iterations
 
bool _is_lumped
 
bool & _var_restriction
 
std::vector< dof_id_type > & _local_indices
 
std::unordered_set< unsigned int > & _vars
 
std::unique_ptr< NumericVector< Number > > _from_subvector
 
const bool & _enabled
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
MooseApp_restartable_app
 
const std::string _restartable_system_name
 
const THREAD_ID _restartable_tid
 
const bool _restartable_read_only
 
NonlinearSystemBase_nl
 
libMesh::NonlinearImplicitSystem_nonlinear_implicit_system
 
NumericVector< Number > * _Re_time
 
NumericVector< Number > * _Re_non_time
 
const TagID _u_dot_factor_tag
 
const TagID _u_dotdot_factor_tag
 
LinearSystem_linear_system
 
libMesh::LinearImplicitSystem_linear_implicit_system
 
FEProblemBase_mci_feproblem
 
const NumericVector< Number > *const & _solution
 
const NumericVector< Number > & _solution_old
 
std::unique_ptr< NumericVector< Number > > & _solution_sub
 
std::unique_ptr< NumericVector< Number > > & _solution_old_sub
 
const Parallel::Communicator & _communicator
 

Private Attributes

std::vector< const Elem * > _boundary_elems = {}
 Empty element vector to help zero out the algebraic range. More...
 
std::vector< const Node * > _no_node = {}
 Empty node vector to help zero out the algebraic range. More...
 
bool _boundary_elems_dirty = true
 Whether the cached boundary element list needs rebuilding. More...
 

Detailed Description

Definition at line 18 of file NEML2CentralDifference.h.

Member Enumeration Documentation

◆ TimeOrder

Enumerator
FIRST 
SECOND 

Definition at line 56 of file ExplicitMixedOrder.h.

Constructor & Destructor Documentation

◆ NEML2CentralDifference()

NEML2CentralDifference::NEML2CentralDifference ( const InputParameters parameters)

Definition at line 33 of file NEML2CentralDifference.C.

35 {
36 }
const InputParameters & parameters() const
ExplicitMixedOrder(const InputParameters &parameters)

Member Function Documentation

◆ advancesProblemState()

virtual bool ExplicitMixedOrder::advancesProblemState ( ) const
inlineoverridevirtualinherited

Reimplemented from ExplicitTimeIntegrator.

Definition at line 44 of file ExplicitMixedOrder.h.

44 { return true; }

◆ computeADTimeDerivatives()

void ExplicitMixedOrder::computeADTimeDerivatives ( ADReal ,
const dof_id_type ,
ADReal  
) const
inlineoverridevirtualinherited

Implements ExplicitTimeIntegrator.

Definition at line 48 of file ExplicitMixedOrder.h.

49  {
50  mooseError("NOT SUPPORTED");
51  }
void mooseError(Args &&... args) const

◆ computeICs()

void ExplicitMixedOrder::computeICs ( )
protectedinherited

Definition at line 363 of file ExplicitMixedOrder.C.

Referenced by ExplicitMixedOrder::init().

364 {
365  // Compute the first-order approximation of the velocity at the current time step
366  // using the Euler scheme, where the velocity is estimated as the difference
367  // between the current solution and the previous time step, divided by the time
368  auto vel = _sys.solutionUDot();
369  *vel = *_solution;
370  *vel -= _solution_old;
371  *vel /= _dt;
372  vel->close();
373 }
virtual NumericVector< Number > * solutionUDot()
const NumericVector< Number > *const & _solution
const NumericVector< Number > & _solution_old

◆ computeTimeDerivativeHelper()

template<typename T , typename T2 , typename T3 , typename T4 >
void ExplicitMixedOrder::computeTimeDerivativeHelper ( T u_dot,
T2 &  u_dotdot,
const T3 &  u_old,
const T4 &  u_older 
) const
protectedinherited

Helper function that actually does the math for computing the time derivative.

Definition at line 124 of file ExplicitMixedOrder.h.

128 {
129  // computing first derivative
130  // using the Central Difference method
131  // u_dot_old = (first_term - second_term) / 2 / dt
132  // first_term = u
133  // second_term = u_older
134  u_dot -= u_older; // 'older than older' solution
135  u_dot *= 1.0 / (2.0 * _dt);
136 
137  // computing second derivative
138  // using the Central Difference method
139  // u_dotdot_old = (first_term - second_term + third_term) / dt / dt
140  // first_term = u
141  // second_term = 2 * u_old
142  // third_term = u_older
143  u_dotdot -= u_old;
144  u_dotdot -= u_old;
145  u_dotdot += u_older;
146  u_dotdot *= 1.0 / (_dt * _dt);
147 }

◆ computeTimeDerivatives()

void ExplicitMixedOrder::computeTimeDerivatives ( )
overridevirtualinherited

Implements ExplicitTimeIntegrator.

Definition at line 105 of file ExplicitMixedOrder.C.

106 {
107  /*
108  Because this is called in NonLinearSystemBase
109  this should not actually compute the time derivatives.
110  Calculating time derivatives here will cause issues for the
111  solution update.
112  */
113  return;
114 }

◆ evaluateRHSResidual()

void NEML2CentralDifference::evaluateRHSResidual ( )
overrideprotectedvirtual

Evaluate the RHS residual.

Reimplemented from ExplicitMixedOrder.

Definition at line 94 of file NEML2CentralDifference.C.

95 {
98 
100  {
101  libMesh::ConstElemRange boundary_elem_range(&_boundary_elems);
102  _fe_problem.setCurrentAlgebraicElementRange(&boundary_elem_range);
103 
104  libMesh::ConstNodeRange null_node_range(&_no_node);
105  _fe_problem.setCurrentAlgebraicNodeRange(&null_node_range);
106  }
107 
109 
110  // Reset the algebraic ranges
113 }
void setCurrentAlgebraicElementRange(libMesh::ConstElemRange *range)
std::vector< const Elem * > _boundary_elems
Empty element vector to help zero out the algebraic range.
std::vector< const Node * > _no_node
Empty node vector to help zero out the algebraic range.
void setCurrentAlgebraicNodeRange(libMesh::ConstNodeRange *range)
FEProblemBase & _fe_problem
bool upToDate() const
NEML2Assembly * _neml2_assembly
The assembly object with cached assembly information.
bool _boundary_elems_dirty
Whether the cached boundary element list needs rebuilding.
NEML2FEInterpolation * _fe
The FE interface for getting variable values/gradients interpolated onto the finite element space...
bool contextUpToDate() const
virtual void evaluateRHSResidual()
Evaluate the RHS residual.

◆ findVariableTimeOrder()

ExplicitMixedOrder::TimeOrder ExplicitMixedOrder::findVariableTimeOrder ( unsigned int  var_num) const
inherited

Retrieve the order of the highest time derivative of a variable.

Returns
Returns the time order enum of this variable.

Definition at line 376 of file ExplicitMixedOrder.C.

Referenced by ExplicitDirichletBCBase::timestepSetup().

377 {
378  if (_vars_first.empty() && _vars_second.empty())
379  mooseError("Time order sets are both empty.");
380  if (_vars_first.count(var_num))
381  return FIRST;
382  else if (_vars_second.count(var_num))
383  return SECOND;
384  else
385  mooseError("Variable " + _sys.system().variable_name(var_num) +
386  " does not exist in time order sets.");
387 }
std::unordered_set< unsigned int > & _vars_second
virtual libMesh::System & system()=0
std::unordered_set< unsigned int > & _vars_first
const std::string & variable_name(const unsigned int i) const
void mooseError(Args &&... args) const

◆ init()

void ExplicitMixedOrder::init ( )
overridevirtualinherited

Reimplemented from ExplicitTimeIntegrator.

Definition at line 290 of file ExplicitMixedOrder.C.

291 {
293 
294  // Compute ICs for velocity
295  computeICs();
296 
297  // Seperate variables into first and second time integration order and find
298  // the local indices for each
299  const auto & var_names_first = getParam<std::vector<VariableName>>("first_order_vars");
300  const auto & var_names_second = getParam<std::vector<VariableName>>("second_order_vars");
301  std::vector<unsigned int> var_num_vec;
302 
303  auto & lm_sys = _sys.system();
304  lm_sys.get_all_variable_numbers(var_num_vec);
305  std::unordered_set<unsigned int> var_nums(var_num_vec.begin(), var_num_vec.end());
306 
307  for (const auto & var_name : var_names_first)
308  if (lm_sys.has_variable(var_name))
309  {
310  const auto var_num = lm_sys.variable_number(var_name);
311  _vars_first.insert(var_num);
312  var_nums.erase(var_num);
313  }
314 
315  for (const auto & var_name : var_names_second)
316  if (lm_sys.has_variable(var_name))
317  {
318  const auto var_num = lm_sys.variable_number(var_name);
319  _vars_second.insert(var_num);
320  var_nums.erase(var_num);
321  }
322 
323  // If var_nums is empty then that means the user has specified all the variables in this system
324  if (!var_nums.empty())
325  mooseError("Not all nonlinear variables have their order specified.");
326 }
std::unordered_set< unsigned int > & _vars_second
virtual libMesh::System & system()=0
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
std::unordered_set< unsigned int > & _vars_first
virtual void init() override
void mooseError(Args &&... args) const

◆ initialSetup()

void NEML2CentralDifference::initialSetup ( )
overridevirtual

Reimplemented from ExplicitTimeIntegrator.

Definition at line 71 of file NEML2CentralDifference.C.

72 {
74  _neml2_assembly = &_fe_problem.getUserObject<NEML2Assembly>("assembly", /*tid=*/0);
77 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
virtual void initialSetup() override
FEProblemBase & _fe_problem
NEML2Assembly * _neml2_assembly
The assembly object with cached assembly information.
NEML2FEInterpolation * _fe
The FE interface for getting variable values/gradients interpolated onto the finite element space...

◆ massMatrixTagID()

TagID ExplicitMixedOrder::massMatrixTagID ( ) const
overrideprotectedvirtualinherited

Reimplemented from ExplicitTimeIntegrator.

Definition at line 132 of file ExplicitMixedOrder.C.

Referenced by ExplicitMixedOrder::solve().

133 {
135 }
const TagName & _mass_matrix_name
Mass matrix name.
virtual TagID getMatrixTagID(const TagName &tag_name) const
SubProblem & subproblem()

◆ meshChanged()

void NEML2CentralDifference::meshChanged ( )
overridevirtual

Reimplemented from ExplicitMixedOrder.

Definition at line 80 of file NEML2CentralDifference.C.

81 {
83  _boundary_elems_dirty = true;
84 }
bool _boundary_elems_dirty
Whether the cached boundary element list needs rebuilding.
virtual void meshChanged() override

◆ order()

virtual int ExplicitMixedOrder::order ( )
inlineoverridevirtualinherited

Implements ExplicitTimeIntegrator.

Definition at line 32 of file ExplicitMixedOrder.h.

32 { return 1; }

◆ overridesSolve()

virtual bool ExplicitMixedOrder::overridesSolve ( ) const
inlineoverridevirtualinherited

Implements ExplicitTimeIntegrator.

Definition at line 37 of file ExplicitMixedOrder.h.

37 { return true; }

◆ performExplicitSolve()

bool ExplicitMixedOrder::performExplicitSolve ( SparseMatrix< Number > &  mass_matrix)
overridevirtualinherited

Reimplemented from ExplicitTimeIntegrator.

Definition at line 217 of file ExplicitMixedOrder.C.

Referenced by ExplicitMixedOrder::solve().

218 {
219  bool converged = false;
220 
221  // Grab all the vectors that we will need
222  auto accel = _sys.solutionUDotDot();
223  auto vel = _sys.solutionUDot();
224 
225  // Compute Forward Euler
226  // Split diag mass and residual vectors into correct subvectors
227  const std::unique_ptr<NumericVector<Number>> mass_inv_first(
229  const std::unique_ptr<NumericVector<Real>> exp_res_first(
231  _mass_matrix_diag_inverted->create_subvector(*mass_inv_first, _local_first_order_indices, false);
232  _explicit_residual->create_subvector(*exp_res_first, _local_first_order_indices, false);
233 
234  // Need velocity vector split into subvectors
235  auto vel_first = vel->get_subvector(_local_first_order_indices);
236 
237  // Velocity update for foward euler
238  vel_first->pointwise_mult(*mass_inv_first, *exp_res_first);
239 
240  // Restore the velocities
241  vel->restore_subvector(std::move(vel_first), _local_first_order_indices);
242 
243  // Compute Central Difference
244  // Split diag mass and residual vectors into correct subvectors
245  const std::unique_ptr<NumericVector<Real>> mass_inv_second(
247  const std::unique_ptr<NumericVector<Real>> exp_res_second(
249  _mass_matrix_diag_inverted->create_subvector(
250  *mass_inv_second, _local_second_order_indices, false);
251  _explicit_residual->create_subvector(*exp_res_second, _local_second_order_indices, false);
252 
253  // Only need acceleration and old velocity vector for central difference
254  auto accel_second = accel->get_subvector(_local_second_order_indices);
255 
256  auto vel_second = vel->get_subvector(_local_second_order_indices);
257 
258  // Compute acceleration for central difference
259  accel_second->pointwise_mult(*mass_inv_second, *exp_res_second);
260 
261  // Scaling the acceleration
262  auto accel_scaled = accel_second->clone();
263  accel_scaled->scale((_dt + _dt_old) / 2);
264 
265  // Velocity update for central difference
266  *vel_second += *accel_scaled;
267 
268  // Restore acceleration
269  accel->restore_subvector(std::move(accel_second), _local_second_order_indices);
270 
271  vel->restore_subvector(std::move(vel_second), _local_second_order_indices);
272 
273  // Same solution update for both methods
274  *_solution_update = *vel;
275  _solution_update->scale(_dt);
276 
277  // Check for convergence by seeing if there is a nan or inf
278  auto sum = _solution_update->sum();
279  converged = std::isfinite(sum);
280 
281  // The linear iteration count remains zero
283  vel->close();
284  accel->close();
285 
286  return converged;
287 }
NumericVector< Real > * _solution_update
const Parallel::Communicator & _communicator
bool converged(const std::vector< std::pair< unsigned int, Real >> &residuals, const std::vector< Real > &abs_tolerances)
Based on the residuals, determine if the iterative process converged or not.
SolverPackage default_solver_package()
std::vector< dof_id_type > & _local_second_order_indices
NumericVector< Real > * _explicit_residual
virtual NumericVector< Number > * solutionUDot()
unsigned int _n_linear_iterations
NumericVector< Real > * _mass_matrix_diag_inverted
static std::unique_ptr< NumericVector< Number > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
virtual NumericVector< Number > * solutionUDotDot()
std::vector< dof_id_type > & _local_first_order_indices

◆ postResidual()

void ExplicitMixedOrder::postResidual ( NumericVector< Number > &  residual)
overridevirtualinherited

Reimplemented from ExplicitTimeIntegrator.

Definition at line 206 of file ExplicitMixedOrder.C.

207 {
208  residual += *_Re_time;
209  residual += *_Re_non_time;
210  residual.close();
211 
212  // Reset time to the time at which to evaluate nodal BCs, which comes next
214 }
virtual Real & time() const
FEProblemBase & _fe_problem
NumericVector< Number > * _Re_time
virtual void close()=0
NumericVector< Number > * _Re_non_time

◆ postSolve()

void NEML2CentralDifference::postSolve ( )
overridevirtual

Reimplemented from ExplicitMixedOrder.

Definition at line 87 of file NEML2CentralDifference.C.

88 {
91 }
virtual void postSolve() override
void invalidateInterpolations()
NEML2FEInterpolation * _fe
The FE interface for getting variable values/gradients interpolated onto the finite element space...

◆ rebuildBoundaryElementList()

void NEML2CentralDifference::rebuildBoundaryElementList ( )
protected

Definition at line 39 of file NEML2CentralDifference.C.

Referenced by evaluateRHSResidual(), and initialSetup().

40 {
41  if (!_nl)
42  return;
43 
44  _boundary_elems.clear();
45 
46  // build boundary element list by iterating over all integrated BCs
47  const auto & ibcs = _nl->getIntegratedBCWarehouse();
48  std::unordered_set<BoundaryID> bnds;
49  for (const auto & ibc : ibcs.getObjects())
50  bnds.insert(ibc->boundaryIDs().begin(), ibc->boundaryIDs().end());
51 
52  if (!bnds.empty())
53  {
54  mooseInfo("Dectected BCs on ", bnds.size(), " boundaries.");
55 
56  // deduplicate elements that have multiple boundaries
57  std::unordered_set<const Elem *> unique_elems;
58  const auto end = _fe_problem.mesh().bndElemsEnd();
59  for (auto it = _fe_problem.mesh().bndElemsBegin(); it != end; ++it)
60  if (bnds.find((*it)->_bnd_id) != bnds.end())
61  unique_elems.insert((*it)->_elem);
62 
63  _boundary_elems.assign(unique_elems.begin(), unique_elems.end());
64  mooseInfo("Adding ", _boundary_elems.size(), " elements to the algebraic range.");
65  }
66 
67  _boundary_elems_dirty = false;
68 }
virtual bnd_elem_iterator bndElemsEnd()
void mooseInfo(Args &&... args) const
std::vector< const Elem * > _boundary_elems
Empty element vector to help zero out the algebraic range.
FEProblemBase & _fe_problem
NonlinearSystemBase * _nl
virtual bnd_elem_iterator bndElemsBegin()
MooseObjectTagWarehouse< IntegratedBCBase > & getIntegratedBCWarehouse()
bool _boundary_elems_dirty
Whether the cached boundary element list needs rebuilding.
virtual MooseMesh & mesh() override

◆ solve()

void ExplicitMixedOrder::solve ( )
overridevirtualinherited

Reimplemented from ExplicitTimeIntegrator.

Definition at line 138 of file ExplicitMixedOrder.C.

139 {
140  // Getting the tagID for the mass matrix
141  auto mass_tag = massMatrixTagID();
142 
143  // Reset iteration counts
146 
148 
149  auto & mass_matrix = _nonlinear_implicit_system->get_system_matrix();
150 
151  if (_mesh_changed)
153 
154  // Compute the mass matrix
156  {
157  // We only want to compute "inverted" lumped mass matrix once.
159  *_nonlinear_implicit_system->current_local_solution, mass_matrix, mass_tag);
160 
161  // Calculate and record the lumped mass matrix for use in residual calculation
162  mass_matrix.vector_mult(*_mass_matrix_lumped, *_ones);
163  _mass_matrix_lumped->close();
164 
165  // "Invert" the diagonal mass matrix
167  _mass_matrix_diag_inverted->reciprocal();
169  }
170 
171  _mesh_changed = false;
172 
173  // Set time to the time at which to evaluate the residual
176 
177  // Evaluate residual and move it to the RHS
179 
180  // Perform the linear solve
181  bool converged = performExplicitSolve(mass_matrix);
183 
184  // Update the solution
187 
189 
192 }
virtual void computeJacobianTag(const NumericVector< libMesh::Number > &soln, libMesh::SparseMatrix< libMesh::Number > &jacobian, TagID tag)
virtual TagID massMatrixTagID() const override
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
void overwriteNodeFace(NumericVector< Number > &soln)
virtual Real & time() const
NumericVector< Real > * _solution_update
NumericVector< Real > * _ones
FEProblemBase & _fe_problem
NonlinearSystemBase * _nl
const bool & _constant_mass
Whether we are reusing the mass matrix.
void setSolution(const NumericVector< Number > &soln)
NumericVector< Real > * _mass_matrix_lumped
Lumped mass matrix.
bool converged(const std::vector< std::pair< unsigned int, Real >> &residuals, const std::vector< Real > &abs_tolerances)
Based on the residuals, determine if the iterative process converged or not.
libMesh::NonlinearImplicitSystem * _nonlinear_implicit_system
std::unique_ptr< NumericVector< Number > > solution
unsigned int _n_linear_iterations
NumericVector< Real > * _mass_matrix_diag_inverted
virtual bool performExplicitSolve(SparseMatrix< Number > &mass_matrix) override
void updateDOFIndices()
compile the dof indices for first and second order in time variables
std::unique_ptr< NumericVector< Number > > current_local_solution
virtual Real & timeOld() const
unsigned int _n_nonlinear_iterations
virtual void evaluateRHSResidual()
Evaluate the RHS residual.
NumericVector< Number > & solutionOld()
bool _mesh_changed
Whether the mesh changed just before the current solve.
const SparseMatrix< Number > & get_system_matrix() const

◆ updateDOFIndices()

void ExplicitMixedOrder::updateDOFIndices ( )
protectedinherited

compile the dof indices for first and second order in time variables

Definition at line 329 of file ExplicitMixedOrder.C.

Referenced by ExplicitMixedOrder::solve().

330 {
331  auto & lm_sys = _sys.system();
332 
333  std::vector<dof_id_type> var_dof_indices, work_vec;
334  for (const auto var_num : _vars_first)
335  {
336  work_vec = _local_first_order_indices;
338  lm_sys.get_dof_map().local_variable_indices(var_dof_indices, lm_sys.get_mesh(), var_num);
339  std::merge(work_vec.begin(),
340  work_vec.end(),
341  var_dof_indices.begin(),
342  var_dof_indices.end(),
343  std::back_inserter(_local_first_order_indices));
344  }
345 
346  work_vec.clear();
347  var_dof_indices.clear();
348 
349  for (const auto var_num : _vars_second)
350  {
351  work_vec = _local_second_order_indices;
353  lm_sys.get_dof_map().local_variable_indices(var_dof_indices, lm_sys.get_mesh(), var_num);
354  std::merge(work_vec.begin(),
355  work_vec.end(),
356  var_dof_indices.begin(),
357  var_dof_indices.end(),
358  std::back_inserter(_local_second_order_indices));
359  }
360 }
std::unordered_set< unsigned int > & _vars_second
virtual libMesh::System & system()=0
std::unordered_set< unsigned int > & _vars_first
std::vector< dof_id_type > & _local_second_order_indices
std::vector< dof_id_type > & _local_first_order_indices

◆ validParams()

InputParameters NEML2CentralDifference::validParams ( )
static

Definition at line 21 of file NEML2CentralDifference.C.

22 {
24  params.addClassDescription(
25  "Central difference time integrator using NEML2 material models and kernels.");
26  params.addRequiredParam<UserObjectName>(
27  "assembly", "The NEML2Assembly object to use to provide assembly information");
28  params.addRequiredParam<UserObjectName>(
29  "fe", "The NEML2FEInterpolation object to use to couple variables");
30  return params;
31 }
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _boundary_elems

std::vector<const Elem *> NEML2CentralDifference::_boundary_elems = {}
private

Empty element vector to help zero out the algebraic range.

Definition at line 41 of file NEML2CentralDifference.h.

Referenced by evaluateRHSResidual(), and rebuildBoundaryElementList().

◆ _boundary_elems_dirty

bool NEML2CentralDifference::_boundary_elems_dirty = true
private

Whether the cached boundary element list needs rebuilding.

Definition at line 47 of file NEML2CentralDifference.h.

Referenced by evaluateRHSResidual(), meshChanged(), and rebuildBoundaryElementList().

◆ _constant_mass

const bool& ExplicitMixedOrder::_constant_mass
protectedinherited

Whether we are reusing the mass matrix.

Definition at line 78 of file ExplicitMixedOrder.h.

Referenced by ExplicitMixedOrder::meshChanged(), and ExplicitMixedOrder::solve().

◆ _fe

NEML2FEInterpolation* NEML2CentralDifference::_fe = nullptr
protected

The FE interface for getting variable values/gradients interpolated onto the finite element space.

Definition at line 37 of file NEML2CentralDifference.h.

Referenced by evaluateRHSResidual(), initialSetup(), and postSolve().

◆ _local_first_order_indices

std::vector<dof_id_type>& ExplicitMixedOrder::_local_first_order_indices
protectedinherited

◆ _local_second_order_indices

std::vector<dof_id_type>& ExplicitMixedOrder::_local_second_order_indices
protectedinherited

◆ _mass_matrix_lumped

NumericVector<Real>* ExplicitMixedOrder::_mass_matrix_lumped
protectedinherited

Lumped mass matrix.

Definition at line 95 of file ExplicitMixedOrder.h.

Referenced by ExplicitMixedOrder::solve().

◆ _mass_matrix_name

const TagName& ExplicitMixedOrder::_mass_matrix_name
protectedinherited

Mass matrix name.

Definition at line 92 of file ExplicitMixedOrder.h.

Referenced by ExplicitMixedOrder::massMatrixTagID().

◆ _mesh_changed

bool ExplicitMixedOrder::_mesh_changed
protectedinherited

Whether the mesh changed just before the current solve.

Definition at line 89 of file ExplicitMixedOrder.h.

Referenced by ExplicitMixedOrder::meshChanged(), and ExplicitMixedOrder::solve().

◆ _neml2_assembly

NEML2Assembly* NEML2CentralDifference::_neml2_assembly = nullptr
protected

The assembly object with cached assembly information.

Definition at line 34 of file NEML2CentralDifference.h.

Referenced by evaluateRHSResidual(), and initialSetup().

◆ _no_node

std::vector<const Node *> NEML2CentralDifference::_no_node = {}
private

Empty node vector to help zero out the algebraic range.

Definition at line 44 of file NEML2CentralDifference.h.

Referenced by evaluateRHSResidual().

◆ _recompute_mass_matrix_on_mesh_change

const bool& ExplicitMixedOrder::_recompute_mass_matrix_on_mesh_change
protectedinherited

Must be set to true to use adaptivity with a constant mass matrix.

This will recompute the mass matrix when the mesh changes. The user must make sure that the underlying material density stays constant, otherwise simulation results will depend on adaptivity.

Definition at line 86 of file ExplicitMixedOrder.h.

Referenced by ExplicitMixedOrder::meshChanged().

◆ _solution_older

const NumericVector<Number>& ExplicitMixedOrder::_solution_older
protectedinherited

The older solution.

Definition at line 98 of file ExplicitMixedOrder.h.

◆ _vars_first

std::unordered_set<unsigned int>& ExplicitMixedOrder::_vars_first
protectedinherited

◆ _vars_second

std::unordered_set<unsigned int>& ExplicitMixedOrder::_vars_second
protectedinherited

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