Line data Source code
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 "MFEML2ZienkiewiczZhuIndicator.h" 13 : #include "MFEMProblem.h" 14 : #include "MFEMKernel.h" 15 : 16 : registerMooseObject("MooseApp", MFEML2ZienkiewiczZhuIndicator); 17 : 18 : InputParameters 19 2150 : MFEML2ZienkiewiczZhuIndicator::validParams() 20 : { 21 2150 : InputParameters params = MFEMIndicator::validParams(); 22 8600 : params.addParam<MFEMFESpaceName>("flux_fespace", "FE space to write the flux into"); 23 6450 : params.addParam<MFEMFESpaceName>("smooth_flux_fespace", "FE space to write the smooth flux into"); 24 2150 : return params; 25 0 : } 26 : 27 : // Make sure we don't do this until all the grid functions etc are set up! 28 26 : MFEML2ZienkiewiczZhuIndicator::MFEML2ZienkiewiczZhuIndicator(const InputParameters & params) 29 26 : : MFEMIndicator(params) 30 : { 31 : // fetch the flux_fespace from the object system 32 78 : if (auto * sn = queryParam<MFEMFESpaceName>("flux_fespace")) 33 0 : _flux_fes = getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace", *sn).getFESpace(); 34 : 35 : // fetch the smooth_flux_fespace from the object system 36 78 : if (auto * sn = queryParam<MFEMFESpaceName>("smooth_flux_fespace")) 37 0 : _smooth_flux_fes = getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace", *sn).getFESpace(); 38 26 : } 39 : 40 : void 41 26 : MFEML2ZienkiewiczZhuIndicator::createEstimator() 42 : { 43 : // fetch the kernel first so we can build an auxiliary blf integrator 44 52 : MFEMKernel & kernel = getMFEMProblem().getMFEMObject<MFEMKernel>("Kernel", _kernel_name); 45 26 : _integ = std::unique_ptr<mfem::BilinearFormIntegrator>(kernel.createBFIntegrator()); 46 : 47 : // Next, we need to check that this integrator is supported by mfem::L2ZienkiewiczZhuEstimator 48 26 : [[maybe_unused]] bool is_supported = false; 49 : 50 : // Check it correctly casts into DiffusionIntegrator 51 26 : is_supported |= (dynamic_cast<mfem::DiffusionIntegrator *>(_integ.get()) != nullptr); 52 : // Check it correctly casts into CurlCurlIntegrator 53 26 : is_supported |= (dynamic_cast<mfem::CurlCurlIntegrator *>(_integ.get()) != nullptr); 54 : // Check it correctly casts into ElasticityIntegrator 55 26 : is_supported |= (dynamic_cast<mfem::ElasticityIntegrator *>(_integ.get()) != nullptr); 56 : 57 26 : if (!is_supported) 58 0 : mooseError("MFEML2ZienkiewiczZhuIndicator only supports MFEMDiffusionKernel, " 59 : "MFEMCurlCurlKernel and MFEMLinearElasticityKernel"); 60 : 61 26 : int order = getFESpace().GetMaxElementOrder(); 62 26 : int dim = getParMesh().Dimension(); 63 26 : int sdim = getParMesh().SpaceDimension(); 64 : 65 26 : if (!_flux_fes) 66 : { 67 : // not supplied by the user - default to L2 68 26 : _flux_fec = std::make_unique<mfem::L2_FECollection>(order, dim); 69 26 : _flux_fes = std::make_unique<mfem::ParFiniteElementSpace>(&getParMesh(), _flux_fec.get(), sdim); 70 : } 71 : 72 26 : if (!_smooth_flux_fes) 73 : { 74 : // not supplied by the user - default to H1 75 26 : _smooth_flux_fec = std::make_unique<mfem::H1_FECollection>(order, dim); 76 : _smooth_flux_fes = 77 26 : std::make_unique<mfem::ParFiniteElementSpace>(&getParMesh(), _smooth_flux_fec.get(), sdim); 78 : } 79 : 80 : // fetch the grid function we need 81 26 : auto gridfunction = getMFEMProblem().getGridFunction(_var_name); 82 : 83 : // finally, initialise the estimator 84 52 : _error_estimator = std::make_shared<mfem::L2ZienkiewiczZhuEstimator>( 85 52 : *_integ, *gridfunction, *_flux_fes, *_smooth_flux_fes); 86 26 : } 87 : 88 : #endif