10#ifdef MOOSE_MFEM_ENABLED
14#include "libmesh/int_range.h"
22 mfem::AssemblyLevel assembly_level)
26 if (gridfunctions.
size())
27 mooseError(
"Mixing real and complex variables is currently not supported.");
31 if (!cmplx_gridfunctions.
Has(test_var_name))
35 " requested by equation system during initialization was "
36 "not found in gridfunctions");
42 cmplx_gridfunctions.
Get(test_var_name)->ParFESpace()));
58 cmplx_gridfunctions.
GetShared(eliminated_var_name));
105 ApplyBoundaryBLFIntegrators<mfem::ParSesquilinearForm>(
107 ApplyDomainBLFIntegrators<mfem::ParSesquilinearForm>(
128 std::make_shared<Moose::MFEM::NamedFieldsMap<mfem::ParMixedSesquilinearForm>>();
132 auto mslf = std::make_shared<mfem::ParMixedSesquilinearForm>(
_coupled_pfespaces.at(j),
138 test_var_name != coupled_var_name)
142 ApplyDomainBLFIntegrators<mfem::ParMixedSesquilinearForm>(
149 test_mslfs->Register(coupled_var_name, mslf);
154 _mslfs.Register(test_var_name, test_mslfs);
160 mfem::ParComplexGridFunction & trial_gf,
161 mfem::Array<int> & global_bdr_markers,
162 mfem::Array<int> & global_ess_tdofs)
165 const auto & bdr_attributes = trial_gf.ParFESpace()->GetParMesh()->bdr_attributes;
166 global_bdr_markers.SetSize(bdr_attributes.Size() ? bdr_attributes.Max() : 0, 0);
167 global_ess_tdofs.SetSize(0);
172 bc->ApplyBC(trial_gf);
174 mfem::Array<int> ess_bdrs(bc->getBoundaryMarkers());
176 for (
const auto i : make_range(ess_bdrs.Size()))
177 global_bdr_markers[i] |= ess_bdrs[i];
180 mfem::Array<int> ess_tdofs;
181 trial_gf.ParFESpace()->GetEssentialTrueDofs(ess_bdrs, ess_tdofs);
182 global_ess_tdofs.Append(ess_tdofs);
190 constraint->ApplyConstraint(trial_gf, global_ess_tdofs);
194 const int num_ess_tdofs = global_ess_tdofs.Size();
195 global_ess_tdofs.Sort();
196 global_ess_tdofs.Unique();
197 if (global_ess_tdofs.Size() != num_ess_tdofs)
198 mooseError(
"Duplicate essential true degrees of freedom for variable '",
200 "'. Check for overlapping essential constraints or boundary conditions.");
228 const auto & trial_var_name = kernel->getTrialVariableName();
229 const auto & test_var_name = kernel->getTestVariableName();
235 auto kernel_field_map =
236 std::make_shared<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>>();
242 auto kernels = std::make_shared<std::vector<std::shared_ptr<MFEMComplexKernel>>>();
245 _cmplx_kernels_map.GetRef(test_var_name).Get(trial_var_name)->push_back(std::move(kernel));
251 const auto & trial_var_name = bc->getTrialVariableName();
252 const auto & test_var_name = bc->getTestVariableName();
258 auto integrated_bc_field_map =
259 std::make_shared<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>>();
265 auto bcs = std::make_shared<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>();
278 const auto & trial_var_name = bc->getTrialVariableName();
282 auto bcs = std::make_shared<std::vector<std::shared_ptr<MFEMComplexEssentialBC>>>();
290 std::shared_ptr<MFEMComplexEssentialConstraint> constraint)
292 const auto & trial_var_name = constraint->getTrialVariableName();
297 std::make_shared<std::vector<std::shared_ptr<MFEMComplexEssentialConstraint>>>();
301 for (
const auto & other : constraints)
302 constraint->checkDisjointSubdomains(*other);
303 constraints.push_back(std::move(constraint));
317 if (
_mslfs.Has(test_var_name) &&
_mslfs.Get(test_var_name)->Has(eliminated_var_name) &&
320 auto & mslf = *
_mslfs.Get(test_var_name)->Get(eliminated_var_name);
321 auto & clf = *
_clfs.
Get(test_var_name);
322 const mfem::real_t
scale = -1.0;
323 const mfem::real_t conv =
324 (mslf.GetConvention() == mfem::ComplexOperator::HERMITIAN) ? 1.0 : -1.0;
342 mfem::BlockVector & trueX,
343 mfem::BlockVector & trueRHS)
346 mfem::Vector aux_x, aux_rhs;
347 mfem::OperatorPtr aux_a;
349 auto slf =
_slfs.
Get(test_var_name);
358 trueX.GetBlock(0) = aux_x;
359 trueRHS.GetBlock(0) = aux_rhs;
360 trueX.SyncFromBlocks();
361 trueRHS.SyncFromBlocks();
363 op.Reset(aux_a.Ptr());
364 aux_a.SetOperatorOwner(
false);
369 mfem::BlockVector & trueX,
370 mfem::BlockVector & trueRHS)
378 trueRHS.SyncToBlocks();
388 mfem::Vector aux_x, aux_rhs;
390 std::unique_ptr<mfem::OperatorHandle> aux_a = std::make_unique<mfem::OperatorHandle>();
392 if (test_var_name == trial_var_name)
394 mooseAssert(i == j,
"Trial and test variables must have the same ordering.");
395 auto slf =
_slfs.
Get(test_var_name);
403 trueX.GetBlock(i) = aux_x;
405 else if (
_mslfs.Has(test_var_name) &&
_mslfs.Get(test_var_name)->Has(trial_var_name))
407 auto mslf =
_mslfs.Get(test_var_name)->Get(trial_var_name);
419 trueRHS.GetBlock(i) += aux_rhs;
420 _h_blocks(i, j) = aux_a->As<mfem::ComplexHypreParMatrix>()->GetSystemMatrix();
425 trueX.SyncFromBlocks();
426 trueRHS.SyncFromBlocks();
429 op.Reset(mfem::HypreParMatrixFromBlocks(
_h_blocks));
447 trueX.GetBlock(i).SyncMemory(trueX);
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void markSolutionChanged()
Notify quadrature function coefficients that solution variables have changed, marking the stored valu...
NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexEssentialConstraint > > > _cmplx_essential_constraint_map
virtual void ApplyComplexEssentialConstraint(const std::string &var_name, mfem::ParComplexGridFunction &trial_gf, mfem::Array< int > &global_bdr_markers, mfem::Array< int > &global_ess_tdofs)
Apply essential constraints associated with var_name to set true DoFs of trial_gf,...
bool HasEssentialConstraints(const std::string &var_name) const override
void EliminateCoupledVariables() override
Perform trivial eliminations of coupled variables lacking corresponding test variables.
virtual void BuildLinearForms() override
Build linear forms and eliminate constrained DoFs.
std::vector< std::unique_ptr< mfem::ParComplexGridFunction > > _cmplx_var_ess_constraints
Complex Gridfunctions holding essential constraints from Dirichlet BCs.
Moose::MFEM::ComplexGridFunctions * _complex_gfuncs
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexKernel > > > > _cmplx_kernels_map
virtual void Mult(const mfem::Vector &x, mfem::Vector &y) const override
Nonlinear Mult (Used by Newton-solver not necessarily nonlinear)
virtual void FormSystemOperator(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS) override
Form matrix-free representation of system operator.
virtual void BuildMixedBilinearForms() override
Build mixed bilinear forms (off-diagonal Jacobian contributions)
virtual void SetTrialVariablesFromTrueVectors(const mfem::BlockVector &trueX) const override
Update variable from solution vector after solve.
NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexEssentialBC > > > _cmplx_essential_bc_map
NamedFieldsMap< mfem::ParSesquilinearForm > _slfs
virtual void BuildBilinearForms() override
Build bilinear forms (diagonal Jacobian contributions)
virtual void Init(GridFunctions &gridfunctions, ComplexGridFunctions &cmplx_gridfunctions, mfem::AssemblyLevel assembly_level) override
Initialise.
void ApplyBoundaryLFIntegrators(const std::string &test_var_name, std::shared_ptr< mfem::ParComplexLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC > > > > &integrated_bc_map)
Method for applying LinearFormIntegrators on boundaries from kernels to a ParComplexLinearForm.
void AddComplexKernel(std::shared_ptr< MFEMComplexKernel > kernel)
Add complex kernels.
void AddComplexEssentialConstraint(std::shared_ptr< MFEMComplexEssentialConstraint > constraint)
Add complex essential (volumetric) constraints.
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC > > > > _cmplx_integrated_bc_map
virtual void ApplyEssentialConstraints() override
Update essential boundary markers and all constrained true DoF lists and values.
void ApplyDomainLFIntegrators(const std::string &test_var_name, std::shared_ptr< mfem::ParComplexLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexKernel > > > > &kernels_map)
Method for applying LinearFormIntegrators on domains from kernels to a ParComplexLinearForm.
NamedFieldsMap< mfem::ParComplexLinearForm > _clfs
NamedFieldsMap< NamedFieldsMap< mfem::ParMixedSesquilinearForm > > _mslfs
virtual void FormSystemMatrix(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS) override
Form matrix representation of system operator as a HypreParMatrix.
void AddComplexIntegratedBC(std::shared_ptr< MFEMComplexIntegratedBC > bc)
Add complex integrated BCs.
ComplexGridFunctions _cmplx_eliminated_variables
Pointers to coupled variables not part of the reduced ComplexEquationSystem.
void AddComplexEssentialBCs(std::shared_ptr< MFEMComplexEssentialBC > bc)
Add complex essential BCs.
void CheckConstrainedVariablesAreTrialVariables(const Moose::MFEM::NamedFieldsMap< std::vector< std::shared_ptr< T > > > &map) const
Error if any variable that map holds strongly constrained DoFs for is not a trial variable of this sy...
virtual void AddTestVariableNameIfMissing(const std::string &test_var_name)
Add test variable to EquationSystem.
std::vector< std::string > _coupled_var_names
Names of all trial variables of kernels and boundary conditions added to this EquationSystem.
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
std::vector< mfem::Array< int > > _ess_bdr_markers
std::vector< mfem::ParFiniteElementSpace * > _coupled_pfespaces
Pointers to finite element spaces associated with coupled variables.
bool VectorContainsName(const std::vector< std::string > &the_vector, const std::string &name) const
mfem::Array2D< const mfem::HypreParMatrix * > _h_blocks
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
mfem::OperatorHandle _linear_operator
mfem::AssemblyLevel _assembly_level
virtual void SetTrialVariableNames()
Set trial variable names from subset of coupled variables that have an associated test variable.
std::vector< mfem::Array< int > > _ess_tdof_lists
CoefficientManager * _coefficient_manager
void DeleteHBlocks()
Deletes the HypreParMatrix associated with any pointer stored in _h_blocks, and then proceeds to dele...
std::vector< std::string > _trial_var_names
Subset of _coupled_var_names of all variables corresponding to gridfunctions with degrees of freedom ...
std::vector< std::string > _eliminated_var_names
Names of all coupled variables without a corresponding test variable.
virtual void AddCoupledVariableNameIfMissing(const std::string &coupled_var_name)
Add coupled variable to EquationSystem.
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
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.
int size() const
Returns the number of elements in the map.
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).