https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEML2ZienkiewiczZhuIndicator.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
13#include "MFEMProblem.h"
14#include "MFEMKernel.h"
15
17
20{
22 params.addParam<MFEMFESpaceName>("flux_fespace", "FE space to write the flux into");
23 params.addParam<MFEMFESpaceName>("smooth_flux_fespace", "FE space to write the smooth flux into");
24 return params;
25}
26
27// Make sure we don't do this until all the grid functions etc are set up!
29 : MFEMIndicator(params)
30{
31 // fetch the flux_fespace from the object system
32 if (auto * sn = queryParam<MFEMFESpaceName>("flux_fespace"))
34
35 // fetch the smooth_flux_fespace from the object system
36 if (auto * sn = queryParam<MFEMFESpaceName>("smooth_flux_fespace"))
38}
39
40void
42{
43 // fetch the kernel first so we can build an auxiliary blf integrator
45 _integ = std::unique_ptr<mfem::BilinearFormIntegrator>(kernel.createBFIntegrator());
46
47 // Next, we need to check that this integrator is supported by mfem::L2ZienkiewiczZhuEstimator
48 [[maybe_unused]] bool is_supported = false;
49
50 // Check it correctly casts into DiffusionIntegrator
51 is_supported |= (dynamic_cast<mfem::DiffusionIntegrator *>(_integ.get()) != nullptr);
52 // Check it correctly casts into CurlCurlIntegrator
53 is_supported |= (dynamic_cast<mfem::CurlCurlIntegrator *>(_integ.get()) != nullptr);
54 // Check it correctly casts into ElasticityIntegrator
55 is_supported |= (dynamic_cast<mfem::ElasticityIntegrator *>(_integ.get()) != nullptr);
56
57 if (!is_supported)
58 mooseError("MFEML2ZienkiewiczZhuIndicator only supports MFEMDiffusionKernel, "
59 "MFEMCurlCurlKernel and MFEMLinearElasticityKernel");
60
61 int order = getFESpace().GetMaxElementOrder();
62 int dim = getParMesh().Dimension();
63 int sdim = getParMesh().SpaceDimension();
64
65 if (!_flux_fes)
66 {
67 // not supplied by the user - default to L2
68 _flux_fec = std::make_unique<mfem::L2_FECollection>(order, dim);
69 _flux_fes = std::make_unique<mfem::ParFiniteElementSpace>(&getParMesh(), _flux_fec.get(), sdim);
70 }
71
73 {
74 // not supplied by the user - default to H1
75 _smooth_flux_fec = std::make_unique<mfem::H1_FECollection>(order, dim);
77 std::make_unique<mfem::ParFiniteElementSpace>(&getParMesh(), _smooth_flux_fec.get(), sdim);
78 }
79
80 // fetch the grid function we need
81 auto gridfunction = getMFEMProblem().getGridFunction(_var_name);
82
83 // finally, initialise the estimator
84 _error_estimator = std::make_shared<mfem::L2ZienkiewiczZhuEstimator>(
85 *_integ, *gridfunction, *_flux_fes, *_smooth_flux_fes);
86}
87
88#endif
registerMooseObject("MooseApp", MFEML2ZienkiewiczZhuIndicator)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int dim
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
Constructs and stores an mfem::ParFiniteElementSpace object.
Definition MFEMFESpace.h:21
static InputParameters validParams()
mfem::ParFiniteElementSpace & getFESpace() const
Get reference to FE space using the name we store when setting up this class.
const std::string & _kernel_name
Name of the kernel providing the error estimate.
mfem::ParMesh & getParMesh() const
Get reference to the FE space's underlying mesh.
std::shared_ptr< mfem::ErrorEstimator > _error_estimator
Shared pointer to the MFEM estimator wrapped by this class.
const VariableName & _var_name
Name of the variable associated with the weak form that the kernel is applied to.
Class to construct an MFEM integrator to apply to the equation system.
Definition MFEMKernel.h:22
virtual mfem::BilinearFormIntegrator * createBFIntegrator()
Create MFEM integrator to apply to the LHS of the weak form. Ownership managed by the caller.
Definition MFEMKernel.h:34
Wrapper for the Zienkiewicz-Zhu estimator with L2 projection.
MFEML2ZienkiewiczZhuIndicator(const InputParameters &parameters)
std::shared_ptr< mfem::ParFiniteElementSpace > _flux_fes
Finite element space for the discontinuous flux.
std::shared_ptr< mfem::FiniteElementCollection > _smooth_flux_fec
Finite element collection for the smoothed flux.
virtual void createEstimator() override
Override the createEstimator method to use a Zienkiewicz-Zhu estimator.
std::shared_ptr< mfem::FiniteElementCollection > _flux_fec
Finite element collection for the discontinuous flux.
std::unique_ptr< mfem::BilinearFormIntegrator > _integ
Auxiliary blf integrator implementing ComputeElementFlux().
std::shared_ptr< mfem::ParFiniteElementSpace > _smooth_flux_fes
Finite element space for the smoothed flux.
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition MFEMObject.h:45
std::shared_ptr< mfem::ParGridFunction > getGridFunction(const std::string &name)
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.