1 #ifndef DUNE_ALBERTA_MACRODATA_HH
2 #define DUNE_ALBERTA_MACRODATA_HH
9 #include <dune/common/fvector.hh>
10 #include <dune/common/fmatrix.hh>
29 typedef ALBERTA MACRO_DATA Data;
31 static const int dimension = dim;
32 static const int numVertices = NumSubEntities< dimension, dimension >::value;
33 static const int numEdges = NumSubEntities< dimension, dimension-1 >::value;
35 static const int initialSize = 4096;
54 operator Data * ()
const
61 return (vertexCount_ < 0 ? data_->n_total_vertices : vertexCount_);
66 return (elementCount_ < 0 ? data_->n_macro_elements : elementCount_);
127 ALBERTA free_macro_data( data_ );
130 vertexCount_ = elementCount_ = -1;
147 assert( vertexCount_ >= 0 );
148 if( vertexCount_ >= data_->n_total_vertices )
149 resizeVertices( 2*vertexCount_ );
150 copy( coords,
vertex( vertexCount_ ) );
151 return vertexCount_++;
161 assert( vertexCount_ >= 0 );
162 if( vertexCount_ >= data_->n_total_vertices )
163 resizeVertices( 2*vertexCount_ );
164 copy( coords,
vertex( vertexCount_ ) );
165 return vertexCount_++;
169 void insertWallTrafo (
const FieldMatrix< Real, dimWorld, dimWorld > &matrix,
170 const FieldVector< Real, dimWorld > &shift );
174 void read (
const std::string &filename,
bool binary =
false );
176 bool write (
const std::string &filename,
bool binary =
false )
const
179 return ALBERTA write_macro_data_xdr( data_, filename.c_str() );
181 return ALBERTA write_macro_data( data_, filename.c_str() );
185 template<
class Vector >
192 void resizeElements (
const int newSize );
194 void resizeVertices (
const int newSize )
196 const int oldSize = data_->n_total_vertices;
197 data_->n_total_vertices = newSize;
198 data_->coords = memReAlloc< GlobalVector >( data_->coords, oldSize, newSize );
199 assert( (data_->coords != NULL) || (newSize == 0) );
227 template<
class Type >
228 static void rotate ( Type *array,
int i,
int shift );
230 static void rotate (
MacroData ¯oData,
int i,
int shift );
231 static void swap (
MacroData ¯oData,
int el,
int v1,
int v2 );
243 assert( (i >= 0) && (i < data_->n_macro_elements) );
244 const int offset = i * numVertices;
245 return *
reinterpret_cast< ElementId *
>( data_->mel_vertices + offset );
252 assert( (i >= 0) && (i < data_->n_total_vertices) );
253 return data_->coords[ i ];
260 assert( (element >= 0) && (element < data_->n_macro_elements) );
261 assert( (i >= 0) && (i < numVertices) );
262 return data_->neigh[ element*numVertices + i ];
269 assert( (element >= 0) && (element < data_->n_macro_elements) );
270 assert( (i >= 0) && (i < numVertices) );
271 return data_->boundary[ element*numVertices + i ];
275 #if DUNE_ALBERTA_VERSION >= 0x300
280 data_ =
ALBERTA alloc_macro_data( dim, initialSize, initialSize );
281 data_->boundary = memAlloc< BoundaryId >( initialSize*numVertices );
283 data_->el_type = memAlloc< ElementType >( initialSize );
284 vertexCount_ = elementCount_ = 0;
287 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
289 #if DUNE_ALBERTA_VERSION == 0x200
294 data_ =
ALBERTA alloc_macro_data( dim, initialSize, initialSize, 0 );
295 data_->boundary = memAlloc< BoundaryId >( initialSize*numVertices );
297 data_->el_type = memAlloc< ElementType >( initialSize );
298 vertexCount_ = elementCount_ = 0;
301 #endif // #if DUNE_ALBERTA_VERSION == 0x200
307 if( (vertexCount_ >= 0) && (elementCount_ >= 0) )
309 resizeVertices( vertexCount_ );
310 resizeElements( elementCount_ );
311 ALBERTA compute_neigh_fast( data_ );
314 for(
int element = 0; element < elementCount_; ++element )
316 for(
int i = 0; i < numVertices; ++i )
319 if( neighbor( element, i ) >= 0 )
329 vertexCount_ = elementCount_ = -1;
331 assert( (vertexCount_ < 0) && (elementCount_ < 0) );
359 assert( elementCount_ >= 0 );
360 if( elementCount_ >= data_->n_macro_elements )
361 resizeElements( 2*elementCount_ );
363 ElementId &e = element( elementCount_ );
364 for(
int i = 0; i < numVertices; ++i )
370 data_->el_type[ elementCount_ ] = 0;
372 return elementCount_++;
376 #if DUNE_ALBERTA_VERSION >= 0x300
381 int &count = data_->n_wall_trafos;
385 array = memReAlloc< AffineTransformation >( array, count, count+1 );
386 assert( data_->wall_trafos != NULL );
390 copy( matrix[ i ], array[ count ].M[ i ] );
391 copy( shift, array[ count ].t );
398 const FieldVector< Real, dimWorld > &shift )
400 int &count = data_->n_wall_trafos;
401 AffineTransformation *&array = data_->wall_trafos;
404 array = memReAlloc< AffineTransformation >( array, count, count+1 );
405 assert( data_->wall_trafos != NULL );
409 copy( matrix[ i ], array[ count ].M[ i ] );
410 copy( shift, array[ count ].t );
413 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
415 #if DUNE_ALBERTA_VERSION <= 0x200
421 "Periodic grids are only supported in ALBERTA 3.0 or higher." );
427 const FieldVector< Real, dimWorld > &shift )
430 "Periodic grids are only supported in ALBERTA 3.0 or higher." );
432 #endif // #if DUNE_ALBERTA_VERSION <= 0x200
440 ALBERTA macro_test( data_, NULL );
449 data_ =
ALBERTA read_macro_xdr( filename.c_str() );
451 data_ =
ALBERTA read_macro( filename.c_str() );
458 const int oldSize = data_->n_macro_elements;
459 data_->n_macro_elements = newSize;
460 data_->mel_vertices =
memReAlloc( data_->mel_vertices, oldSize*numVertices, newSize*numVertices );
461 data_->boundary =
memReAlloc( data_->boundary, oldSize*numVertices, newSize*numVertices );
463 data_->el_type =
memReAlloc( data_->el_type, oldSize, newSize );
464 assert( (newSize == 0) || (data_->mel_vertices != NULL) );
471 #endif // #if HAVE_ALBERTA