14 #include "libmesh/elem.h" 15 #include "libmesh/boundary_info.h" 16 #include "libmesh/mesh_base.h" 31 "subdomain_name",
"projected",
"Name of the subdomain of the projected surface");
34 "Maximum distance from the sideset to search for the projected point in " 35 "the projection direction.");
39 "input",
"The input mesh generator in which the sideset exists.");
40 params.
addRequiredParam<BoundaryName>(
"sideset",
"The name of the sideset to project");
45 "Level set to define the surface to project onto as a function of x, y, and z. The surface " 46 "should be 'in front of' the sideset when following the projection direction.");
47 params.
addParam<std::vector<std::string>>(
48 "constant_names", {},
"Vector of constants used in the parsed function");
49 params.
addParam<std::vector<std::string>>(
50 "constant_expressions",
52 "Vector of values for the constants in constant_names (can be an FParser expression)");
53 params.
addParamNamesToGroup(
"level_set constant_names constant_expressions",
"Level set surface");
56 "Projects a sideset onto a surface defined by a level set and creates a surface mesh.");
65 _input_name(getParam<MeshGeneratorName>(
"input")),
66 _input(getMeshByName(_input_name)),
67 _level_set(getParam<
std::string>(
"level_set")),
68 _max_search_distance(getParam<
Real>(
"max_search_distance"))
75 getParam<std::vector<std::string>>(
"constant_names"),
76 getParam<std::vector<std::string>>(
"constant_expressions"),
81 auto proj_d = getParam<Point>(
"direction");
82 if (MooseUtils::absoluteFuzzyEqual(proj_d.norm_sq(), 0))
87 std::unique_ptr<MeshBase>
90 auto mesh_uptr = std::move(
_input);
91 auto mesh = mesh_uptr.get();
94 if (!mesh_uptr->is_serial())
95 paramError(
"input",
"Input mesh must not be distributed");
100 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
101 const auto bdry_side_list = boundary_info.build_side_list();
102 const auto side_id = boundary_info.get_id_by_name(getParam<BoundaryName>(
"sideset"));
105 for (
const auto & [elem_id, side_i, bc_id] : bdry_side_list)
111 std::unique_ptr<Elem> side_elem =
mesh->elem_ptr(elem_id)->build_side_ptr(side_i);
112 const auto n_nodes = side_elem->n_nodes();
113 const auto side_type = side_elem->type();
114 std::vector<Node *> new_nodes(
n_nodes);
118 const auto start = side_elem->point(i);
126 mooseError(
"Projection of polygonal sides is not supported at this time");
127 std::unique_ptr<Elem> new_elem = Elem::build(side_type);
129 new_elem->set_node(i, new_nodes[i]);
132 new_elem->subdomain_id() = projection_block_id;
134 new_mesh->add_elem(std::move(new_elem));
137 new_mesh->subdomain_name(projection_block_id) = getParam<SubdomainName>(
"subdomain_name");
138 new_mesh->unset_is_prepared();
144 const Point & point2)
149 if (MooseUtils::absoluteFuzzyEqual(dist1, 0.0) || MooseUtils::absoluteFuzzyEqual(dist2, 0.0))
150 mooseError(
"At least one of the two points are on the plane.");
151 if (MooseUtils::absoluteFuzzyGreaterThan(dist1 * dist2, 0.0))
152 mooseError(
"The two points are on the same side of the plane.");
160 unsigned int num_its = 0;
161 while (MooseUtils::absoluteFuzzyGreaterThan(dist, 0.0) && num_its < 1e3)
164 mid_point = 0.5 * (p1 + p2);
169 else if (dist_mid * dist1 < 0.0)
173 dist =
abs(dist1) +
abs(dist2);
179 dist =
abs(dist1) +
abs(dist2);
185 ". Is the level set 'in front of' the sideset when following the projection " GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
ProjectSideSetOntoLevelSetGenerator(const InputParameters ¶meters)
registerMooseObject("MooseApp", ProjectSideSetOntoLevelSetGenerator)
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
const boundary_id_type side_id
std::unique_ptr< MeshBase > & _input
Reference to input mesh pointer.
const Parallel::Communicator & comm() const
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
Point _proj_dir
Projection direction.
SymFunctionPtr _func_level_set
function parser object describing the level set
static InputParameters validParams()
const std::string _level_set
The analytic level set function in the form of a string that can be parsed by FParser.
const Real _max_search_distance
Maximum distance to search for from starting nodeset to projection point.
const dof_id_type n_nodes
Point pointPairLevelSetInterception(const Point &point1, const Point &point2)
Calculate the intersection point of a level set and a line segment defined by two points separated by...
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.
static InputParameters validParams()
std::string stringify(const T &t)
conversion to string
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Projects a sideset onto a level set function using a fixed vector.
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
static InputParameters validParams()
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
Build a MeshBase object whose underlying type will be determined by the Mesh input file block...
SubdomainID getNextFreeSubdomainID(MeshBase &input_mesh)
Checks input mesh and returns max(block ID) + 1, which represents a block ID that is not currently in...
Real levelSetEvaluator(const Point &point)
Evaluate the level set function at a given point.
MeshGenerators are objects that can modify or add to an existing mesh.