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 "MFEMSamplerBase.h" 13 : #include "MFEMProblem.h" 14 : #include "MFEMVectorUtils.h" 15 : #include "MooseError.h" 16 : 17 : InputParameters 18 13630 : MFEMSamplerBase::validParams() 19 : { 20 13630 : InputParameters params = MFEMVectorPostprocessor::validParams(); 21 : // The MFEM ordering option names the index that varies fastest in the flattened point vector. 22 54520 : MooseEnum ordering("NODES VDIM", "VDIM", false); 23 54520 : ordering.addDocumentation("NODES", "Point/node index varies fastest: x0 x1 ... y0 y1 ..."); 24 54520 : ordering.addDocumentation("VDIM", 25 : "Spatial-component index varies fastest: x0 y0 z0 x1 y1 z1 ..."); 26 54520 : params.addParam<MooseEnum>( 27 : "point_ordering", ordering, "Ordering style to use for point vector DoFs."); 28 27260 : params.addParam<double>("mesh_boundary_tolerance", 29 27260 : 1e-8, 30 : "Distance from point to mesh boundary below which the point is " 31 : "considered to be on the boundary rather than outside the mesh."); 32 27260 : return params; 33 13630 : } 34 : 35 424 : MFEMSamplerBase::MFEMSamplerBase(const InputParameters & parameters, 36 : const std::vector<Point> & points, 37 424 : mfem::ParMesh & mesh) 38 : : MFEMVectorPostprocessor(parameters), 39 424 : _query_points(points), 40 424 : _mesh(mesh), 41 424 : _finder(this->comm().get()), 42 848 : _points_ordering(getParam<MooseEnum>("point_ordering") == "NODES" ? mfem::Ordering::byNODES 43 : : mfem::Ordering::byVDIM), 44 424 : _points( 45 1272 : Moose::MFEM::libMeshPointsToMFEMVector(points, _mesh.SpaceDimension(), _points_ordering)) 46 : { 47 424 : if (getMFEMProblem().mesh().shouldDisplace()) 48 0 : mooseError("MFEMSamplerBase does not yet support problems with displacement."); 49 : 50 848 : _finder.SetDistanceToleranceForPointsFoundOnBoundary(getParam<double>("mesh_boundary_tolerance")); 51 : 52 424 : _mesh.EnsureNodes(); 53 424 : _finder.Setup(_mesh); 54 424 : _finder.FindPoints(_points, _points_ordering); 55 : 56 424 : const auto mesh_dim = _mesh.SpaceDimension(); 57 1421 : for (const auto i : make_range(mesh_dim)) 58 : { 59 997 : auto & declared = this->declareVector("x_" + std::to_string(i)); 60 997 : declared.resize(points.size()); 61 997 : _declared_points.push_back(declared); 62 : } 63 424 : } 64 : 65 : void 66 422 : MFEMSamplerBase::initialSetup() 67 : { 68 422 : const auto & point_codes = _finder.GetCode(); 69 4019 : for (const auto i : index_range(_query_points)) 70 3603 : if (PointLocationCode(point_codes[i]) == PointLocationCode::NOT_FOUND) 71 6 : mooseError(typeAndName(), " could not find point at ", _query_points[i], "."); 72 416 : } 73 : 74 : void 75 1070 : MFEMSamplerBase::finalize() 76 : { 77 1070 : _points.HostReadWrite(); 78 : 79 1070 : const auto mesh_dim = _mesh.SpaceDimension(); 80 1070 : const auto num_points = _declared_points[0].get().size(); 81 3377 : for (const auto i_dim : index_range(_declared_points)) 82 11447 : for (const auto i_point : make_range(num_points)) 83 9140 : _declared_points[i_dim].get()[i_point] = 84 9140 : _points(Moose::MFEM::MFEMIndex(i_dim, i_point, mesh_dim, num_points, _points_ordering)); 85 : 86 1070 : finalizeValues(); 87 1070 : } 88 : 89 : #endif // MOOSE_MFEM_ENABLED