diff --git a/MeshLib/Elements/Cell.cpp b/MeshLib/Elements/Cell.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1c997a85f32f11abf61f1d4af09ef0acb9b5083c --- /dev/null +++ b/MeshLib/Elements/Cell.cpp @@ -0,0 +1,59 @@ +/** + * \file + * \author Karsten Rink + * \date 2012-05-02 + * \brief Implementation of the Cell class. + * + * \copyright + * Copyright (c) 2012-2014, 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 "Cell.h" + +#include "MathLib/Vector3.h" +#include "MeshLib/Node.h" + +namespace MeshLib { + +#ifndef WIN32 +/// \todo Windows compiler does not accept this definition and issues a linking error. +const unsigned Cell::dimension; +#endif // WIN32 + +/* +Cell::Cell(Node** nodes, MeshElemType type, unsigned value) + : Element(nodes, type, value) +{ +} +*/ +Cell::Cell(unsigned value, std::size_t id) + : Element(value, id), _volume(-1.0) // init with invalid value to detect errors +{ +} + +Cell::~Cell() +{} + +bool Cell::testElementNodeOrder() const +{ + const MathLib::Vector3 c (getCenterOfGravity()); + const unsigned nFaces (this->getNFaces()); + for (unsigned j=0; j<nFaces; ++j) + { + MeshLib::Face const*const face (dynamic_cast<const MeshLib::Face*>(this->getFace(j))); + const MeshLib::Node x (*(face->getNode(1))); + const MathLib::Vector3 cx (c, x); + const double s = MathLib::scalarProduct(face->getSurfaceNormal(), cx); + delete face; + if (s >= 0) + return false; + } + return true; +} + +} + diff --git a/MeshLib/Elements/Cell.h b/MeshLib/Elements/Cell.h index b143a98359b201ee7452a371aafeef06b83ce3c0..d64fe479870d83307108041b9f10a9828835ace3 100644 --- a/MeshLib/Elements/Cell.h +++ b/MeshLib/Elements/Cell.h @@ -39,7 +39,7 @@ public: virtual double getVolume() const { return _volume; }; /// Destructor - virtual ~Cell() = default; + virtual ~Cell(); /** * This method is pure virtual and is inherited from class @sa Element. @@ -56,22 +56,7 @@ public: * (non-planar faces, non-convex geometry, possibly zero volume) which causes the calculated * center of gravity to lie outside of the actual element */ - virtual bool testElementNodeOrder() const - { - const MathLib::Vector3 c (getCenterOfGravity()); - const unsigned nFaces (this->getNFaces()); - for (unsigned j=0; j<nFaces; ++j) - { - MeshLib::Face const*const face (dynamic_cast<const MeshLib::Face*>(this->getFace(j))); - const MeshLib::Node x (*(face->getNode(1))); - const MathLib::Vector3 cx (c, x); - const double s = MathLib::scalarProduct(face->getSurfaceNormal(), cx); - delete face; - if (s >= 0) - return false; - } - return true; - } + virtual bool testElementNodeOrder() const; protected: /* @@ -79,9 +64,7 @@ protected: Cell(Node** nodes, MeshElemType type, unsigned value = 0); */ /// Constructor for a generic mesh element without an array of mesh nodes. - Cell(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()) - : Element(value, id), _volume(-1.0) // init with invalid value to detect errors - { } + Cell(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()); double _volume; diff --git a/MeshLib/Elements/Face.cpp b/MeshLib/Elements/Face.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2f888f157132d054b314cdb96d6a116e51a2fb1c --- /dev/null +++ b/MeshLib/Elements/Face.cpp @@ -0,0 +1,57 @@ +/** + * \file + * \author Karsten Rink + * \date 2012-05-02 + * \brief Implementation of the Face class. + * + * \copyright + * Copyright (c) 2012-2014, 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 "Face.h" + +#include "MathLib/MathTools.h" +#include "MathLib/Vector3.h" + +#include "Line.h" + +namespace MeshLib { + +#ifndef WIN32 + /// \todo Windows compiler does not accept this definition and issues a linking error. + const unsigned Face::dimension; +#endif // WIN32 + +/* +Face::Face(Node** nodes, MeshElemType type, unsigned value) + : Element(nodes, type, value) +{ +} +*/ +Face::Face(unsigned value, std::size_t id) + : Element(value, id), _area(-1.0) // init with invalid value to detect errors +{ +} + +Face::~Face() +{} + +MathLib::Vector3 Face::getSurfaceNormal() const +{ + const MathLib::Vector3 u (*_nodes[1], *_nodes[0]); + const MathLib::Vector3 v (*_nodes[1], *_nodes[2]); + return MathLib::crossProduct(u,v); +} + +bool Face::testElementNodeOrder() const +{ + MathLib::Vector3 up_vec (0,0,1); + return (MathLib::scalarProduct(this->getSurfaceNormal(), up_vec) < 0) ? true : false; +} + +} + diff --git a/MeshLib/Elements/Face.h b/MeshLib/Elements/Face.h index b8f6c2a10d9c55bfe68a597b061e8013d59b0988..70efd57ba698cd99a926bd68ffcad511528c4644 100644 --- a/MeshLib/Elements/Face.h +++ b/MeshLib/Elements/Face.h @@ -20,7 +20,6 @@ #include "GeoLib/Point.h" #include "MathLib/Vector3.h" -#include "MeshLib/Node.h" #include "Element.h" @@ -54,15 +53,10 @@ public: unsigned getNFaces() const { return 0; }; /// Returns the surface normal of a 2D element. - MathLib::Vector3 getSurfaceNormal() const - { - const MathLib::Vector3 u (*_nodes[1], *_nodes[0]); - const MathLib::Vector3 v (*_nodes[1], *_nodes[2]); - return MathLib::crossProduct(u,v); - } + MathLib::Vector3 getSurfaceNormal() const; /// Destructor - virtual ~Face() = default; + virtual ~Face(); /** * This method is pure virtual and is inherited from class @sa Element. @@ -75,12 +69,7 @@ public: * 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. */ - virtual bool testElementNodeOrder() const - { - MathLib::Vector3 up_vec (0,0,1); - return (MathLib::scalarProduct(this->getSurfaceNormal(), up_vec) < 0) - ? true : false; - } + virtual bool testElementNodeOrder() const; protected: /* @@ -88,9 +77,7 @@ protected: Face(Node** nodes, MeshElemType type, unsigned value = 0); */ /// Constructor for a generic mesh element without an array of mesh nodes. - Face(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()) - : Element(value, id), _area(-1.0) // init with invalid value to detect errors - { } + Face(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()); double _area;