Skip to content
Snippets Groups Projects
Commit ef46ee59 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[MeL] Tabs to whitespaces.

parent f8560f56
No related branches found
No related tags found
No related merge requests found
Showing
with 664 additions and 664 deletions
......@@ -3,7 +3,7 @@ GET_SOURCE_FILES(SOURCES_MESHLIB)
# It should be removed too for other MPI based DDC approach in future.
if(NOT OGS_USE_PETSC)
list(REMOVE_ITEM SOURCES_MESHLIB NodePartitionedMesh.h)
list(REMOVE_ITEM SOURCES_MESHLIB NodePartitionedMesh.h)
endif()
GET_SOURCE_FILES(SOURCES_ELEMENTS Elements)
......@@ -22,19 +22,19 @@ set(SOURCES ${SOURCES_MESHLIB} ${SOURCES_ELEMENTS} ${SOURCES_EDITING}
# It could be used for other MPI based DDC approach in future.
if(OGS_USE_PETSC)
GET_SOURCE_FILES(SOURCES_MPI_IO IO/MPI_IO)
set(SOURCES ${SOURCES} ${SOURCES_MPI_IO})
GET_SOURCE_FILES(SOURCES_MPI_IO IO/MPI_IO)
set(SOURCES ${SOURCES} ${SOURCES_MPI_IO})
endif()
# Create the library
add_library(MeshLib STATIC ${SOURCES})
target_link_libraries(MeshLib
BaseLib
GeoLib
MathLib
InSituLib # VtkMappedMeshSource
${VTK_LIBRARIES}
BaseLib
GeoLib
MathLib
InSituLib # VtkMappedMeshSource
${VTK_LIBRARIES}
)
ADD_VTK_DEPENDENCY(MeshLib)
......
......@@ -25,104 +25,104 @@ ElementStatus::ElementStatus(Mesh const* const mesh, bool hasAnyInactive)
_element_status(mesh->getNElements(), true),
_hasAnyInactive(hasAnyInactive)
{
const std::vector<MeshLib::Node*>& nodes(_mesh->getNodes());
for (auto node : nodes)
_active_nodes.push_back(node->getNElements());
const std::vector<MeshLib::Node*>& nodes(_mesh->getNodes());
for (auto node : nodes)
_active_nodes.push_back(node->getNElements());
}
ElementStatus::ElementStatus(Mesh const* const mesh,
std::vector<int> const& vec_inactive_matIDs)
: ElementStatus(mesh, !vec_inactive_matIDs.empty())
{
auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs");
if (materialIds) {
for (auto material_id : vec_inactive_matIDs) {
for (auto e : _mesh->getElements()) {
if ((*materialIds)[e->getID()] == material_id) {
setElementStatus(e->getID(), false);
}
}
}
}
auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs");
if (materialIds) {
for (auto material_id : vec_inactive_matIDs) {
for (auto e : _mesh->getElements()) {
if ((*materialIds)[e->getID()] == material_id) {
setElementStatus(e->getID(), false);
}
}
}
}
_vec_active_eles.reserve(getNActiveElements());
const std::size_t nElems (_mesh->getNElements());
for (std::size_t i=0; i<nElems; ++i)
if (_element_status[i])
_vec_active_eles.push_back(const_cast<MeshLib::Element*>(_mesh->getElement(i)));
_vec_active_eles.reserve(getNActiveElements());
const std::size_t nElems (_mesh->getNElements());
for (std::size_t i=0; i<nElems; ++i)
if (_element_status[i])
_vec_active_eles.push_back(const_cast<MeshLib::Element*>(_mesh->getElement(i)));
_vec_active_nodes.reserve(this->getNActiveNodes());
const std::size_t nNodes (_mesh->getNNodes());
for (std::size_t i=0; i<nNodes; ++i)
if (_active_nodes[i]>0)
_vec_active_nodes.push_back(const_cast<MeshLib::Node*>(_mesh->getNode(i)));
_vec_active_nodes.reserve(this->getNActiveNodes());
const std::size_t nNodes (_mesh->getNNodes());
for (std::size_t i=0; i<nNodes; ++i)
if (_active_nodes[i]>0)
_vec_active_nodes.push_back(const_cast<MeshLib::Node*>(_mesh->getNode(i)));
DBUG(
"Deactivated %d materials and resulting active %d nodes and %d "
"elements",
vec_inactive_matIDs.size(),
_vec_active_nodes.size(),
_vec_active_eles.size());
DBUG(
"Deactivated %d materials and resulting active %d nodes and %d "
"elements",
vec_inactive_matIDs.size(),
_vec_active_nodes.size(),
_vec_active_eles.size());
}
std::vector<MeshLib::Element*> const& ElementStatus::getActiveElements() const
{
if (_hasAnyInactive)
return _vec_active_eles;
else
return _mesh->getElements();
if (_hasAnyInactive)
return _vec_active_eles;
else
return _mesh->getElements();
}
std::vector<MeshLib::Node*> const& ElementStatus::getActiveNodes() const
{
if (_hasAnyInactive)
return _vec_active_nodes;
else
return _mesh->getNodes();
if (_hasAnyInactive)
return _vec_active_nodes;
else
return _mesh->getNodes();
}
std::vector<MeshLib::Element*> ElementStatus::getActiveElementsAtNode(std::size_t node_id) const
{
const std::size_t nActiveElements (_active_nodes[node_id]);
std::vector<MeshLib::Element*> active_elements;
active_elements.reserve(nActiveElements);
for (auto elem : _mesh->getNode(node_id)->getElements())
{
if (active_elements.size() == nActiveElements)
return active_elements;
if (_element_status[elem->getID()])
active_elements.push_back(elem);
}
return active_elements;
const std::size_t nActiveElements (_active_nodes[node_id]);
std::vector<MeshLib::Element*> active_elements;
active_elements.reserve(nActiveElements);
for (auto elem : _mesh->getNode(node_id)->getElements())
{
if (active_elements.size() == nActiveElements)
return active_elements;
if (_element_status[elem->getID()])
active_elements.push_back(elem);
}
return active_elements;
}
std::size_t ElementStatus::getNActiveNodes() const
{
return _active_nodes.size() - std::count(_active_nodes.cbegin(), _active_nodes.cend(), 0);
return _active_nodes.size() - std::count(_active_nodes.cbegin(), _active_nodes.cend(), 0);
}
std::size_t ElementStatus::getNActiveElements() const
{
return static_cast<std::size_t>(
std::count(_element_status.cbegin(), _element_status.cend(), true));
return static_cast<std::size_t>(
std::count(_element_status.cbegin(), _element_status.cend(), true));
}
void ElementStatus::setElementStatus(std::size_t i, bool status)
{
if (_element_status[i] != status)
{
const int change = (status) ? 1 : -1;
_element_status[i] = status;
const unsigned nElemNodes (_mesh->getElement(i)->getNBaseNodes());
MeshLib::Node const*const*const nodes = _mesh->getElement(i)->getNodes();
for (unsigned j=0; j<nElemNodes; ++j)
{
assert(_active_nodes[j] < 255); // if one node has >255 connected
// elements the data type is too
// small
_active_nodes[nodes[j]->getID()] += change;
}
}
if (_element_status[i] != status)
{
const int change = (status) ? 1 : -1;
_element_status[i] = status;
const unsigned nElemNodes (_mesh->getElement(i)->getNBaseNodes());
MeshLib::Node const*const*const nodes = _mesh->getElement(i)->getNodes();
for (unsigned j=0; j<nElemNodes; ++j)
{
assert(_active_nodes[j] < 255); // if one node has >255 connected
// elements the data type is too
// small
_active_nodes[nodes[j]->getID()] += change;
}
}
}
}
......@@ -18,54 +18,54 @@
#include <vector>
namespace MeshLib {
class Mesh;
class Element;
class Node;
class Mesh;
class Element;
class Node;
class ElementStatus
{
public:
/// Constructor assuming all nodes and elements
explicit ElementStatus(MeshLib::Mesh const* const mesh,
bool hasAnyInactive = false);
/// Constructor assuming all nodes and elements
explicit ElementStatus(MeshLib::Mesh const* const mesh,
bool hasAnyInactive = false);
/// Constructor taking a vector of inactive material IDs
ElementStatus(MeshLib::Mesh const* const mesh,
std::vector<int> const& vec_inactive_matIDs);
/// Constructor taking a vector of inactive material IDs
ElementStatus(MeshLib::Mesh const* const mesh,
std::vector<int> const& vec_inactive_matIDs);
/// Returns a vector of active element IDs
std::vector<MeshLib::Element*> const& getActiveElements() const;
/// Returns a vector of active element IDs
std::vector<MeshLib::Element*> const& getActiveElements() const;
/// Returns a vector of active node IDs
std::vector<MeshLib::Node*> const& getActiveNodes() const;
/// Returns a vector of active node IDs
std::vector<MeshLib::Node*> const& getActiveNodes() const;
/// Returns the status of element i
bool isActive(std::size_t i) const { return _element_status[i]; }
/// Returns the status of element i
bool isActive(std::size_t i) const { return _element_status[i]; }
/// Returns a vector of active elements connected to a node
std::vector<MeshLib::Element*> getActiveElementsAtNode(std::size_t node_id) const;
/// Returns a vector of active elements connected to a node
std::vector<MeshLib::Element*> getActiveElementsAtNode(std::size_t node_id) const;
/// Returns the total number of active nodes
std::size_t getNActiveNodes() const;
/// Returns the total number of active nodes
std::size_t getNActiveNodes() const;
/// Returns the total number of active elements
std::size_t getNActiveElements() const;
/// Returns the total number of active elements
std::size_t getNActiveElements() const;
protected:
/// Sets the status of element i
void setElementStatus(std::size_t i, bool status);
/// The mesh for which the element status is administrated
MeshLib::Mesh const*const _mesh;
/// Element status for each mesh element (active/inactive = true/false)
std::vector<bool> _element_status;
/// Node status for each mesh node (value = number of active elements connected to node, 0 means inactive)
std::vector<unsigned char> _active_nodes;
bool const _hasAnyInactive;
std::vector<MeshLib::Node*> _vec_active_nodes;
std::vector<MeshLib::Element*> _vec_active_eles;
/// Sets the status of element i
void setElementStatus(std::size_t i, bool status);
/// The mesh for which the element status is administrated
MeshLib::Mesh const*const _mesh;
/// Element status for each mesh element (active/inactive = true/false)
std::vector<bool> _element_status;
/// Node status for each mesh node (value = number of active elements connected to node, 0 means inactive)
std::vector<unsigned char> _active_nodes;
bool const _hasAnyInactive;
std::vector<MeshLib::Node*> _vec_active_nodes;
std::vector<MeshLib::Element*> _vec_active_eles;
}; /* class */
......
......@@ -18,23 +18,23 @@ namespace MeshLib {
bool CellRule::testElementNodeOrder(const Element* e)
{
const MathLib::Vector3 c (e->getCenterOfGravity());
const unsigned nFaces (e->getNFaces());
for (unsigned j=0; j<nFaces; ++j)
{
MeshLib::Element const*const face (e->getFace(j));
// Node 1 is checked below because that way all nodes are used for the test
// at some point, while for node 0 at least one node in every element
// type would be used for checking twice and one wouldn't be checked at
// all. (based on the definition of the _face_nodes variable)
const MeshLib::Node x (*(face->getNode(1)));
const MathLib::Vector3 cx (c, x);
const double s = MathLib::scalarProduct(FaceRule::getSurfaceNormal(face), cx);
delete face;
if (s >= 0)
return false;
}
return true;
const MathLib::Vector3 c (e->getCenterOfGravity());
const unsigned nFaces (e->getNFaces());
for (unsigned j=0; j<nFaces; ++j)
{
MeshLib::Element const*const face (e->getFace(j));
// Node 1 is checked below because that way all nodes are used for the test
// at some point, while for node 0 at least one node in every element
// type would be used for checking twice and one wouldn't be checked at
// all. (based on the definition of the _face_nodes variable)
const MeshLib::Node x (*(face->getNode(1)));
const MathLib::Vector3 cx (c, x);
const double s = MathLib::scalarProduct(FaceRule::getSurfaceNormal(face), cx);
delete face;
if (s >= 0)
return false;
}
return true;
}
} /* namespace */
......@@ -18,18 +18,18 @@ class Element;
class CellRule
{
public:
/// Constant: Dimension of this mesh element
static const unsigned dimension = 3u;
/**
* Checks if the node order of an element is correct by testing surface normals.
* For 3D elements true is returned if the normals of all faces points away from the centre of
* the element.
* Note: This method might give wrong results if something else is wrong with the element
* (non-planar faces, non-convex geometry, possibly zero volume) which causes the calculated
* center of gravity to lie outside of the actual element
*/
static bool testElementNodeOrder(const Element* /*e*/);
/// Constant: Dimension of this mesh element
static const unsigned dimension = 3u;
/**
* Checks if the node order of an element is correct by testing surface normals.
* For 3D elements true is returned if the normals of all faces points away from the centre of
* the element.
* Note: This method might give wrong results if something else is wrong with the element
* (non-planar faces, non-convex geometry, possibly zero volume) which causes the calculated
* center of gravity to lie outside of the actual element
*/
static bool testElementNodeOrder(const Element* /*e*/);
}; /* class */
} /* namespace */
......
......@@ -20,29 +20,29 @@ namespace MeshLib
const Element* LinearEdgeReturn::getEdge(const Element* e, unsigned i)
{
if (i < e->getNEdges())
{
Node** nodes = new Node*[2];
nodes[0] = const_cast<Node*>(e->getEdgeNode(i,0));
nodes[1] = const_cast<Node*>(e->getEdgeNode(i,1));
return new Line(nodes);
}
ERR("Error in MeshLib::Element::getEdge() - Index does not exist.");
return nullptr;
if (i < e->getNEdges())
{
Node** nodes = new Node*[2];
nodes[0] = const_cast<Node*>(e->getEdgeNode(i,0));
nodes[1] = const_cast<Node*>(e->getEdgeNode(i,1));
return new Line(nodes);
}
ERR("Error in MeshLib::Element::getEdge() - Index does not exist.");
return nullptr;
}
const Element* QuadraticEdgeReturn::getEdge(const Element* e, unsigned i)
{
if (i < e->getNEdges())
{
Node** nodes = new Node*[3];
nodes[0] = const_cast<Node*>(e->getEdgeNode(i,0));
nodes[1] = const_cast<Node*>(e->getEdgeNode(i,1));
nodes[2] = const_cast<Node*>(e->getEdgeNode(i,2));
return new Line3(nodes);
}
ERR("Error in MeshLib::Element::getEdge() - Index does not exist.");
return nullptr;
if (i < e->getNEdges())
{
Node** nodes = new Node*[3];
nodes[0] = const_cast<Node*>(e->getEdgeNode(i,0));
nodes[1] = const_cast<Node*>(e->getEdgeNode(i,1));
nodes[2] = const_cast<Node*>(e->getEdgeNode(i,2));
return new Line3(nodes);
}
ERR("Error in MeshLib::Element::getEdge() - Index does not exist.");
return nullptr;
}
} // end MeshLib
......
......@@ -19,27 +19,27 @@ class Element;
class NoEdgeReturn
{
public:
/// Returns i-th edge of the given element
static const Element* getEdge(const Element* /*e*/, unsigned /*i*/)
{
return nullptr;
}
/// Returns i-th edge of the given element
static const Element* getEdge(const Element* /*e*/, unsigned /*i*/)
{
return nullptr;
}
};
/// Returns linear order edge
class LinearEdgeReturn
{
public:
/// Returns i-th edge of the given element
static const Element* getEdge(const Element* e, unsigned i);
/// Returns i-th edge of the given element
static const Element* getEdge(const Element* e, unsigned i);
};
/// Returns quadratic order edge
class QuadraticEdgeReturn
{
public:
/// Returns i-th edge of the given element
static const Element* getEdge(const Element* e, unsigned i);
/// Returns i-th edge of the given element
static const Element* getEdge(const Element* e, unsigned i);
};
} // end MeshLib
......
......@@ -18,26 +18,26 @@ class Element;
class EdgeRule
{
public:
/// Constant: Dimension of this mesh element
static const unsigned dimension = 1u;
/// Constant: Dimension of this mesh element
static const unsigned dimension = 1u;
/// Constant: The number of faces
static const unsigned n_faces = 0;
/// Constant: The number of faces
static const unsigned n_faces = 0;
/// Constant: The number of edges
static const unsigned n_edges = 0;
/// Constant: The number of edges
static const unsigned n_edges = 0;
/// Get the number of nodes for face i.
static unsigned getNFaceNodes(unsigned /*i*/) { return 0; }
/// Get the number of nodes for face i.
static unsigned getNFaceNodes(unsigned /*i*/) { return 0; }
/// Returns the i-th face of the element.
static const Element* getFace(const Element* /*e*/, unsigned /*i*/) { return nullptr; }
/// Returns the i-th face of the element.
static const Element* getFace(const Element* /*e*/, unsigned /*i*/) { return nullptr; }
/**
* Checks if the node order of an element is correct by testing surface normals.
* For 1D elements this always returns true.
*/
static bool testElementNodeOrder(const Element* /*e*/) { return true; }
/**
* Checks if the node order of an element is correct by testing surface normals.
* For 1D elements this always returns true.
*/
static bool testElementNodeOrder(const Element* /*e*/) { return true; }
}; /* class */
......
......@@ -24,161 +24,161 @@
namespace MeshLib {
Element::Element(std::size_t id)
: _nodes(nullptr), _id(id), _content(-1.0), _neighbors(nullptr)
: _nodes(nullptr), _id(id), _content(-1.0), _neighbors(nullptr)
{
}
Element::~Element()
{
delete [] this->_nodes;
delete [] this->_neighbors;
delete [] this->_nodes;
delete [] this->_neighbors;
}
void Element::setNeighbor(Element* neighbor, unsigned const face_id)
{
if (neighbor == this)
return;
if (neighbor == this)
return;
this->_neighbors[face_id] = neighbor;
this->_neighbors[face_id] = neighbor;
}
boost::optional<unsigned> Element::addNeighbor(Element* e)
{
if (e == this ||
e == nullptr ||
e->getDimension() != this->getDimension())
return boost::optional<unsigned>();
if (this->hasNeighbor(e))
return boost::optional<unsigned>();
Node* face_nodes[3];
const unsigned nNodes (this->getNBaseNodes());
const unsigned eNodes (e->getNBaseNodes());
const Node* const* e_nodes = e->getNodes();
unsigned count(0);
const unsigned dim (this->getDimension());
for (unsigned i(0); i<nNodes; i++)
for (unsigned j(0); j<eNodes; j++)
if (_nodes[i] == e_nodes[j])
{
face_nodes[count] = _nodes[i];
// increment shared nodes counter and check if enough nodes are similar to be sure e is a neighbour of this
if ((++count)>=dim)
{
_neighbors[ this->identifyFace(face_nodes) ] = e;
return boost::optional<unsigned>(e->identifyFace(face_nodes));
}
}
return boost::optional<unsigned>();
if (e == this ||
e == nullptr ||
e->getDimension() != this->getDimension())
return boost::optional<unsigned>();
if (this->hasNeighbor(e))
return boost::optional<unsigned>();
Node* face_nodes[3];
const unsigned nNodes (this->getNBaseNodes());
const unsigned eNodes (e->getNBaseNodes());
const Node* const* e_nodes = e->getNodes();
unsigned count(0);
const unsigned dim (this->getDimension());
for (unsigned i(0); i<nNodes; i++)
for (unsigned j(0); j<eNodes; j++)
if (_nodes[i] == e_nodes[j])
{
face_nodes[count] = _nodes[i];
// increment shared nodes counter and check if enough nodes are similar to be sure e is a neighbour of this
if ((++count)>=dim)
{
_neighbors[ this->identifyFace(face_nodes) ] = e;
return boost::optional<unsigned>(e->identifyFace(face_nodes));
}
}
return boost::optional<unsigned>();
}
MeshLib::Node Element::getCenterOfGravity() const
{
const unsigned nNodes (this->getNBaseNodes());
MeshLib::Node center(0,0,0);
for (unsigned i=0; i<nNodes; ++i)
{
center[0] += (*_nodes[i])[0];
center[1] += (*_nodes[i])[1];
center[2] += (*_nodes[i])[2];
}
center[0] /= nNodes;
center[1] /= nNodes;
center[2] /= nNodes;
return center;
const unsigned nNodes (this->getNBaseNodes());
MeshLib::Node center(0,0,0);
for (unsigned i=0; i<nNodes; ++i)
{
center[0] += (*_nodes[i])[0];
center[1] += (*_nodes[i])[1];
center[2] += (*_nodes[i])[2];
}
center[0] /= nNodes;
center[1] /= nNodes;
center[2] /= nNodes;
return center;
}
void Element::computeSqrEdgeLengthRange(double &min, double &max) const
{
min = std::numeric_limits<double>::max();
max = 0;
const unsigned nEdges (this->getNEdges());
for (unsigned i=0; i<nEdges; i++)
{
const double dist (MathLib::sqrDist(*getEdgeNode(i,0), *getEdgeNode(i,1)));
min = (dist<min) ? dist : min;
max = (dist>max) ? dist : max;
}
min = std::numeric_limits<double>::max();
max = 0;
const unsigned nEdges (this->getNEdges());
for (unsigned i=0; i<nEdges; i++)
{
const double dist (MathLib::sqrDist(*getEdgeNode(i,0), *getEdgeNode(i,1)));
min = (dist<min) ? dist : min;
max = (dist>max) ? dist : max;
}
}
void Element::computeSqrNodeDistanceRange(double &min, double &max, bool check_allnodes) const
{
min = std::numeric_limits<double>::max();
max = 0;
const unsigned nnodes = check_allnodes ? getNNodes() : getNBaseNodes();
for (unsigned i=0; i<nnodes; i++)
{
for (unsigned j=i+1; j<nnodes; j++)
{
const double dist (MathLib::sqrDist(*getNode(i), *getNode(j)));
min = std::min(dist, min);
max = std::max(dist, max);
}
}
min = std::numeric_limits<double>::max();
max = 0;
const unsigned nnodes = check_allnodes ? getNNodes() : getNBaseNodes();
for (unsigned i=0; i<nnodes; i++)
{
for (unsigned j=i+1; j<nnodes; j++)
{
const double dist (MathLib::sqrDist(*getNode(i), *getNode(j)));
min = std::min(dist, min);
max = std::max(dist, max);
}
}
}
const Element* Element::getNeighbor(unsigned i) const
{
#ifndef NDEBUG
if (i < getNNeighbors())
if (i < getNNeighbors())
#endif
return _neighbors[i];
return _neighbors[i];
#ifndef NDEBUG
ERR("Error in MeshLib::Element::getNeighbor() - Index does not exist.");
return nullptr;
ERR("Error in MeshLib::Element::getNeighbor() - Index does not exist.");
return nullptr;
#endif
}
unsigned Element::getNodeIDinElement(const MeshLib::Node* node) const
{
const unsigned nNodes (this->getNBaseNodes());
for (unsigned i(0); i<nNodes; i++)
if (node == _nodes[i])
return i;
return std::numeric_limits<unsigned>::max();
const unsigned nNodes (this->getNBaseNodes());
for (unsigned i(0); i<nNodes; i++)
if (node == _nodes[i])
return i;
return std::numeric_limits<unsigned>::max();
}
const Node* Element::getNode(unsigned i) const
{
#ifndef NDEBUG
if (i < getNNodes())
if (i < getNNodes())
#endif
return _nodes[i];
return _nodes[i];
#ifndef NDEBUG
ERR("Error in MeshLib::Element::getNode() - Index %d in %s", i, MeshElemType2String(getGeomType()).c_str());
return nullptr;
ERR("Error in MeshLib::Element::getNode() - Index %d in %s", i, MeshElemType2String(getGeomType()).c_str());
return nullptr;
#endif
}
void Element::setNode(unsigned idx, Node* node)
{
#ifndef NDEBUG
if (idx < getNNodes())
if (idx < getNNodes())
#endif
_nodes[idx] = node;
_nodes[idx] = node;
}
unsigned Element::getNodeIndex(unsigned i) const
{
#ifndef NDEBUG
if (i<getNNodes())
if (i<getNNodes())
#endif
return _nodes[i]->getID();
return _nodes[i]->getID();
#ifndef NDEBUG
ERR("Error in MeshLib::Element::getNodeIndex() - Index does not exist.");
return std::numeric_limits<unsigned>::max();
ERR("Error in MeshLib::Element::getNodeIndex() - Index does not exist.");
return std::numeric_limits<unsigned>::max();
#endif
}
bool Element::hasNeighbor(Element* elem) const
{
unsigned nNeighbors (this->getNNeighbors());
for (unsigned i=0; i<nNeighbors; i++)
if (this->_neighbors[i]==elem)
return true;
return false;
unsigned nNeighbors (this->getNNeighbors());
for (unsigned i=0; i<nNeighbors; i++)
if (this->_neighbors[i]==elem)
return true;
return false;
}
bool Element::isBoundaryElement() const
......@@ -190,18 +190,18 @@ bool Element::isBoundaryElement() const
#ifndef NDEBUG
std::ostream& operator<<(std::ostream& os, Element const& e)
{
os << "Element #" << e._id << " @ " << &e << " with " << e.getNNeighbors()
<< " neighbours\n";
unsigned const nnodes = e.getNNodes();
MeshLib::Node* const* const nodes = e.getNodes();
os << "MeshElemType: "
<< static_cast<std::underlying_type<MeshElemType>::type>(e.getGeomType())
<< " with " << nnodes << " nodes: { ";
for (unsigned n = 0; n < nnodes; ++n)
os << nodes[n]->getID() << " @ " << nodes[n] << " ";
os << "}\n";
return os;
os << "Element #" << e._id << " @ " << &e << " with " << e.getNNeighbors()
<< " neighbours\n";
unsigned const nnodes = e.getNNodes();
MeshLib::Node* const* const nodes = e.getNodes();
os << "MeshElemType: "
<< static_cast<std::underlying_type<MeshElemType>::type>(e.getGeomType())
<< " with " << nnodes << " nodes: { ";
for (unsigned n = 0; n < nnodes; ++n)
os << nodes[n]->getID() << " @ " << nodes[n] << " ";
os << "}\n";
return os;
}
#endif // NDEBUG
......
......@@ -34,186 +34,186 @@ class Node;
*/
class Element
{
/* friend classes */
friend class Mesh;//void Mesh::setElementInformationForNodes();
/* friend classes */
friend class Mesh;//void Mesh::setElementInformationForNodes();
public:
/// Compute the minimum and maximum squared edge length for this element
virtual void computeSqrEdgeLengthRange(double &min, double &max) const;
/// Compute the minimum and maximum node distances for this element.
virtual void computeSqrNodeDistanceRange(double &min, double &max, bool check_allnodes=true) const;
/**
* \brief Tries to add an element e as neighbour to this element.
* If the elements really are neighbours, the element is added to the
* neighbour-list and the face id of the neighbour connected to this element
* is returned. Otherwise the maximum value of the value type is returned.
*/
boost::optional<unsigned> addNeighbor(Element* e);
/// Calculates the center of gravity for the mesh element
MeshLib::Node getCenterOfGravity() const;
/// Returns the length, area or volume of a 1D, 2D or 3D element
double getContent() const { return _content; }
/**
* Get node with local index i where i should be at most the number
* of nodes of the element
* @param i local index of node, at most the number of nodes of the
* element that you can obtain with Element::getNBaseNodes()
* @return a pointer to the appropriate (and constant, i.e. not
* modifiable by the user) instance of class Node or a NULL pointer
* @sa Element::getNodeIndex()
*/
const Node* getNode(unsigned i) const;
/**
* (Re)Sets the node of the element.
* @param idx the index of the pointer to a node within the element
* @param node a pointer to a node
*/
void setNode(unsigned idx, Node* node);
/// Get array of element nodes.
Node* const* getNodes() const { return _nodes; }
/// Get dimension of the mesh element.
virtual unsigned getDimension() const = 0;
/// Returns the i-th edge of the element.
virtual const Element* getEdge(unsigned i) const = 0;
/// Returns the i-th face of the element.
virtual const Element* getFace(unsigned i) const = 0;
/// Returns the ID of the element.
virtual std::size_t getID() const final { return _id; }
/// Get the number of edges for this element.
virtual unsigned getNEdges() const = 0;
/// Get the number of nodes for face i.
virtual unsigned getNFaceNodes(unsigned i) const = 0;
/// Get the number of faces for this element.
virtual unsigned getNFaces() const = 0;
/// Get the specified neighbor.
const Element* getNeighbor(unsigned i) const;
/// Get the number of neighbors for this element.
virtual unsigned getNNeighbors() const = 0;
/**
* Returns the number of linear nodes.
*/
virtual unsigned getNBaseNodes() const = 0;
/// Returns the number of all nodes including both linear and nonlinear nodes
virtual unsigned getNNodes() const = 0;
/// Returns the position of the given node in the node array of this element.
virtual unsigned getNodeIDinElement(const MeshLib::Node* node) const;
/**
* Get the global index for the Node with local index i.
* The index i should be at most the number of nodes of the element.
* @param i local index of Node, at most the number of nodes of the
* element that you can obtain with Element::getNBaseNodes()
* @return the global index or std::numeric_limits<unsigned>::max()
* @sa Element::getNode()
*/
unsigned getNodeIndex(unsigned i) const;
/**
* Get the type of the mesh element in geometric context (as a MeshElemType-enum).
*/
virtual MeshElemType getGeomType() const = 0;
/**
* Get the type of the element in context of the finite element method.
* @return a value of the enum FEMElemType::type
*/
virtual CellType getCellType() const = 0;
/**
* Returns true if the element has zero length/area/volume.
*/
bool hasZeroVolume() const { return this->getContent() < std::numeric_limits<double>::epsilon(); }
/// Returns true if the element is located at a boundary (i.e. has at least one face without neighbour)
virtual bool isBoundaryElement() const;
/// Returns true if these two indeces form an edge and false otherwise
virtual bool isEdge(unsigned i, unsigned j) const = 0;
/**
* Checks if a point is inside the element.
* @param pnt a 3D MathLib::Point3d object
* @param eps tolerance for numerical algorithm used or computing the property
* @return true if the point is not outside the element, false otherwise
*/
virtual bool isPntInElement(MathLib::Point3d const& pnt, double eps = std::numeric_limits<double>::epsilon()) const = 0;
/**
* Tests if the element is geometrically valid.
*/
virtual ElementErrorCode validate() const = 0;
/// Returns true if elem is a neighbour of this element and false otherwise.
bool hasNeighbor(Element* elem) const;
/// Destructor
virtual ~Element();
/// Compute the minimum and maximum squared edge length for this element
virtual void computeSqrEdgeLengthRange(double &min, double &max) const;
/// Compute the minimum and maximum node distances for this element.
virtual void computeSqrNodeDistanceRange(double &min, double &max, bool check_allnodes=true) const;
/**
* \brief Tries to add an element e as neighbour to this element.
* If the elements really are neighbours, the element is added to the
* neighbour-list and the face id of the neighbour connected to this element
* is returned. Otherwise the maximum value of the value type is returned.
*/
boost::optional<unsigned> addNeighbor(Element* e);
/// Calculates the center of gravity for the mesh element
MeshLib::Node getCenterOfGravity() const;
/// Returns the length, area or volume of a 1D, 2D or 3D element
double getContent() const { return _content; }
/**
* Get node with local index i where i should be at most the number
* of nodes of the element
* @param i local index of node, at most the number of nodes of the
* element that you can obtain with Element::getNBaseNodes()
* @return a pointer to the appropriate (and constant, i.e. not
* modifiable by the user) instance of class Node or a NULL pointer
* @sa Element::getNodeIndex()
*/
const Node* getNode(unsigned i) const;
/**
* (Re)Sets the node of the element.
* @param idx the index of the pointer to a node within the element
* @param node a pointer to a node
*/
void setNode(unsigned idx, Node* node);
/// Get array of element nodes.
Node* const* getNodes() const { return _nodes; }
/// Get dimension of the mesh element.
virtual unsigned getDimension() const = 0;
/// Returns the i-th edge of the element.
virtual const Element* getEdge(unsigned i) const = 0;
/// Returns the i-th face of the element.
virtual const Element* getFace(unsigned i) const = 0;
/// Returns the ID of the element.
virtual std::size_t getID() const final { return _id; }
/// Get the number of edges for this element.
virtual unsigned getNEdges() const = 0;
/// Get the number of nodes for face i.
virtual unsigned getNFaceNodes(unsigned i) const = 0;
/// Get the number of faces for this element.
virtual unsigned getNFaces() const = 0;
/// Get the specified neighbor.
const Element* getNeighbor(unsigned i) const;
/// Get the number of neighbors for this element.
virtual unsigned getNNeighbors() const = 0;
/**
* Returns the number of linear nodes.
*/
virtual unsigned getNBaseNodes() const = 0;
/// Returns the number of all nodes including both linear and nonlinear nodes
virtual unsigned getNNodes() const = 0;
/// Returns the position of the given node in the node array of this element.
virtual unsigned getNodeIDinElement(const MeshLib::Node* node) const;
/**
* Get the global index for the Node with local index i.
* The index i should be at most the number of nodes of the element.
* @param i local index of Node, at most the number of nodes of the
* element that you can obtain with Element::getNBaseNodes()
* @return the global index or std::numeric_limits<unsigned>::max()
* @sa Element::getNode()
*/
unsigned getNodeIndex(unsigned i) const;
/**
* Get the type of the mesh element in geometric context (as a MeshElemType-enum).
*/
virtual MeshElemType getGeomType() const = 0;
/**
* Get the type of the element in context of the finite element method.
* @return a value of the enum FEMElemType::type
*/
virtual CellType getCellType() const = 0;
/**
* Returns true if the element has zero length/area/volume.
*/
bool hasZeroVolume() const { return this->getContent() < std::numeric_limits<double>::epsilon(); }
/// Returns true if the element is located at a boundary (i.e. has at least one face without neighbour)
virtual bool isBoundaryElement() const;
/// Returns true if these two indeces form an edge and false otherwise
virtual bool isEdge(unsigned i, unsigned j) const = 0;
/**
* Checks if a point is inside the element.
* @param pnt a 3D MathLib::Point3d object
* @param eps tolerance for numerical algorithm used or computing the property
* @return true if the point is not outside the element, false otherwise
*/
virtual bool isPntInElement(MathLib::Point3d const& pnt, double eps = std::numeric_limits<double>::epsilon()) const = 0;
/**
* Tests if the element is geometrically valid.
*/
virtual ElementErrorCode validate() const = 0;
/// Returns true if elem is a neighbour of this element and false otherwise.
bool hasNeighbor(Element* elem) const;
/// Destructor
virtual ~Element();
/**
* Method clone is a pure virtual method in the abstract base class Element.
* It has to be implemented in the derived classes (for instance in class Hex).
* @return an exact copy of the object
*/
virtual Element* clone() const = 0;
/**
* Method clone is a pure virtual method in the abstract base class Element.
* It has to be implemented in the derived classes (for instance in class Hex).
* @return an exact copy of the object
*/
virtual Element* clone() const = 0;
/**
* Computes the length / area / volumen of this element. This is automatically
* done at initalisation time but can be repeated by calling this function at any time.
*/
virtual double computeVolume() = 0;
/**
* Computes the length / area / volumen of this element. This is automatically
* done at initalisation time but can be repeated by calling this function at any time.
*/
virtual double computeVolume() = 0;
/// Returns the ID of a face given an array of nodes.
virtual unsigned identifyFace(Node* nodes[3]) const = 0;
/// Returns the ID of a face given an array of nodes.
virtual unsigned identifyFace(Node* nodes[3]) const = 0;
/**
* Checks if the node order of an element is correct by testing surface normals.
*/
virtual bool testElementNodeOrder() const = 0;
/// Return a specific edge node.
virtual Node* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0;
/**
* Checks if the node order of an element is correct by testing surface normals.
*/
virtual bool testElementNodeOrder() const = 0;
/// Return a specific edge node.
virtual Node* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0;
#ifndef NDEBUG
friend std::ostream& operator<<(std::ostream& os, Element const& e);
friend std::ostream& operator<<(std::ostream& os, Element const& e);
#endif // NDEBUG
protected:
/// Constructor for a generic mesh element without an array of mesh nodes.
/// @param id element id
explicit Element(std::size_t id);
/// Sets the element ID.
virtual void setID(std::size_t id) final { _id = id; }
Node** _nodes;
std::size_t _id;
/// Content corresponds to length for 1D, area for 2D, and volume for 3D elements
double _content;
Element** _neighbors;
/// Sets the neighbor over the face with \c face_id to the given \c
/// neighbor.
void setNeighbor(Element* neighbor, unsigned const face_id);
/// Constructor for a generic mesh element without an array of mesh nodes.
/// @param id element id
explicit Element(std::size_t id);
/// Sets the element ID.
virtual void setID(std::size_t id) final { _id = id; }
Node** _nodes;
std::size_t _id;
/// Content corresponds to length for 1D, area for 2D, and volume for 3D elements
double _content;
Element** _neighbors;
/// Sets the neighbor over the face with \c face_id to the given \c
/// neighbor.
void setNeighbor(Element* neighbor, unsigned const face_id);
}; /* class */
......
......@@ -18,16 +18,16 @@ namespace MeshLib
bool FaceRule::testElementNodeOrder(const Element* e)
{
MathLib::Vector3 up_vec (0,0,1);
return (MathLib::scalarProduct(getSurfaceNormal(e), up_vec) < 0) ? true : false;
MathLib::Vector3 up_vec (0,0,1);
return (MathLib::scalarProduct(getSurfaceNormal(e), up_vec) < 0) ? true : false;
}
MathLib::Vector3 FaceRule::getSurfaceNormal(const Element* e)
{
Node * const * _nodes = e->getNodes();
const MathLib::Vector3 u (*_nodes[1], *_nodes[0]);
const MathLib::Vector3 v (*_nodes[1], *_nodes[2]);
return MathLib::crossProduct(u,v);
Node * const * _nodes = e->getNodes();
const MathLib::Vector3 u (*_nodes[1], *_nodes[0]);
const MathLib::Vector3 v (*_nodes[1], *_nodes[2]);
return MathLib::crossProduct(u,v);
}
} /* namespace */
......
......@@ -19,26 +19,26 @@ namespace MeshLib
class FaceRule
{
public:
/// Constant: Dimension of this mesh element
static const unsigned dimension = 2u;
/// Constant: Dimension of this mesh element
static const unsigned dimension = 2u;
/// Returns the face i of the element.
static const Element* getFace(const Element* e, unsigned i) { return e->getEdge(i); }
/// Returns the face i of the element.
static const Element* getFace(const Element* e, unsigned i) { return e->getEdge(i); }
/// Get the number of nodes for face i.
static unsigned getNFaceNodes(unsigned /*i*/) { return 2; }
/// Get the number of nodes for face i.
static unsigned getNFaceNodes(unsigned /*i*/) { return 2; }
/// Constant: The number of faces
static const unsigned n_faces = 0;
/// Constant: The number of faces
static const unsigned n_faces = 0;
/**
* Checks if the node order of an element is correct by testing surface normals.
* For 2D elements true is returned if the normal points (roughly) upwards.
*/
static bool testElementNodeOrder(const Element* /*e*/);
/**
* Checks if the node order of an element is correct by testing surface normals.
* For 2D elements true is returned if the normal points (roughly) upwards.
*/
static bool testElementNodeOrder(const Element* /*e*/);
/// Returns the surface normal of a 2D element.
static MathLib::Vector3 getSurfaceNormal(const Element* e);
/// Returns the surface normal of a 2D element.
static MathLib::Vector3 getSurfaceNormal(const Element* e);
}; /* class */
......
......@@ -23,41 +23,41 @@ namespace MeshLib {
const unsigned HexRule20::face_nodes[6][8] =
{
{0, 3, 2, 1, 11, 10, 9, 8}, // Face 0
{0, 1, 5, 4, 8, 17, 12, 11}, // Face 1
{1, 2, 6, 5, 9, 18, 13, 17}, // Face 2
{2, 3, 7, 6, 10, 19, 14, 18}, // Face 3
{3, 0, 4, 7, 11, 16, 15, 19}, // Face 4
{4, 5, 6, 7, 12, 13, 14, 15} // Face 5
{0, 3, 2, 1, 11, 10, 9, 8}, // Face 0
{0, 1, 5, 4, 8, 17, 12, 11}, // Face 1
{1, 2, 6, 5, 9, 18, 13, 17}, // Face 2
{2, 3, 7, 6, 10, 19, 14, 18}, // Face 3
{3, 0, 4, 7, 11, 16, 15, 19}, // Face 4
{4, 5, 6, 7, 12, 13, 14, 15} // Face 5
};
const unsigned HexRule20::edge_nodes[12][3] =
{
{0, 1, 8}, // Edge 0
{1, 2, 9}, // Edge 1
{2, 3, 10}, // Edge 2
{0, 3, 11}, // Edge 3
{4, 5, 12}, // Edge 4
{5, 6, 13}, // Edge 5
{6, 7, 14}, // Edge 6
{4, 7, 15}, // Edge 7
{0, 4, 16}, // Edge 8
{1, 5, 17}, // Edge 9
{2, 6, 18}, // Edge 10
{3, 7, 19} // Edge 11
{0, 1, 8}, // Edge 0
{1, 2, 9}, // Edge 1
{2, 3, 10}, // Edge 2
{0, 3, 11}, // Edge 3
{4, 5, 12}, // Edge 4
{5, 6, 13}, // Edge 5
{6, 7, 14}, // Edge 6
{4, 7, 15}, // Edge 7
{0, 4, 16}, // Edge 8
{1, 5, 17}, // Edge 9
{2, 6, 18}, // Edge 10
{3, 7, 19} // Edge 11
};
const Element* HexRule20::getFace(const Element* e, unsigned i)
{
if (i < n_faces)
{
std::array<Node*, 8> nodes;
for (unsigned j=0; j<8; j++)
nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j]));
return new Quad8(nodes);
}
ERR("Error in MeshLib::Element::getFace() - Index %d does not exist.", i);
return nullptr;
if (i < n_faces)
{
std::array<Node*, 8> nodes;
for (unsigned j=0; j<8; j++)
nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j]));
return new Quad8(nodes);
}
ERR("Error in MeshLib::Element::getFace() - Index %d does not exist.", i);
return nullptr;
}
} // end namespace MeshLib
......@@ -46,26 +46,26 @@ namespace MeshLib
class HexRule20 : public HexRule8
{
public:
/// Constant: The number of all nodes for this element
static const unsigned n_all_nodes = 20u;
/// Constant: The number of all nodes for this element
static const unsigned n_all_nodes = 20u;
/// Constant: The FEM type of the element
static const CellType cell_type = CellType::HEX20;
/// Constant: The FEM type of the element
static const CellType cell_type = CellType::HEX20;
/// Constant: Local node index table for faces
static const unsigned face_nodes[6][8];
/// Constant: Local node index table for faces
static const unsigned face_nodes[6][8];
/// Constant: Local node index table for edge
static const unsigned edge_nodes[12][3];
/// Constant: Local node index table for edge
static const unsigned edge_nodes[12][3];
/// Returns the i-th edge of the element.
typedef QuadraticEdgeReturn EdgeReturn;
/// Returns the i-th edge of the element.
typedef QuadraticEdgeReturn EdgeReturn;
/// Get the number of nodes for face i.
static unsigned getNFaceNodes(unsigned /*i*/) { return 8; }
/// Get the number of nodes for face i.
static unsigned getNFaceNodes(unsigned /*i*/) { return 8; }
/// Returns the i-th face of the element.
static const Element* getFace(const Element* e, unsigned i);
/// Returns the i-th face of the element.
static const Element* getFace(const Element* e, unsigned i);
}; /* class */
......
......@@ -23,94 +23,94 @@ namespace MeshLib {
const unsigned HexRule8::face_nodes[6][4] =
{
{0, 3, 2, 1}, // Face 0
{0, 1, 5, 4}, // Face 1
{1, 2, 6, 5}, // Face 2
{2, 3, 7, 6}, // Face 3
{3, 0, 4, 7}, // Face 4
{4, 5, 6, 7} // Face 5
{0, 3, 2, 1}, // Face 0
{0, 1, 5, 4}, // Face 1
{1, 2, 6, 5}, // Face 2
{2, 3, 7, 6}, // Face 3
{3, 0, 4, 7}, // Face 4
{4, 5, 6, 7} // Face 5
};
const unsigned HexRule8::edge_nodes[12][2] =
{
{0, 1}, // Edge 0
{1, 2}, // Edge 1
{2, 3}, // Edge 2
{0, 3}, // Edge 3
{4, 5}, // Edge 4
{5, 6}, // Edge 5
{6, 7}, // Edge 6
{4, 7}, // Edge 7
{0, 4}, // Edge 8
{1, 5}, // Edge 9
{2, 6}, // Edge 10
{3, 7} // Edge 11
{0, 1}, // Edge 0
{1, 2}, // Edge 1
{2, 3}, // Edge 2
{0, 3}, // Edge 3
{4, 5}, // Edge 4
{5, 6}, // Edge 5
{6, 7}, // Edge 6
{4, 7}, // Edge 7
{0, 4}, // Edge 8
{1, 5}, // Edge 9
{2, 6}, // Edge 10
{3, 7} // Edge 11
};
const Element* HexRule8::getFace(const Element* e, unsigned i)
{
if (i < n_faces)
{
std::array<Node*, 4> nodes;
for (unsigned j=0; j<4; j++)
nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j]));
return new Quad(nodes);
}
ERR("Error in MeshLib::Element::getFace() - Index %d does not exist.", i);
return nullptr;
if (i < n_faces)
{
std::array<Node*, 4> nodes;
for (unsigned j=0; j<4; j++)
nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j]));
return new Quad(nodes);
}
ERR("Error in MeshLib::Element::getFace() - Index %d does not exist.", i);
return nullptr;
}
double HexRule8::computeVolume(Node const* const* _nodes)
{
return GeoLib::calcTetrahedronVolume(*_nodes[4], *_nodes[7], *_nodes[5], *_nodes[0])
+ GeoLib::calcTetrahedronVolume(*_nodes[5], *_nodes[3], *_nodes[1], *_nodes[0])
+ GeoLib::calcTetrahedronVolume(*_nodes[5], *_nodes[7], *_nodes[3], *_nodes[0])
+ GeoLib::calcTetrahedronVolume(*_nodes[5], *_nodes[7], *_nodes[6], *_nodes[2])
+ GeoLib::calcTetrahedronVolume(*_nodes[1], *_nodes[3], *_nodes[5], *_nodes[2])
+ GeoLib::calcTetrahedronVolume(*_nodes[3], *_nodes[7], *_nodes[5], *_nodes[2]);
return GeoLib::calcTetrahedronVolume(*_nodes[4], *_nodes[7], *_nodes[5], *_nodes[0])
+ GeoLib::calcTetrahedronVolume(*_nodes[5], *_nodes[3], *_nodes[1], *_nodes[0])
+ GeoLib::calcTetrahedronVolume(*_nodes[5], *_nodes[7], *_nodes[3], *_nodes[0])
+ GeoLib::calcTetrahedronVolume(*_nodes[5], *_nodes[7], *_nodes[6], *_nodes[2])
+ GeoLib::calcTetrahedronVolume(*_nodes[1], *_nodes[3], *_nodes[5], *_nodes[2])
+ GeoLib::calcTetrahedronVolume(*_nodes[3], *_nodes[7], *_nodes[5], *_nodes[2]);
}
bool HexRule8::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps)
{
return (GeoLib::isPointInTetrahedron(pnt, *_nodes[4], *_nodes[7], *_nodes[5], *_nodes[0], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[3], *_nodes[1], *_nodes[0], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[3], *_nodes[0], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[6], *_nodes[2], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[1], *_nodes[3], *_nodes[5], *_nodes[2], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[3], *_nodes[7], *_nodes[5], *_nodes[2], eps));
return (GeoLib::isPointInTetrahedron(pnt, *_nodes[4], *_nodes[7], *_nodes[5], *_nodes[0], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[3], *_nodes[1], *_nodes[0], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[3], *_nodes[0], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[6], *_nodes[2], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[1], *_nodes[3], *_nodes[5], *_nodes[2], eps) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[3], *_nodes[7], *_nodes[5], *_nodes[2], eps));
}
unsigned HexRule8::identifyFace(Node const* const* _nodes, Node* nodes[3])
{
for (unsigned i=0; i<6; i++)
{
unsigned flag(0);
for (unsigned j=0; j<4; j++)
for (unsigned k=0; k<3; k++)
if (_nodes[face_nodes[i][j]] == nodes[k])
flag++;
if (flag==3)
return i;
}
return std::numeric_limits<unsigned>::max();
for (unsigned i=0; i<6; i++)
{
unsigned flag(0);
for (unsigned j=0; j<4; j++)
for (unsigned k=0; k<3; k++)
if (_nodes[face_nodes[i][j]] == nodes[k])
flag++;
if (flag==3)
return i;
}
return std::numeric_limits<unsigned>::max();
}
ElementErrorCode HexRule8::validate(const Element* e)
{
ElementErrorCode error_code;
error_code[ElementErrorFlag::ZeroVolume] = e->hasZeroVolume();
for (unsigned i=0; i<6; ++i)
{
if (error_code.all())
break;
const MeshLib::Element* quad (e->getFace(i));
error_code |= quad->validate();
delete quad;
}
error_code[ElementErrorFlag::NodeOrder] = !e->testElementNodeOrder();
return error_code;
ElementErrorCode error_code;
error_code[ElementErrorFlag::ZeroVolume] = e->hasZeroVolume();
for (unsigned i=0; i<6; ++i)
{
if (error_code.all())
break;
const MeshLib::Element* quad (e->getFace(i));
error_code |= quad->validate();
delete quad;
}
error_code[ElementErrorFlag::NodeOrder] = !e->testElementNodeOrder();
return error_code;
}
} // end namespace MeshLib
......@@ -46,60 +46,60 @@ namespace MeshLib
class HexRule8 : public CellRule
{
public:
/// Constant: The number of base nodes for this element
static const unsigned n_base_nodes = 8u;
/// Constant: The number of base nodes for this element
static const unsigned n_base_nodes = 8u;
/// Constant: The number of all nodes for this element
static const unsigned n_all_nodes = 8u;
/// Constant: The number of all nodes for this element
static const unsigned n_all_nodes = 8u;
/// Constant: The geometric type of the element
static const MeshElemType mesh_elem_type = MeshElemType::HEXAHEDRON;
/// Constant: The geometric type of the element
static const MeshElemType mesh_elem_type = MeshElemType::HEXAHEDRON;
/// Constant: The FEM type of the element
static const CellType cell_type = CellType::HEX8;
/// Constant: The FEM type of the element
static const CellType cell_type = CellType::HEX8;
/// Constant: The number of faces
static const unsigned n_faces = 6;
/// Constant: The number of faces
static const unsigned n_faces = 6;
/// Constant: The number of edges
static const unsigned n_edges = 12;
/// Constant: The number of edges
static const unsigned n_edges = 12;
/// Constant: The number of neighbors
static const unsigned n_neighbors = 6;
/// Constant: The number of neighbors
static const unsigned n_neighbors = 6;
/// Constant: Local node index table for faces
static const unsigned face_nodes[6][4];
/// Constant: Local node index table for faces
static const unsigned face_nodes[6][4];
/// Constant: Local node index table for edge
static const unsigned edge_nodes[12][2];
/// Constant: Local node index table for edge
static const unsigned edge_nodes[12][2];
/// Returns the i-th edge of the element.
typedef LinearEdgeReturn EdgeReturn;
/// Returns the i-th edge of the element.
typedef LinearEdgeReturn EdgeReturn;
/// Get the number of nodes for face i.
static unsigned getNFaceNodes(unsigned /*i*/) { return 4; }
/// Get the number of nodes for face i.
static unsigned getNFaceNodes(unsigned /*i*/) { return 4; }
/// Returns the i-th face of the element.
static const Element* getFace(const Element* e, unsigned i);
/// Returns the i-th face of the element.
static const Element* getFace(const Element* e, unsigned i);
/**
* Checks if a point is inside the element.
* @param pnt a 3D MathLib::Point3D object
* @param eps tolerance for numerical algorithm used or computing the property
* @return true if the point is not outside the element, false otherwise
*/
static bool isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps);
/**
* Checks if a point is inside the element.
* @param pnt a 3D MathLib::Point3D object
* @param eps tolerance for numerical algorithm used or computing the property
* @return true if the point is not outside the element, false otherwise
*/
static bool isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps);
/**
* Tests if the element is geometrically valid.
*/
static ElementErrorCode validate(const Element* e);
/**
* Tests if the element is geometrically valid.
*/
static ElementErrorCode validate(const Element* e);
/// Returns the ID of a face given an array of nodes.
static unsigned identifyFace(Node const* const*, Node* nodes[3]);
/// Returns the ID of a face given an array of nodes.
static unsigned identifyFace(Node const* const*, Node* nodes[3]);
/// Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.
static double computeVolume(Node const* const* _nodes);
/// Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.
static double computeVolume(Node const* const* _nodes);
}; /* class */
......
......@@ -19,36 +19,36 @@ namespace MeshLib {
const unsigned LineRule2::edge_nodes[1][2] =
{
{0, 1} // Edge 0
{0, 1} // Edge 0
};
double LineRule2::computeVolume(Node const* const* _nodes)
{
return sqrt(MathLib::sqrDist(_nodes[0]->getCoords(), _nodes[1]->getCoords()));
return sqrt(MathLib::sqrDist(_nodes[0]->getCoords(), _nodes[1]->getCoords()));
}
bool LineRule2::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps)
{
double tmp;
double tmp_dst(0);
double const dist =MathLib::calcProjPntToLineAndDists(pnt.getCoords(), _nodes[0]->getCoords(), _nodes[1]->getCoords(), tmp, tmp_dst);
return (dist < eps);
double tmp;
double tmp_dst(0);
double const dist =MathLib::calcProjPntToLineAndDists(pnt.getCoords(), _nodes[0]->getCoords(), _nodes[1]->getCoords(), tmp, tmp_dst);
return (dist < eps);
}
unsigned LineRule2::identifyFace(Node const* const* _nodes, Node* nodes[1])
{
if (nodes[0] == _nodes[0])
return 0;
if (nodes[0] == _nodes[1])
return 1;
return std::numeric_limits<unsigned>::max();
if (nodes[0] == _nodes[0])
return 0;
if (nodes[0] == _nodes[1])
return 1;
return std::numeric_limits<unsigned>::max();
}
ElementErrorCode LineRule2::validate(const Element* e)
{
ElementErrorCode error_code;
error_code[ElementErrorFlag::ZeroVolume] = e->hasZeroVolume();
return error_code;
ElementErrorCode error_code;
error_code[ElementErrorFlag::ZeroVolume] = e->hasZeroVolume();
return error_code;
}
} // end namespace MeshLib
......@@ -27,45 +27,45 @@ namespace MeshLib
class LineRule2 : public EdgeRule
{
public:
/// Constant: The number of base nodes for this element
static const unsigned n_base_nodes = 2u;
/// Constant: The number of base nodes for this element
static const unsigned n_base_nodes = 2u;
/// Constant: The number of all nodes for this element
static const unsigned n_all_nodes = 2u;
/// Constant: The number of all nodes for this element
static const unsigned n_all_nodes = 2u;
/// Constant: The geometric type of the element
static const MeshElemType mesh_elem_type = MeshElemType::LINE;
/// Constant: The geometric type of the element
static const MeshElemType mesh_elem_type = MeshElemType::LINE;
/// Constant: The FEM type of the element
static const CellType cell_type = CellType::LINE2;
/// Constant: The FEM type of the element
static const CellType cell_type = CellType::LINE2;
/// Constant: The number of neighbors
static const unsigned n_neighbors = 2;
/// Constant: The number of neighbors
static const unsigned n_neighbors = 2;
/// Constant: Local node index table for edge
static const unsigned edge_nodes[1][2];
/// Constant: Local node index table for edge
static const unsigned edge_nodes[1][2];
/// Edge rule
typedef NoEdgeReturn EdgeReturn;
/// Edge rule
typedef NoEdgeReturn EdgeReturn;
/**
* Checks if a point is inside the element.
* @param pnt a 3D MathLib::Point3d object
* @param eps tolerance for numerical algorithm used or computing the property
* @return true if the point is not outside the element, false otherwise
*/
static bool isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps);
/**
* Checks if a point is inside the element.
* @param pnt a 3D MathLib::Point3d object
* @param eps tolerance for numerical algorithm used or computing the property
* @return true if the point is not outside the element, false otherwise
*/
static bool isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps);
/**
* Tests if the element is geometrically valid.
*/
static ElementErrorCode validate(const Element* e);
/**
* Tests if the element is geometrically valid.
*/
static ElementErrorCode validate(const Element* e);
/// Returns the ID of a face given an array of nodes.
static unsigned identifyFace(Node const* const*, Node* nodes[1]);
/// Returns the ID of a face given an array of nodes.
static unsigned identifyFace(Node const* const*, Node* nodes[1]);
/// Calculates the length of a line
static double computeVolume(Node const* const* _nodes);
/// Calculates the length of a line
static double computeVolume(Node const* const* _nodes);
}; /* class */
......
......@@ -25,11 +25,11 @@ namespace MeshLib
class LineRule3 : public LineRule2
{
public:
/// Constant: The number of all nodes for this element
static const unsigned n_all_nodes = 3u;
/// Constant: The number of all nodes for this element
static const unsigned n_all_nodes = 3u;
/// Constant: The FEM type of the element
static const CellType cell_type = CellType::LINE3;
/// Constant: The FEM type of the element
static const CellType cell_type = CellType::LINE3;
}; /* class */
} /* namespace */
......
......@@ -17,7 +17,7 @@ extern template class MeshLib::TemplateElement<MeshLib::PointRule1>;
namespace MeshLib
{
using Point = TemplateElement<PointRule1>;
using Point = TemplateElement<PointRule1>;
}
#endif // MESHLIB_POINT_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