https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
LevelSetMeshingHelper Class Reference

Helper class to define, parameterize and create a level set function used in meshing, often to correct the position of nodes on a surface. More...

#include <LevelSetMeshingHelper.h>

Inheritance diagram for LevelSetMeshingHelper:
[legend]

Public Types

typedef GenericSymFunction< is_ad > SymFunction
 Shorthand for an autodiff function parser object.
 
typedef std::shared_ptr< SymFunctionSymFunctionPtr
 Shorthand for an smart pointer to an autodiff function parser object.
 

Public Member Functions

 LevelSetMeshingHelper (const InputParameters &parameters)
 
void setParserFeatureFlags (SymFunctionPtr &) const
 apply input parameters to internal feature flags of the parser object
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Types

enum  FailureMethod
 Enum for failure method. More...
 

Protected Member Functions

Real levelSetEvaluator (const Point &point)
 Evaluate the level set function at a given point.
 
void levelSetCorrection (Node &node)
 Correct the position of a node based on the level set function.
 
GenericReal< is_ad > evaluate (SymFunctionPtr &, const std::string &object_name="")
 Evaluate FParser object and check EvalError.
 
GenericReal< is_ad > evaluate (SymFunctionPtr &, const std::vector< GenericReal< is_ad > > &, const std::string &object_name="")
 Evaluate FParser object and check EvalError.
 
void addFParserConstants (SymFunctionPtr &parser, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions) const
 add constants (which can be complex expressions) to the parser object
 
virtual void functionsOptimize (SymFunctionPtr &parsed_function)
 run FPOptimizer on the parsed function
 
void functionsOptimize (SymFunctionPtr &parsed_function)
 
void functionsOptimize (SymFunctionPtr &parsed_function)
 
void parsedFunctionSetup (SymFunctionPtr &function, const std::string &expression, const std::string &variables, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions, const libMesh::Parallel::Communicator &comm) const
 Performs setup steps on a SymFunction.
 

Protected Attributes

const unsigned int _max_level_set_correction_iterations
 Maximum number of iterations to correct the nodes based on the level set function.
 
SymFunctionPtr _func_level_set
 function parser object describing the level set
 
enum FunctionParserUtils::FailureMethod _evalerror_behavior
 
const Real _quiet_nan
 appropriate not a number value to return
 
std::vector< GenericReal< is_ad > > _func_params
 Array to stage the parameters passed to the functions when calling Eval.
 
const Real _epsilon
 fuzzy comparison tolerance
 
bool _enable_jit
 feature flags
 
bool _enable_ad_cache
 
bool _disable_fpoptimizer
 
bool _enable_auto_optimize
 

Static Protected Attributes

static const char * _eval_error_msg []
 table of FParser eval error codes
 

Detailed Description

Helper class to define, parameterize and create a level set function used in meshing, often to correct the position of nodes on a surface.

Definition at line 19 of file LevelSetMeshingHelper.h.

Member Typedef Documentation

◆ SymFunction

typedef GenericSymFunction<is_ad> FunctionParserUtils< is_ad >::SymFunction
inherited

Shorthand for an autodiff function parser object.

Definition at line 62 of file FunctionParserUtils.h.

◆ SymFunctionPtr

typedef std::shared_ptr<SymFunction> FunctionParserUtils< is_ad >::SymFunctionPtr
inherited

Shorthand for an smart pointer to an autodiff function parser object.

Definition at line 65 of file FunctionParserUtils.h.

Member Enumeration Documentation

◆ FailureMethod

enum FunctionParserUtils::FailureMethod
strongprotectedinherited

Enum for failure method.

Definition at line 116 of file FunctionParserUtils.h.

116{ nan, nan_warning, error, exception } _evalerror_behavior;
enum FunctionParserUtils::FailureMethod _evalerror_behavior

Constructor & Destructor Documentation

◆ LevelSetMeshingHelper()

LevelSetMeshingHelper::LevelSetMeshingHelper ( const InputParameters parameters)

Definition at line 31 of file LevelSetMeshingHelper.C.

