LCOV - code coverage report
Current view: top level - src/positions - TransformedPositions.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 45 49 91.8 %
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 "TransformedPositions.h"
      11             : #include "GeometryUtils.h"
      12             : 
      13             : registerMooseObject("MooseApp", TransformedPositions);
      14             : 
      15             : InputParameters
      16       14337 : TransformedPositions::validParams()
      17             : {
      18       14337 :   InputParameters params = Positions::validParams();
      19             : 
      20       14337 :   params.addRequiredParam<PositionsName>("base_positions",
      21             :                                          "Positions object providing the positions to transform");
      22             : 
      23       14337 :   MooseEnum transforms("TRANSLATE ROTATE_XYZ SCALE");
      24       14337 :   params.addRequiredParam<MooseEnum>(
      25             :       "transform",
      26             :       transforms,
      27             :       "The type of transformation to perform (TRANSLATE, ROTATE_XYZ, SCALE)");
      28       14337 :   params.addParam<RealVectorValue>(
      29             :       "vector_value",
      30             :       "The value to use for the transformation. When using TRANSLATE or SCALE, the "
      31             :       "xyz coordinates are applied in each direction respectively. When using "
      32             :       "ROTATE_XYZ, the values are interpreted as rotations in degrees around the X, Y and Z axis, "
      33             :       "in that order.");
      34             : 
      35             :   // Use base position ordering
      36       14337 :   params.set<bool>("auto_sort") = false;
      37             :   // If the base position is broadcast already we do not need to
      38       14337 :   params.set<bool>("auto_broadcast") = false;
      39             :   // Keep as up-to-date as possible given that the base position could be changing
      40       43011 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_BEGIN};
      41             : 
      42       14337 :   params.addClassDescription(
      43             :       "Transform, with a linear transformation, positions from another Positions object");
      44       28674 :   return params;
      45       28674 : }
      46             : 
      47          36 : TransformedPositions::TransformedPositions(const InputParameters & parameters)
      48             :   : Positions(parameters),
      49          36 :     _transform(getParam<MooseEnum>("transform")),
      50          72 :     _vector_value(getParam<RealVectorValue>("vector_value"))
      51             : {
      52          36 :   const auto & base_name = getParam<PositionsName>("base_positions");
      53          36 :   if (_fe_problem.hasUserObject(base_name))
      54          36 :     _base_positions = &_fe_problem.getPositionsObject(base_name);
      55             :   else
      56           0 :     mooseError("Base positions has not been created yet. If it exists, re-order Positions objects "
      57             :                "in the input file or implement automated construction ordering for Positions");
      58             : 
      59             :   // Obtain the positions from the base, then transform them
      60          36 :   initialize();
      61             :   // Sort if needed (user-specified)
      62          36 :   finalize();
      63          36 : }
      64             : 
      65             : void
      66         102 : TransformedPositions::initialize()
      67             : {
      68         102 :   clearPositions();
      69         102 :   const bool initial = _fe_problem.getCurrentExecuteOnFlag() == EXEC_INITIAL;
      70         102 :   if (!_base_positions->initialized(initial))
      71           0 :     mooseError("Positions '", _base_positions->name(), "' is not initialized.");
      72             : 
      73         102 :   const auto n_positions = _base_positions->getNumPositions(initial);
      74         102 :   _positions.resize(n_positions);
      75             : 
      76         408 :   for (const auto i : make_range(n_positions))
      77             :   {
      78         306 :     const auto & base_point = _base_positions->getPosition(i, initial);
      79         306 :     if (_transform == "ROTATE_XYZ")
      80         102 :       _positions[i] = geom_utils::rotatePointAboutAxis(
      81         102 :           geom_utils::rotatePointAboutAxis(
      82           0 :               geom_utils::rotatePointAboutAxis(
      83         102 :                   base_point, _vector_value(0) / 90 * M_PI_2, Point(1, 0, 0)),
      84         102 :               _vector_value(1) / 90 * M_PI_2,
      85           0 :               Point(0, 1, 0)),
      86         102 :           _vector_value(2) / 90 * M_PI_2,
      87         204 :           Point(0, 0, 1));
      88         204 :     else if (_transform == "SCALE")
      89         102 :       _positions[i] = Point(base_point(0) * _vector_value(0),
      90         102 :                             base_point(1) * _vector_value(1),
      91         102 :                             base_point(2) * _vector_value(2));
      92             :     else
      93         102 :       _positions[i] = Point(base_point(0) + _vector_value(0),
      94         102 :                             base_point(1) + _vector_value(1),
      95         102 :                             base_point(2) + _vector_value(2));
      96             : 
      97         306 :     _initialized = true;
      98             :   }
      99         102 : }

Generated by: LCOV version 1.14