1 #ifndef __ADAPTIVETRIANGMESH_H 2 #define __ADAPTIVETRIANGMESH_H 11 template <
typename DomVecType>
20 template<
typename DataTypeContainer,
typename TriangleType >
26 typedef typename DataTypeContainer::DomVecType
DomVecType;
30 typedef typename DataTypeContainer::MaskType
MaskType;
57 _mesh(Mesh), _triangle (triangleIndex), _node(localNodeIndex), _edge(localEdgeIndex) {}
65 _mesh(Mesh), _triangle (triangleIndex), _node((localEdgeIndex + 1) % 3), _edge(localEdgeIndex) {}
96 return 3 - (_node + _edge);
101 return 3 - (_node + _edge);
115 template<
typename DartIteratorType>
118 if(_triangle != d.getGlobalTriangleIndex())
119 throw std::invalid_argument(
aol::strprintf(
"T=%d, but this->tringle = %d. In File %s at line %d.", d.getGlobalTriangleIndex(), _triangle, __FILE__, __LINE__).c_str() );
120 if ( _edge == d.getLocalEdgeIndex() )
121 throw std::invalid_argument(
aol::strprintf(
"points to same edge=. In File %s at line %d.", __FILE__, __LINE__).c_str() );
122 return 3 - ( getLocalEdgeIndex() + d.getLocalEdgeIndex() );
126 template<
typename DartIteratorType>
129 if ( getGlobalNodeIndex() == d.getGlobalNodeIndex() || getGlobalNodeIndex() == d.getNextNodeGlobalIndex() )
130 return getGlobalNodeIndex();
131 if ( getNextNodeGlobalIndex() == d.getGlobalNodeIndex() || getNextNodeGlobalIndex() == d.getNextNodeGlobalIndex() )
132 return getNextNodeGlobalIndex();
133 throw std::invalid_argument(
aol::strprintf(
"Dart d and *this have no node in common. In File %s at line %d.", __FILE__, __LINE__).c_str() );
139 cerr <<
"triangle = " << _triangle <<
", node = " << _node <<
", edge = " << _edge << endl;
145 return this->getNextTriangleIndex() !=
IndexNotSet ;
151 if( !canFlipTriangle() )
152 throw std::invalid_argument(
aol::strprintf(
"Cannot flip triangle. In File %s at line %d.", __FILE__, __LINE__).c_str() );
154 GlobalIndex newTriangleIndex = getNextTriangleIndex();
170 if ( _mesh.
getTriangNodeIdx( newTriangleIndex,(newNodeIndex + i) % 3 ) == globalOtherNodesIndex ) {
171 newOtherNodesIndex = (newNodeIndex + i) % 3;
176 if ( min( newNodeIndex, newOtherNodesIndex ) < 0 )
177 throw std::invalid_argument(
aol::strprintf(
"newTriang should neighbour of _triangle but has no common node .In File %s at line %d.", __FILE__, __LINE__ ).c_str() );
179 LocalIndex newEdgeIndex = (-(newNodeIndex + newOtherNodesIndex)) % 3;
180 if (newEdgeIndex < 0) newEdgeIndex += 3;
183 _triangle = newTriangleIndex;
184 _node = newNodeIndex;
185 _edge = newEdgeIndex;
191 _node = getNextNodeLocalIndex();
197 _edge = getNextEdgeLocalIndex();
208 _markedForRefinement( this->getNumTriangs(), false )
210 this->makeNeighbour();
215 return _interpolationMap;
221 _markedForRefinement[ element ] =
true;
227 for(
unsigned i = 0; i < _markedForRefinement.size(); i++ ) _markedForRefinement[i] =
true;
233 _markedForRefinement[ element ] =
false;
239 for(
unsigned i = 0; i < _markedForRefinement.size(); i++ )
240 _markedForRefinement[i] =
false;
244 return _markedForRefinement[element];
250 _markedForRefinement.push_back(
false );
258 const int numElements = this->getNumTriangs();
259 for (
int elementIndex = 0; elementIndex < numElements; ++elementIndex )
260 if ( isMarkedForRefinement( elementIndex ) ) refine( elementIndex );
261 this->makeOrientationConsistent();
262 this->updateAllTriangles();
268 VectorType oldFunction =
function;
269 int oldSize =
function.size();
270 function.resize( this->getNumVertices() );
271 for(
int i = 0; i < oldSize; ++i )
function[i] = oldFunction[i];
272 typename std::map< int, ParentInformation<DomVecType> >::const_iterator iter;
273 for(
int i = oldSize; i <
function.size(); ++i ) {
274 iter = _interpolationMap.find( i );
275 if( iter == _interpolationMap.end() )
throw std::invalid_argument (
aol::strprintf (
"unknown vertex in File %s at line %d.", __FILE__, __LINE__ ).c_str() );
276 function[i] = 0.5 * (
function[iter->second.globalIndices[0]] +
function[iter->second.globalIndices[1]] );
284 const Indices3DType &triangIdx ( this->getTriang( triangle ).getGlobalNodeIdx() );
287 Point3DType edge = this->getVertex( triangIdx[1] );
288 edge -= this->getVertex( triangIdx[2] );
289 RealType maxLength = edge.squaredNorm();
291 edge = this->getVertex( triangIdx[2] );
292 edge -= this->getVertex( triangIdx[0] );
293 RealType candidate = edge.squaredNorm();
294 if( candidate > maxLength ) {
296 maxLength = candidate;
299 edge = this->getVertex( triangIdx[0] );
300 edge -= this->getVertex( triangIdx[1] );
301 candidate = edge.squaredNorm();
302 if( candidate > maxLength ) localIdx = 2;
311 DartIterator d( *
this, triangleToRefine, getLongestEdgeIndex( triangleToRefine ) );
336 Point3DType newVertex;
343 int newNodeIdx = this->pushBackVertex( newVertex );
void flipEdge()
moves to other edge with _node (inside current triangle)
GlobalIndex refine(GlobalIndex triangleToRefine)
void flipNode()
Moves to other node along _edge (inside current triangle)
GlobalIndex getNextNodeGlobalIndex() const
DataTypeContainer::MaskType MaskType
GlobalIndex getGlobalTriangleIndex() const
void unmarkAll()
Unmark all elements.
std::map< int, ParentInformation< DomVecType > > _interpolationMap
void refineMarkedTriangles()
Refines at least all triangles that have been marked.
short LocalIndex
defines for local node and edge numbering
void flipTriangle()
Moves to neighbouring triangle across _edge.
void mark(int element)
Mark element for refinement.
int getNeighbour(const int elementID, const int acrossLocalEdge) const
Get neighbor on edge.
DataTypeContainer::RealType RealType
std::vector< bool > _markedForRefinement
GlobalIndex getNextTriangleIndex() const
int pushBackTriang(const Indices3DType newTriang)
bool canFlipTriangle() const
Does _triangle have a neighbour across _edge?
DataTypeContainer::VectorType VectorType
void prolongateLinearly(VectorType &function) const
Prolongate by linear interpolation.
void markAll()
Mark all elements for refinement.
std::vector< Indices3DType > VertexIndicesType
LocalIndex getLocalEdgeIndex() const
LocalIndex getLongestEdgeIndex(GlobalIndex triangle) const
Get longest edge index (starting search possibly with a preferred edge)
LocalIndex getNextNodeLocalIndex() const
GlobalIndex getCommonNodeGlobalIndex(const DartIteratorType &d) const
Returns global index of common node (also if "d" refers to a different triangle than _triangle ) ...
LocalIndex getNextEdgeLocalIndex() const
int getTriangNodeIdx(const int num, const int localNode) const
GlobalIndex addEdgeMidpoint(const DartIterator &d)
Add edge midpoint on d.edge, update _interpolationMap and return global index of node.
string strprintf(const char *format,...)
Give back formatted string, analogously to sprintf, but save the long way 'round with char arrays...
DartIterator(const MeshType &Mesh, GlobalIndex triangleIndex, LocalIndex localEdgeIndex, LocalIndex localNodeIndex)
Constructor.
LocalIndex getCommonNodeLocalIndex(const DartIteratorType &d) const
Returns local index of common node (first checking if "d" also refers to _triangle, but to a different node)
DartIterator(const MeshType &Mesh, GlobalIndex triangleIndex, LocalIndex localEdgeIndex)
Constructor. Does not take a note, but orients the DartIterator counterclockwise. ...
LocalIndex getLocalNodeIndex() const
ConfiguratorType::VectorType VectorType
std::vector< Point3DType > VertexCoordsType
bool isMarkedForRefinement(int element) const
DataTypeContainer::Point3DType Point3DType
GlobalIndex getGlobalNodeIndex() const
DataTypeContainer::Indices3DType Indices3DType
void unmark(int element)
Ensure that element is not marked for refinement.
AdaptiveTriangMesh(const string &fileName)
DataTypeContainer::DomVecType DomVecType
Triangle which has a tangent space at each node.
GlobalIndex refine(const DartIterator &d)
const std::map< int, ParentInformation< DomVecType > > & getInterpolationMap() const
AdaptiveTriangMesh< DataTypeContainer, TriangleType > MeshType