https://mooseframework.inl.gov
MFEMLineValueSampler.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 
12 #include "MFEMLineValueSampler.h"
13 
14 #include "libmesh/point.h"
15 #include "MooseError.h"
16 #include "MFEMProblem.h"
17 
18 #include <vector>
19 
21 
22 namespace
23 {
24 std::vector<Point>
25 generateLinePoints(const Point & start_point, const Point & end_point, unsigned int num_points)
26 {
27  if (num_points < 2)
28  {
29  mooseError("In MFEMLineValueSampler: line must have at least 2 points,"
30  "for single points use MFEMPointValueSampler.");
31  }
32 
33  // initialize and populate vector with linearly-spaced points along line
34  std::vector<Point> points;
35  points.reserve(num_points);
36  for (unsigned int i_point = 0; i_point < num_points; i_point++)
37  {
38  // fractional distance along line [0, 1]
39  Real t = static_cast<Real>(i_point) / static_cast<Real>(num_points - 1);
40  points.push_back(t * end_point + (1 - t) * start_point);
41  }
42 
43  return points;
44 }
45 }
46 
49 {
51 
52  params.addClassDescription("Sample an MFEM variable along a specified line.");
53 
54  // these should not be of type libmesh::Point - need mfem::Point parsing
55  params.addRequiredParam<Point>("start_point", "The beginning of the line");
56  params.addRequiredParam<Point>("end_point", "The ending of the line");
57 
58  params.addRequiredParam<unsigned int>("num_points",
59  "The number of points to sample along the line");
60 
61  return params;
62 }
63 
65  : MFEMValueSamplerBase(parameters,
66  // can't call getParam as that requires initialized base class
67  // so calling parameters.get directly
68  generateLinePoints(parameters.get<Point>("start_point"),
69  parameters.get<Point>("end_point"),
70  parameters.get<unsigned int>("num_points")))
71 {
72 }
73 
74 #endif // MOOSE_MFEM_ENABLED
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
registerMooseObject("MooseApp", MFEMLineValueSampler)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
static InputParameters validParams()
MFEMLineValueSampler(const InputParameters &parameters)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
static InputParameters validParams()
void ErrorVector unsigned int
const Elem & get(const ElemType type_in)