LCOV - code coverage report
Current view: top level - src/actions - AddNodalNormalsAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 51 51 100.0 %
Date: 2025-08-08 20:01:16 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 "AddNodalNormalsAction.h"
      11             : #include "FEProblem.h"
      12             : #include "Factory.h"
      13             : 
      14             : #include "libmesh/fe.h"
      15             : #include "libmesh/string_to_enum.h"
      16             : 
      17             : using namespace libMesh;
      18             : 
      19             : registerMooseAction("MooseApp", AddNodalNormalsAction, "add_aux_variable");
      20             : registerMooseAction("MooseApp", AddNodalNormalsAction, "add_postprocessor");
      21             : registerMooseAction("MooseApp", AddNodalNormalsAction, "add_user_object");
      22             : 
      23             : InputParameters
      24         399 : AddNodalNormalsAction::validParams()
      25             : {
      26         399 :   InputParameters params = Action::validParams();
      27         399 :   params.addClassDescription("Creates Auxiliary variables and objects for computing the outward "
      28             :                              "facing normal from a node.");
      29             : 
      30             :   // Initialize the 'boundary' input option to default to any boundary
      31        1197 :   params.addParam<std::vector<BoundaryName>>(
      32             :       "boundary",
      33             :       {"ANY_BOUNDARY_ID"},
      34             :       "The boundary ID or name where the normals will be computed");
      35         399 :   params.addParam<BoundaryName>("corner_boundary", "boundary ID or name with nodes at 'corners'");
      36         399 :   MooseEnum orders("FIRST SECOND", "FIRST");
      37         399 :   params.addParam<MooseEnum>("order",
      38             :                              orders,
      39             :                              "Specifies the order of variables that hold the "
      40             :                              "nodal normals. Needs to match the order of the "
      41             :                              "mesh");
      42             : 
      43         798 :   return params;
      44         798 : }
      45             : 
      46         195 : AddNodalNormalsAction::AddNodalNormalsAction(const InputParameters & parameters)
      47             :   : Action(parameters),
      48         195 :     _boundary(getParam<std::vector<BoundaryName>>("boundary")),
      49         195 :     _has_corners(isParamValid("corner_boundary")),
      50         390 :     _corner_boundary(_has_corners ? getParam<BoundaryName>("corner_boundary") : BoundaryName())
      51             : {
      52         195 : }
      53             : 
      54             : void
      55         585 : AddNodalNormalsAction::act()
      56             : {
      57             :   // Set the order from the input
      58         585 :   auto enum_order = getParam<MooseEnum>("order");
      59         585 :   Order order = Utility::string_to_enum<Order>(enum_order);
      60         585 :   FEFamily family = LAGRANGE;
      61             : 
      62         585 :   auto var_params = _factory.getValidParams("MooseVariable");
      63         585 :   var_params.set<MooseEnum>("family") = "LAGRANGE";
      64         585 :   var_params.set<MooseEnum>("order") = enum_order;
      65             : 
      66             :   // Add 3 aux variables for each component of the normal
      67         585 :   if (_current_task == "add_aux_variable")
      68             :   {
      69         195 :     _problem->addAuxVariable("MooseVariable", "nodal_normal_x", var_params);
      70         195 :     _problem->addAuxVariable("MooseVariable", "nodal_normal_y", var_params);
      71         195 :     _problem->addAuxVariable("MooseVariable", "nodal_normal_z", var_params);
      72             :   }
      73             : 
      74             :   // Set the execute options
      75         585 :   ExecFlagEnum execute_options = MooseUtils::getDefaultExecFlagEnum();
      76        1755 :   execute_options = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
      77             : 
      78             :   // Create the NodalNormalsPreprocessor UserObject
      79         585 :   if (_current_task == "add_postprocessor")
      80             :   {
      81         195 :     InputParameters pars = _factory.getValidParams("NodalNormalsPreprocessor");
      82         195 :     pars.set<Order>("fe_order") = order;
      83         195 :     pars.set<FEFamily>("fe_family") = family;
      84         195 :     pars.set<ExecFlagEnum>("execute_on") = execute_options;
      85         195 :     pars.set<std::vector<BoundaryName>>("surface_boundary") = _boundary;
      86             : 
      87         195 :     if (_has_corners)
      88         143 :       pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
      89             : 
      90         195 :     _problem->addUserObject("NodalNormalsPreprocessor", "nodal_normals_preprocessor", pars);
      91         195 :   }
      92             : 
      93         585 :   if (_current_task == "add_user_object")
      94             :   {
      95             :     /// Create the NodalNormalsCorner UserObject (only if corner boundary is given)
      96         195 :     if (_has_corners)
      97             :     {
      98         143 :       InputParameters pars = _factory.getValidParams("NodalNormalsCorner");
      99         143 :       pars.set<ExecFlagEnum>("execute_on") = execute_options;
     100         143 :       pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
     101         143 :       pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
     102         143 :       _problem->addUserObject("NodalNormalsCorner", "nodal_normals_corner", pars);
     103         143 :     }
     104             : 
     105             :     /// Create the NodalNormalsEvaluator UserObject
     106             :     {
     107         195 :       InputParameters pars = _factory.getValidParams("NodalNormalsEvaluator");
     108         195 :       pars.set<ExecFlagEnum>("execute_on") = execute_options;
     109         195 :       pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
     110         195 :       _problem->addUserObject("NodalNormalsEvaluator", "nodal_normals_evaluator", pars);
     111         195 :     }
     112             :   }
     113        1170 : }

Generated by: LCOV version 1.14