Skip to content

Commit

Permalink
Cleanup extra node set generator (idaholab#14936)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Mar 21, 2020
1 parent 6423990 commit 9c7b2ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
72 changes: 37 additions & 35 deletions framework/src/meshgenerators/ExtraNodesetGenerator.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ExtraNodesetGenerator.h"
#include "MooseApp.h"
#include "MooseMesh.h"
#include "FEProblem.h"
#include "ActionWarehouse.h"
#include "Conversion.h"
#include "MooseMeshUtils.h"
#include "CastUniquePointer.h"

Expand All @@ -32,10 +30,11 @@ ExtraNodesetGenerator::validParams()
"The nodes you want to be in the nodeset "
"(Either this parameter or \"coord\" must be "
"supplied).");
params.addParam<std::vector<Real>>("coord",
"The nodes with coordinates you want to be in the "
"nodeset (Either this parameter or \"nodes\" must be "
"supplied).");
params.addParam<std::vector<std::vector<Real>>>(
"coord",
"The nodes with coordinates you want to be in the "
"nodeset. Separate multple coords with ';' (Either this parameter or \"nodes\" must be "
"supplied).");
params.addParam<Real>(
"tolerance", TOLERANCE, "The tolerance in which two nodes are considered identical");

Expand All @@ -51,20 +50,16 @@ std::unique_ptr<MeshBase>
ExtraNodesetGenerator::generate()
{
std::unique_ptr<MeshBase> mesh = std::move(_input);
const auto coord = getParam<std::vector<std::vector<Real>>>("coord");
const auto nodes = getParam<std::vector<unsigned int>>("nodes");

// make sure the input is not empty
bool data_valid = false;
if (isParamValid("nodes"))
if (getParam<std::vector<unsigned int>>("nodes").size() != 0)
data_valid = true;
if (_pars.isParamValid("coord"))
{
unsigned int n_coord = getParam<std::vector<Real>>("coord").size();
if (n_coord % mesh->mesh_dimension() != 0)
mooseError("Size of node coordinates does not match the mesh dimension");
if (n_coord != 0)
data_valid = true;
}
if (isParamValid("nodes") && nodes.size() != 0)
data_valid = true;
if (_pars.isParamValid("coord") && coord.size() != 0)
data_valid = true;

if (!data_valid)
mooseError("Node set can not be empty!");

Expand All @@ -77,40 +72,49 @@ ExtraNodesetGenerator::generate()
BoundaryInfo & boundary_info = mesh->get_boundary_info();

// add nodes with their ids
const std::vector<unsigned int> & nodes = getParam<std::vector<unsigned int>>("nodes");
for (const auto & node_id : nodes)
for (const auto & boundary_id : boundary_ids)
boundary_info.add_node(node_id, boundary_id);

// add nodes with their coordinates
const std::vector<Real> & coord = getParam<std::vector<Real>>("coord");
unsigned int dim = mesh->mesh_dimension();
unsigned int n_nodes = coord.size() / dim;
const auto dim = mesh->mesh_dimension();

std::unique_ptr<PointLocatorBase> locator = mesh->sub_point_locator();
locator->enable_out_of_mesh_mode();

for (unsigned int i = 0; i < n_nodes; ++i)
const auto tolerance = getParam<Real>("tolerance");
for (const auto & c : coord)
{
Point p;
if (c.size() < dim)
paramError("coord",
"Coordinate ",
Moose::stringify(c),
" does not have enough components for a ",
dim,
"D mesh.");

if (c.size() > 3)
paramError("coord",
"Coordinate ",
Moose::stringify(c),
" has too many components. Did you maybe forget to separate multiple coordinates "
"with a ';'?");

for (unsigned int j = 0; j < dim; ++j)
p(j) = coord[i * dim + j];
p(j) = c[j];

// locate candidate element
bool on_node = false;

bool found_elem = false;
const Elem * elem = (*locator)(p);

if (elem)
{
found_elem = true;
for (unsigned int j = 0; j < elem->n_nodes(); ++j)
{
const Node * node = elem->node_ptr(j);

Point q;
for (unsigned int k = 0; k < dim; ++k)
q(k) = (*node)(k);

if (p.absolute_fuzzy_equals(q, getParam<Real>("tolerance")))
if (p.absolute_fuzzy_equals(*node, tolerance))
{
for (const auto & boundary_id : boundary_ids)
boundary_info.add_node(node, boundary_id);
Expand All @@ -121,8 +125,6 @@ ExtraNodesetGenerator::generate()
}
}

bool found_elem = elem;

// If we are on a distributed mesh, then any particular processor
// may be unable to find any particular node, but *some* processor
// should have found it.
Expand All @@ -138,7 +140,7 @@ ExtraNodesetGenerator::generate()
p);

if (!on_node)
mooseError("Point can not be located!");
mooseError("No node found at point:\n", p);
}

for (unsigned int i = 0; i < boundary_ids.size(); ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
input = gen
type = ExtraNodesetGenerator
new_boundary = central_nodes
coord = '0 0 0 0 0 10'
coord = '0 0 0; 0 0 10'
[../]
[]

Expand Down

0 comments on commit 9c7b2ca

Please sign in to comment.