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

just a few changes to make the code look better (nullptr, for each loops, etc.

parent dcf5a27f
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@
namespace MeshLib {
Element::Element(unsigned value)
: _nodes(NULL), _value(value), _neighbors(NULL)
: _nodes(nullptr), _value(value), _neighbors(nullptr)
{
}
......@@ -43,7 +43,7 @@ bool Element::addNeighbor(Element* e)
{
if (this->_neighbors[n] == e)
return false;
if (this->_neighbors[n] == NULL)
if (this->_neighbors[n] == nullptr)
break;
}
......@@ -79,7 +79,7 @@ const Element* Element::getEdge(unsigned i) const
return new Edge(nodes);
}
ERR("Error in MeshLib::Element::getEdge() - Index does not exist.");
return NULL;
return nullptr;
}
void Element::computeSqrEdgeLengthRange(double &min, double &max) const
......@@ -100,7 +100,7 @@ const Element* Element::getNeighbor(unsigned i) const
if (i < getNNeighbors())
return _neighbors[i];
ERR("Error in MeshLib::Element::getNeighbor() - Index does not exist.");
return NULL;
return nullptr;
}
unsigned Element::getNodeIDinElement(const MeshLib::Node* node) const
......@@ -117,7 +117,7 @@ const Node* Element::getNode(unsigned i) const
if (i < getNNodes())
return _nodes[i];
ERR("Error in MeshLib::Element::getNode() - Index %d in %s", i, MshElemType2String(getGeomType()).c_str());
return NULL;
return nullptr;
}
void Element::setNode(unsigned idx, Node* node)
......
......@@ -57,8 +57,7 @@ TemplateHex<NNODES,CELLHEXTYPE>::TemplateHex(Node* nodes[NNODES], unsigned value
_nodes = nodes;
_neighbors = new Element*[6];
for (unsigned i=0; i<6; i++)
_neighbors[i] = NULL;
std::fill(_neighbors, _neighbors + 6, nullptr);
this->_volume = this->computeVolume();
}
......
......@@ -57,8 +57,7 @@ TemplatePrism<NNODES,CELLPRISMTYPE>::TemplatePrism(Node* nodes[NNODES], unsigned
{
_nodes = nodes;
_neighbors = new Element*[5];
for (unsigned i=0; i<5; i++)
_neighbors[i] = NULL;
std::fill(_neighbors, _neighbors + 5, nullptr);
this->_volume = this->computeVolume();
}
......
......@@ -57,8 +57,7 @@ TemplatePyramid<NNODES,CELLPYRAMIDTYPE>::TemplatePyramid(Node* nodes[NNODES], un
_nodes = nodes;
_neighbors = new Element*[5];
for (unsigned i=0; i<5; i++)
_neighbors[i] = NULL;
std::fill(_neighbors, _neighbors + 5, nullptr);
this->_volume = this->computeVolume();
}
......
......@@ -23,13 +23,12 @@
namespace MeshLib
{
template<unsigned NNODES, CellType::type CELLQUADTYPE>
TemplateQuad<NNODES,CELLQUADTYPE>::TemplateQuad(std::array<Node*, NNODES> const& nodes,
unsigned value)
template <unsigned NNODES, CellType::type CELLQUADTYPE>
TemplateQuad<NNODES,CELLQUADTYPE>::TemplateQuad(Node* nodes[NNODES], unsigned value)
: Face(value)
{
_nodes = new Node*[NNODES];
std::copy(nodes.begin(), nodes.end(), _nodes);
_nodes = nodes;
_neighbors = new Element*[4];
std::fill(_neighbors, _neighbors + 4, nullptr);
......@@ -37,15 +36,16 @@ TemplateQuad<NNODES,CELLQUADTYPE>::TemplateQuad(std::array<Node*, NNODES> const&
this->_area = this->computeVolume();
}
template <unsigned NNODES, CellType::type CELLQUADTYPE>
TemplateQuad<NNODES,CELLQUADTYPE>::TemplateQuad(Node* nodes[NNODES], unsigned value)
template<unsigned NNODES, CellType::type CELLQUADTYPE>
TemplateQuad<NNODES,CELLQUADTYPE>::TemplateQuad(std::array<Node*, NNODES> const& nodes,
unsigned value)
: Face(value)
{
_nodes = nodes;
_nodes = new Node*[NNODES];
std::copy(nodes.begin(), nodes.end(), _nodes);
_neighbors = new Element*[4];
for (unsigned i=0; i<4; i++)
_neighbors[i] = NULL;
std::fill(_neighbors, _neighbors + 4, nullptr);
this->_area = this->computeVolume();
}
......
......@@ -48,8 +48,7 @@ TemplateTet<NNODES,CELLTETTYPE>::TemplateTet(Node* nodes[NNODES], unsigned value
_nodes = nodes;
_neighbors = new Element*[4];
for (unsigned i=0; i<4; i++)
_neighbors[i] = NULL;
std::fill(_neighbors, _neighbors + 4, nullptr);
this->_volume = this->computeVolume();
}
......
......@@ -23,8 +23,7 @@ TemplateTri<NNODES,CELLTRITYPE>::TemplateTri(Node* nodes[NNODES], unsigned value
{
_nodes = nodes;
_neighbors = new Element*[3];
for (unsigned i=0; i<3; i++)
_neighbors[i] = NULL;
std::fill(_neighbors, _neighbors + 3, nullptr);
this->_area = this->computeVolume();
}
......
......@@ -137,24 +137,25 @@ void Mesh::setDimension()
void Mesh::setElementsConnectedToNodes()
{
const size_t nElements (_elements.size());
for (unsigned i=0; i<nElements; ++i)
//const size_t nElements (_elements.size());
for (MeshLib::Element* element : _elements)
{
MeshLib::Element* element = _elements[i];
const unsigned nNodes (element->getNNodes());
for (unsigned j=0; j<nNodes; ++j)
element->_nodes[j]->addElement(element);
}
//#ifndef NDEBUG
// search for nodes that are not part of any element
unsigned count(0);
const size_t nNodes (_nodes.size());
for (unsigned i=0; i<nNodes; ++i)
if (_nodes[i]->getNElements() == 0)
for (MeshLib::Node* node : _nodes)
{
if (node->getNElements() == 0)
{
WARN ("Node %d is not part of any element.", i);
WARN ("Node %d is not part of any element.", node->getID());
++count;
}
}
if (count)
WARN ("%d unused mesh nodes found.", count);
//#endif
......
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