https://mooseframework.inl.gov
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"))
33  _flux_fes = getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace", *sn).getFESpace();
34 
35  // fetch the smooth_flux_fespace from the object system
36  if (auto * sn = queryParam<MFEMFESpaceName>("smooth_flux_fespace"))
38 }
39 
40 void
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 
72  if (!_smooth_flux_fes)
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
std::shared_ptr< mfem::ParGridFunction > getGridFunction(const std::string &name)
Definition: MFEMProblem.h:323
Wrapper for the Zienkiewicz-Zhu estimator with L2 projection.
virtual void createEstimator() override
Override the createEstimator method to use a Zienkiewicz-Zhu estimator.
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition: MFEMObject.h:45
const VariableName & _var_name
Name of the variable associated with the weak form that the kernel is applied to. ...
Definition: MFEMIndicator.h:45
std::shared_ptr< mfem::FiniteElementCollection > _flux_fec
Finite element collection for the discontinuous flux.
std::shared_ptr< mfem::ParFiniteElementSpace > _flux_fes
Finite element space for the discontinuous flux.
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.
Definition: MFEMProblem.h:377
static InputParameters validParams()
Definition: MFEMIndicator.C:16
mfem::ParMesh & getParMesh() const
Get reference to the FE space&#39;s underlying mesh.
Definition: MFEMIndicator.h:38
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< mfem::BilinearFormIntegrator > _integ
Auxiliary blf integrator implementing ComputeElementFlux().
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
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:163
mfem::ParFiniteElementSpace & getFESpace() const
Get reference to FE space using the name we store when setting up this class.
Definition: MFEMIndicator.h:35
std::shared_ptr< mfem::ParFiniteElementSpace > _smooth_flux_fes
Finite element space for the smoothed flux.
const std::string & _kernel_name
Name of the kernel providing the error estimate.
Definition: MFEMIndicator.h:48
std::shared_ptr< mfem::ErrorEstimator > _error_estimator
Shared pointer to the MFEM estimator wrapped by this class.
Definition: MFEMIndicator.h:51
registerMooseObject("MooseApp", MFEML2ZienkiewiczZhuIndicator)
Constructs and stores an mfem::ParFiniteElementSpace object.
Definition: MFEMFESpace.h:20
std::shared_ptr< mfem::FiniteElementCollection > _smooth_flux_fec
Finite element collection for the smoothed flux.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
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...
MFEML2ZienkiewiczZhuIndicator(const InputParameters &parameters)
Class to construct an MFEM integrator to apply to the equation system.
Definition: MFEMKernel.h:21