LCOV - code coverage report
Current view: top level - src/dirackernels - FunctionPointForce.C (source / functions) Hit Total Coverage
Test: idaholab/mastodon: 55510a Lines: 48 52 92.3 %
Date: 2025-08-26 23:09:31 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*************************************************/
       2             : /*           DO NOT MODIFY THIS HEADER           */
       3             : /*                                               */
       4             : /*                     MASTODON                  */
       5             : /*                                               */
       6             : /*    (c) 2015 Battelle Energy Alliance, LLC     */
       7             : /*            ALL RIGHTS RESERVED                */
       8             : /*                                               */
       9             : /*   Prepared by Battelle Energy Alliance, LLC   */
      10             : /*     With the U. S. Department of Energy       */
      11             : /*                                               */
      12             : /*     See COPYRIGHT for full restrictions       */
      13             : /*************************************************/
      14             : #include "Function.h"
      15             : #include "FunctionPointForce.h"
      16             : #include "MooseMesh.h"
      17             : 
      18             : registerMooseObject("MastodonApp", FunctionPointForce);
      19             : 
      20             : InputParameters
      21          16 : FunctionPointForce::validParams()
      22             : {
      23          16 :   InputParameters params = DiracKernel::validParams();
      24          16 :   params.addClassDescription("This class applies a force at the given "
      25             :                              "point/points in a given direction. The force can "
      26             :                              "be given as a function of space and/or time.");
      27          32 :   params.addParam<Real>("alpha", 0.0, "The Hilber Hughes Taylor (HHT) time integration parameter.");
      28          32 :   params.addParam<std::vector<Real>>("point", "The x,y,z coordinates of the point.");
      29          32 :   params.addParam<FunctionName>("x_position",
      30             :                                 "The function containing the x coordinates of the points. "
      31             :                                 "The first column gives point number (starting with 1) and "
      32             :                                 "second column gives x coordinate.");
      33          32 :   params.addParam<FunctionName>("y_position",
      34             :                                 "The function containing the y coordinates of the points. "
      35             :                                 "The first column gives point number (starting with 1) and "
      36             :                                 "second column gives y coordinate.");
      37          32 :   params.addParam<FunctionName>("z_position",
      38             :                                 "The function containing the z coordinates of the points. "
      39             :                                 "The first column gives point number (starting with 1) and "
      40             :                                 "second column gives z coordinate.");
      41          32 :   params.addParam<unsigned int>("number", "The number of points.");
      42          32 :   params.addRequiredParam<FunctionName>(
      43             :       "function", "The function defining the force as a function of space and/or time");
      44          16 :   return params;
      45           0 : }
      46             : 
      47          10 : FunctionPointForce::FunctionPointForce(const InputParameters & parameters) : DiracKernel(parameters)
      48             : {
      49          40 :   if (!isParamValid("point") && !isParamValid("x_position"))
      50           1 :     mooseError("Either the 'point' or a set of points ('x_position') should be "
      51             :                "given as input in the \"",
      52             :                name(),
      53             :                "\" block.");
      54             : 
      55          35 :   if (isParamValid("x_position") && !isParamValid("number"))
      56           1 :     mooseError("The 'number' parameter is required in the \"",
      57             :                name(),
      58             :                "\" block when 'x_position' function is provided.");
      59             : 
      60           8 :   if (_mesh.dimension() > 1)
      61             :   {
      62          30 :     if (isParamValid("x_position") && !isParamValid("y_position"))
      63           1 :       mooseError("The number of position functions should be equal to mesh "
      64             :                  "dimension in the \"",
      65             :                  name(),
      66             :                  "\" block.");
      67             : 
      68           7 :     if (_mesh.dimension() > 2)
      69           4 :       if (isParamValid("x_position") && !isParamValid("z_position"))
      70           1 :         mooseError("The number of position functions should be equal to mesh "
      71             :                    "dimension in the \"",
      72             :                    name(),
      73             :                    "\" block.");
      74             :   }
      75           6 : }
      76             : 
      77             : void
      78          60 : FunctionPointForce::addPoints()
      79             : {
      80         120 :   if (isParamValid("point"))
      81             :   {
      82          90 :     std::vector<Real> point_param = getParam<std::vector<Real>>("point");
      83          30 :     _p(0) = point_param[0];
      84          30 :     if (point_param.size() > 1)
      85             :     {
      86          30 :       _p(1) = point_param[1];
      87          30 :       if (point_param.size() > 2)
      88           0 :         _p(2) = point_param[2];
      89             :     }
      90          30 :     addPoint(_p, 0);
      91          30 :   }
      92          60 :   else if (isParamValid("x_position"))
      93             :   {
      94          60 :     unsigned int number = getParam<unsigned int>("number");
      95             : 
      96         150 :     for (unsigned int i = 0; i < number; ++i)
      97             :     {
      98         120 :       const Function * const function_x = &getFunction("x_position");
      99         120 :       _p(0) = function_x->value(i + 1, Point());
     100             : 
     101         120 :       if (_mesh.dimension() > 1)
     102             :       {
     103         120 :         const Function * const function_y = &getFunction("y_position");
     104         120 :         _p(1) = function_y->value(i + 1, Point());
     105             : 
     106         120 :         if (_mesh.dimension() > 2)
     107             :         {
     108           0 :           const Function * const function_z = &getFunction("z_position");
     109           0 :           _p(2) = function_z->value(i + 1, Point());
     110             :         }
     111             :       }
     112         120 :       addPoint(_p, i);
     113             :     }
     114             :   }
     115          60 : }
     116             : 
     117             : Real
     118         400 : FunctionPointForce::computeQpResidual()
     119             : {
     120         400 :   const Function * const force_function = &getFunction("function");
     121         800 :   Real alpha = getParam<Real>("alpha");
     122             : 
     123         400 :   Real force = force_function->value(_t + alpha * _dt, _qp);
     124             : 
     125         400 :   return -_test[_i][_qp] * force;
     126             : }

Generated by: LCOV version 1.14