32 : FunctionParserUtils<false>(parameters),
34 parameters.get<unsigned int>("max_level_set_correction_iterations"))
35{
36 if (parameters.isParamValid("level_set"))
37 {
38 _func_level_set = std::make_shared<SymFunction>();
39 // set FParser internal feature flags
41 if (parameters.isParamValid("constant_names") &&
42 parameters.isParamValid("constant_expressions"))
44 parameters.get<std::vector<std::string>>("constant_names"),
45 parameters.get<std::vector<std::string>>("constant_expressions"));
46 if (_func_level_set->Parse(parameters.get<std::string>("level_set"), "x,y,z") >= 0)
48 "Invalid function f(x,y,z)\n", _func_level_set, ".\n", _func_level_set->ErrorMsg());
49
50 _func_params.resize(3);
51 }
52}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
void addFParserConstants(SymFunctionPtr &parser, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions) const
add constants (which can be complex expressions) to the parser object
void setParserFeatureFlags(SymFunctionPtr &) const
apply input parameters to internal feature flags of the parser object
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
const unsigned int _max_level_set_correction_iterations
Maximum number of iterations to correct the nodes based on the level set function.
SymFunctionPtr _func_level_set
function parser object describing the level set

Member Function Documentation

◆ addFParserConstants()

void FunctionParserUtils< is_ad >::addFParserConstants ( SymFunctionPtr parser,
const std::vector< std::string > &  constant_names,
const std::vector< std::string > &  constant_expressions 
) const
protectedinherited

add constants (which can be complex expressions) to the parser object

◆ evaluate() [1/2]

GenericReal< is_ad > FunctionParserUtils< is_ad >::evaluate ( SymFunctionPtr ,
const std::string &  object_name = "" 
)
protectedinherited

Evaluate FParser object and check EvalError.

◆ evaluate() [2/2]

GenericReal< is_ad > FunctionParserUtils< is_ad >::evaluate ( SymFunctionPtr ,
const std::vector< GenericReal< is_ad > > &  ,
const std::string &  object_name = "" 
)
protectedinherited

Evaluate FParser object and check EvalError.

This version uses a supplied vector of function parameters, which is useful if an object uses more than one parsed function, which may have different function parameter values.

◆ functionsOptimize() [1/3]

virtual void FunctionParserUtils< is_ad >::functionsOptimize ( SymFunctionPtr parsed_function)
protectedvirtualinherited

run FPOptimizer on the parsed function

◆ functionsOptimize() [2/3]

void FunctionParserUtils< true >::functionsOptimize ( SymFunctionPtr parsed_function)
protectedinherited

◆ functionsOptimize() [3/3]

void FunctionParserUtils< true >::functionsOptimize ( SymFunctionPtr parsed_function)
protectedinherited

Definition at line 211 of file FunctionParserUtils.C.

212{
213 // set desired epsilon for optimization!
214 auto tmp_eps = parsed_function->epsilon();
215 parsed_function->setEpsilon(_epsilon);
216
217 // base function
219 parsed_function->Optimize();
220 if (!_enable_jit || !parsed_function->JITCompile())
221 mooseError("AD parsed objects require JIT compilation to be enabled and working.");
222
223 parsed_function->setEpsilon(tmp_eps);
224}
const Real _epsilon
fuzzy comparison tolerance

◆ levelSetCorrection()

void LevelSetMeshingHelper::levelSetCorrection ( Node &  node)
protected

Correct the position of a node based on the level set function.

Parameters
nodeThe node to be corrected

Definition at line 61 of file LevelSetMeshingHelper.C.

62{
63 // Based on the given level set, we try to move the node in its normal direction
64 const Real diff = libMesh::TOLERANCE * 10.0; // A small value to perturb the node
65 const Real original_eval = levelSetEvaluator(node);
66 const Real xp_eval = levelSetEvaluator(node + Point(diff, 0.0, 0.0));
67 const Real yp_eval = levelSetEvaluator(node + Point(0.0, diff, 0.0));
68 const Real zp_eval = levelSetEvaluator(node + Point(0.0, 0.0, diff));
69 const Real xm_eval = levelSetEvaluator(node - Point(diff, 0.0, 0.0));
70 const Real ym_eval = levelSetEvaluator(node - Point(0.0, diff, 0.0));
71 const Real zm_eval = levelSetEvaluator(node - Point(0.0, 0.0, diff));
72 const Point grad = Point((xp_eval - xm_eval) / (2.0 * diff),
73 (yp_eval - ym_eval) / (2.0 * diff),
74 (zp_eval - zm_eval) / (2.0 * diff));
75 const Real xyz_diff = -original_eval / grad.contract(grad);
76 node(0) += xyz_diff * grad(0);
77 node(1) += xyz_diff * grad(1);
78 node(2) += xyz_diff * grad(2);
79}
Real levelSetEvaluator(const Point &point)
Evaluate the level set function at a given point.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Referenced by Boundary2DDelaunayGenerator::General2DDelaunay(), and SurfaceSubdomainsDelaunayRemesher::General2DDelaunay().

◆ levelSetEvaluator()

Real LevelSetMeshingHelper::levelSetEvaluator ( const Point &  point)
protected

Evaluate the level set function at a given point.

