|
| 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 "MFEMCrossProductAux.h" |
| 13 | +#include "MFEMProblem.h" |
| 14 | +#include "mfem.hpp" |
| 15 | + |
| 16 | +registerMooseObject("MooseApp", MFEMCrossProductAux); |
| 17 | + |
| 18 | +InputParameters |
| 19 | +MFEMCrossProductAux::validParams() |
| 20 | +{ |
| 21 | + InputParameters params = MFEMAuxKernel::validParams(); |
| 22 | + params.addClassDescription("Projects s(x) * (U x V) onto a vector MFEM auxvariable"); |
| 23 | + params.addRequiredParam<VariableName>("first_source_vec", "Vector MFEMVariable U (vdim=3)"); |
| 24 | + params.addRequiredParam<VariableName>("second_source_vec", "Vector MFEMVariable V (vdim=3)"); |
| 25 | + params.addParam<mfem::real_t>( |
| 26 | + "scale_factor", 1.0, "Constant multiplier applied to the cross product"); |
| 27 | + return params; |
| 28 | +} |
| 29 | + |
| 30 | +MFEMCrossProductAux::MFEMCrossProductAux(const InputParameters & parameters) |
| 31 | + : MFEMAuxKernel(parameters), |
| 32 | + _u_var_name(getParam<VariableName>("first_source_vec")), |
| 33 | + _v_var_name(getParam<VariableName>("second_source_vec")), |
| 34 | + _u_var(*getMFEMProblem().getProblemData().gridfunctions.Get(_u_var_name)), |
| 35 | + _v_var(*getMFEMProblem().getProblemData().gridfunctions.Get(_v_var_name)), |
| 36 | + _scale_factor(getParam<mfem::real_t>("scale_factor")), |
| 37 | + _u_coef(&_u_var), |
| 38 | + _v_coef(&_v_var), |
| 39 | + _cross_uv(_u_coef, _v_coef), |
| 40 | + _scale_c(_scale_factor), |
| 41 | + _final_coef(_scale_c, _cross_uv) |
| 42 | +{ |
| 43 | + // Check the target variable type and dimensions |
| 44 | + mfem::ParFiniteElementSpace * fes = _result_var.ParFESpace(); |
| 45 | + const int mesh_dim = fes->GetMesh()->Dimension(); |
| 46 | + |
| 47 | + // Enforce 3D cross product |
| 48 | + if (mesh_dim != 3) |
| 49 | + mooseError("MFEMCrossProductAux requires a 3D mesh (Dimension == 3)."); |
| 50 | + |
| 51 | + if (fes->GetVDim() != 3) |
| 52 | + mooseError("MFEMCrossProductAux requires AuxVariable to have vdim == 3."); |
| 53 | + |
| 54 | + // Must be L2 |
| 55 | + if (!dynamic_cast<const mfem::L2_FECollection *>(fes->FEColl())) |
| 56 | + mooseError("MFEMCrossProductAux requires the target variable to use L2_FECollection."); |
| 57 | + |
| 58 | + // Must have no shared/constrained DOFs (pure interior DOFs) |
| 59 | + if (fes->GetTrueVSize() != fes->GetVSize()) |
| 60 | + mooseError("MFEMCrossProductAux currently supports only L2 spaces with interior DOFs " |
| 61 | + "(no shared/constrained DOFs)."); |
| 62 | +} |
| 63 | + |
| 64 | +void |
| 65 | +MFEMCrossProductAux::execute() |
| 66 | +{ |
| 67 | + |
| 68 | + // MFEM element projection for L2 |
| 69 | + _result_var = 0.0; |
| 70 | + _result_var.ProjectCoefficient(_final_coef); |
| 71 | +} |
| 72 | + |
| 73 | +#endif // MOOSE_MFEM_ENABLED |
0 commit comments