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

added calculation of min- and max-edge-length; fixed more warnings

parent 7216a6df
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,7 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) ...@@ -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 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()) while (!in.eof())
{ {
getline(in, line_string); getline(in, line_string);
...@@ -86,13 +87,21 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) ...@@ -86,13 +87,21 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name)
for (unsigned i = 0; i < nElements; i++) for (unsigned i = 0; i < nElements; i++)
{ {
getline(in, line_string); getline(in, line_string);
size_t elem_idx (elements.size());
elements.push_back(readElement(line_string, nodes)); 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)); 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. Nodes: " << nodes.size() << std::endl;
std::cout << "Nr. Elements: " << elements.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 ...@@ -163,6 +172,7 @@ MeshLib::Element* MeshIO::readElement(const std::string& line, const std::vector
elem = NULL; elem = NULL;
} }
/* /*
neighbors.resize(nfaces); neighbors.resize(nfaces);
for (unsigned i = 0; i < nfaces; i++) for (unsigned i = 0; i < nfaces; i++)
...@@ -174,6 +184,7 @@ MeshLib::Element* MeshIO::readElement(const std::string& line, const std::vector ...@@ -174,6 +184,7 @@ MeshLib::Element* MeshIO::readElement(const std::string& line, const std::vector
int MeshIO::write(std::ostream &out) int MeshIO::write(std::ostream &out)
{ {
(void)out;
/* /*
if(!_mesh) if(!_mesh)
{ {
......
...@@ -44,6 +44,9 @@ public: ...@@ -44,6 +44,9 @@ public:
/// Returns the face i of the element. /// Returns the face i of the element.
const Element* getFace(unsigned i) const { (void)i; return NULL; }; 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 /// 1D elements have no edges
unsigned getNEdges() const { return 0; }; unsigned getNEdges() const { return 0; };
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "Node.h" #include "Node.h"
#include "Edge.h" #include "Edge.h"
#include <cassert> #include "MathTools.h"
namespace MeshLib { namespace MeshLib {
...@@ -41,6 +41,19 @@ const Element* Element::getEdge(unsigned i) const ...@@ -41,6 +41,19 @@ const Element* Element::getEdge(unsigned i) const
return NULL; 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 const Element* Element::getNeighbor(unsigned i) const
{ {
if (i < getNNeighbors()) if (i < getNNeighbors())
...@@ -62,7 +75,7 @@ unsigned Element::getNodeIndex(unsigned i) const ...@@ -62,7 +75,7 @@ unsigned Element::getNodeIndex(unsigned i) const
if (i<getNNodes()) if (i<getNNodes())
return _nodes[i]->getID(); return _nodes[i]->getID();
std::cerr << "Error in MeshLib::Element::getNodeIndex() - Index does not exist." << std::endl; 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 bool Element::hasNeighbor(Element* elem) const
......
...@@ -27,6 +27,9 @@ class Element ...@@ -27,6 +27,9 @@ class Element
public: 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. /// Get node with local index i.
const Node* getNode(unsigned i) const; const Node* getNode(unsigned i) const;
......
...@@ -30,6 +30,8 @@ public: ...@@ -30,6 +30,8 @@ public:
/// Destructor /// Destructor
virtual ~FemMesh(); virtual ~FemMesh();
private:
}; /* class */ }; /* class */
......
...@@ -20,7 +20,8 @@ namespace MeshLib { ...@@ -20,7 +20,8 @@ namespace MeshLib {
Mesh::Mesh(const std::string &name, const std::vector<Node*> &nodes, const std::vector<Element*> &elements) Mesh::Mesh(const std::string &name, const std::vector<Node*> &nodes, const std::vector<Element*> &elements)
: _name(name), _nodes(nodes), _elements(elements) : _name(name), _nodes(nodes), _elements(elements)
{ {
double _edge_length[2] = {0, 0}; _edge_length[0] = 0;
_edge_length[1] = 0;
this->makeNodesUnique(); this->makeNodesUnique();
this->setElementInformationForNodes(); this->setElementInformationForNodes();
this->setNeighborInformationForElements(); this->setNeighborInformationForElements();
...@@ -86,6 +87,16 @@ void Mesh::setElementInformationForNodes() ...@@ -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() void Mesh::setNeighborInformationForElements()
{ {
/* TODO /* TODO
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace MeshLib namespace MeshLib
{ {
class Node; class Node;
...@@ -52,6 +51,12 @@ public: ...@@ -52,6 +51,12 @@ public:
/// Get the element with the given index. /// Get the element with the given index.
const Element* getElement(unsigned idx) const { return _elements[idx]; }; 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 /// Get the number of elements
size_t getNElements() const { return _elements.size(); }; size_t getNElements() const { return _elements.size(); };
...@@ -66,6 +71,8 @@ public: ...@@ -66,6 +71,8 @@ public:
/// Get the element-vector for the mesh. /// Get the element-vector for the mesh.
const std::vector<Element*> getElements() const { return _elements; }; const std::vector<Element*> getElements() const { return _elements; };
void setEdgeLengthRange(const double &min_length, const double &max_length);
protected: protected:
/// Checks the coordinates of all mesh nodes and removes identical nodes. Elements are adapted accordingly. /// Checks the coordinates of all mesh nodes and removes identical nodes. Elements are adapted accordingly.
...@@ -77,7 +84,7 @@ protected: ...@@ -77,7 +84,7 @@ protected:
/// Fills in the neighbor-information for elements. /// Fills in the neighbor-information for elements.
void setNeighborInformationForElements(); void setNeighborInformationForElements();
static double _edge_length[2]; double _edge_length[2];
std::string _name; std::string _name;
std::vector<Node*> _nodes; std::vector<Node*> _nodes;
std::vector<Element*> _elements; std::vector<Element*> _elements;
......
...@@ -17,13 +17,13 @@ ...@@ -17,13 +17,13 @@
int main(int argc, char *argv[]) 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(double): " << sizeof (double) << std::endl;
std::cout << "sizeof(GeoLib::Point): " << sizeof (GEOLIB::Point) << 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(GeoLib::PointWithID): " << sizeof (GEOLIB::PointWithID) << std::endl;
std::cout << "sizeof(Node): " << sizeof (MeshLib::Node) << std::endl; std::cout << "sizeof(Node): " << sizeof (MeshLib::Node) << std::endl;
std::cout << "sizeof(Element): " << sizeof (MeshLib::Element) << std::endl; std::cout << "sizeof(Element): " << sizeof (MeshLib::Element) << std::endl;
//std::string file_name("c:/Project/PlyTestMesh.msh");
FileIO::MeshIO mesh_io; FileIO::MeshIO mesh_io;
#ifndef WIN32 #ifndef WIN32
BaseLib::MemWatch mem_watch; BaseLib::MemWatch mem_watch;
......
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