Skip to content

Commit

Permalink
Merge pull request #28873 from GiudGiud/PR_nodeset_gen
Browse files Browse the repository at this point in the history
Add a versatile nodeset generator
  • Loading branch information
GiudGiud authored Nov 1, 2024
2 parents 41806cb + 28b6fa1 commit af6bed7
Show file tree
Hide file tree
Showing 19 changed files with 816 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ParsedGenerateNodeset

!syntax description /Mesh/ParsedGenerateNodeset

Optionally, additional constraints can be imposed when examining a node based on :

- the subdomain of the element owning the node considered for the nodeset
- whether the node is already part of (or not part of) an existing boundary
- whether the node is 'external', e.g. it lies on the mesh exterior boundary

!syntax parameters /Mesh/ParsedGenerateNodeset

!syntax inputs /Mesh/ParsedGenerateNodeset

!syntax children /Mesh/ParsedGenerateNodeset

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

!syntax description /Mesh/ParsedGenerateSideset

Optionally, additional constraints can be imposed when examining a node based on :

- the side's normal
- the subdomain of the element owning the side considered for the sideset
- the neighbor of this element, on the other side of the side
- whether the side is already part of (or not part of) an existing boundary
- whether the side is 'external', e.g. it lies on the mesh exterior boundary

!syntax parameters /Mesh/ParsedGenerateSideset

!syntax inputs /Mesh/ParsedGenerateSideset
Expand Down
111 changes: 111 additions & 0 deletions framework/include/meshgenerators/NodeSetsGeneratorBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "MeshGenerator.h"

/*
* Base class for mesh generators that add nodesets to the mesh
*/
class NodeSetsGeneratorBase : public MeshGenerator
{
public:
static InputParameters validParams();

NodeSetsGeneratorBase(const InputParameters & parameters);

protected:
/**
* This method prepares a few attributes which are commonly needed for nodeset generation such
* as a map from nodes to elements, and checks the existence and validity of several user
* parameters
*/
void setup(MeshBase & mesh);

/**
* Determines whether the node is on the exterior of the mesh
* @param node node of interest
* @param node_elems vector of the ids of all the elements sharing this node
* @param mesh mesh which contains the node
*/
bool nodeOnMeshExteriorBoundary(const Node * node,
const std::vector<dof_id_type> & node_elems,
const MeshBase & mesh) const;

/**
* Determines whether any neighbor element of the node has a subdomain id in the given
* subdomain_id_list.
* @param node_elems vector of the ids of all the elements sharing this node
* @param mesh mesh which contains the node (and the elements)
*/
bool nodeElementsInIncludedSubdomains(const std::vector<dof_id_type> node_elems,
const MeshBase & mesh) const;

/**
* Determines whether the given node belongs to any nodesets in the
* included_nodesets parameter.
* @param node_nodesets vector of the ids of all the nodesets the node is part of
*/
bool nodeInIncludedNodesets(const std::vector<BoundaryID> & node_nodesets) const;

/**
* Determines whether the given node of an element belongs to any nodesets in the
* excluded_nodesets parameter.
* @param node_nodesets vector of the ids of all the nodesets the node is part of
*/
bool nodeInExcludedNodesets(const std::vector<BoundaryID> & node_nodesets) const;

/**
* Determines whether the given node satisfies the user-specified constraints
* @param node node of interest
* @param node_nodesets vector of the ids of all the nodesets the node is part of
* @param node_elems vector of the ids of all the elements sharing this node
* @param mesh mesh which contains the node
*/
bool nodeSatisfiesRequirements(const Node * node,
const std::vector<BoundaryID> & node_nodesets,
const std::vector<dof_id_type> & node_elems,
const MeshBase & mesh) const;

/// the mesh to add the nodesets to
std::unique_ptr<MeshBase> & _input;

/// The list of new nodeset names
std::vector<BoundaryName> _nodeset_names;

/// Whether or not to remove the old nodesets (all of them, if any) when adding nodesets
const bool _replace;

/// whether to check nodeset ids against the included nodeset list when adding nodes or not
const bool _check_included_nodesets;

/// whether to check nodeset ids against the excluded nodeset list when adding nodes or not
const bool _check_excluded_nodesets;

/// whether to check subdomain ids of the element that included this node
const bool _check_included_subdomains;

/// A list of nodeset ids that the node has to be part of, extracted from the included_nodesets parameter
std::vector<boundary_id_type> _included_nodeset_ids;

/// A list of nodeset ids that the node must not be a part of, extracted from the excluded_nodesets parameter
std::vector<boundary_id_type> _excluded_nodeset_ids;

/// A list of included subdomain ids that the node has to be part of, extracted from the included_subdomains parameter
std::vector<subdomain_id_type> _included_subdomain_ids;

/// Whether to only include external node when considering nodes to add to the nodeset
const bool _include_only_external_nodes;

/// A map from nodes (ids) to local elements (ids) which comprise the node
// Build the node to element map, which is usually provided by a MooseMesh but here we have a
// MeshBase.
std::unordered_map<dof_id_type, std::vector<dof_id_type>> _node_to_elem_map;
};
36 changes: 36 additions & 0 deletions framework/include/meshgenerators/ParsedGenerateNodeset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "FunctionParserUtils.h"
#include "NodeSetsGeneratorBase.h"
#include "libmesh/point.h"

/**
* MeshGenerator for defining a nodeset by a parsed expression
*/
class ParsedGenerateNodeset : public NodeSetsGeneratorBase, public FunctionParserUtils<false>
{
public:
static InputParameters validParams();

ParsedGenerateNodeset(const InputParameters & parameters);

std::unique_ptr<MeshBase> generate() override;

protected:
/// function expression
std::string _function;

/// function parser object describing the combinatorial geometry
SymFunctionPtr _func_F;

usingFunctionParserUtilsMembers(false);
};
7 changes: 4 additions & 3 deletions framework/include/meshgenerators/ParsedGenerateSideset.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
#include "libmesh/point.h"

/**
* MeshGenerator for defining a Sideset by a parsed expression and
* optionally by looking at the subdomain a side's element belongs to
* and the side's normal vector
* MeshGenerator for defining a sideset by a parsed expression and
* optionally by considering additional constraints on sides being included, for example
* based on their normal, on the subdomains of the element owning the side, or on pre-existing
* sidesets in the mesh
*/
class ParsedGenerateSideset : public SideSetsGeneratorBase, public FunctionParserUtils<false>
{
Expand Down
Loading

0 comments on commit af6bed7

Please sign in to comment.