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_++;
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) );
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 ];
281 data_ =
ALBERTA alloc_macro_data( dim, initialSize, initialSize );
282 data_->boundary = memAlloc< BoundaryId >( initialSize*numVertices );
284 data_->el_type = memAlloc< ElementType >( initialSize );
285 vertexCount_ = elementCount_ = 0;
293 if( (vertexCount_ >= 0) && (elementCount_ >= 0) )
295 resizeVertices( vertexCount_ );
296 resizeElements( elementCount_ );
297 ALBERTA compute_neigh_fast( data_ );
300 for(
int element = 0; element < elementCount_; ++element )
302 for(
int i = 0; i < numVertices; ++i )
305 if( neighbor( element, i ) >= 0 )
315 vertexCount_ = elementCount_ = -1;
317 assert( (vertexCount_ < 0) && (elementCount_ < 0) );
345 assert( elementCount_ >= 0 );
346 if( elementCount_ >= data_->n_macro_elements )
347 resizeElements( 2*elementCount_ );
349 ElementId &e = element( elementCount_ );
350 for(
int i = 0; i < numVertices; ++i )
356 data_->el_type[ elementCount_ ] = 0;
358 return elementCount_++;
366 int &count = data_->n_wall_trafos;
370 array = memReAlloc< AffineTransformation >( array, count, count+1 );
371 assert( data_->wall_trafos != NULL );
375 copy( matrix[ i ], array[ count ].M[ i ] );
376 copy( shift, array[ count ].t );
383 const FieldVector< Real, dimWorld > &shift )
385 int &count = data_->n_wall_trafos;
389 array = memReAlloc< AffineTransformation >( array, count, count+1 );
390 assert( data_->wall_trafos != NULL );
394 copy( matrix[ i ], array[ count ].M[ i ] );
395 copy( shift, array[ count ].t );
405 ALBERTA macro_test( data_, NULL );
414 data_ =
ALBERTA read_macro_xdr( filename.c_str() );
416 data_ =
ALBERTA read_macro( filename.c_str() );
423 const int oldSize = data_->n_macro_elements;
424 data_->n_macro_elements = newSize;
425 data_->mel_vertices =
memReAlloc( data_->mel_vertices, oldSize*numVertices, newSize*numVertices );
426 data_->boundary =
memReAlloc( data_->boundary, oldSize*numVertices, newSize*numVertices );
428 data_->el_type =
memReAlloc( data_->el_type, oldSize, newSize );
429 assert( (newSize == 0) || (data_->mel_vertices != NULL) );
#define ALBERTA
Definition albertaheader.hh:27
Include standard header files.
Definition agrid.hh:60
ALBERTA REAL_DD GlobalMatrix
Definition misc.hh:48
ALBERTA AFF_TRAFO AffineTransformation
Definition misc.hh:49
ALBERTA BNDRY_TYPE BoundaryId
Definition misc.hh:58
static const int InteriorBoundary
Definition misc.hh:56
ALBERTA REAL Real
Definition misc.hh:45
Data * memReAlloc(Data *ptr, size_t oldSize, size_t newSize)
Definition misc.hh:82
static const int DirichletBoundary
Definition misc.hh:57
static const int dimWorld
Definition misc.hh:43
ALBERTA REAL_D GlobalVector
Definition misc.hh:47
Definition macrodata.hh:28
friend struct InstantiateMacroDataLibrary
Definition macrodata.hh:43
BoundaryId & boundaryId(int element, int i) const
Definition macrodata.hh:269
int insertVertex(const GlobalVector &coords)
insert vertex
Definition macrodata.hh:147
int ElementId[numVertices]
Definition macrodata.hh:46
static const int supportPeriodicity
Definition macrodata.hh:48
void release()
release the macro data structure
Definition macrodata.hh:125
int elementCount() const
Definition macrodata.hh:66
GlobalVector & vertex(int i) const
Definition macrodata.hh:252
int vertexCount() const
Definition macrodata.hh:61
void markLongestEdge()
mark the longest edge of all elements as refinement edges
Definition macrodata.hh:322
int insertVertex(const FieldVector< Real, dimWorld > &coords)
insert vertex
Definition macrodata.hh:161
bool checkNeighbors() const
check the neighbor information
Definition macrodata.hh:336
void insertWallTrafo(const FieldMatrix< Real, dimWorld, dimWorld > &matrix, const FieldVector< Real, dimWorld > &shift)
Definition macrodata.hh:382
ElementId & element(int i) const
Definition macrodata.hh:243
void checkCycles()
Definition macrodata.hh:401
int & neighbor(int element, int i) const
Definition macrodata.hh:260
MacroData()
Definition macrodata.hh:50
void finalize()
compress macro data structure
Definition macrodata.hh:291
void insertWallTrafo(const GlobalMatrix &m, const GlobalVector &t)
Definition macrodata.hh:364
void setOrientation(const Real orientation)
set the orientation of all elements
Definition macrodata.hh:329
void create()
create a new macro data structure
Definition macrodata.hh:278
int insertElement(const ElementId &id)
insert element
Definition macrodata.hh:343
bool write(const std::string &filename, bool binary=false) const
Definition macrodata.hh:178
void read(const std::string &filename, bool binary=false)
Definition macrodata.hh:410
Definition macrodata.hh:218
static void markLongestEdge(MacroData ¯oData)
Alberta::MacroData< dim > MacroData
Definition macrodata.hh:219