Commit 694b1c95 authored by Andreas Wagner's avatar Andreas Wagner
Browse files

gives FaceDoFFunction::add same semantics as FaceDoFFunction::assign

parent 0a6b923b
......@@ -62,18 +62,49 @@ void FaceDoFFunction< ValueType >::add(
uint_t level,
DoFType flag ) const
{
this->startTiming( "Add" );
WALBERLA_ASSERT_EQUAL( scalars.size(), functions.size() )
// Collect all source IDs in a vector
// std::vector<PrimitiveDataID<FunctionMemory< ValueType >, Vertex>> srcVertexIDs;
// std::vector<PrimitiveDataID<FunctionMemory< ValueType >, Edge>> srcEdgeIDs;
std::vector< PrimitiveDataID< FunctionMemory< ValueType >, Face > > srcFaceIDs;
std::vector< PrimitiveDataID< FunctionMemory< ValueType >, Vertex > > srcVertexIDs;
std::vector< PrimitiveDataID< FunctionMemory< ValueType >, Edge > > srcEdgeIDs;
std::vector< PrimitiveDataID< FunctionMemory< ValueType >, Face > > srcFaceIDs;
for ( auto& function : functions )
{
// srcVertexIDs.push_back(function->vertexDataID_);
// srcEdgeIDs.push_back(function->edgeDataID_);
srcVertexIDs.push_back( function.get().vertexDataID_ );
srcEdgeIDs.push_back( function.get().edgeDataID_ );
srcFaceIDs.push_back( function.get().faceDataID_ );
}
for ( auto& it : this->getStorage()->getVertices() )
{
Vertex& vertex = *it.second;
const DoFType vertexBC = this->getBoundaryCondition().getBoundaryType( vertex.getMeshBoundaryFlag() );
if ( testFlag( vertexBC, flag ) )
{
facedof::macrovertex::add< ValueType >( level, vertex, scalars, srcVertexIDs, vertexDataID_ );
}
}
startCommunication< Vertex, Edge >( level );
for ( auto& it : this->getStorage()->getEdges() )
{
Edge& edge = *it.second;
const DoFType edgeBC = this->getBoundaryCondition().getBoundaryType( edge.getMeshBoundaryFlag() );
if ( testFlag( edgeBC, flag ) )
{
facedof::macroedge::add< ValueType >( level, edge, scalars, srcEdgeIDs, edgeDataID_ );
}
}
endCommunication< Vertex, Edge >( level );
startCommunication< Edge, Face >( level );
for ( auto& it : this->getStorage()->getFaces() )
{
Face& face = *it.second;
......@@ -84,6 +115,9 @@ void FaceDoFFunction< ValueType >::add(
facedof::macroface::add< ValueType >( level, face, scalars, srcFaceIDs, faceDataID_ );
}
}
endCommunication< Edge, Face >( level );
this->stopTiming( "Add" );
}
template < typename ValueType >
......
......@@ -154,6 +154,44 @@ inline void assign( const uint_t&
}
}
template < typename ValueType >
inline void add( const uint_t& Level,
Edge& edge,
const std::vector< ValueType >& scalars,
const std::vector< PrimitiveDataID< FunctionMemory< ValueType >, Edge > >& srcIds,
const PrimitiveDataID< FunctionMemory< ValueType >, Edge >& dstId )
{
size_t rowsize = levelinfo::num_microvertices_per_edge( Level );
auto dst = edge.getData( dstId )->getPointer( Level );
// gray south cells
for ( size_t i = 1; i < rowsize - 2; ++i )
{
uint_t cellIndex = facedof::macroedge::indexFaceFromVertex( Level, i, stencilDirection::CELL_GRAY_SE );
ValueType tmp = scalars[0] * edge.getData( srcIds[0] )->getPointer( Level )[cellIndex];
for ( uint_t k = 1; k < srcIds.size(); ++k )
{
tmp += scalars[k] * edge.getData( srcIds[k] )->getPointer( Level )[cellIndex];
}
dst[cellIndex] += tmp;
}
if ( edge.getNumNeighborFaces() == 2 )
{
for ( size_t i = 1; i < rowsize - 2; ++i )
{
uint_t cellIndex = facedof::macroedge::indexFaceFromVertex( Level, i, stencilDirection::CELL_GRAY_NE );
ValueType tmp = scalars[0] * edge.getData( srcIds[0] )->getPointer( Level )[cellIndex];
for ( uint_t k = 1; k < srcIds.size(); ++k )
{
tmp += scalars[k] * edge.getData( srcIds[k] )->getPointer( Level )[cellIndex];
}
dst[cellIndex] += tmp;
}
}
}
template < typename ValueType >
inline void multElementwise( const uint_t& level,
Edge& edge,
......
......@@ -102,6 +102,28 @@ inline void assign( const uint_t&
}
}
template < typename ValueType >
inline void add( const uint_t& Level,
Vertex& vertex,
const std::vector< ValueType >& scalars,
const std::vector< PrimitiveDataID< FunctionMemory< ValueType >, Vertex > >& srcIds,
const PrimitiveDataID< FunctionMemory< ValueType >, Vertex >& dstId )
{
auto dst = vertex.getData( dstId )->getPointer( Level );
for ( uint_t i = 0; i < vertex.getNumNeighborFaces(); ++i )
{
uint_t index = i * 2;
//tmp is necessary since dstId can also be in srcIds
ValueType tmp = scalars[0] * vertex.getData( srcIds[0] )->getPointer( Level )[index];
for ( uint_t k = 1; k < srcIds.size(); ++k )
{
tmp += scalars[k] * vertex.getData( srcIds[k] )->getPointer( Level )[index];
}
dst[index] += tmp;
}
}
template < typename ValueType >
inline void multElementwise( const uint_t& level,
Vertex& vertex,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment