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
21#include <map>
22
23namespace Moose::MFEM
24{
25struct SolutionState;
26}
27
29{
30public:
35
39 MFEMProblem(const InputParameters & params);
40
44 virtual ~MFEMProblem() {}
45
46 virtual void initialSetup() override;
47 virtual void execute(const ExecFlagType & exec_type) override;
48 virtual void externalSolve() override {}
49 virtual void syncSolutions(Direction) override {}
50
55 virtual MFEMMesh & mesh() override;
56 virtual const MFEMMesh & mesh() const override;
58
63 virtual std::vector<VariableName> getAuxVariableNames();
64
65 void addBoundaryCondition(const std::string & bc_name,
66 const std::string & name,
67 InputParameters & parameters) override;
68
69 void addMaterial(const std::string & material_name,
70 const std::string & name,
71 InputParameters & parameters) override;
72
73 void addFunctorMaterial(const std::string & material_name,
74 const std::string & name,
75 InputParameters & parameters) override;
76
80 void addFESpace(const std::string & type, const std::string & name, InputParameters & parameters);
81
85 void addFESpaceHierarchy(const std::string & type,
86 const std::string & name,
88
92 void setMesh();
93
97 void addSubMesh(const std::string & type, const std::string & name, InputParameters & parameters);
98
102 void addQuadratureFunction(const std::string & type,
103 const std::string & name,
105
109 void addTransfer(const std::string & transfer_name,
110 const std::string & name,
111 InputParameters & parameters) override;
116 virtual void addVariable(const std::string & var_type,
117 const std::string & var_name,
118 InputParameters & parameters) override;
119
123 void addGridFunction(const std::string & var_type,
124 const std::string & var_name,
126
132 void addAuxVariable(const std::string & var_type,
133 const std::string & var_name,
134 InputParameters & parameters) override;
135
140 void
141 addElementalFieldVariable(const std::string &, const std::string &, InputParameters &) override
142 {
143 }
144
149 void addKernel(const std::string & kernel_name,
150 const std::string & name,
151 InputParameters & parameters) override;
152
156 void addRealComponentToKernel(const std::string & kernel_name,
157 const std::string & name,
159
163 void addImagComponentToKernel(const std::string & kernel_name,
164 const std::string & name,
166
170 void addRealComponentToBC(const std::string & kernel_name,
171 const std::string & name,
173
177 void addImagComponentToBC(const std::string & kernel_name,
178 const std::string & name,
180
184 void addAuxKernel(const std::string & kernel_name,
185 const std::string & name,
186 InputParameters & parameters) override;
187
192 void addFunction(const std::string & type,
193 const std::string & name,
194 InputParameters & parameters) override;
195
199 void addInitialCondition(const std::string & ic_name,
200 const std::string & name,
201 InputParameters & parameters) override;
202
208 void addPostprocessor(const std::string & type,
209 const std::string & name,
210 InputParameters & parameters) override;
211
215 void addVectorPostprocessor(const std::string & type,
216 const std::string & name,
217 InputParameters & parameters) override;
218
223 void addIndicator(const std::string & type,
224 const std::string & name,
225 InputParameters & parameters) override;
226
231 void addMarker(const std::string & type,
232 const std::string & name,
233 InputParameters & parameters) override;
234
239 virtual void addMFEMSolver(const std::string & user_object_name,
240 const std::string & name,
242
246 virtual void resolveMFEMSolvers();
247
251 void executeMFEMObjects(const ExecFlagType & exec_type);
252
259
266
272
276 const MFEMProblemData & getProblemData() const { return _problem_data; }
277
281 MPI_Comm getComm() { return getProblemData().comm; }
282
286 const mfem::ParMesh & getMFEMVariableMesh(std::string var_name)
287 {
288 if (_problem_data.gridfunctions.Has(var_name))
289 return *_problem_data.gridfunctions.Get(var_name)->ParFESpace()->GetParMesh();
290 else if (_problem_data.cmplx_gridfunctions.Has(var_name))
291 return *_problem_data.cmplx_gridfunctions.Get(var_name)->ParFESpace()->GetParMesh();
292 else
293 mooseError("Variable " + var_name +
294 " not found in MFEMProblem real or complex gridfunctions.");
295 }
296
300 void displaceMesh();
301
305 void rebalanceMesh(mfem::ParMesh & pmesh);
306
310 std::optional<std::reference_wrapper<mfem::ParGridFunction const>>
312
314
315 std::string solverTypeString(unsigned int solver_sys_num) override;
316
320 void updateFESpaces();
321
325 void updateGridFunctions();
326
330 bool hRefine() { return _problem_data.refiner && _problem_data.refiner->hRefine(); }
331
335 bool pRefine() { return _problem_data.refiner && _problem_data.refiner->pRefine(); }
336
340 std::shared_ptr<mfem::ParGridFunction> getGridFunction(const std::string & name)
341 {
343 }
344
348 std::shared_ptr<mfem::ParComplexGridFunction> getComplexGridFunction(const std::string & name)
349 {
351 }
352
356 enum class NumericType
357 {
358 REAL,
359 COMPLEX
360 };
361
366
370 template <typename T>
371 T & getMFEMObject(const std::string & system,
372 const std::string & name,
373 const THREAD_ID tid = 0) const;
374
378 bool hasMFEMObject(const std::string & system, const std::string & name) const;
379
380protected:
384 void validateVariableNumericType(const std::string & var_type,
385 const std::string & var_name) const;
386
388 {
389 std::string type;
391 bool referenced = false;
392 };
393
398
403
410 std::map<std::string, MFEMSolverDefinition> _mfem_solver_definitions;
411
414};
415
416template <typename T>
417T &
418MFEMProblem::getMFEMObject(const std::string & system,
419 const std::string & name,
420 const THREAD_ID tid) const
421{
422 std::vector<T *> objs;
424 .query()
425 .condition<AttribSystem>(system)
426 .condition<AttribThread>(tid)
427 .condition<AttribName>(name)
428 .queryInto(objs);
429 if (objs.empty())
430 mooseError("Unable to find MFEM object with system '" + system + "' and name '" + name + "'");
431 mooseAssert(objs.size() == 1, "Shouldn't find more than one object with given system and name");
432 return *(objs[0]);
433}
434
435#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.
MFEMMesh inherits a MOOSE mesh class which allows us to work with other MOOSE objects.
Definition MFEMMesh.h:21
virtual std::vector< VariableName > getAuxVariableNames()
Returns all the variable names from the auxiliary system base.
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...
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:49
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:48
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.
void addQuadratureFunction(const std::string &type, const std::string &name, InputParameters &parameters)
Add an MFEM QuadratureFunction-backed coefficient to the problem.
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:44
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