Newer
Older
/***************************************************************************
tnlMeshSuperentityStorageInitializer.h - description
-------------------
begin : Feb 27, 2014
copyright : (C) 2014 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef TNLMESHSUPERENTITYSTORAGEINITIALIZER_H_
#define TNLMESHSUPERENTITYSTORAGEINITIALIZER_H_
#include <mesh/tnlDimensionsTag.h>
bool SuperentityStorage = tnlMeshSuperentityTraits< MeshConfig, EntityTopology, DimensionsTag::value >::storageEnabled >
class tnlMeshSuperentityStorageInitializerLayer;
class tnlMeshSuperentityStorageInitializer :
public tnlMeshSuperentityStorageInitializerLayer< MeshConfig, EntityTopology, tnlDimensionsTag< tnlMeshTraits< MeshConfig >::meshDimensions > >
class tnlMeshSuperentityStorageInitializerLayer< MeshConfig,
: public tnlMeshSuperentityStorageInitializerLayer< MeshConfig,
typename DimensionsTag::Decrement >
typedef tnlMeshSuperentityStorageInitializerLayer< MeshConfig,
typename DimensionsTag::Decrement > BaseType;
Tomáš Oberhuber
committed
static const int Dimensions = DimensionsTag::value;
typedef tnlDimensionsTag< EntityTopology::dimensions > EntityDimensions;
Tomáš Oberhuber
committed
typedef tnlMeshTraits< MeshConfig > MeshTraits;
typedef typename MeshTraits::GlobalIdArrayType GlobalIdArrayType;
Tomáš Oberhuber
committed
typedef typename MeshTraits::GlobalIndexType GlobalIndexType;
typedef typename MeshTraits::LocalIndexType LocalIndexType;
typedef tnlMeshInitializer< MeshConfig > MeshInitializer;
typedef typename MeshTraits::template SuperentityTraits< EntityTopology, Dimensions > SuperentityTraits;
typedef typename SuperentityTraits::StorageNetworkType SuperentityStorageNetwork;
public:
using BaseType::addSuperentity;
void addSuperentity( DimensionsTag, GlobalIndexType entityIndex, GlobalIndexType superentityIndex)
{
//cout << "Adding superentity with " << DimensionsTag::value << " dimensions of enity with " << EntityDimensions::value << " ... " << endl;
indexPairs.push_back( IndexPair{ entityIndex, superentityIndex } );
void initSuperentities( MeshInitializer& meshInitializer )
{
std::sort( indexPairs.begin(),
indexPairs.end(),
[]( IndexPair pair0, IndexPair pair1 ){ return ( pair0.entityIndex < pair1.entityIndex ); } );
Tomáš Oberhuber
committed
GlobalIdArrayType &superentityIdsArray = meshInitializer.template meshSuperentityIdsArray< EntityDimensions, DimensionsTag >();
superentityIdsArray.setSize( static_cast< GlobalIndexType >( indexPairs.size() ) );
GlobalIndexType currentBegin = 0;
GlobalIndexType lastEntityIndex = 0;
cout << "There are " << superentityIdsArray.getSize() << " superentities with " << DimensionsTag::value << " dimensions of enities with " << EntityDimensions::value << " ... " << endl;
for( GlobalIndexType i = 0; i < superentityIdsArray.getSize(); i++)
{
superentityIdsArray[ i ] = indexPairs[i].superentityIndex;
//cout << "Adding superentity " << indexPairs[i].superentityIndex << " to entity " << lastEntityIndex << endl;
if( indexPairs[ i ].entityIndex != lastEntityIndex )
{
meshInitializer.template superentityIdsArray< DimensionsTag >( meshInitializer.template meshEntitiesArray< EntityDimensions >()[ lastEntityIndex ] ).bind( superentityIdsArray, currentBegin, i - currentBegin );
currentBegin = i;
lastEntityIndex = indexPairs[ i ].entityIndex;
}
}
meshInitializer.template superentityIdsArray< DimensionsTag >( meshInitializer.template meshEntitiesArray< EntityDimensions >()[ lastEntityIndex ] ).bind( superentityIdsArray, currentBegin, superentityIdsArray.getSize() - currentBegin );
indexPairs.clear();
/****
* Network initializer
*/
Tomáš Oberhuber
committed
SuperentityStorageNetwork& superentityStorageNetwork = meshInitializer.template meshSuperentityStorageNetwork< EntityTopology, DimensionsTag >();
//GlobalIndexType lastEntityIndex( 0 );
superentityStorageNetwork.setRanges(
Tomáš Oberhuber
committed
meshInitializer.template meshEntitiesArray< EntityDimensions >().getSize(),
meshInitializer.template meshEntitiesArray< DimensionsTag >().getSize() );
lastEntityIndex = 0;
typename SuperentityStorageNetwork::ValuesAllocationVectorType storageNetworkAllocationVector;
Tomáš Oberhuber
committed
storageNetworkAllocationVector.setSize( meshInitializer.template meshEntitiesArray< EntityDimensions >().getSize() );
storageNetworkAllocationVector.setValue( 0 );
for( GlobalIndexType i = 0; i < superentityIdsArray.getSize(); i++)
{
if( indexPairs[ i ].entityIndex == lastEntityIndex )
storageNetworkAllocationVector[ lastEntityIndex ]++;
else
lastEntityIndex++;
}
superentityStorageNetwork.allocate( storageNetworkAllocationVector );
Tomáš Oberhuber
committed
lastEntityIndex = 0;
LocalIndexType superentitiesCount( 0 );
typename SuperentityStorageNetwork::ValuesAccessorType superentitiesIndecis =
superentityStorageNetwork.getValues( lastEntityIndex );
Tomáš Oberhuber
committed
for( GlobalIndexType i = 0; i < superentityIdsArray.getSize(); i++)
{
if( indexPairs[ i ].entityIndex != lastEntityIndex )
{
superentitiesIndecis = superentityStorageNetwork.getValues( ++lastEntityIndex );
Tomáš Oberhuber
committed
superentitiesCount = 0;
}
superentitiesIndecis[ superentitiesCount++ ] = indexPairs[ i ].superentityIndex;
}
BaseType::initSuperentities( meshInitializer );
}
struct IndexPair
{
GlobalIndexType entityIndex;
GlobalIndexType superentityIndex;
};
std::vector< IndexPair > indexPairs;
class tnlMeshSuperentityStorageInitializerLayer< MeshConfig,
: public tnlMeshSuperentityStorageInitializerLayer< MeshConfig,
typename DimensionsTag::Decrement >
typedef tnlMeshSuperentityStorageInitializerLayer< MeshConfig,
typedef tnlMeshInitializer< MeshConfig > MeshInitializerType;
public:
void addSuperentity() {} // This method is due to 'using BaseType::...;' in the derived classes.
using BaseType::initSuperentities;
void initSuperentities( MeshInitializerType& ) {cerr << "***" << endl;}
class tnlMeshSuperentityStorageInitializerLayer< MeshConfig,
EntityTopology,
tnlDimensionsTag< EntityTopology::dimensions >,
typedef tnlMeshInitializer< MeshConfig > MeshInitializerType;
void addSuperentity() {} // This method is due to 'using BaseType::...;' in the derived classes.
void initSuperentities( MeshInitializerType& ) {}
class tnlMeshSuperentityStorageInitializerLayer< MeshConfig,
EntityTopology,
tnlDimensionsTag< EntityTopology::dimensions >,
typedef tnlMeshInitializer< MeshConfig > MeshInitializerType;
void addSuperentity() {} // This method is due to 'using BaseType::...;' in the derived classes.
void initSuperentities( MeshInitializerType& ) {}
#endif /* TNLMESHSUPERENTITYSTORAGEINITIALIZER_H_ */