https://mooseframework.inl.gov
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Moose::MFEM::ProblemOperatorBase Class Referenceabstract

Interface inherited by ProblemOperator and TimeDependentProblemOperator. Removes duplicated code in both classes. More...

#include <ProblemOperatorBase.h>

Inheritance diagram for Moose::MFEM::ProblemOperatorBase:
[legend]

Public Member Functions

 ProblemOperatorBase (MFEMProblem &problem)
 
virtual ~ProblemOperatorBase ()=default
 
virtual void SetGridFunctions ()
 
virtual void SetTrialVariablesFromTrueVectors ()
 
virtual void Init (mfem::BlockVector &X)
 
virtual void Solve ()=0
 

Public Attributes

mfem::Array< int_block_true_offsets_test
 
mfem::Array< int_block_true_offsets_trial
 
mfem::BlockVector _true_x
 
mfem::BlockVector _true_rhs
 

Protected Member Functions

void SolveWithOperator (EquationSystem &equation_system, const mfem::Vector &rhs, mfem::Vector &x)
 Solve the current equation system/operator using the configured nonlinear solver or linear solver for a purely linear problem. More...
 

Protected Attributes

MFEMProblem_problem
 Reference to the current problem. More...
 
MFEMProblemData_problem_data
 
std::vector< std::string > _trial_var_names
 Vector of names of state gridfunctions used in formulation, ordered by appearance in block vector during solve. More...
 
std::vector< std::string > _test_var_names
 
std::vector< mfem::ParGridFunction * > _trial_variables
 
std::vector< mfem::ParGridFunction * > _test_variables
 
mfem::Vector * _trial_true_vector = nullptr
 

Detailed Description

Interface inherited by ProblemOperator and TimeDependentProblemOperator. Removes duplicated code in both classes.

Definition at line 22 of file ProblemOperatorBase.h.

Constructor & Destructor Documentation

◆ ProblemOperatorBase()

Moose::MFEM::ProblemOperatorBase::ProblemOperatorBase ( MFEMProblem problem)

Definition at line 20 of file ProblemOperatorBase.C.

21  : _problem(problem), _problem_data(problem.getProblemData())
22 {
23 }
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem...
Definition: MFEMProblem.h:254
MFEMProblem & _problem
Reference to the current problem.

◆ ~ProblemOperatorBase()

virtual Moose::MFEM::ProblemOperatorBase::~ProblemOperatorBase ( )
virtualdefault

Member Function Documentation

◆ Init()

void Moose::MFEM::ProblemOperatorBase::Init ( mfem::BlockVector &  X)
virtual

Reimplemented in Moose::MFEM::TimeDependentEquationSystemProblemOperator.

Definition at line 50 of file ProblemOperatorBase.C.

Referenced by Moose::MFEM::TimeDependentEquationSystemProblemOperator::Init().

51 {
53  for (const auto i : index_range(_trial_variables))
54  X.GetBlock(i) = _trial_variables[i]->GetTrueVector();
55  // Sync the flags from the global vector with the sub-vectors (copies to global vector location)
56  X.SyncFromBlocks();
57 
58  // After initial assignment of X from the grid function, which may contain initial conditions,
59  // we alias the grid function to X
60  for (const auto i : index_range(_trial_variables))
61  _trial_variables[i]->MakeTRef(
62  _trial_variables[i]->ParFESpace(), X, _block_true_offsets_trial[i]);
64 }
mfem::Array< int > _block_true_offsets_trial
std::vector< mfem::ParGridFunction * > _trial_variables
auto index_range(const T &sizable)

◆ SetGridFunctions()

void Moose::MFEM::ProblemOperatorBase::SetGridFunctions ( )
virtual

Reimplemented in Moose::MFEM::TimeDependentEquationSystemProblemOperator, Moose::MFEM::ComplexEquationSystemProblemOperator, Moose::MFEM::EquationSystemProblemOperator, Moose::MFEM::TimeDependentProblemOperator, and Moose::MFEM::ProblemOperator.

Definition at line 26 of file ProblemOperatorBase.C.

Referenced by Moose::MFEM::ProblemOperator::SetGridFunctions(), and Moose::MFEM::TimeDependentProblemOperator::SetGridFunctions().

27 {
30 
31  // Set operator size and block structure for trial spaces
32  _block_true_offsets_trial.SetSize(_trial_variables.size() + 1);
34  for (const auto ind : index_range(_trial_variables))
35  _block_true_offsets_trial[ind + 1] = _trial_variables.at(ind)->ParFESpace()->TrueVSize();
36  _block_true_offsets_trial.PartialSum();
37 
38  // Set operator size and block structure for test spaces
39  _block_true_offsets_test.SetSize(_test_variables.size() + 1);
41  for (const auto ind : index_range(_test_variables))
42  _block_true_offsets_test[ind + 1] = _test_variables.at(ind)->ParFESpace()->TrueVSize();
43  _block_true_offsets_test.PartialSum();
44 
47 }
std::vector< std::string > _test_var_names
std::vector< std::string > _trial_var_names
Vector of names of state gridfunctions used in formulation, ordered by appearance in block vector dur...
mfem::Array< int > _block_true_offsets_test
std::vector< mfem::ParGridFunction * > _test_variables
mfem::Array< int > _block_true_offsets_trial
T * Get(const std::string &field_name) const
Returns a non-owning pointer to the field. This is guaranteed to return a non-null pointer...
std::vector< mfem::ParGridFunction * > _trial_variables
Moose::MFEM::GridFunctions gridfunctions
auto index_range(const T &sizable)

