LCOV - code coverage report
Current view: top level - src/positions - FunctorPositions.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 36 38 94.7 %
Date: 2025-07-17 01:28:37 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             : #include "FunctorPositions.h"
      11             : 
      12             : registerMooseObject("MooseApp", FunctorPositions);
      13             : 
      14             : InputParameters
      15       14285 : FunctorPositions::validParams()
      16             : {
      17       14285 :   InputParameters params = Positions::validParams();
      18       14285 :   params += NonADFunctorInterface::validParams();
      19             : 
      20       14285 :   params.addRequiredParam<std::vector<MooseFunctorName>>(
      21             :       "positions_functors", "Functors providing the XYZ coordinates of the positions");
      22             :   // Use user-provided ordering
      23       14285 :   params.set<bool>("auto_sort") = false;
      24             :   // All functors defined on all processes for now
      25       14285 :   params.set<bool>("auto_broadcast") = false;
      26             :   // Keep as up-to-date as possible given the generality of functors
      27       42855 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_BEGIN};
      28             : 
      29       14285 :   params.addClassDescription(
      30             :       "Computes positions from groups of three functors specified by the user");
      31       14285 :   return params;
      32       14285 : }
      33             : 
      34          10 : FunctorPositions::FunctorPositions(const InputParameters & parameters)
      35          10 :   : Positions(parameters), NonADFunctorInterface(this)
      36             : 
      37             : {
      38          10 :   const auto & functor_names = getParam<std::vector<MooseFunctorName>>("positions_functors");
      39             : 
      40             :   // Check input sizes
      41          10 :   if (functor_names.size() % 3 != 0)
      42           0 :     paramError("position_functors",
      43             :                "The list of functors must be divisible by three, the number of coordinates");
      44             : 
      45          70 :   for (const auto & name : functor_names)
      46          60 :     _pos_functors.push_back(&getFunctor<Real>(name));
      47             : 
      48             :   // Obtain the positions by evaluating the functors
      49          10 :   initialize();
      50             :   // Sort if needed (user-specified)
      51          10 :   finalize();
      52          10 : }
      53             : 
      54             : void
      55          46 : FunctorPositions::initialize()
      56             : {
      57          46 :   clearPositions();
      58          46 :   const auto n_positions = _pos_functors.size() / 3;
      59          46 :   _positions.resize(n_positions);
      60             : 
      61             :   // Use the mesh center as a global argument for now
      62          46 :   _fe_problem.mesh().errorIfDistributedMesh(type());
      63             :   // Locate the origin on the mesh
      64          46 :   const Point p(0, 0, 0);
      65          46 :   auto pl = _fe_problem.mesh().getMesh().sub_point_locator();
      66          46 :   auto * const elem = (*pl)(p);
      67          46 :   if (!elem)
      68           0 :     mooseError("Origin point not in local mesh, cannot evaluate the functor there");
      69          46 :   const Moose::ElemPointArg elem_origin = {elem, p, false};
      70          46 :   const auto t = determineState();
      71             : 
      72         138 :   for (auto i : make_range(n_positions))
      73         276 :     _positions[i] = {(*_pos_functors[3 * i])(elem_origin, t),
      74          92 :                      (*_pos_functors[3 * i + 1])(elem_origin, t),
      75          92 :                      (*_pos_functors[3 * i + 2])(elem_origin, t)};
      76          46 :   _initialized = true;
      77          46 : }

Generated by: LCOV version 1.14