Skip to content
Snippets Groups Projects
Element.cpp 3.29 KiB
Newer Older
Lars Bilke's avatar
Lars Bilke committed
 * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
Lars Bilke's avatar
Lars Bilke committed
 *            Distributed under a Modified BSD License.
 *              See accompanying file LICENSE.txt or
Lars Bilke's avatar
Lars Bilke committed
 *              http://www.opengeosys.org/project/license
Lars Bilke's avatar
Lars Bilke committed
 *
 *
Lars Bilke's avatar
Lars Bilke committed
 * \file Element.cpp
Lars Bilke's avatar
Lars Bilke committed
 * Created on 2012-05-02 by Karsten Rink
#include "logog/include/logog.hpp"

#include "Element.h"
#include "Node.h"
Element::Element(unsigned value)
	: _nodes(NULL), _value(value), _neighbors(NULL)
	delete [] this->_nodes;
	delete [] this->_neighbors;
Karsten Rink's avatar
Karsten Rink committed
	if (e == this)
		return false;

	unsigned nNeighbors (this->getNNeighbors());
	{
		if (this->_neighbors[n] == e)
			return false;
		if (this->_neighbors[n] == NULL)
			break;
	}

	Node* face_nodes[3];
	const unsigned nNodes (this->getNNodes());
	const unsigned eNodes (e->getNNodes());
	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 true;
				}
			}

const Element* Element::getEdge(unsigned i) const
{
	if (i < getNEdges())
	{
		Node** nodes = new Node*[2];
		nodes[0] = const_cast<Node*>(getEdgeNode(i,0));
		nodes[1] = const_cast<Node*>(getEdgeNode(i,1));
	ERR("Error in MeshLib::Element::getEdge() - Index does not exist.");
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), getEdgeNode(i,1)));
		min = (dist<min) ? dist : min;
		max = (dist>max) ? dist : max;
	}
}

const Element* Element::getNeighbor(unsigned i) const
	ERR("Error in MeshLib::Element::getNeighbor() - Index does not exist.");
unsigned Element::getNodeIDinElement(const MeshLib::Node* node) const
{
	const unsigned nNodes (this->getNNodes());
	for (unsigned i(0); i<nNodes; i++)
Lars Bilke's avatar
Lars Bilke committed
		if (node == _nodes[i])
			return i;
	return std::numeric_limits<unsigned>::max();
}

const Node* Element::getNode(unsigned i) const
	ERR("Error in MeshLib::Element::getNode() - Index %d in %s", i, MshElemType2String(getGeomType()).c_str());
void Element::setNode(unsigned idx, Node* node)
{
	if (idx < getNNodes())
		_nodes[idx] = node;
}

Lars Bilke's avatar
Lars Bilke committed
unsigned Element::getNodeIndex(unsigned i) const
	ERR("Error in MeshLib::Element::getNodeIndex() - Index does not exist.");
	return std::numeric_limits<unsigned>::max();
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;
}