https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMProblem.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#ifdef MOOSE_MFEM_ENABLED
11
12#pragma once
13
14#include "Attributes.h"
15#include "ExternalProblem.h"
16#include "MFEMProblemData.h"
17#include "MFEMWeakFormBase.h"
18#include "MFEMMesh.h"
20#include "MFEMComplexVariable.h"
21#include "MFEMProblemComposer.h"
22#include "ProblemOperatorBase.h"
23
24#include <map>
25
26namespace Moose::MFEM
27{
28struct SolutionState;
29}
30
32{
33public:
38
42 MFEMProblem(const InputParameters & params);
43
47 virtual ~MFEMProblem() {}
48
49 virtual void initialSetup() override;
50 virtual void execute(const ExecFlagType & exec_type) override;
51 virtual void externalSolve() override {}
52 virtual void syncSolutions(Direction) override {}
53
58 virtual MFEMMesh & mesh() override;
59 virtual const MFEMMesh & mesh() const override;
61
66 virtual std::vector<VariableName> getAuxVariableNames();
67
68 template <typename T>
69 std::vector<std::shared_ptr<T>>
70 addObject(const std::string & type, const std::string & name, InputParameters & parameters)
71 {
72 return ExternalProblem::addObject<T>(type, name, parameters, /*threaded=*/false);
73 }
74
75 void addBoundaryCondition(const std::string & bc_name,
76 const std::string & name,
77 InputParameters & parameters) override;
78
79 void addMaterial(const std::string & material_name,
80 const std::string & name,
81 InputParameters & parameters) override;
82
83 void addFunctorMaterial(const std::string & material_name,
84 const std::string & name,
85 InputParameters & parameters) override;
86
90 void addFESpace(const std::string & type, const std::string & name, InputParameters & parameters);
91
95 void addFESpaceHierarchy(const std::string & type,
96 const std::string & name,
98
102 void setMesh();
103
107 void addSubMesh(const std::string & type, const std::string & name, InputParameters & parameters);
108
112 void addTransfer(const std::string & transfer_name,
113 const std::string & name,
114 InputParameters & parameters) override;
119 virtual void addVariable(const std::string & var_type,
120 const std::string & var_name,
121 InputParameters & parameters) override;
122
126 void addGridFunction(const std::string & var_type,
127 const std::string & var_name,
129
135 void addAuxVariable(const std::string & var_type,
136 const std::string & var_name,
137 InputParameters & parameters) override;
138
143 void
144 addElementalFieldVariable(const std::string &, const std::string &, InputParameters &) override
145 {
146 }
147
152 void addKernel(const std::string & kernel_name,
153 const std::string & name,
154 InputParameters & parameters) override;
155
159 void addRealComponentToKernel(const std::string & kernel_name,
160 const std::string & name,
162
166 void addImagComponentToKernel(const std::string & kernel_name,
167 const std::string & name,
169
173 void addRealComponentToBC(const std::string & kernel_name,
174 const std::string & name,
176
180 void addImagComponentToBC(const std::string & kernel_name,
181 const std::string & name,
183
187 void addWeakForm(const std::string & weak_form_name,
188 const std::string & name,
190
194 virtual std::shared_ptr<MFEMWeakFormBase> addDefaultWeakForm();
195
199 void setEquationSystems();
200
206 std::shared_ptr<Moose::MFEM::EquationSystem>
207 getEquationSystem(const std::string & weak_form_name = "") const;
208
212 void addProblemComposer(const std::string & composer_type,
213 const std::string & name,
215
219 virtual std::shared_ptr<MFEMProblemComposer> addDefaultProblemComposer();
220
224 void setProblemOperators();
225
229 std::vector<std::shared_ptr<Moose::MFEM::ProblemOperatorBase>> & getProblemOperators();
230
234 void addAuxKernel(const std::string & kernel_name,
235 const std::string & name,
236 InputParameters & parameters) override;
237
242 void addFunction(const std::string & type,
243 const std::string & name,
244 InputParameters & parameters) override;
245
249 void addInitialCondition(const std::string & ic_name,
250 const std::string & name,
251 InputParameters & parameters) override;
252
258 void addPostprocessor(const std::string & type,
259 const std::string & name,
260 InputParameters & parameters) override;
261
265 void addVectorPostprocessor(const std::string & type,
266 const std::string & name,
267 InputParameters & parameters) override;
268
273 void addIndicator(const std::string & type,
274 const std::string & name,
275 InputParameters & parameters) override;
276
281 void addMarker(const std::string & type,
282 const std::string & name,
283 InputParameters & parameters) override;
284
289 virtual void addMFEMSolver(const std::string & user_object_name,
290 const std::string & name,
292
296 virtual void resolveMFEMSolvers();
297
301 void executeMFEMObjects(const ExecFlagType & exec_type);
302
309
316
322
326 const MFEMProblemData & getProblemData() const { return _problem_data; }
327
331 MPI_Comm getComm() { return getProblemData().comm; }
332
336 const mfem::ParMesh & getMFEMVariableMesh(std::string var_name)
337 {
338 if (_problem_data.gridfunctions.Has(var_name))
339 return *_problem_data.gridfunctions.Get(var_name)->ParFESpace()->GetParMesh();
340 else if (_problem_data.cmplx_gridfunctions.Has(var_name))
341 return *_problem_data.cmplx_gridfunctions.Get(var_name)->ParFESpace()->GetParMesh();
342 else
343 mooseError("Variable " + var_name +
344 " not found in MFEMProblem real or complex gridfunctions.");
345 }
346
350 void displaceMesh();
351
355 void rebalanceMesh(mfem::ParMesh & pmesh);
356
360 const mfem::ParGridFunction & getMeshDisplacementGridFunction();
361
363
364 std::string solverTypeString(unsigned int solver_sys_num) override;
365
369 void updateFESpaces();
370
374 void updateGridFunctions();
375
379 bool hRefine() { return _problem_data.refiner && _problem_data.refiner->hRefine(); }
380
384 bool pRefine() { return _problem_data.refiner && _problem_data.refiner->pRefine(); }
385
389 std::shared_ptr<mfem::ParGridFunction> getGridFunction(const std::string & name)
390 {
392 }
393
397 std::shared_ptr<mfem::ParComplexGridFunction> getComplexGridFunction(const std::string & name)
398 {
400 }
401
405 enum class NumericType
406 {
407 REAL,
408 COMPLEX
409 };
410
415
419 template <typename T>
420 T & getMFEMObject(const std::string & system,
421 const std::string & name,
422 const THREAD_ID tid = 0) const;
423
427 bool hasMFEMObject(const std::string & system, const std::string & name) const;
428
432 mfem::AssemblyLevel assemblyLevel() const { return _assembly_level; }
433
439 void setAssemblyLevel(mfem::AssemblyLevel assembly_level) { _assembly_level = assembly_level; }
440
441protected:
445 void validateVariableNumericType(const std::string & var_type,
446 const std::string & var_name) const;
447
449 {
450 std::string type;
452 bool referenced = false;
453 };
454
459
464
471 std::map<std::string, MFEMSolverDefinition> _mfem_solver_definitions;
472
475
479 std::shared_ptr<MFEMProblemComposer> _problem_composer;
483 std::vector<std::shared_ptr<Moose::MFEM::ProblemOperatorBase>> _problem_operators;
484
490 mfem::AssemblyLevel _assembly_level{mfem::AssemblyLevel::LEGACY};
491};
492
493template <typename T>
494T &
495MFEMProblem::getMFEMObject(const std::string & system,
496 const std::string & name,
497 const THREAD_ID tid) const
498{
499 std::vector<T *> objs;
501 .query()
502 .condition<AttribSystem>(system)
503 .condition<AttribThread>(tid)
504 .condition<AttribName>(name)
505 .queryInto(objs);
506 if (objs.empty())
507 mooseError("Unable to find MFEM object with system '" + system + "' and name '" + name + "'");
508 mooseAssert(objs.size() == 1, "Shouldn't find more than one object with given system and name");
509 return *(objs[0]);
510}
511
512#endif
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int THREAD_ID
Definition MooseTypes.h:237
virtual MooseMesh & mesh() override
virtual void addAuxVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
Canonical method for adding an auxiliary variable.
TheWarehouse & theWarehouse() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Abstract MooseMesh base for all MFEM-backed mesh types (MFEMFileMesh, MFEMMeshGeneratorMesh).
Definition MFEMMesh.h:24
virtual std::vector< VariableName > getAuxVariableNames()
Returns all the variable names from the auxiliary system base.
std::shared_ptr< MFEMProblemComposer > _problem_composer
The problem operator builders for this mfem problem.
void addPostprocessor(const std::string &type, const std::string &name, InputParameters &parameters) override
Override of ExternalProblem::addPostprocessor.
virtual MFEMMesh & mesh() override
Overwritten mesh() method from base MooseMesh to retrieve the correct mesh type, in this case MFEMMes...
void addWeakForm(const std::string &weak_form_name, const std::string &name, InputParameters &parameters)
Add an MFEM WeakForm to the problem.
bool hRefine()
If AMR is enabled, request (and perform if needed) h-refinement.
NumericType
Enumerates the supported numeric representations for MFEM variables and operators.
const MFEMProblemData & getProblemData() const
Return the current MFEM problem data in a const context.
void addFESpace(const std::string &type, const std::string &name, InputParameters &parameters)
Add an MFEM FESpace to the problem.
void addMarker(const std::string &type, const std::string &name, InputParameters &parameters) override
Override of FEProblemBase::addMarker.
virtual void syncSolutions(Direction) override
Method to transfer data to/from the external application to the associated transfer mesh.
Definition MFEMProblem.h:52
void addFESpaceHierarchy(const std::string &type, const std::string &name, InputParameters &parameters)
Add an MFEMFESpaceHierarchy to the problem.
std::shared_ptr< mfem::ParComplexGridFunction > getComplexGridFunction(const std::string &name)
void setProblemOperators()
Set all MFEM ProblemOperators to solve in this problem.
virtual void addMFEMSolver(const std::string &user_object_name, const std::string &name, InputParameters &parameters)
Method called in AddMFEMSolverAction which records a solver for later dependency-ordered construction...
Moose::MFEM::CoefficientManager & getCoefficients()
Method to get the PropertyManager object for storing material properties and converting them to MFEM ...
std::vector< std::shared_ptr< T > > addObject(const std::string &type, const std::string &name, InputParameters &parameters)
Definition MFEMProblem.h:70
std::string solverTypeString(unsigned int solver_sys_num) override
Return solver type as a human readable string.
std::vector< std::shared_ptr< Moose::MFEM::ProblemOperatorBase > > _problem_operators
Vector of MFEM problem operators executed in this problem.
bool hasMFEMObject(const std::string &system, const std::string &name) const
Determine whether an MFEM object with the supplied system and name exists.
std::shared_ptr< mfem::ParGridFunction > getGridFunction(const std::string &name)
std::vector< std::shared_ptr< Moose::MFEM::ProblemOperatorBase > > & getProblemOperators()
Get vector of all ProblemOperators added to this problem.
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem.
virtual void externalSolve() override
New interface for solving an External problem.
Definition MFEMProblem.h:51
mfem::AssemblyLevel assemblyLevel() const
Return the default assembly level to use for EquationSystem assembly.
mfem::AssemblyLevel _assembly_level
Default assembly level to use for EquationSystem assembly.
void updateFESpaces()
Calls Update() on all FE spaces.
void addElementalFieldVariable(const std::string &, const std::string &, InputParameters &) override
Override of FEProblemBase::addElementalFieldVariable to be a no-op because we do not use the Marker/I...
void addIndicator(const std::string &type, const std::string &name, InputParameters &parameters) override
Override of FEProblemBase::addIndicator.
void setEquationSystems()
Set all MFEM EquationSystems for this problem.
bool pRefine()
If AMR is enabled, request (and perform if needed) p-refinement.
Moose::MFEM::SolutionState & _solution_state_data
Restartable MFEM solution state associated with this problem.
const mfem::ParMesh & getMFEMVariableMesh(std::string var_name)
Return the ParMesh associated with a particular variable.
void rebalanceMesh(mfem::ParMesh &pmesh)
Rebalance the (necessarily nonconforming) mesh.
void addVectorPostprocessor(const std::string &type, const std::string &name, InputParameters &parameters) override
Add a vector postprocessor and register its vectors with the MFEM execution system.
void addAuxKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters) override
Override of ExternalProblem::addAuxKernel.
void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters) override
void addProblemComposer(const std::string &composer_type, const std::string &name, InputParameters &parameters)
Method called in AddMFEMProblemComposerAction which will create the problem composer.
void addSubMesh(const std::string &type, const std::string &name, InputParameters &parameters)
Add an MFEM SubMesh to the problem.
void validateVariableNumericType(const std::string &var_type, const std::string &var_name) const
Verify that a primary variable's numeric type matches the problem's equation system.
void addInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters) override
Add an MFEM initial condition to the problem.
static InputParameters validParams()
Return the input parameters used to construct an MFEM problem.
Definition MFEMProblem.C:62
void setMesh()
Set the mesh used by MFEM.
void setAssemblyLevel(mfem::AssemblyLevel assembly_level)
Set the default assembly level to use for EquationSystem assembly.
void addKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters) override
Override of ExternalProblem::addKernel.
T & getMFEMObject(const std::string &system, const std::string &name, const THREAD_ID tid=0) const
Retrieve an MFEM object from the warehouse by system and name.
virtual std::shared_ptr< MFEMWeakFormBase > addDefaultWeakForm()
Add default weak form if none has been added by the user.
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters) override
Override of ExternalProblem::addVariable.
NumericType getNumericType() const
Retrieve the numeric type of the problem.
void updateGridFunctions()
Calls Update() on all gridfunctions.
void addRealComponentToKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a real component kernel to the parent MFEMComplexKernel.
MFEMProblemData _problem_data
Aggregated MFEM-side state for meshes, spaces, variables, coefficients, and solvers.
void addRealComponentToBC(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a real component BC to the parent MFEMComplexIntegratedBC.
virtual ~MFEMProblem()
Destroy the MFEM problem.
Definition MFEMProblem.h:47
void addFunction(const std::string &type, const std::string &name, InputParameters &parameters) override
Override of ExternalProblem::addFunction.
std::shared_ptr< Moose::MFEM::EquationSystem > getEquationSystem(const std::string &weak_form_name="") const
Return the EquationSystem built by the weak form named weak_form_name.
InputParameters addMFEMFESpaceFromMOOSEVariable(InputParameters &moosevar_params)
Method used to get an mfem FEC depending on the variable family specified in the input file.
void addGridFunction(const std::string &var_type, const std::string &var_name, InputParameters &parameters)
Adds one MFEM GridFunction to be used in the MFEM solve.
void addTransfer(const std::string &transfer_name, const std::string &name, InputParameters &parameters) override
Add transfers between MultiApps and/or MFEM SubMeshes.
void displaceMesh()
Displace the mesh, if mesh displacement is enabled.
void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters &parameters) override
virtual void execute(const ExecFlagType &exec_type) override
Convenience function for performing execution of MOOSE systems.
NumericType _num_type
The numeric representation currently active for this problem.
Moose::FEBackend feBackend() const override
const mfem::ParGridFunction & getMeshDisplacementGridFunction()
Returns reference to the displacement GridFunction to apply to nodes.
void addImagComponentToBC(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds an imaginary component BC to the parent MFEMComplexIntegratedBC.
virtual std::shared_ptr< MFEMProblemComposer > addDefaultProblemComposer()
Add default problem composer if none has been added by the user.
void executeMFEMObjects(const ExecFlagType &exec_type)
Execute MFEM executed objects scheduled on the supplied execute flag.
std::map< std::string, MFEMSolverDefinition > _mfem_solver_definitions
Solver definitions recorded by AddMFEMSolverAction before the dependency resolver constructs them.
void addAuxVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters) override
Override of ExternalProblem::addAuxVariable.
virtual void resolveMFEMSolvers()
Construct recorded MFEM solvers in dependency order and select the problem driver solver(s).
void addFunctorMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters) override
void addImagComponentToKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds an imaginary component kernel to the parent MFEMComplexKernel.
MPI_Comm getComm()
Return the MPI communicator associated with this FE problem's mesh.
virtual void initialSetup() override
Definition MFEMProblem.C:85
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
Class for containing MooseEnum item information.
Front-end class for creating and storing MFEM coefficients.
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
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::shared_ptr< T > GetShared(const std::string &field_name) const
Returns a shared pointer to the field. This is guaranteed to return a non-null shared pointer.
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
SolutionState
Definition MooseTypes.h:262
Base problem data struct.
Moose::MFEM::CoefficientManager coefficients
Moose::MFEM::ComplexGridFunctions cmplx_gridfunctions
std::shared_ptr< MFEMRefinementMarker > refiner
Moose::MFEM::GridFunctions gridfunctions