LCOV - code coverage report
Current view: top level - src/meshgenerators - ParsedNodeTransformGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 28 30 93.3 %
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 "ParsedNodeTransformGenerator.h"
      11             : #include "CastUniquePointer.h"
      12             : 
      13             : #include <libmesh/int_range.h>
      14             : 
      15             : registerMooseObject("MooseApp", ParsedNodeTransformGenerator);
      16             : 
      17             : const std::string ParsedNodeTransformGenerator::_func_name[] = {
      18             :     "x_function", "y_function", "z_function"};
      19             : 
      20             : InputParameters
      21       14833 : ParsedNodeTransformGenerator::validParams()
      22             : {
      23       14833 :   InputParameters params = MeshGenerator::validParams();
      24       14833 :   params += FunctionParserUtils<false>::validParams();
      25             : 
      26       14833 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      27       14833 :   params.addClassDescription("Applies a transform to a the x,y,z coordinates of a Mesh");
      28       14833 :   params.addParam<ParsedFunctionExpression>(
      29             :       _func_name[0], "x", "Function for the updated x component of the node");
      30       14833 :   params.addParam<ParsedFunctionExpression>(
      31             :       _func_name[1], "y", "Function for the updated y component of the node");
      32       14833 :   params.addParam<ParsedFunctionExpression>(
      33             :       _func_name[2], "z", "Function for the updated z component of the node");
      34             : 
      35       14833 :   params.addParam<std::vector<std::string>>(
      36             :       "constant_names", {}, "Vector of constants used in the parsed function");
      37       14833 :   params.addParam<std::vector<std::string>>(
      38             :       "constant_expressions",
      39             :       {},
      40             :       "Vector of values for the constants in constant_names (can be an FParser expression)");
      41             : 
      42       14833 :   return params;
      43           0 : }
      44             : 
      45         284 : ParsedNodeTransformGenerator::ParsedNodeTransformGenerator(const InputParameters & parameters)
      46         284 :   : MeshGenerator(parameters), FunctionParserUtils<false>(parameters), _input(getMesh("input"))
      47             : {
      48        1136 :   for (const auto i : index_range(_functions))
      49             :   {
      50             :     // Create parsed function
      51         852 :     _functions[i] = std::make_shared<SymFunction>();
      52        1704 :     parsedFunctionSetup(_functions[i],
      53         852 :                         getParam<ParsedFunctionExpression>(_func_name[i]),
      54             :                         "x,y,z",
      55             :                         getParam<std::vector<std::string>>("constant_names"),
      56             :                         getParam<std::vector<std::string>>("constant_expressions"),
      57             :                         comm());
      58             :   }
      59             : 
      60         284 :   _func_params.resize(3);
      61         284 : }
      62             : 
      63             : std::unique_ptr<MeshBase>
      64         272 : ParsedNodeTransformGenerator::generate()
      65             : {
      66         272 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      67             : 
      68       15006 :   for (auto & node : mesh->node_ptr_range())
      69             :   {
      70       29468 :     for (const auto i : make_range(3))
      71       22101 :       _func_params[i] = (*node)(i);
      72             : 
      73       29468 :     for (const auto i : make_range(3))
      74       22101 :       (*node)(i) = evaluate(_functions[i], _func_name[i]);
      75         272 :   }
      76             : 
      77         272 :   return mesh;
      78           0 : }

Generated by: LCOV version 1.14