◆ SetTrialVariablesFromTrueVectors()

void Moose::MFEM::ProblemOperatorBase::SetTrialVariablesFromTrueVectors ( )
virtual

Definition at line 67 of file ProblemOperatorBase.C.

Referenced by Moose::MFEM::TimeDependentEquationSystemProblemOperator::Solve().

68 {
69  mooseAssert(_trial_true_vector, "The true vector should already have been set");
70  for (const auto trial_var : _trial_variables)
71  {
72  // Sync the memory flags from the global true vector to the gridfunction aliases
73  trial_var->GetTrueVector().SyncMemory(*_trial_true_vector);
74  trial_var->SetFromTrueVector();
75  }
76 }
std::vector< mfem::ParGridFunction * > _trial_variables

◆ Solve()

virtual void Moose::MFEM::ProblemOperatorBase::Solve ( )
pure virtual

◆ SolveWithOperator()

void Moose::MFEM::ProblemOperatorBase::SolveWithOperator ( EquationSystem equation_system,
const mfem::Vector &  rhs,
mfem::Vector &  x 
)
protected

Solve the current equation system/operator using the configured nonlinear solver or linear solver for a purely linear problem.

Definition at line 79 of file ProblemOperatorBase.C.

Referenced by Moose::MFEM::TimeDependentEquationSystemProblemOperator::ImplicitSolve(), Moose::MFEM::EquationSystemProblemOperator::Solve(), and Moose::MFEM::ComplexEquationSystemProblemOperator::Solve().

82 {
83  const bool nonlinear = equation_system.Nonlinear();
84 
85  // `nonlinear` describes the assembled MFEM operator, not whether the user configured a
86  // nonlinear solver object. A linear problem may still intentionally be solved through the
87  // nonlinear solver machinery when one is provided.
88  if (nonlinear || _problem_data.nonlinear_solver)
89  {
90  if (nonlinear && !_problem_data.nonlinear_solver)
91  mooseError("A nonlinear MFEM solve requires a nonlinear solver, but none was provided.");
92 
93  auto & nonlinear_solver = *_problem_data.nonlinear_solver;
94  if (nonlinear_solver.RequiresExternalLinearSolver())
95  {
97  mooseError("The configured MFEM nonlinear solver requires an external linear solver, but "
98  "none was provided.");
99  auto & linear_solver = *_problem_data.jacobian_solver;
100  equation_system.PrepareLinearSolver(linear_solver);
101  nonlinear_solver.SetLinearSolver(linear_solver.GetSolver());
102  }
103 
104  nonlinear_solver.SetOperator(equation_system);
105  nonlinear_solver.Mult(rhs, x);
106  return;
107  }
108  else
109  {
110  //
111  // pure linear path
112  //
113 
115  mooseError("A linear MFEM solve requires a linear solver, but none was provided.");
116 
117  auto & linear_solver = *_problem_data.jacobian_solver;
118  equation_system.PrepareLinearSolver(linear_solver);
119  linear_solver.GetSolver().Mult(rhs, x);
120  }
121 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::shared_ptr< Moose::MFEM::LinearSolverBase > jacobian_solver
std::shared_ptr< Moose::MFEM::NonlinearSolverBase > nonlinear_solver

Member Data Documentation

◆ _block_true_offsets_test

mfem::Array<int> Moose::MFEM::ProblemOperatorBase::_block_true_offsets_test

◆ _block_true_offsets_trial

mfem::Array<int> Moose::MFEM::ProblemOperatorBase::_block_true_offsets_trial

◆ _problem

MFEMProblem& Moose::MFEM::ProblemOperatorBase::_problem
protected

◆ _problem_data

MFEMProblemData& Moose::MFEM::ProblemOperatorBase::_problem_data
protected

◆ _test_var_names

std::vector<std::string> Moose::MFEM::ProblemOperatorBase::_test_var_names
protected

◆ _test_variables

std::vector<mfem::ParGridFunction *> Moose::MFEM::ProblemOperatorBase::_test_variables
protected

◆ _trial_true_vector

mfem::Vector* Moose::MFEM::ProblemOperatorBase::_trial_true_vector = nullptr
protected

◆ _trial_var_names

std::vector<std::string> Moose::MFEM::ProblemOperatorBase::_trial_var_names
protected

◆ _trial_variables

std::vector<mfem::ParGridFunction *> Moose::MFEM::ProblemOperatorBase::_trial_variables
protected

◆ _true_rhs

mfem::BlockVector Moose::MFEM::ProblemOperatorBase::_true_rhs

◆ _true_x

mfem::BlockVector Moose::MFEM::ProblemOperatorBase::_true_x

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