LCOV - code coverage report
Current view: top level - src/mfem/vectorpostprocessors - MFEMLineValueSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 20 23 87.0 %
Date: 2026-05-29 20:35:17 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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 "MFEMLineValueSampler.h"
      13             : 
      14             : #include "libmesh/point.h"
      15             : #include "MooseError.h"
      16             : #include "MFEMProblem.h"
      17             : 
      18             : #include <vector>
      19             : 
      20             : registerMooseObject("MooseApp", MFEMLineValueSampler);
      21             : 
      22             : namespace
      23             : {
      24             : std::vector<Point>
      25         248 : generateLinePoints(const Point & start_point, const Point & end_point, unsigned int num_points)
      26             : {
      27         248 :   if (num_points < 2)
      28             :   {
      29           0 :     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         248 :   std::vector<Point> points;
      35         248 :   points.reserve(num_points);
      36        3462 :   for (unsigned int i_point = 0; i_point < num_points; i_point++)
      37             :   {
      38             :     // fractional distance along line [0, 1]
      39        3214 :     Real t = static_cast<Real>(i_point) / static_cast<Real>(num_points - 1);
      40        3214 :     points.push_back(t * end_point + (1 - t) * start_point);
      41             :   }
      42             : 
      43         248 :   return points;
      44           0 : }
      45             : }
      46             : 
      47             : InputParameters
      48        2594 : MFEMLineValueSampler::validParams()
      49             : {
      50        2594 :   InputParameters params = MFEMValueSamplerBase::validParams();
      51             : 
      52        5188 :   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       10376 :   params.addRequiredParam<Point>("start_point", "The beginning of the line");
      56       10376 :   params.addRequiredParam<Point>("end_point", "The ending of the line");
      57             : 
      58        7782 :   params.addRequiredParam<unsigned int>("num_points",
      59             :                                         "The number of points to sample along the line");
      60             : 
      61        2594 :   return params;
      62           0 : }
      63             : 
      64         248 : MFEMLineValueSampler::MFEMLineValueSampler(const InputParameters & parameters)
      65             :   : MFEMValueSamplerBase(parameters,
      66             :                          // can't call getParam as that requires initialized base class
      67             :                          // so calling parameters.get directly
      68         496 :                          generateLinePoints(parameters.get<Point>("start_point"),
      69         248 :                                             parameters.get<Point>("end_point"),
      70         496 :                                             parameters.get<unsigned int>("num_points")))
      71             : {
      72         248 : }
      73             : 
      74             : #endif // MOOSE_MFEM_ENABLED

Generated by: LCOV version 1.14