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 "MFEMMesh.h"
19#include "MFEMComplexVariable.h"
20#include "MFEMProblemComposer.h"
21
22#include <map>
23
24namespace Moose::MFEM
25{
26struct SolutionState;
27}
28
30{
31public:
36
40 MFEMProblem(const InputParameters & params);
41
45 virtual ~MFEMProblem() {}
46
47 virtual void initialSetup() override;
48 virtual void execute(const ExecFlagType & exec_type) override;
49 virtual void externalSolve() override {}
50 virtual void syncSolutions(Direction) override {}
51
56 virtual MFEMMesh & mesh() override;
57 virtual const MFEMMesh & mesh() const override;
59
64 virtual std::vector<VariableName> getAuxVariableNames();
65
66 void addBoundaryCondition(const std::string & bc_name,
67 const std::string & name,
68 InputParameters & parameters) override;
69
70 void addMaterial(const std::string & material_name,
71 const std::string & name,
72 InputParameters & parameters) override;
73
74 void addFunctorMaterial(const std::string & material_name,
75 const std::string & name,
76 InputParameters & parameters) override;
77
81 void addFESpace(const std::string & type, const std::string & name, InputParameters & parameters);
82
86 void addFESpaceHierarchy(const std::string & type,
87 const std::string & name,
89
93 void setMesh();
94
98 void addSubMesh(const std::string & type, const std::string & name, InputParameters & parameters);
99
103 void addTransfer(const std::string & transfer_name,
104 const std::string & name,
105 InputParameters & parameters) override;
110 virtual void addVariable(const std::string & var_type,
111 const std::string & var_name,
112 InputParameters & parameters) override;
113
117 void addGridFunction(const std::string & var_type,
118 const std::string & var_name,
120
126 void addAuxVariable(const std::string & var_type,
127 const std::string & var_name,
128 InputParameters & parameters) override;
129
134 void
135 addElementalFieldVariable(const std::string &, const std::string &, InputParameters &) override
136 {
137 }
138
143 void addKernel(const std::string & kernel_name,
144 const std::string & name,
145 InputParameters & parameters) override;
146
150 void addRealComponentToKernel(const std::string & kernel_name,
151 const std::string & name,
153
157 void addImagComponentToKernel(const std::string & kernel_name,
158 const std::string & name,
160
164 void addRealComponentToBC(const std::string & kernel_name,
165 const std::string & name,
167
171 void addImagComponentToBC(const std::string & kernel_name,
172 const std::string & name,
174
178 void addAuxKernel(const std::string & kernel_name,
179 const std::string & name,
180 InputParameters & parameters) override;
181
186 void addFunction(const std::string & type,
187 const std::string & name,
188 InputParameters & parameters) override;
189
193 void addInitialCondition(const std::string & ic_name,
194 const std::string & name,
195 InputParameters & parameters) override;
196
202 void addPostprocessor(const std::string & type,
203 const std::string & name,
204 InputParameters & parameters) override;
205
209 void addVectorPostprocessor(const std::string & type,
210 const std::string & name,
211 InputParameters & parameters) override;
212
217 void addIndicator(const std::string & type,
218 const std::string & name,
219 InputParameters & parameters) override;
220
225 void addMarker(const std::string & type,
226 const std::string & name,
227 InputParameters & parameters) override;
228
232 void addMFEMProblemComposer(const std::string & user_object_name,
233 const std::string & name,
235
240 virtual void addMFEMSolver(const std::string & user_object_name,
241 const std::string & name,
243
247 virtual void resolveMFEMSolvers();
248
252 void executeMFEMObjects(const ExecFlagType & exec_type);
253
260
267
273
277 const MFEMProblemData & getProblemData() const { return _problem_data; }
278
282 std::shared_ptr<MFEMProblemComposer> & getProblemComposer() { return _problem_composer; }
283
287 MPI_Comm getComm() { return getProblemData().comm; }
288
292 const mfem::ParMesh & getMFEMVariableMesh(std::string var_name)
293 {
294 if (_problem_data.gridfunctions.Has(var_name))
295 return *_problem_data.gridfunctions.Get(var_name)->ParFESpace()->GetParMesh();
296 else if (_problem_data.cmplx_gridfunctions.Has(var_name))
297 return *_problem_data.cmplx_gridfunctions.Get(var_name)->ParFESpace()->GetParMesh();
298 else
299 mooseError("Variable " + var_name +
300 " not found in MFEMProblem real or complex gridfunctions.");
301 }
302
306 void displaceMesh();
307
311 void rebalanceMesh(mfem::ParMesh & pmesh);
312
316 std::optional<std::reference_wrapper<mfem::ParGridFunction const>>
318
320
321 std::string solverTypeString(unsigned int solver_sys_num) override;
322
326 void updateFESpaces();
327
331 void updateGridFunctions();
332
336 bool hRefine() { return _problem_data.refiner && _problem_data.refiner->hRefine(); }
337
341 bool pRefine() { return _problem_data.refiner && _problem_data.refiner->pRefine(); }
342
346 std::shared_ptr<mfem::ParGridFunction> getGridFunction(const std::string & name)
347 {
349 }
350
354 std::shared_ptr<mfem::ParComplexGridFunction> getComplexGridFunction(const std::string & name)
355 {
357 }
358
362 enum class NumericType
363 {
364 REAL,
365 COMPLEX
366 };
367
372
376 template <typename T>
377 T & getMFEMObject(const std::string & system,
378 const std::string & name,
379 const THREAD_ID tid = 0) const;
380
384 bool hasMFEMObject(const std::string & system, const std::string & name) const;
385
386protected:
390 void validateVariableNumericType(const std::string & var_type,
391 const std::string & var_name) const;
392
394 {
395 std::string type;
397 bool referenced = false;
398 };
399
404
409
416 std::map<std::string, MFEMSolverDefinition> _mfem_solver_definitions;
417
420
424 std::shared_ptr<MFEMProblemComposer> _problem_composer;
425};
426
427template <typename T>
428T &
429MFEMProblem::getMFEMObject(const std::string & system,
430 const std::string & name,
431 const THREAD_ID tid) const
432{
433 std::vector<T *> objs;
435 .query()
436 .condition<AttribSystem>(system)
437 .condition<AttribThread>(tid)
438 .condition<AttribName>(name)
439 .queryInto(objs);
440 if (objs.empty())
441 mooseError("Unable to find MFEM object with system '" + system + "' and name '" + name + "'");
442 mooseAssert(objs.size() == 1, "Shouldn't find more than one object with given system and name");
443 return *(objs[0]);
444}
445
446#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.
std::shared_ptr< MFEMProblemComposer > & getProblemComposer()
Method to get the Problem Composer(s).
virtual MFEMMesh & mesh() override
Overwritten mesh() method from base MooseMesh to retrieve the correct mesh type, in this case MFEMMes...
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:50
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)
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::string solverTypeString(unsigned int solver_sys_num) override
Return solver type as a human readable string.
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)
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:49
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.
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 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:60
void setMesh()
Set the mesh used by MFEM.
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 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:45
void addMFEMProblemComposer(const std::string &user_object_name, const std::string &name, InputParameters &parameters)
Method called in AddMFEMProblemComposerAction which will create the problem composer.
void addFunction(const std::string &type, const std::string &name, InputParameters &parameters) override
Override of ExternalProblem::addFunction.
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.
std::optional< std::reference_wrapper< mfem::ParGridFunction const > > getMeshDisplacementGridFunction()
Returns optional reference to the displacement GridFunction to apply to nodes.
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
void addImagComponentToBC(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds an imaginary component BC to the parent MFEMComplexIntegratedBC.
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:88
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