diff --git a/FileIO/MeshIO.cpp b/FileIO/MeshIO.cpp index 2444bae5a56ad1d4b80c241898cdd5e83e2ed105..ca1931a5aa73f5bdf1a768e0b0245951841fdea4 100644 --- a/FileIO/MeshIO.cpp +++ b/FileIO/MeshIO.cpp @@ -51,6 +51,7 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) if(line_string.find("#FEM_MSH") != std::string::npos) // OGS mesh file { + double edge_length[2] = { std::numeric_limits<double>::max(), std::numeric_limits<double>::min() }; while (!in.eof()) { getline(in, line_string); @@ -86,13 +87,21 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) for (unsigned i = 0; i < nElements; i++) { getline(in, line_string); - + + size_t elem_idx (elements.size()); elements.push_back(readElement(line_string, nodes)); + + double elem_min_length, elem_max_length; + elements[elem_idx]->computeSqrEdgeLengthRange(elem_min_length, elem_max_length); + edge_length[0] = (elem_min_length<edge_length[0]) ? elem_min_length : edge_length[0]; + edge_length[1] = (elem_max_length>edge_length[1]) ? elem_max_length : edge_length[1]; } } } MeshLib::Mesh* mesh (new MeshLib::Mesh(file_name, nodes, elements)); + mesh->setEdgeLengthRange(sqrt(edge_length[0]), sqrt(edge_length[1])); + std::cout << "Nr. Nodes: " << nodes.size() << std::endl; std::cout << "Nr. Elements: " << elements.size() << std::endl; @@ -163,6 +172,7 @@ MeshLib::Element* MeshIO::readElement(const std::string& line, const std::vector elem = NULL; } + /* neighbors.resize(nfaces); for (unsigned i = 0; i < nfaces; i++) @@ -174,6 +184,7 @@ MeshLib::Element* MeshIO::readElement(const std::string& line, const std::vector int MeshIO::write(std::ostream &out) { + (void)out; /* if(!_mesh) { diff --git a/MeshLib/Elements/Edge.h b/MeshLib/Elements/Edge.h index 1d1ba8117d688345288c7c363955414e201187d0..5d430ec84863ed0f1bf9d0c152bb6b2ade486d22 100644 --- a/MeshLib/Elements/Edge.h +++ b/MeshLib/Elements/Edge.h @@ -44,6 +44,9 @@ public: /// Returns the face i of the element. const Element* getFace(unsigned i) const { (void)i; return NULL; }; + /// Compute the minimum and maximum squared edge length for this element + void computeSqrEdgeLengthRange(double &min, double &max) const { min = _length; max = _length; }; + /// 1D elements have no edges unsigned getNEdges() const { return 0; }; diff --git a/MeshLib/Elements/Element.cpp b/MeshLib/Elements/Element.cpp index 967e287e94a8c1cd961fcb7e8e41db3b9f3b93e3..d0d33a6e108b18fac39de5ddddda49e068b06a96 100644 --- a/MeshLib/Elements/Element.cpp +++ b/MeshLib/Elements/Element.cpp @@ -9,7 +9,7 @@ #include "Node.h" #include "Edge.h" -#include <cassert> +#include "MathTools.h" namespace MeshLib { @@ -41,6 +41,19 @@ const Element* Element::getEdge(unsigned i) const return NULL; } +void Element::computeSqrEdgeLengthRange(double &min, double &max) const +{ + min = std::numeric_limits<double>::max(); + max = std::numeric_limits<double>::min(); + unsigned nEdges (this->getNEdges()); + for (unsigned i=0; i<nEdges; i++) + { + double dist (MathLib::sqrDist(getEdgeNode(i,0)->getData(), getEdgeNode(i,1)->getData())); + min = (dist<min) ? dist : min; + max = (dist>max) ? dist : max; + } +} + const Element* Element::getNeighbor(unsigned i) const { if (i < getNNeighbors()) @@ -62,7 +75,7 @@ unsigned Element::getNodeIndex(unsigned i) const if (i<getNNodes()) return _nodes[i]->getID(); std::cerr << "Error in MeshLib::Element::getNodeIndex() - Index does not exist." << std::endl; - return NULL; + return std::numeric_limits<unsigned>::max(); } bool Element::hasNeighbor(Element* elem) const diff --git a/MeshLib/Elements/Element.h b/MeshLib/Elements/Element.h index 7c29d7e32c91b160be6ee78059ba760e61876f29..e00aa97c405a962c5a0be6e4877161e5c89fd547 100644 --- a/MeshLib/Elements/Element.h +++ b/MeshLib/Elements/Element.h @@ -27,6 +27,9 @@ class Element public: + /// Compute the minimum and maximum squared edge length for this element + virtual void computeSqrEdgeLengthRange(double &min, double &max) const; + /// Get node with local index i. const Node* getNode(unsigned i) const; diff --git a/MeshLib/FemMesh.h b/MeshLib/FemMesh.h index 9a390cd4e6cbb849b5cb3a4a2e161e56ecd3e0b3..9cf4617441d44bb23b4cf535e4e8b67e3e4fb3ff 100644 --- a/MeshLib/FemMesh.h +++ b/MeshLib/FemMesh.h @@ -30,6 +30,8 @@ public: /// Destructor virtual ~FemMesh(); +private: + }; /* class */ diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index cf99e0ea3498214815f9af60be4a10d07703e194..1ccd564a0b50734f6bf6354c0517db2416f47bd8 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -20,7 +20,8 @@ namespace MeshLib { Mesh::Mesh(const std::string &name, const std::vector<Node*> &nodes, const std::vector<Element*> &elements) : _name(name), _nodes(nodes), _elements(elements) { - double _edge_length[2] = {0, 0}; + _edge_length[0] = 0; + _edge_length[1] = 0; this->makeNodesUnique(); this->setElementInformationForNodes(); this->setNeighborInformationForElements(); @@ -86,6 +87,16 @@ void Mesh::setElementInformationForNodes() } } +void Mesh::setEdgeLengthRange(const double &min_length, const double &max_length) +{ + if (min_length <= max_length) + { + _edge_length[0] = min_length; + _edge_length[1] = max_length; + } + std::cerr << "Error in MeshLib::Mesh::setEdgeLengthRange() - min length < max length." << std::endl; +} + void Mesh::setNeighborInformationForElements() { /* TODO diff --git a/MeshLib/Mesh.h b/MeshLib/Mesh.h index 9959cc8d89c6a11452dab6e7de33429d5b87cfe2..ba570f9973428e7f6cb69639be67df31a775e0fb 100644 --- a/MeshLib/Mesh.h +++ b/MeshLib/Mesh.h @@ -12,7 +12,6 @@ #include <string> #include <vector> - namespace MeshLib { class Node; @@ -52,6 +51,12 @@ public: /// Get the element with the given index. const Element* getElement(unsigned idx) const { return _elements[idx]; }; + /// Get the minimum edge length for the mesh + double getMinEdgeLength() const { return _edge_length[0]; }; + + /// Get the maximum edge length for the mesh + double getMaxEdgeLength() const { return _edge_length[1]; }; + /// Get the number of elements size_t getNElements() const { return _elements.size(); }; @@ -66,6 +71,8 @@ public: /// Get the element-vector for the mesh. const std::vector<Element*> getElements() const { return _elements; }; + + void setEdgeLengthRange(const double &min_length, const double &max_length); protected: /// Checks the coordinates of all mesh nodes and removes identical nodes. Elements are adapted accordingly. @@ -77,7 +84,7 @@ protected: /// Fills in the neighbor-information for elements. void setNeighborInformationForElements(); - static double _edge_length[2]; + double _edge_length[2]; std::string _name; std::vector<Node*> _nodes; std::vector<Element*> _elements; diff --git a/SimpleTests/MeshTests/MeshRead.cpp b/SimpleTests/MeshTests/MeshRead.cpp index 0cca029a58f63adde12c8f6340feac4eb08af38d..6a3b4250e5f875c4ca594c6e7b24a17b7b2ae54e 100644 --- a/SimpleTests/MeshTests/MeshRead.cpp +++ b/SimpleTests/MeshTests/MeshRead.cpp @@ -17,13 +17,13 @@ int main(int argc, char *argv[]) { - std::string file_name("/mnt/visdata/tom/data/TestMeshes/Mesh-dx1.00-Layered20.msh"); + //std::string file_name("/mnt/visdata/tom/data/TestMeshes/Mesh-dx1.00-Layered20.msh"); + std::string file_name("c:/Project/PlyTestMesh.msh"); std::cout << "sizeof(double): " << sizeof (double) << std::endl; std::cout << "sizeof(GeoLib::Point): " << sizeof (GEOLIB::Point) << std::endl; std::cout << "sizeof(GeoLib::PointWithID): " << sizeof (GEOLIB::PointWithID) << std::endl; std::cout << "sizeof(Node): " << sizeof (MeshLib::Node) << std::endl; std::cout << "sizeof(Element): " << sizeof (MeshLib::Element) << std::endl; - //std::string file_name("c:/Project/PlyTestMesh.msh"); FileIO::MeshIO mesh_io; #ifndef WIN32 BaseLib::MemWatch mem_watch;