5#ifndef DUNE_ALBERTA_MACRODATA_HH
6#define DUNE_ALBERTA_MACRODATA_HH
16#include <dune/grid/albertagrid/misc.hh>
17#include <dune/grid/albertagrid/algebra.hh>
18#include <dune/grid/albertagrid/albertaheader.hh>
31 typedef MacroData< dim > This;
33 typedef ALBERTA MACRO_DATA Data;
35 static const int dimension = dim;
36 static const int numVertices = NumSubEntities< dimension, dimension >::value;
37 static const int numEdges = NumSubEntities< dimension, dimension-1 >::value;
39 static const int initialSize = 4096;
45 template<
int >
friend struct InstantiateMacroDataLibrary;
48 typedef int ElementId[ numVertices ];
50 static const int supportPeriodicity = 1;
58 operator Data * ()
const
63 int vertexCount ()
const
65 return (vertexCount_ < 0 ? data_->n_total_vertices : vertexCount_);
68 int elementCount ()
const
70 return (elementCount_ < 0 ? data_->n_macro_elements : elementCount_);
73 ElementId &element (
int i )
const;
74 GlobalVector &
vertex (
int i )
const;
75 int &neighbor (
int element,
int i )
const;
76 BoundaryId &boundaryId (
int element,
int i )
const;
102 void markLongestEdge ();
112 void setOrientation (
const Real orientation );
124 bool checkNeighbors ()
const;
131 ALBERTA free_macro_data( data_ );
134 vertexCount_ = elementCount_ = -1;
142 int insertElement (
const ElementId &
id );
149 int insertVertex (
const GlobalVector &coords )
151 assert( vertexCount_ >= 0 );
152 if( vertexCount_ >= data_->n_total_vertices )
153 resizeVertices( 2*vertexCount_ );
154 copy( coords,
vertex( vertexCount_ ) );
155 return vertexCount_++;
163 int insertVertex (
const FieldVector< Real, dimWorld > &coords )
165 assert( vertexCount_ >= 0 );
166 if( vertexCount_ >= data_->n_total_vertices )
167 resizeVertices( 2*vertexCount_ );
168 copy( coords,
vertex( vertexCount_ ) );
169 return vertexCount_++;
172 void insertWallTrafo (
const GlobalMatrix &m,
const GlobalVector &t );
173 void insertWallTrafo (
const FieldMatrix< Real, dimWorld, dimWorld > &matrix,
174 const FieldVector< Real, dimWorld > &shift );
178 void read (
const std::string &filename,
bool binary =
false );
180 bool write (
const std::string &filename,
bool binary =
false )
const
183 return ALBERTA write_macro_data_xdr( data_, filename.c_str() );
185 return ALBERTA write_macro_data( data_, filename.c_str() );
189 template<
class Vector >
190 void copy (
const Vector &x, GlobalVector &y )
192 for(
int i = 0; i < dimWorld; ++i )
196 void resizeElements (
const int newSize );
198 void resizeVertices (
const int newSize )
200 const int oldSize = data_->n_total_vertices;
201 data_->n_total_vertices = newSize;
202 data_->coords = memReAlloc< GlobalVector >( data_->coords, oldSize, newSize );
203 assert( (data_->coords != NULL) || (newSize == 0) );
219 struct MacroData< dim >::Library
221 typedef Alberta::MacroData< dim > MacroData;
223 static bool checkNeighbors (
const MacroData ¯oData );
224 static void markLongestEdge ( MacroData ¯oData );
225 static void setOrientation ( [[maybe_unused]] MacroData ¯oData,
226 [[maybe_unused]]
const Real orientation );
229 static Real edgeLength (
const MacroData ¯oData,
const ElementId &e,
int edge );
230 static int longestEdge (
const MacroData ¯oData,
const ElementId &e );
232 template<
class Type >
233 static void rotate ( Type *array,
int i,
int shift );
235 static void rotate ( MacroData ¯oData,
int i,
int shift );
236 static void swap ( MacroData ¯oData,
int el,
int v1,
int v2 );
245 inline typename MacroData< dim >::ElementId &
246 MacroData< dim >::element (
int i )
const
248 assert( (i >= 0) && (i < data_->n_macro_elements) );
249 const int offset = i * numVertices;
250 return *
reinterpret_cast< ElementId *
>( data_->mel_vertices + offset );
257 assert( (i >= 0) && (i < data_->n_total_vertices) );
258 return data_->coords[ i ];
263 inline int &MacroData< dim >::neighbor (
int element,
int i )
const
265 assert( (element >= 0) && (element < data_->n_macro_elements) );
266 assert( (i >= 0) && (i < numVertices) );
267 return data_->neigh[ element*numVertices + i ];
272 inline BoundaryId &MacroData< dim >::boundaryId (
int element,
int i )
const
274 assert( (element >= 0) && (element < data_->n_macro_elements) );
275 assert( (i >= 0) && (i < numVertices) );
276 return data_->boundary[ element*numVertices + i ];
281 inline void MacroData< dim >::create ()
284 data_ = ALBERTA alloc_macro_data( dim, initialSize, initialSize );
285 data_->boundary = memAlloc< BoundaryId >( initialSize*numVertices );
287 data_->el_type = memAlloc< ElementType >( initialSize );
288 vertexCount_ = elementCount_ = 0;
294 inline void MacroData< dim >::finalize ()
296 if( (vertexCount_ >= 0) && (elementCount_ >= 0) )
298 resizeVertices( vertexCount_ );
299 resizeElements( elementCount_ );
300 ALBERTA compute_neigh_fast( data_ );
303 for(
int element = 0; element < elementCount_; ++element )
305 for(
int i = 0; i < numVertices; ++i )
307 BoundaryId &
id = boundaryId( element, i );
308 if( neighbor( element, i ) >= 0 )
310 assert(
id == InteriorBoundary );
311 id = InteriorBoundary;
314 id = (
id == InteriorBoundary ? DirichletBoundary : id);
318 vertexCount_ = elementCount_ = -1;
320 assert( (vertexCount_ < 0) && (elementCount_ < 0) );
325 inline void MacroData< dim >::markLongestEdge ()
327 Library< dimWorld >::markLongestEdge( *
this );
332 inline void MacroData< dim >::setOrientation (
const Real orientation )
334 Library< dimWorld >::setOrientation( *
this, orientation );
339 inline bool MacroData< dim >::checkNeighbors ()
const
341 return Library< dimWorld >::checkNeighbors( *
this );
346 inline int MacroData< dim >::insertElement (
const ElementId &
id )
348 assert( elementCount_ >= 0 );
349 if( elementCount_ >= data_->n_macro_elements )
350 resizeElements( 2*elementCount_ );
352 ElementId &e = element( elementCount_ );
353 for(
int i = 0; i < numVertices; ++i )
356 boundaryId( elementCount_, i ) = InteriorBoundary;
359 data_->el_type[ elementCount_ ] = 0;
361 return elementCount_++;
366 inline void MacroData< dim >
367 ::insertWallTrafo (
const GlobalMatrix &matrix,
const GlobalVector &shift )
369 int &count = data_->n_wall_trafos;
370 AffineTransformation *&array = data_->wall_trafos;
373 array = memReAlloc< AffineTransformation >( array, count, count+1 );
374 assert( data_->wall_trafos != NULL );
377 for(
int i = 0; i < dimWorld; ++i )
378 copy( matrix[ i ], array[ count ].M[ i ] );
379 copy( shift, array[ count ].t );
384 inline void MacroData< dim >
385 ::insertWallTrafo (
const FieldMatrix< Real, dimWorld, dimWorld > &matrix,
386 const FieldVector< Real, dimWorld > &shift )
388 int &count = data_->n_wall_trafos;
389 AffineTransformation *&array = data_->wall_trafos;
392 array = memReAlloc< AffineTransformation >( array, count, count+1 );
393 assert( data_->wall_trafos != NULL );
396 for(
int i = 0; i < dimWorld; ++i )
397 copy( matrix[ i ], array[ count ].M[ i ] );
398 copy( shift, array[ count ].t );
404 inline void MacroData< dim >::checkCycles ()
408 ALBERTA macro_test( data_, NULL );
413 inline void MacroData< dim >::read (
const std::string &filename,
bool binary )
417 data_ = ALBERTA read_macro_xdr( filename.c_str() );
419 data_ = ALBERTA read_macro( filename.c_str() );
424 inline void MacroData< dim >::resizeElements (
const int newSize )
426 const int oldSize = data_->n_macro_elements;
427 data_->n_macro_elements = newSize;
428 data_->mel_vertices = memReAlloc( data_->mel_vertices, oldSize*numVertices, newSize*numVertices );
429 data_->boundary = memReAlloc( data_->boundary, oldSize*numVertices, newSize*numVertices );
431 data_->el_type = memReAlloc( data_->el_type, oldSize, newSize );
432 assert( (newSize == 0) || (data_->mel_vertices != NULL) );
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
Dune namespace.
Definition: alignedallocator.hh:13