Skip to content
Snippets Groups Projects
Commit 5adc7184 authored by Karsten Rink's avatar Karsten Rink
Browse files

added functionality for flipping elements

parent dd835eda
No related branches found
No related tags found
No related merge requests found
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "FlipElements.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/Node.h"
#include "MeshLib/Elements/Line.h"
#include "MeshLib/Elements/Tri.h"
#include "MeshLib/Elements/Quad.h"
#include "DuplicateMeshComponents.h"
namespace MeshLib
{
MeshLib::Element* flipElement(MeshLib::Element const& elem, std::vector<MeshLib::Node*> const& nodes)
{
if (elem.getDimension()>2)
return nullptr;
std::size_t const n_nodes (elem.getNNodes());
MeshLib::Node** elem_nodes = new MeshLib::Node*[n_nodes];
for (unsigned i=0; i<n_nodes; ++i)
elem_nodes[i] = nodes[elem.getNode(i)->getID()];
MeshLib::Node* tmp (elem_nodes[0]);
elem_nodes[0] = elem_nodes[1];
elem_nodes[1] = tmp;
if (elem.getGeomType() == MeshElemType::LINE)
return new MeshLib::Line(elem_nodes, elem.getID());
else if (elem.getGeomType() == MeshElemType::TRIANGLE)
return new MeshLib::Tri(elem_nodes, elem.getID());
else if (elem.getGeomType() == MeshElemType::QUAD)
{
tmp = elem_nodes[2];
elem_nodes[2] = elem_nodes[3];
elem_nodes[3] = tmp;
return new MeshLib::Quad(elem_nodes, elem.getID());
}
return nullptr;
}
MeshLib::Mesh* flipMeshElements(MeshLib::Mesh const& mesh)
{
if (mesh.getDimension() > 2)
return nullptr;
std::vector<MeshLib::Node*> new_nodes (MeshLib::copyNodeVector(mesh.getNodes()));
std::vector<MeshLib::Element*> const& elems (mesh.getElements());
std::vector<MeshLib::Element*> new_elems;
std::size_t n_elems (mesh.getNElements());
new_elems.reserve(n_elems);
for (std::size_t i=0; i<n_elems; ++i)
new_elems.push_back(flipElement(*elems[i], new_nodes));
MeshLib::Properties new_props (mesh.getProperties());
return new MeshLib::Mesh("FlippedElementMesh", new_nodes, new_elems, new_props);
}
} // end namespace MeshLib
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef FLIPELEMENTS_H_
#define FLIPELEMENTS_H_
#include <vector>
#include "MeshLib/Elements/Element.h"
namespace MeshLib
{
class Mesh;
class Node;
/**
* Reverses the node order of a 1D / 2D element such that the direction
* of a line changes and normals of 2D elements changes its sign.
*/
MeshLib::Element* flipElement(MeshLib::Element const& elem, std::vector<MeshLib::Node*> const& nodes);
/**
* Reverses the node order of all elements in a 1D / 2D mesh such that
* the direction of lines changes and normals of 2D elements changes
* their sign.
*/
MeshLib::Mesh* flipMeshElements(MeshLib::Mesh const& mesh);
}
#endif //FLIPELEMENTS_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment