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 ( [[maybe_unused]] MacroData ¯oData,
224 [[maybe_unused]]
const Real orientation );
227 static Real edgeLength (
const MacroData ¯oData,
const ElementId &e,
int edge );
228 static int longestEdge (
const MacroData ¯oData,
const ElementId &e );
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 );
243 inline typename MacroData< dim >::ElementId &
244 MacroData< dim >::element (
int i )
const
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 ];
261 inline int &MacroData< dim >::neighbor (
int element,
int i )
const
263 assert( (element >= 0) && (element < data_->n_macro_elements) );
264 assert( (i >= 0) && (i < numVertices) );
265 return data_->neigh[ element*numVertices + i ];
270 inline BoundaryId &MacroData< dim >::boundaryId (
int element,
int i )
const
272 assert( (element >= 0) && (element < data_->n_macro_elements) );
273 assert( (i >= 0) && (i < numVertices) );
274 return data_->boundary[ element*numVertices + i ];
279 inline void MacroData< dim >::create ()
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;
292 inline void MacroData< dim >::finalize ()
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 )
305 BoundaryId &
id = boundaryId( element, i );
306 if( neighbor( element, i ) >= 0 )
308 assert(
id == InteriorBoundary );
309 id = InteriorBoundary;
312 id = (
id == InteriorBoundary ? DirichletBoundary : id);
316 vertexCount_ = elementCount_ = -1;
318 assert( (vertexCount_ < 0) && (elementCount_ < 0) );
323 inline void MacroData< dim >::markLongestEdge ()
325 Library< dimWorld >::markLongestEdge( *
this );
330 inline void MacroData< dim >::setOrientation (
const Real orientation )
332 Library< dimWorld >::setOrientation( *
this, orientation );
337 inline bool MacroData< dim >::checkNeighbors ()
const
339 return Library< dimWorld >::checkNeighbors( *
this );
344 inline int MacroData< dim >::insertElement (
const ElementId &
id )
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 )
354 boundaryId( elementCount_, i ) = InteriorBoundary;
357 data_->el_type[ elementCount_ ] = 0;
359 return elementCount_++;
364 inline void MacroData< dim >
365 ::insertWallTrafo (
const GlobalMatrix &matrix,
const GlobalVector &shift )
367 int &count = data_->n_wall_trafos;
368 AffineTransformation *&array = data_->wall_trafos;
371 array = memReAlloc< AffineTransformation >( array, count, count+1 );
372 assert( data_->wall_trafos != NULL );
375 for(
int i = 0; i < dimWorld; ++i )
376 copy( matrix[ i ], array[ count ].M[ i ] );
377 copy( shift, array[ count ].t );
382 inline void MacroData< dim >
383 ::insertWallTrafo (
const FieldMatrix< Real, dimWorld, dimWorld > &matrix,
384 const FieldVector< Real, dimWorld > &shift )
386 int &count = data_->n_wall_trafos;
387 AffineTransformation *&array = data_->wall_trafos;
390 array = memReAlloc< AffineTransformation >( array, count, count+1 );
391 assert( data_->wall_trafos != NULL );
394 for(
int i = 0; i < dimWorld; ++i )
395 copy( matrix[ i ], array[ count ].M[ i ] );
396 copy( shift, array[ count ].t );
402 inline void MacroData< dim >::checkCycles ()
406 ALBERTA macro_test( data_, NULL );
411 inline void MacroData< dim >::read (
const std::string &filename,
bool binary )
415 data_ = ALBERTA read_macro_xdr( filename.c_str() );
417 data_ = ALBERTA read_macro( filename.c_str() );
422 inline void MacroData< dim >::resizeElements (
const int newSize )
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) );
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.
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:504
Dune namespace.
Definition: alignedallocator.hh:11