https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LevelSetMeshingHelper.C
Go to the documentation of this file.
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
11
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}
30
32 : FunctionParserUtils<false>(parameters),
33 _max_level_set_correction_iterations(
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}
53
54Real
56{
57 return evaluate(_func_level_set, std::vector<Real>({point(0), point(1), point(2), 0}));
58}
59
60void
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}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void ErrorVector unsigned int
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
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
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.
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.
void renameParameterGroup(const std::string &old_name, const std::string &new_name)
This method renames a parameter group.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
void levelSetCorrection(Node &node)
Correct the position of a node based on the level set function.
static InputParameters validParams()
SymFunctionPtr _func_level_set
function parser object describing the level set
Real levelSetEvaluator(const Point &point)
Evaluate the level set function at a given point.
LevelSetMeshingHelper(const InputParameters &parameters)
static constexpr Real TOLERANCE