Commit a8267844 authored by Dmitry Yu. Naumov's avatar Dmitry Yu. Naumov Committed by Dmitry Yu. Naumov
Browse files

Pass boolean to create a centre nodes.

The quadratic mesh generation from the quad-4 elements
now can also create a quad-9 element.
parent 2f1654b1
......@@ -36,6 +36,9 @@ int main(int argc, char *argv[])
cmd.add( input_arg );
TCLAP::ValueArg<std::string> output_arg("o", "output-mesh-file","output mesh file",true,"","string");
cmd.add( output_arg );
TCLAP::SwitchArg add_centre_node_arg("c", "add-centre-node",
"add centre node", false);
cmd.add(add_centre_node_arg);
cmd.parse( argc, argv );
std::unique_ptr<MeshLib::Mesh> mesh(
......@@ -46,7 +49,8 @@ int main(int argc, char *argv[])
}
INFO("Create a quadratic order mesh");
auto new_mesh(MeshLib::createQuadraticOrderMesh(*mesh));
auto new_mesh(MeshLib::createQuadraticOrderMesh(
*mesh, add_centre_node_arg.getValue()));
INFO("Save the new mesh into a file");
MeshLib::IO::writeMeshToFile(*new_mesh, output_arg.getValue());
......
......@@ -52,9 +52,50 @@ std::unique_ptr<QuadraticElement> convertLinearToQuadratic(
return std::make_unique<QuadraticElement>(nodes, e.getID());
}
/// Special case for Quad-9 adding a centre node too.
template <>
std::unique_ptr<MeshLib::Quad9> convertLinearToQuadratic<MeshLib::Quad9>(
MeshLib::Element const& e)
{
int const n_all_nodes = MeshLib::Quad9::n_all_nodes;
int const n_base_nodes = MeshLib::Quad9::n_base_nodes;
assert(n_base_nodes == e.getNumberOfBaseNodes());
// Copy base nodes of element to the quadratic element new nodes'.
std::array<MeshLib::Node*, n_all_nodes> nodes{};
for (int i = 0; i < n_base_nodes; i++)
{
nodes[i] = const_cast<MeshLib::Node*>(e.getNode(i));
}
// For each edge create a middle node.
int const number_of_edges = e.getNumberOfEdges();
for (int i = 0; i < number_of_edges; i++)
{
auto const& a = *e.getEdgeNode(i, 0);
auto const& b = *e.getEdgeNode(i, 1);
nodes[n_base_nodes + i] = new MeshLib::Node(
(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2);
}
// Compute the centre point coordinates.
auto* centre_node = new MeshLib::Node(0, 0, 0);
for (int i = 0; i < n_base_nodes; i++)
{
for (int d = 0; d < 3; d++)
{
(*centre_node)[d] += (*nodes[i])[d] / n_base_nodes;
}
}
nodes[n_all_nodes - 1] = centre_node;
return std::make_unique<MeshLib::Quad9>(nodes, e.getID());
}
/// Return a new quadratic element corresponding to the linear element's type.
std::unique_ptr<MeshLib::Element> createQuadraticElement(
MeshLib::Element const& e)
MeshLib::Element const& e, bool const add_centre_node)
{
if (e.getCellType() == MeshLib::CellType::LINE2)
{
......@@ -70,6 +111,10 @@ std::unique_ptr<MeshLib::Element> createQuadraticElement(
}
if (e.getCellType() == MeshLib::CellType::QUAD4)
{
if (add_centre_node)
{
return convertLinearToQuadratic<MeshLib::Quad9>(e);
}
return convertLinearToQuadratic<MeshLib::Quad8>(e);
}
if (e.getCellType() == MeshLib::CellType::HEX8)
......@@ -91,7 +136,8 @@ struct nodeByCoordinatesComparator
namespace MeshLib
{
std::unique_ptr<Mesh> createQuadraticOrderMesh(Mesh const& linear_mesh)
std::unique_ptr<Mesh> createQuadraticOrderMesh(Mesh const& linear_mesh,
bool const add_centre_node)
{
// Clone the linear mesh nodes.
auto quadratic_mesh_nodes = MeshLib::copyNodeVector(linear_mesh.getNodes());
......@@ -104,7 +150,7 @@ std::unique_ptr<Mesh> createQuadraticOrderMesh(Mesh const& linear_mesh)
auto const& linear_mesh_elements = linear_mesh.getElements();
for (MeshLib::Element const* e : linear_mesh_elements)
{
auto quadratic_element = createQuadraticElement(*e);
auto quadratic_element = createQuadraticElement(*e, add_centre_node);
// Replace the base nodes with cloned linear nodes.
int const number_base_nodes = quadratic_element->getNumberOfBaseNodes();
......
......@@ -16,7 +16,10 @@ class Mesh;
namespace MeshLib
{
/// create a quadratic order mesh from the linear order mesh
std::unique_ptr<Mesh> createQuadraticOrderMesh(Mesh const& linear_mesh);
/// Create a quadratic order mesh from the linear order mesh. For some element
/// types like Quad-4, a centre node might be added if the \c add_centre_node
/// flag is set, yielding a Quad-9.
std::unique_ptr<Mesh> createQuadraticOrderMesh(Mesh const& linear_mesh,
bool const add_centre_node);
} // namespace MeshLib
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment