https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMWeakFormBase.C
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#include "MFEMWeakFormBase.h"
13#include "MFEMProblem.h"
14
17{
19 params.addClassDescription("Base class for MFEM weak forms, which build the EquationSystem "
20 "solved by an MFEM problem operator.");
21 params.registerBase("MFEMWeakFormBase");
22 params.registerSystemAttributeName("MFEMWeakFormBase");
23 params.addParam<std::vector<MFEMBoundaryConditionName>>(
24 "bcs", {}, "List of boundary conditions to add to the weak form");
25 params.addParam<std::vector<MFEMKernelName>>(
26 "kernels", {}, "List of kernels to add to the weak form");
27 params.addParam<std::vector<MFEMConstraintName>>(
28 "constraints", {}, "List of constraints to add to the weak form");
29 return params;
30}
31
33 : MFEMObject(parameters),
34 _bc_names(getParam<std::vector<MFEMBoundaryConditionName>>("bcs")),
35 _kernel_names(getParam<std::vector<MFEMKernelName>>("kernels")),
36 _constraint_names(getParam<std::vector<MFEMConstraintName>>("constraints"))
37{
38}
39
40std::shared_ptr<Moose::MFEM::EquationSystem>
47
48void
50{
51 auto & problem_data = getMFEMProblem().getProblemData();
52 if (_bc_names.empty()) // default to all BCs added by user
53 for (const auto & [bc_name, bc] : problem_data.bcs)
54 addBoundaryCondition(bc_name, bc);
55 else
56 for (const auto & bc_name : _bc_names)
57 {
58 if (!problem_data.bcs.Has(bc_name))
60 "bcs", "No boundary condition named '", bc_name, "' has been added to the problem.");
61 addBoundaryCondition(bc_name, problem_data.bcs.GetShared(bc_name));
62 }
63
64 if (_kernel_names.empty()) // default to all kernels added by user
65 for (const auto & [kernel_name, kernel] : problem_data.kernels)
66 addKernel(kernel_name, kernel);
67 else
68 for (const auto & kernel_name : _kernel_names)
69 {
70 if (!problem_data.kernels.Has(kernel_name))
71 paramError("kernels", "No kernel named '", kernel_name, "' has been added to the problem.");
72 addKernel(kernel_name, problem_data.kernels.GetShared(kernel_name));
73 }
74
75 if (_constraint_names.empty()) // default to all constraints added by user
76 for (const auto & [constraint_name, constraint] : problem_data.constraints)
77 addConstraint(constraint_name, constraint);
78 else
79 for (const auto & constraint_name : _constraint_names)
80 {
81 if (!problem_data.constraints.Has(constraint_name))
82 paramError("constraints",
83 "No constraint named '",
84 constraint_name,
85 "' has been added to the problem.");
86 addConstraint(constraint_name, problem_data.constraints.GetShared(constraint_name));
87 }
88
89 if (problem_data.nonlinear_solver)
90 _equation_system->SetGradientRequired(problem_data.nonlinear_solver->RequiresGradient());
91
92 _equation_system->SetCoefficientManager(problem_data.coefficients);
93
94 // Set up initial conditions
95 _equation_system->Init(problem_data.gridfunctions,
96 problem_data.cmplx_gridfunctions,
97 getMFEMProblem().assemblyLevel());
98}
99
100#endif
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void registerSystemAttributeName(const std::string &value)
This method is used to define the MOOSE system name that is used by the TheWarehouse object for stori...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Thin base for MFEM objects backed directly by MooseObject instead of UserObject.
Definition MFEMObject.h:30
static InputParameters validParams()
Declare the common parameters required by MFEM MooseObject-backed classes.
Definition MFEMObject.C:17
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition MFEMObject.h:45
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem.
MFEMWeakFormBase(const InputParameters &parameters)
std::vector< MFEMConstraintName > _constraint_names
std::vector< MFEMKernelName > _kernel_names
virtual std::shared_ptr< Moose::MFEM::EquationSystem > makeEquationSystem()=0
Constructs the empty EquationSystem of the type this weak form builds.
std::shared_ptr< Moose::MFEM::EquationSystem > _equation_system
Stores the constructed EquationSystem.
virtual void addBoundaryCondition(const std::string &name, std::shared_ptr< MFEMBoundaryCondition > bc)=0
void initEquationSystem()
Initialise the equation system. TODO: move all setup into EquationSystem constructors.
virtual void addKernel(const std::string &name, std::shared_ptr< MFEMKernel > kernel)=0
virtual void addConstraint(const std::string &name, std::shared_ptr< MFEMConstraint > constraint)=0
static InputParameters validParams()
std::shared_ptr< Moose::MFEM::EquationSystem > createEquationSystem()
Constructs the EquationSystem, adds the requested kernels, boundary conditions and constraints to it,...
std::vector< MFEMBoundaryConditionName > _bc_names
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:466