3 #ifndef DUNE_ALBERTA_MACRODATA_HH
4 #define DUNE_ALBERTA_MACRODATA_HH
11 #include <dune/common/fvector.hh>
12 #include <dune/common/fmatrix.hh>
31 typedef ALBERTA MACRO_DATA Data;
33 static const int dimension = dim;
35 static const int numEdges =
NumSubEntities< dimension, dimension-1 >::value;
37 static const int initialSize = 4096;
56 operator Data * ()
const
63 return (vertexCount_ < 0 ? data_->n_total_vertices : vertexCount_);
68 return (elementCount_ < 0 ? data_->n_macro_elements : elementCount_);
129 ALBERTA free_macro_data( data_ );
132 vertexCount_ = elementCount_ = -1;
149 assert( vertexCount_ >= 0 );
150 if( vertexCount_ >= data_->n_total_vertices )
151 resizeVertices( 2*vertexCount_ );
152 copy( coords,
vertex( vertexCount_ ) );
153 return vertexCount_++;
163 assert( vertexCount_ >= 0 );
164 if( vertexCount_ >= data_->n_total_vertices )
165 resizeVertices( 2*vertexCount_ );
166 copy( coords,
vertex( vertexCount_ ) );
167 return vertexCount_++;
171 void insertWallTrafo (
const FieldMatrix< Real, dimWorld, dimWorld > &matrix,
172 const FieldVector< Real, dimWorld > &shift );
176 void read (
const std::string &filename,
bool binary =
false );
178 bool write (
const std::string &filename,
bool binary =
false )
const
181 return ALBERTA write_macro_data_xdr( data_, filename.c_str() );
183 return ALBERTA write_macro_data( data_, filename.c_str() );
187 template<
class Vector >
194 void resizeElements (
const int newSize );
196 void resizeVertices (
const int newSize )
198 const int oldSize = data_->n_total_vertices;
199 data_->n_total_vertices = newSize;
200 data_->coords = memReAlloc< GlobalVector >( data_->coords, oldSize, newSize );
201 assert( (data_->coords != NULL) || (newSize == 0) );
217 struct MacroData< dim >::Library
229 template<
class Type >
230 static void rotate ( Type *array,
int i,
int shift );
232 static void rotate (
MacroData ¯oData,
int i,
int shift );
233 static void swap (
MacroData ¯oData,
int el,
int v1,
int v2 );
245 assert( (i >= 0) && (i < data_->n_macro_elements) );
246 const int offset = i * numVertices;
247 return *
reinterpret_cast< ElementId *
>( data_->mel_vertices + offset );
254 assert( (i >= 0) && (i < data_->n_total_vertices) );
255 return data_->coords[ i ];
262 assert( (element >= 0) && (element < data_->n_macro_elements) );
263 assert( (i >= 0) && (i < numVertices) );
264 return data_->neigh[ element*numVertices + i ];
271 assert( (element >= 0) && (element < data_->n_macro_elements) );
272 assert( (i >= 0) && (i < numVertices) );
273 return data_->boundary[ element*numVertices + i ];
277 #if DUNE_ALBERTA_VERSION >= 0x300
282 data_ =
ALBERTA alloc_macro_data( dim, initialSize, initialSize );
283 data_->boundary = memAlloc< BoundaryId >( initialSize*numVertices );
285 data_->el_type = memAlloc< ElementType >( initialSize );
286 vertexCount_ = elementCount_ = 0;
289 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
291 #if DUNE_ALBERTA_VERSION == 0x200
296 data_ =
ALBERTA alloc_macro_data( dim, initialSize, initialSize, 0 );
297 data_->boundary = memAlloc< BoundaryId >( initialSize*numVertices );
299 data_->el_type = memAlloc< ElementType >( initialSize );
300 vertexCount_ = elementCount_ = 0;
303 #endif // #if DUNE_ALBERTA_VERSION == 0x200
309 if( (vertexCount_ >= 0) && (elementCount_ >= 0) )
311 resizeVertices( vertexCount_ );
312 resizeElements( elementCount_ );
313 ALBERTA compute_neigh_fast( data_ );
316 for(
int element = 0; element < elementCount_; ++element )
318 for(
int i = 0; i < numVertices; ++i )
321 if( neighbor( element, i ) >= 0 )
331 vertexCount_ = elementCount_ = -1;
333 assert( (vertexCount_ < 0) && (elementCount_ < 0) );
361 assert( elementCount_ >= 0 );
362 if( elementCount_ >= data_->n_macro_elements )
363 resizeElements( 2*elementCount_ );
365 ElementId &e = element( elementCount_ );
366 for(
int i = 0; i < numVertices; ++i )
372 data_->el_type[ elementCount_ ] = 0;
374 return elementCount_++;
378 #if DUNE_ALBERTA_VERSION >= 0x300
383 int &count = data_->n_wall_trafos;
387 array = memReAlloc< AffineTransformation >( array, count, count+1 );
388 assert( data_->wall_trafos != NULL );
392 copy( matrix[ i ], array[ count ].M[ i ] );
393 copy( shift, array[ count ].t );
400 const FieldVector< Real, dimWorld > &shift )
402 int &count = data_->n_wall_trafos;
403 AffineTransformation *&array = data_->wall_trafos;
406 array = memReAlloc< AffineTransformation >( array, count, count+1 );
407 assert( data_->wall_trafos != NULL );
411 copy( matrix[ i ], array[ count ].M[ i ] );
412 copy( shift, array[ count ].t );
415 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
417 #if DUNE_ALBERTA_VERSION <= 0x200
423 "Periodic grids are only supported in ALBERTA 3.0 or higher." );
429 const FieldVector< Real, dimWorld > &shift )
432 "Periodic grids are only supported in ALBERTA 3.0 or higher." );
434 #endif // #if DUNE_ALBERTA_VERSION <= 0x200
442 ALBERTA macro_test( data_, NULL );
451 data_ =
ALBERTA read_macro_xdr( filename.c_str() );
453 data_ =
ALBERTA read_macro( filename.c_str() );
460 const int oldSize = data_->n_macro_elements;
461 data_->n_macro_elements = newSize;
462 data_->mel_vertices =
memReAlloc( data_->mel_vertices, oldSize*numVertices, newSize*numVertices );
463 data_->boundary =
memReAlloc( data_->boundary, oldSize*numVertices, newSize*numVertices );
465 data_->el_type =
memReAlloc( data_->el_type, oldSize, newSize );
466 assert( (newSize == 0) || (data_->mel_vertices != NULL) );
473 #endif // #if HAVE_ALBERTA
static const int dimWorld
Definition: misc.hh:43
static const int DirichletBoundary
Definition: misc.hh:67
void create()
create a new macro data structure
bool checkNeighbors() const
check the neighbor information
Definition: macrodata.hh:352
static const int InteriorBoundary
Definition: misc.hh:66
int insertVertex(const FieldVector< Real, dimWorld > &coords)
insert vertex
Definition: macrodata.hh:161
friend struct InstantiateMacroDataLibrary
Definition: macrodata.hh:41
Definition: macrodata.hh:41
MacroData()
Definition: macrodata.hh:50
void markLongestEdge()
mark the longest edge of all elements as refinement edges
Definition: macrodata.hh:338
ALBERTA REAL_D GlobalVector
Definition: misc.hh:47
int vertexCount() const
Definition: macrodata.hh:61
int & neighbor(int element, int i) const
Definition: macrodata.hh:260
bool write(const std::string &filename, bool binary=false) const
Definition: macrodata.hh:178
S_CHAR BoundaryId
Definition: misc.hh:71
Definition: macrodata.hh:27
void checkCycles()
Definition: macrodata.hh:438
Data * memReAlloc(Data *ptr, size_t oldSize, size_t newSize)
Definition: misc.hh:96
ElementId & element(int i) const
Definition: macrodata.hh:243
void read(const std::string &filename, bool binary=false)
Definition: macrodata.hh:447
#define ALBERTA
Definition: albertaheader.hh:27
void insertWallTrafo(const GlobalMatrix &m, const GlobalVector &t)
Definition: macrodata.hh:420
void setOrientation(const Real orientation)
set the orientation of all elements
Definition: macrodata.hh:345
GlobalVector & vertex(int i) const
Definition: macrodata.hh:252
int insertElement(const ElementId &id)
insert element
Definition: macrodata.hh:359
BoundaryId & boundaryId(int element, int i) const
Definition: macrodata.hh:269
Alberta::MacroData< dim > MacroData
Definition: macrodata.hh:219
ALBERTA REAL_DD GlobalMatrix
Definition: misc.hh:48
ALBERTA REAL Real
Definition: misc.hh:45
static const int supportPeriodicity
Definition: macrodata.hh:48
int insertVertex(const GlobalVector &coords)
insert vertex
Definition: macrodata.hh:147
void finalize()
compress macro data structure
Definition: macrodata.hh:307
int ElementId[numVertices]
Definition: macrodata.hh:46
void release()
release the macro data structure
Definition: macrodata.hh:125
int elementCount() const
Definition: macrodata.hh:66