3#ifndef DUNE_ALBERTA_MACRODATA_HH
4#define DUNE_ALBERTA_MACRODATA_HH
14#include <dune/grid/albertagrid/misc.hh>
15#include <dune/grid/albertagrid/algebra.hh>
16#include <dune/grid/albertagrid/albertaheader.hh>
29 typedef MacroData< dim > This;
31 typedef ALBERTA MACRO_DATA Data;
33 static const int dimension = dim;
34 static const int numVertices = NumSubEntities< dimension, dimension >::value;
35 static const int numEdges = NumSubEntities< dimension, dimension-1 >::value;
37 static const int initialSize = 4096;
43 template<
int >
friend struct InstantiateMacroDataLibrary;
46 typedef int ElementId[ numVertices ];
48 static const int supportPeriodicity = 1;
56 operator Data * ()
const
61 int vertexCount ()
const
63 return (vertexCount_ < 0 ? data_->n_total_vertices : vertexCount_);
66 int elementCount ()
const
68 return (elementCount_ < 0 ? data_->n_macro_elements : elementCount_);
71 ElementId &element (
int i )
const;
72 GlobalVector &vertex (
int i )
const;
73 int &neighbor (
int element,
int i )
const;
74 BoundaryId &boundaryId (
int element,
int i )
const;
100 void markLongestEdge ();
110 void setOrientation (
const Real orientation );
122 bool checkNeighbors ()
const;
129 ALBERTA free_macro_data( data_ );
132 vertexCount_ = elementCount_ = -1;
140 int insertElement (
const ElementId &
id );
147 int insertVertex (
const GlobalVector &coords )
149 assert( vertexCount_ >= 0 );
150 if( vertexCount_ >= data_->n_total_vertices )
151 resizeVertices( 2*vertexCount_ );
152 copy( coords, vertex( vertexCount_ ) );
153 return vertexCount_++;
161 int insertVertex (
const FieldVector< Real, dimWorld > &coords )
163 assert( vertexCount_ >= 0 );
164 if( vertexCount_ >= data_->n_total_vertices )
165 resizeVertices( 2*vertexCount_ );
166 copy( coords, vertex( vertexCount_ ) );
167 return vertexCount_++;
170 void insertWallTrafo (
const GlobalMatrix &m,
const GlobalVector &t );
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 >
188 void copy (
const Vector &x, GlobalVector &y )
190 for(
int i = 0; i < dimWorld; ++i )
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
219 typedef Alberta::MacroData< dim > MacroData;
221 static bool checkNeighbors (
const MacroData ¯oData );
222 static void markLongestEdge ( MacroData ¯oData );
223 static void setOrientation ( MacroData ¯oData,
const Real orientation );
226 static Real edgeLength (
const MacroData ¯oData,
const ElementId &e,
int edge );
227 static int longestEdge (
const MacroData ¯oData,
const ElementId &e );
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 );
242 inline typename MacroData< dim >::ElementId &
243 MacroData< dim >::element (
int i )
const
245 assert( (i >= 0) && (i < data_->n_macro_elements) );
246 const int offset = i * numVertices;
247 return *
reinterpret_cast< ElementId *
>( data_->mel_vertices + offset );
252 inline GlobalVector &MacroData< dim >::vertex (
int i )
const
254 assert( (i >= 0) && (i < data_->n_total_vertices) );
255 return data_->coords[ i ];
260 inline int &MacroData< dim >::neighbor (
int element,
int i )
const
262 assert( (element >= 0) && (element < data_->n_macro_elements) );
263 assert( (i >= 0) && (i < numVertices) );
264 return data_->neigh[ element*numVertices + i ];
269 inline BoundaryId &MacroData< dim >::boundaryId (
int element,
int i )
const
271 assert( (element >= 0) && (element < data_->n_macro_elements) );
272 assert( (i >= 0) && (i < numVertices) );
273 return data_->boundary[ element*numVertices + i ];
278 inline void MacroData< dim >::create ()
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;
291 inline void MacroData< dim >::finalize ()
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 )
304 BoundaryId &
id = boundaryId( element, i );
305 if( neighbor( element, i ) >= 0 )
307 assert(
id == InteriorBoundary );
308 id = InteriorBoundary;
311 id = (
id == InteriorBoundary ? DirichletBoundary : id);
315 vertexCount_ = elementCount_ = -1;
317 assert( (vertexCount_ < 0) && (elementCount_ < 0) );
322 inline void MacroData< dim >::markLongestEdge ()
324 Library< dimWorld >::markLongestEdge( *
this );
329 inline void MacroData< dim >::setOrientation (
const Real orientation )
331 Library< dimWorld >::setOrientation( *
this, orientation );
336 inline bool MacroData< dim >::checkNeighbors ()
const
338 return Library< dimWorld >::checkNeighbors( *
this );
343 inline int MacroData< dim >::insertElement (
const ElementId &
id )
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 )
353 boundaryId( elementCount_, i ) = InteriorBoundary;
356 data_->el_type[ elementCount_ ] = 0;
358 return elementCount_++;
363 inline void MacroData< dim >
364 ::insertWallTrafo (
const GlobalMatrix &matrix,
const GlobalVector &shift )
366 int &count = data_->n_wall_trafos;
367 AffineTransformation *&array = data_->wall_trafos;
370 array = memReAlloc< AffineTransformation >( array, count, count+1 );
371 assert( data_->wall_trafos != NULL );
374 for(
int i = 0; i < dimWorld; ++i )
375 copy( matrix[ i ], array[ count ].M[ i ] );
376 copy( shift, array[ count ].t );
381 inline void MacroData< dim >
382 ::insertWallTrafo (
const FieldMatrix< Real, dimWorld, dimWorld > &matrix,
383 const FieldVector< Real, dimWorld > &shift )
385 int &count = data_->n_wall_trafos;
386 AffineTransformation *&array = data_->wall_trafos;
389 array = memReAlloc< AffineTransformation >( array, count, count+1 );
390 assert( data_->wall_trafos != NULL );
393 for(
int i = 0; i < dimWorld; ++i )
394 copy( matrix[ i ], array[ count ].M[ i ] );
395 copy( shift, array[ count ].t );
401 inline void MacroData< dim >::checkCycles ()
405 ALBERTA macro_test( data_, NULL );
410 inline void MacroData< dim >::read (
const std::string &filename,
bool binary )
414 data_ = ALBERTA read_macro_xdr( filename.c_str() );
416 data_ = ALBERTA read_macro( filename.c_str() );
421 inline void MacroData< dim >::resizeElements (
const int newSize )
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) );
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignment.hh:11