LCOV - code coverage report
Current view: top level - src/actioncomponents - ComponentMeshTransformHelper.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 41 43 95.3 %
Date: 2025-07-17 01:28:37 Functions: 3 4 75.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 "ComponentMeshTransformHelper.h"
      11             : #include "RotationMatrix.h"
      12             : #include "Factory.h"
      13             : #include "MooseApp.h"
      14             : 
      15             : InputParameters
      16         343 : ComponentMeshTransformHelper::validParams()
      17             : {
      18         343 :   auto params = ActionComponent::validParams();
      19             : 
      20             :   // If your component is 0D, you should make these two parameters private!
      21         343 :   params.addParam<RealVectorValue>(
      22             :       "rotation",
      23             :       "Rotation angles (XZX convention, in degrees NOT radians) to rotate the "
      24             :       "mesh of this component with. Note that this rotation "
      25             :       "is applied before the translation.");
      26         343 :   params.addParam<RealVectorValue>(
      27             :       "direction",
      28             :       "Direction to orient the component mesh with, assuming it is initially oriented along the "
      29             :       "X-axis (1, 0, 0). Note that this rotation is applied before the translation.");
      30             :   // Position is widely applicable to components
      31        1029 :   params.addParam<Point>(
      32         686 :       "position", Point(0., 0., 0.), "Vector to translate the mesh of this component by.");
      33             : 
      34         343 :   params.addParamNamesToGroup("rotation direction position",
      35             :                               "Position and orientation of the component");
      36         343 :   return params;
      37           0 : }
      38             : 
      39         144 : ComponentMeshTransformHelper::ComponentMeshTransformHelper(const InputParameters & params)
      40             :   : ActionComponent(params),
      41         144 :     _rotation(queryParam<RealVectorValue>("rotation")),
      42         144 :     _direction(queryParam<RealVectorValue>("direction")),
      43         288 :     _translation(getParam<Point>("position"))
      44             : {
      45         144 :   addRequiredTask("add_mesh_generator");
      46         144 :   checkSecondParamNotSetIfFirstOneSet("rotation", "direction");
      47         144 : }
      48             : 
      49             : void
      50         144 : ComponentMeshTransformHelper::addMeshGenerators()
      51             : {
      52             :   // Rotate the mesh as desired
      53         144 :   if (_rotation || _direction)
      54             :   {
      55         144 :     InputParameters params = _factory.getValidParams("TransformGenerator");
      56         144 :     params.set<MeshGeneratorName>("input") = _mg_names.back();
      57         144 :     params.set<MooseEnum>("transform") = "ROTATE";
      58         144 :     if (_rotation)
      59           0 :       params.set<RealVectorValue>("vector_value") = *_rotation;
      60             :     else
      61             :     {
      62             :       const auto rotation_matrix =
      63         144 :           RotationMatrix::rotVec1ToVec2<false>(RealVectorValue(1, 0, 0), *_direction);
      64         144 :       RealVectorValue angles;
      65         144 :       angles(0) = std::atan2(rotation_matrix(1, 0), rotation_matrix(0, 0));
      66         144 :       angles(1) = std::asin(-rotation_matrix(2, 0));
      67         144 :       angles(2) = std::atan2(rotation_matrix(2, 1), rotation_matrix(2, 2));
      68         144 :       params.set<RealVectorValue>("vector_value") = angles / M_PI_2 * 90;
      69         144 :     }
      70         288 :     _app.getMeshGeneratorSystem().addMeshGenerator(
      71         288 :         "TransformGenerator", name() + "_rotated", params);
      72         144 :     _mg_names.push_back(name() + "_rotated");
      73         144 :   }
      74             : 
      75             :   // Add a translation
      76             :   {
      77         144 :     InputParameters params = _factory.getValidParams("TransformGenerator");
      78         144 :     params.set<MeshGeneratorName>("input") = _mg_names.back();
      79         144 :     params.set<MooseEnum>("transform") = "TRANSLATE";
      80         144 :     params.set<RealVectorValue>("vector_value") = getParam<Point>("position");
      81         288 :     _app.getMeshGeneratorSystem().addMeshGenerator(
      82         288 :         "TransformGenerator", name() + "_translated", params);
      83         144 :     _mg_names.push_back(name() + "_translated");
      84         144 :   }
      85         144 : }

Generated by: LCOV version 1.14