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) );
224 [[maybe_unused]]
const Real orientation );
230 template<
class Type >
231 static void rotate ( Type *array,
int i,
int shift );
233 static void rotate (
MacroData ¯oData,
int i,
int shift );
234 static void swap (
MacroData ¯oData,
int el,
int v1,
int v2 );
246 assert( (i >= 0) && (i < data_->n_macro_elements) );
247 const int offset = i * numVertices;
248 return *
reinterpret_cast< ElementId *
>( data_->mel_vertices + offset );
255 assert( (i >= 0) && (i < data_->n_total_vertices) );
256 return data_->coords[ i ];
263 assert( (element >= 0) && (element < data_->n_macro_elements) );
264 assert( (i >= 0) && (i < numVertices) );
265 return data_->neigh[ element*numVertices + i ];
272 assert( (element >= 0) && (element < data_->n_macro_elements) );
273 assert( (i >= 0) && (i < numVertices) );
274 return data_->boundary[ element*numVertices + i ];
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;
294 if( (vertexCount_ >= 0) && (elementCount_ >= 0) )
296 resizeVertices( vertexCount_ );
297 resizeElements( elementCount_ );
298 ALBERTA compute_neigh_fast( data_ );
301 for(
int element = 0; element < elementCount_; ++element )
303 for(
int i = 0; i < numVertices; ++i )
306 if( neighbor( element, i ) >= 0 )
316 vertexCount_ = elementCount_ = -1;
318 assert( (vertexCount_ < 0) && (elementCount_ < 0) );
346 assert( elementCount_ >= 0 );
347 if( elementCount_ >= data_->n_macro_elements )
348 resizeElements( 2*elementCount_ );
350 ElementId &e = element( elementCount_ );
351 for(
int i = 0; i < numVertices; ++i )
357 data_->el_type[ elementCount_ ] = 0;
359 return elementCount_++;
367 int &count = data_->n_wall_trafos;
371 array = memReAlloc< AffineTransformation >( array, count, count+1 );
372 assert( data_->wall_trafos != NULL );
376 copy( matrix[ i ], array[ count ].M[ i ] );
377 copy( shift, array[ count ].t );
384 const FieldVector< Real, dimWorld > &shift )
386 int &count = data_->n_wall_trafos;
390 array = memReAlloc< AffineTransformation >( array, count, count+1 );
391 assert( data_->wall_trafos != NULL );
395 copy( matrix[ i ], array[ count ].M[ i ] );
396 copy( shift, array[ count ].t );
406 ALBERTA macro_test( data_, NULL );
415 data_ =
ALBERTA read_macro_xdr( filename.c_str() );
417 data_ =
ALBERTA read_macro( filename.c_str() );
424 const int oldSize = data_->n_macro_elements;
425 data_->n_macro_elements = newSize;
426 data_->mel_vertices =
memReAlloc( data_->mel_vertices, oldSize*numVertices, newSize*numVertices );
427 data_->boundary =
memReAlloc( data_->boundary, oldSize*numVertices, newSize*numVertices );
429 data_->el_type =
memReAlloc( data_->el_type, oldSize, newSize );
430 assert( (newSize == 0) || (data_->mel_vertices != NULL) );
#define ALBERTA
Definition: albertaheader.hh:27
Include standard header files.
Definition: agrid.hh:58
ALBERTA REAL_DD GlobalMatrix
Definition: misc.hh:49
ALBERTA AFF_TRAFO AffineTransformation
Definition: misc.hh:50
ALBERTA BNDRY_TYPE BoundaryId
Definition: misc.hh:59
static const int InteriorBoundary
Definition: misc.hh:57
ALBERTA REAL Real
Definition: misc.hh:46
Data * memReAlloc(Data *ptr, size_t oldSize, size_t newSize)
Definition: misc.hh:83
static const int DirichletBoundary
Definition: misc.hh:58
static const int dimWorld
Definition: misc.hh:44
ALBERTA REAL_D GlobalVector
Definition: misc.hh:48
Definition: macrodata.hh:28
friend struct InstantiateMacroDataLibrary
Definition: macrodata.hh:43
BoundaryId & boundaryId(int element, int i) const
Definition: macrodata.hh:270
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:253
int vertexCount() const
Definition: macrodata.hh:61
void markLongestEdge()
mark the longest edge of all elements as refinement edges
Definition: macrodata.hh:323
int insertVertex(const FieldVector< Real, dimWorld > &coords)
insert vertex
Definition: macrodata.hh:161
bool checkNeighbors() const
check the neighbor information
Definition: macrodata.hh:337
void insertWallTrafo(const FieldMatrix< Real, dimWorld, dimWorld > &matrix, const FieldVector< Real, dimWorld > &shift)
Definition: macrodata.hh:383
ElementId & element(int i) const
Definition: macrodata.hh:244
void checkCycles()
Definition: macrodata.hh:402
int & neighbor(int element, int i) const
Definition: macrodata.hh:261
MacroData()
Definition: macrodata.hh:50
void finalize()
compress macro data structure
Definition: macrodata.hh:292
void insertWallTrafo(const GlobalMatrix &m, const GlobalVector &t)
Definition: macrodata.hh:365
void setOrientation(const Real orientation)
set the orientation of all elements
Definition: macrodata.hh:330
void create()
create a new macro data structure
Definition: macrodata.hh:279
int insertElement(const ElementId &id)
insert element
Definition: macrodata.hh:344
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:411
Definition: macrodata.hh:218
static void markLongestEdge(MacroData ¯oData)
Alberta::MacroData< dim > MacroData
Definition: macrodata.hh:219