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 "MFEMLineVariableValueSampler.h" 13 : 14 : #include "libmesh/point.h" 15 : #include "MooseError.h" 16 : #include "MFEMProblem.h" 17 : 18 : #include <vector> 19 : 20 : registerMooseObject("MooseApp", MFEMLineVariableValueSampler); 21 : registerMooseObjectRenamed("MooseApp", 22 : MFEMLineValueSampler, 23 : "06/30/2027 24:00", 24 : MFEMLineVariableValueSampler); 25 : 26 : namespace 27 : { 28 : std::vector<Point> 29 262 : generateLinePoints(const Point & start_point, 30 : const Point & end_point, 31 : unsigned int num_points, 32 : const std::string & object_name) 33 : { 34 262 : if (num_points < 2) 35 : { 36 2 : mooseError("In MFEMLineVariableValueSampler \"", 37 : object_name, 38 : "\": line must have at least 2 points, " 39 : "for single points use MFEMPointVariableValueSampler."); 40 : } 41 : 42 : // initialize and populate vector with linearly-spaced points along line 43 260 : std::vector<Point> points; 44 260 : points.reserve(num_points); 45 3611 : for (unsigned int i_point = 0; i_point < num_points; i_point++) 46 : { 47 : // fractional distance along line [0, 1] 48 3351 : Real t = static_cast<Real>(i_point) / static_cast<Real>(num_points - 1); 49 3351 : points.push_back(t * end_point + (1 - t) * start_point); 50 : } 51 : 52 260 : return points; 53 0 : } 54 : } 55 : 56 : InputParameters 57 4782 : MFEMLineVariableValueSampler::validParams() 58 : { 59 4782 : InputParameters params = MFEMVariableValueSamplerBase::validParams(); 60 : 61 9564 : params.addClassDescription("Sample an MFEM variable along a specified line."); 62 : 63 : // these should not be of type libmesh::Point - need mfem::Point parsing 64 19128 : params.addRequiredParam<Point>("start_point", "The beginning of the line"); 65 19128 : params.addRequiredParam<Point>("end_point", "The ending of the line"); 66 : 67 14346 : params.addRequiredParam<unsigned int>("num_points", 68 : "The number of points to sample along the line"); 69 : 70 4782 : return params; 71 0 : } 72 : 73 262 : MFEMLineVariableValueSampler::MFEMLineVariableValueSampler(const InputParameters & parameters) 74 : : MFEMVariableValueSamplerBase(parameters, 75 : // can't call getParam as that requires initialized base class 76 : // so calling parameters.get directly 77 522 : generateLinePoints(parameters.get<Point>("start_point"), 78 262 : parameters.get<Point>("end_point"), 79 262 : parameters.get<unsigned int>("num_points"), 80 522 : parameters.getObjectName())) 81 : { 82 260 : } 83 : 84 : #endif // MOOSE_MFEM_ENABLED