LCOV - code coverage report
Current view: top level - src/meshgenerators - LevelSetMeshingHelper.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 38 44 86.4 %
Date: 2026-05-29 20:35:17 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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 "LevelSetMeshingHelper.h"
      11             : 
      12             : InputParameters
      13        6546 : LevelSetMeshingHelper::validParams()
      14             : {
      15        6546 :   InputParameters params = FunctionParserUtils<false>::validParams();
      16       26184 :   params.renameParameterGroup("Parsed expression advanced", "Level set shape parsed expression");
      17             : 
      18       26184 :   params.addParam<std::string>(
      19             :       "level_set",
      20             :       "Level set used to achieve more accurate reverse projection compared to interpolation.");
      21       19638 :   params.addParam<unsigned int>(
      22             :       "max_level_set_correction_iterations",
      23       13092 :       3,
      24             :       "Maximum number of iterations to correct the nodes based on the level set function.");
      25       19638 :   params.addParamNamesToGroup("level_set max_level_set_correction_iterations",
      26             :                               "Level set shape correction");
      27             : 
      28        6546 :   return params;
      29           0 : }
      30             : 
      31         212 : LevelSetMeshingHelper::LevelSetMeshingHelper(const InputParameters & parameters)
      32             :   : FunctionParserUtils<false>(parameters),
      33         212 :     _max_level_set_correction_iterations(
      34         212 :         parameters.get<unsigned int>("max_level_set_correction_iterations"))
      35             : {
      36         424 :   if (parameters.isParamValid("level_set"))
      37             :   {
      38          67 :     _func_level_set = std::make_shared<SymFunction>();
      39             :     // set FParser internal feature flags
      40          67 :     setParserFeatureFlags(_func_level_set);
      41         268 :     if (parameters.isParamValid("constant_names") &&
      42          67 :         parameters.isParamValid("constant_expressions"))
      43           0 :       addFParserConstants(_func_level_set,
      44           0 :                           parameters.get<std::vector<std::string>>("constant_names"),
      45           0 :                           parameters.get<std::vector<std::string>>("constant_expressions"));
      46         201 :     if (_func_level_set->Parse(parameters.get<std::string>("level_set"), "x,y,z") >= 0)
      47           0 :       mooseError(
      48           0 :           "Invalid function f(x,y,z)\n", _func_level_set, ".\n", _func_level_set->ErrorMsg());
      49             : 
      50          67 :     _func_params.resize(3);
      51             :   }
      52         212 : }
      53             : 
      54             : Real
      55      102747 : LevelSetMeshingHelper::levelSetEvaluator(const Point & point)
      56             : {
      57      410988 :   return evaluate(_func_level_set, std::vector<Real>({point(0), point(1), point(2), 0}));
      58             : }
      59             : 
      60             : void
      61       12264 : LevelSetMeshingHelper::levelSetCorrection(Node & node)
      62             : {
      63             :   // Based on the given level set, we try to move the node in its normal direction
      64       12264 :   const Real diff = libMesh::TOLERANCE * 10.0; // A small value to perturb the node
      65       12264 :   const Real original_eval = levelSetEvaluator(node);
      66       12264 :   const Real xp_eval = levelSetEvaluator(node + Point(diff, 0.0, 0.0));
      67       12264 :   const Real yp_eval = levelSetEvaluator(node + Point(0.0, diff, 0.0));
      68       12264 :   const Real zp_eval = levelSetEvaluator(node + Point(0.0, 0.0, diff));
      69       12264 :   const Real xm_eval = levelSetEvaluator(node - Point(diff, 0.0, 0.0));
      70       12264 :   const Real ym_eval = levelSetEvaluator(node - Point(0.0, diff, 0.0));
      71       12264 :   const Real zm_eval = levelSetEvaluator(node - Point(0.0, 0.0, diff));
      72       12264 :   const Point grad = Point((xp_eval - xm_eval) / (2.0 * diff),
      73       12264 :                            (yp_eval - ym_eval) / (2.0 * diff),
      74       12264 :                            (zp_eval - zm_eval) / (2.0 * diff));
      75       12264 :   const Real xyz_diff = -original_eval / grad.contract(grad);
      76       12264 :   node(0) += xyz_diff * grad(0);
      77       12264 :   node(1) += xyz_diff * grad(1);
      78       12264 :   node(2) += xyz_diff * grad(2);
      79       12264 : }

Generated by: LCOV version 1.14