5#ifndef DUNE_ALBERTA_MACRODATA_HH
6#define DUNE_ALBERTA_MACRODATA_HH
13#include <dune/common/fvector.hh>
14#include <dune/common/fmatrix.hh>
33 typedef ALBERTA MACRO_DATA Data;
35 static const int dimension = dim;
37 static const int numEdges =
NumSubEntities< dimension, dimension-1 >::value;
39 static const int initialSize = 4096;
58 operator Data * ()
const
65 return (vertexCount_ < 0 ? data_->n_total_vertices : vertexCount_);
70 return (elementCount_ < 0 ? data_->n_macro_elements : elementCount_);
131 ALBERTA free_macro_data( data_ );
134 vertexCount_ = elementCount_ = -1;
151 assert( vertexCount_ >= 0 );
152 if( vertexCount_ >= data_->n_total_vertices )
153 resizeVertices( 2*vertexCount_ );
154 copy( coords,
vertex( vertexCount_ ) );
155 return vertexCount_++;
165 assert( vertexCount_ >= 0 );
166 if( vertexCount_ >= data_->n_total_vertices )
167 resizeVertices( 2*vertexCount_ );
168 copy( coords,
vertex( vertexCount_ ) );
169 return vertexCount_++;
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 >
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) );
226 [[maybe_unused]]
const Real orientation );
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 );
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 ];
265 assert( (element >= 0) && (element < data_->n_macro_elements) );
266 assert( (i >= 0) && (i < numVertices) );
267 return data_->neigh[ element*numVertices + i ];
274 assert( (element >= 0) && (element < data_->n_macro_elements) );
275 assert( (i >= 0) && (i < numVertices) );
276 return data_->boundary[ element*numVertices + i ];
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;
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 )
308 if( neighbor( element, i ) >= 0 )
318 vertexCount_ = elementCount_ = -1;
320 assert( (vertexCount_ < 0) && (elementCount_ < 0) );
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 )
359 data_->el_type[ elementCount_ ] = 0;
361 return elementCount_++;
369 int &count = data_->n_wall_trafos;
373 array = memReAlloc< AffineTransformation >( array, count, count+1 );
374 assert( data_->wall_trafos != NULL );
378 copy( matrix[ i ], array[ count ].M[ i ] );
379 copy( shift, array[ count ].t );
386 const FieldVector< Real, dimWorld > &shift )
388 int &count = data_->n_wall_trafos;
392 array = memReAlloc< AffineTransformation >( array, count, count+1 );
393 assert( data_->wall_trafos != NULL );
397 copy( matrix[ i ], array[ count ].M[ i ] );
398 copy( shift, array[ count ].t );
408 ALBERTA macro_test( data_, NULL );
417 data_ =
ALBERTA read_macro_xdr( filename.c_str() );
419 data_ =
ALBERTA read_macro( filename.c_str() );
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) );
#define ALBERTA
Definition: albertaheader.hh:29
void swap(Dune::PersistentContainer< G, T > &a, Dune::PersistentContainer< G, T > &b)
Definition: utility/persistentcontainer.hh:83
Include standard header files.
Definition: agrid.hh:60
ALBERTA REAL_DD GlobalMatrix
Definition: misc.hh:51
ALBERTA AFF_TRAFO AffineTransformation
Definition: misc.hh:52
ALBERTA BNDRY_TYPE BoundaryId
Definition: misc.hh:61
static const int InteriorBoundary
Definition: misc.hh:59
ALBERTA REAL Real
Definition: misc.hh:48
Data * memReAlloc(Data *ptr, size_t oldSize, size_t newSize)
Definition: misc.hh:85
static const int DirichletBoundary
Definition: misc.hh:60
static const int dimWorld
Definition: misc.hh:46
ALBERTA REAL_D GlobalVector
Definition: misc.hh:50
Definition: macrodata.hh:30
friend struct InstantiateMacroDataLibrary
Definition: macrodata.hh:45
BoundaryId & boundaryId(int element, int i) const
Definition: macrodata.hh:272
int insertVertex(const GlobalVector &coords)
insert vertex
Definition: macrodata.hh:149
int ElementId[numVertices]
Definition: macrodata.hh:48
static const int supportPeriodicity
Definition: macrodata.hh:50
void release()
release the macro data structure
Definition: macrodata.hh:127
int elementCount() const
Definition: macrodata.hh:68
GlobalVector & vertex(int i) const
Definition: macrodata.hh:255
int vertexCount() const
Definition: macrodata.hh:63
void markLongestEdge()
mark the longest edge of all elements as refinement edges
Definition: macrodata.hh:325
int insertVertex(const FieldVector< Real, dimWorld > &coords)
insert vertex
Definition: macrodata.hh:163
bool checkNeighbors() const
check the neighbor information
Definition: macrodata.hh:339
void insertWallTrafo(const FieldMatrix< Real, dimWorld, dimWorld > &matrix, const FieldVector< Real, dimWorld > &shift)
Definition: macrodata.hh:385
ElementId & element(int i) const
Definition: macrodata.hh:246
void checkCycles()
Definition: macrodata.hh:404
int & neighbor(int element, int i) const
Definition: macrodata.hh:263
MacroData()
Definition: macrodata.hh:52
void finalize()
compress macro data structure
Definition: macrodata.hh:294
void insertWallTrafo(const GlobalMatrix &m, const GlobalVector &t)
Definition: macrodata.hh:367
void setOrientation(const Real orientation)
set the orientation of all elements
Definition: macrodata.hh:332
void create()
create a new macro data structure
Definition: macrodata.hh:281
int insertElement(const ElementId &id)
insert element
Definition: macrodata.hh:346
bool write(const std::string &filename, bool binary=false) const
Definition: macrodata.hh:180
void read(const std::string &filename, bool binary=false)
Definition: macrodata.hh:413
Definition: macrodata.hh:220
static void markLongestEdge(MacroData ¯oData)
Alberta::MacroData< dim > MacroData
Definition: macrodata.hh:221