LCOV - code coverage report
Current view: top level - src/actions - AddNodalNormalsAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 51 51 100.0 %
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 "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         384 : AddNodalNormalsAction::validParams()
      25             : {
      26         384 :   InputParameters params = Action::validParams();
      27         384 :   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        1152 :   params.addParam<std::vector<BoundaryName>>(
      32             :       "boundary",
      33             :       {"ANY_BOUNDARY_ID"},
      34             :       "The boundary ID or name where the normals will be computed");
      35         384 :   params.addParam<BoundaryName>("corner_boundary", "boundary ID or name with nodes at 'corners'");
      36         384 :   MooseEnum orders("FIRST SECOND", "FIRST");
      37         384 :   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         768 :   return params;
      44         768 : }
      45             : 
      46         180 : AddNodalNormalsAction::AddNodalNormalsAction(const InputParameters & parameters)
      47             :   : Action(parameters),
      48         180 :     _boundary(getParam<std::vector<BoundaryName>>("boundary")),
      49         180 :     _has_corners(isParamValid("corner_boundary")),
      50         360 :     _corner_boundary(_has_corners ? getParam<BoundaryName>("corner_boundary") : BoundaryName())
      51             : {
      52         180 : }
      53             : 
      54             : void
      55         540 : AddNodalNormalsAction::act()
      56             : {
      57             :   // Set the order from the input
      58         540 :   auto enum_order = getParam<MooseEnum>("order");
      59         540 :   Order order = Utility::string_to_enum<Order>(enum_order);
      60         540 :   FEFamily family = LAGRANGE;
      61             : 
      62         540 :   auto var_params = _factory.getValidParams("MooseVariable");
      63         540 :   var_params.set<MooseEnum>("family") = "LAGRANGE";
      64         540 :   var_params.set<MooseEnum>("order") = enum_order;
      65             : 
      66             :   // Add 3 aux variables for each component of the normal
      67         540 :   if (_current_task == "add_aux_variable")
      68             :   {
      69         180 :     _problem->addAuxVariable("MooseVariable", "nodal_normal_x", var_params);
      70         180 :     _problem->addAuxVariable("MooseVariable", "nodal_normal_y", var_params);
      71         180 :     _problem->addAuxVariable("MooseVariable", "nodal_normal_z", var_params);
      72             :   }
      73             : 
      74             :   // Set the execute options
      75         540 :   ExecFlagEnum execute_options = MooseUtils::getDefaultExecFlagEnum();
      76        1620 :   execute_options = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
      77             : 
      78             :   // Create the NodalNormalsPreprocessor UserObject
      79         540 :   if (_current_task == "add_postprocessor")
      80             :   {
      81         180 :     InputParameters pars = _factory.getValidParams("NodalNormalsPreprocessor");
      82         180 :     pars.set<Order>("fe_order") = order;
      83         180 :     pars.set<FEFamily>("fe_family") = family;
      84         180 :     pars.set<ExecFlagEnum>("execute_on") = execute_options;
      85         180 :     pars.set<std::vector<BoundaryName>>("surface_boundary") = _boundary;
      86             : 
      87         180 :     if (_has_corners)
      88         132 :       pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
      89             : 
      90         180 :     _problem->addUserObject("NodalNormalsPreprocessor", "nodal_normals_preprocessor", pars);
      91         180 :   }
      92             : 
      93         540 :   if (_current_task == "add_user_object")
      94             :   {
      95             :     /// Create the NodalNormalsCorner UserObject (only if corner boundary is given)
      96         180 :     if (_has_corners)
      97             :     {
      98         132 :       InputParameters pars = _factory.getValidParams("NodalNormalsCorner");
      99         132 :       pars.set<ExecFlagEnum>("execute_on") = execute_options;
     100         132 :       pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
     101         132 :       pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
     102         132 :       _problem->addUserObject("NodalNormalsCorner", "nodal_normals_corner", pars);
     103         132 :     }
     104             : 
     105             :     /// Create the NodalNormalsEvaluator UserObject
     106             :     {
     107         180 :       InputParameters pars = _factory.getValidParams("NodalNormalsEvaluator");
     108         180 :       pars.set<ExecFlagEnum>("execute_on") = execute_options;
     109         180 :       pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
     110         180 :       _problem->addUserObject("NodalNormalsEvaluator", "nodal_normals_evaluator", pars);
     111         180 :     }
     112             :   }
     113        1080 : }

Generated by: LCOV version 1.14