LCOV - code coverage report
Current view: top level - src/times - FunctorTimes.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 23 25 92.0 %
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 "FunctorTimes.h"
      11             : 
      12             : registerMooseObject("MooseApp", FunctorTimes);
      13             : 
      14             : InputParameters
      15       14285 : FunctorTimes::validParams()
      16             : {
      17       14285 :   InputParameters params = Times::validParams();
      18       14285 :   params += NonADFunctorInterface::validParams();
      19       14285 :   params.addClassDescription(
      20             :       "Times created by evaluating a functor at the (0,0,0) point and the current time");
      21             : 
      22       14285 :   params.addRequiredParam<MooseFunctorName>("functor", "Functor to evaluate to provide the time");
      23       14285 :   params.addParam<MooseFunctorName>("factor", 1, "Factor to multiply the evaluated time with");
      24             : 
      25             :   // Times are known for all processes already
      26       14285 :   params.set<bool>("auto_broadcast") = false;
      27             :   // Timestep_begin seems like a decent default here
      28       14285 :   params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_BEGIN;
      29             : 
      30       14285 :   return params;
      31           0 : }
      32             : 
      33          10 : FunctorTimes::FunctorTimes(const InputParameters & parameters)
      34             :   : Times(parameters),
      35             :     NonADFunctorInterface(this),
      36          10 :     _functor(getFunctor<Real>("functor")),
      37          20 :     _factor(getFunctor<Real>("factor"))
      38             : {
      39          10 : }
      40             : 
      41             : void
      42          36 : FunctorTimes::initialize()
      43             : {
      44          36 :   _fe_problem.mesh().errorIfDistributedMesh(type());
      45             :   // Locate the origin on the mesh
      46          36 :   Point p(0, 0, 0);
      47          36 :   auto pl = _fe_problem.mesh().getMesh().sub_point_locator();
      48          36 :   auto * elem = (*pl)(p);
      49          36 :   if (!elem)
      50           0 :     mooseError("Origin point not in local mesh, cannot evaluate the functor there");
      51          36 :   Moose::ElemArg elem_origin = makeElemArg(elem);
      52             : 
      53          36 :   const auto t = determineState();
      54             :   // Initialize is by default what is called by ::execute()
      55          36 :   _times.push_back(_factor(elem_origin, t) * _functor(elem_origin, t));
      56             :   // if this is performed multiple times (fixed point iterations, similar results at various
      57             :   // execution flags) it will be caught by our logic to make the vector hold unique times
      58          36 : }

Generated by: LCOV version 1.14