Parameters
pointThe point at which the level set function is to be evaluated
Returns
the value of the level set function at the given point

Definition at line 55 of file LevelSetMeshingHelper.C.

56{
57 return evaluate(_func_level_set, std::vector<Real>({point(0), point(1), point(2), 0}));
58}
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.

Referenced by Boundary2DDelaunayGenerator::General2DDelaunay(), SurfaceSubdomainsDelaunayRemesher::General2DDelaunay(), and levelSetCorrection().

◆ parsedFunctionSetup()

void FunctionParserUtils< is_ad >::parsedFunctionSetup ( SymFunctionPtr function,
const std::string &  expression,
const std::string &  variables,
const std::vector< std::string > &  constant_names,
const std::vector< std::string > &  constant_expressions,
const libMesh::Parallel::Communicator comm 
) const
protectedinherited

Performs setup steps on a SymFunction.

Parameters
functionreference to pointer to the function to set up
expressionexpression to parse
variablescomma separated string holding all the variables of the expression
constant_namesvector of names (symbols) of constants in the expression
constant_expressionsvectors of expressions (=values) of constants in the expression
commcommunicator used to stagger JIT file creations

◆ setParserFeatureFlags()

void FunctionParserUtils< is_ad >::setParserFeatureFlags ( SymFunctionPtr ) const
inherited

apply input parameters to internal feature flags of the parser object

◆ validParams()

InputParameters LevelSetMeshingHelper::validParams ( )
static

Definition at line 13 of file LevelSetMeshingHelper.C.

14{
16 params.renameParameterGroup("Parsed expression advanced", "Level set shape parsed expression");
17
18 params.addParam<std::string>(
19 "level_set",
20 "Level set used to achieve more accurate reverse projection compared to interpolation.");
21 params.addParam<unsigned int>(
22 "max_level_set_correction_iterations",
23 3,
24 "Maximum number of iterations to correct the nodes based on the level set function.");
25 params.addParamNamesToGroup("level_set max_level_set_correction_iterations",
26 "Level set shape correction");
27
28 return params;
29}
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void renameParameterGroup(const std::string &old_name, const std::string &new_name)
This method renames a parameter group.

Referenced by Boundary2DDelaunayGenerator::validParams(), and SurfaceSubdomainsDelaunayRemesher::validParams().

Member Data Documentation

◆ _disable_fpoptimizer

bool FunctionParserUtils< is_ad >::_disable_fpoptimizer
protectedinherited

Definition at line 111 of file FunctionParserUtils.h.

◆ _enable_ad_cache

bool FunctionParserUtils< is_ad >::_enable_ad_cache
protectedinherited

Definition at line 110 of file FunctionParserUtils.h.

◆ _enable_auto_optimize

bool FunctionParserUtils< is_ad >::_enable_auto_optimize
protectedinherited

Definition at line 112 of file FunctionParserUtils.h.

◆ _enable_jit

bool FunctionParserUtils< is_ad >::_enable_jit
protectedinherited

feature flags

Definition at line 109 of file FunctionParserUtils.h.

◆ _epsilon

const Real FunctionParserUtils< is_ad >::_epsilon
protectedinherited

fuzzy comparison tolerance

Definition at line 128 of file FunctionParserUtils.h.

◆ _eval_error_msg

const char* FunctionParserUtils< is_ad >::_eval_error_msg[]
staticprotectedinherited

table of FParser eval error codes

Definition at line 122 of file FunctionParserUtils.h.

◆ _evalerror_behavior

enum FunctionParserUtils::FailureMethod FunctionParserUtils< is_ad >::_evalerror_behavior
protectedinherited

◆ _func_level_set

SymFunctionPtr LevelSetMeshingHelper::_func_level_set
protected

◆ _func_params

std::vector<GenericReal<is_ad> > FunctionParserUtils< is_ad >::_func_params
protectedinherited

Array to stage the parameters passed to the functions when calling Eval.

Definition at line 125 of file FunctionParserUtils.h.

◆ _max_level_set_correction_iterations

const unsigned int LevelSetMeshingHelper::_max_level_set_correction_iterations
protected

Maximum number of iterations to correct the nodes based on the level set function.

Definition at line 28 of file LevelSetMeshingHelper.h.

Referenced by Boundary2DDelaunayGenerator::General2DDelaunay(), and SurfaceSubdomainsDelaunayRemesher::General2DDelaunay().

◆ _quiet_nan

const Real FunctionParserUtils< is_ad >::_quiet_nan
protectedinherited

appropriate not a number value to return

Definition at line 119 of file FunctionParserUtils.h.


The documentation for this class was generated from the following files: