Commit 9b10108e authored by Andreas Wagner's avatar Andreas Wagner
Browse files

adds swap method to DGFunction with test

parent 46933641
......@@ -554,5 +554,14 @@ inline void add( const uint_t& lev
}
}
template < typename ValueType >
inline void swap( const uint_t& level,
Edge& edge,
const PrimitiveDataID< FunctionMemory< ValueType >, Edge >& srcID,
const PrimitiveDataID< FunctionMemory< ValueType >, Edge >& dstID )
{
edge.getData( srcID )->swap( *edge.getData( dstID ), level );
}
}//namespace DGEdge
}//namespace hyteg
......@@ -694,5 +694,14 @@ inline void add( const uint_t& lev
}
}
template < typename ValueType >
inline void swap( const uint_t& level,
Face& face,
const PrimitiveDataID< FunctionMemory< ValueType >, Face >& srcID,
const PrimitiveDataID< FunctionMemory< ValueType >, Face >& dstID )
{
face.getData( srcID )->swap( *face.getData( dstID ), level );
}
} //namespace DGFace
} //namespace hyteg
......@@ -186,10 +186,7 @@ class DGFunction final : public Function< DGFunction< ValueType > >
WALBERLA_ABORT( "DGFunction::assign with const qualifier not implemented!" )
}
void swap( const DGFunction< ValueType >& other, const uint_t& level, const DoFType& flag = All ) const
{
WALBERLA_ABORT( "DGFunction::swap not implemented!" )
}
inline void swap( const DGFunction< ValueType >& other, const uint_t& level, const DoFType& flag = All ) const;
/// @}
......@@ -656,4 +653,44 @@ void DGFunction< ValueType >::add( const ValueType scalar, uint_t level, DoFType
this->stopTiming( "Add scalar" );
}
template < typename ValueType >
inline void DGFunction< ValueType >::swap( const DGFunction< ValueType >& other, const uint_t& level, const DoFType& flag ) const
{
this->startTiming( "Swap" );
if ( this->getStorage()->hasGlobalCells() )
{
WALBERLA_ABORT( "DGFunction::swap() not implemented for 3D!" );
}
for ( auto& it : this->getStorage()->getVertices() )
{
Vertex& vertex = *it.second;
if ( testFlag( boundaryCondition_.getBoundaryType( vertex.getMeshBoundaryFlag() ), flag ) )
{
DGVertex::swap( level, vertex, vertexDataID_, other.vertexDataID_ );
}
}
for ( auto& it : this->getStorage()->getEdges() )
{
Edge& edge = *it.second;
if ( testFlag( boundaryCondition_.getBoundaryType( edge.getMeshBoundaryFlag() ), flag ) )
{
DGEdge::swap( level, edge, edgeDataID_, other.edgeDataID_ );
}
}
for ( auto& it : this->getStorage()->getFaces() )
{
Face& face = *it.second;
if ( testFlag( boundaryCondition_.getBoundaryType( face.getMeshBoundaryFlag() ), flag ) )
{
DGFace::swap( level, face, faceDataID_, other.faceDataID_ );
}
}
this->stopTiming( "Swap" );
}
} // namespace hyteg
......@@ -296,6 +296,14 @@ inline void projectP1(const uint_t & Level, Vertex &vertex,
}
}
template < typename ValueType >
inline void swap( const uint_t& level,
Vertex& vertex,
const PrimitiveDataID< FunctionMemory< ValueType >, Vertex >& srcID,
const PrimitiveDataID< FunctionMemory< ValueType >, Vertex >& dstID )
{
vertex.getData( srcID )->swap( *vertex.getData( dstID ), level );
}
}//namespace DGVertex
}//namespace hyteg
......@@ -511,6 +511,9 @@ waLBerla_execute_test(NAME DGInterpolateTest)
waLBerla_compile_test(FILES DGAddTest.cpp DEPENDS hyteg core)
waLBerla_execute_test(NAME DGAddTest)
waLBerla_compile_test(FILES DGSwapTest.cpp DEPENDS hyteg core)
waLBerla_execute_test(NAME DGSwapTest)
waLBerla_compile_test(FILES vCycleTest.cpp DEPENDS hyteg core)
waLBerla_execute_test(NAME vCycleTest1 COMMAND $<TARGET_FILE:vCycleTest> )
......
/*
* Copyright (c) 2021 Andreas Wagner.
*
* This file is part of HyTeG
* (see https://i10git.cs.fau.de/hyteg/hyteg).
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "core/debug/all.h"
#include "core/mpi/all.h"
#include "hyteg/dataexport/VTKOutput.hpp"
#include "hyteg/dgfunctionspace/DGFunction.hpp"
#include "hyteg/mesh/MeshInfo.hpp"
#include "hyteg/primitivestorage/PrimitiveStorage.hpp"
#include "hyteg/primitivestorage/SetupPrimitiveStorage.hpp"
#include "hyteg/primitivestorage/loadbalancing/SimpleBalancer.hpp"
using namespace hyteg;
using walberla::real_t;
int main( int argc, char** argv )
{
walberla::mpi::Environment MPIenv( argc, argv );
walberla::MPIManager::instance()->useWorldComm();
walberla::debug::enterTestMode();
MeshInfo meshInfo = MeshInfo::meshRectangle( Point2D( { 0, 0 } ), Point2D( { 1, 1 } ), MeshInfo::CRISS, 1, 1 );
SetupPrimitiveStorage setupStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) );
std::shared_ptr< PrimitiveStorage > storage = std::make_shared< PrimitiveStorage >( setupStorage );
const uint_t minLevel = 2;
const uint_t maxLevel = 4;
hyteg::DGFunction< real_t > x( "x", storage, minLevel, maxLevel );
hyteg::DGFunction< real_t > y( "y", storage, minLevel, maxLevel );
x.interpolate( 1, maxLevel, hyteg::All );
y.interpolate( 2, maxLevel, hyteg::All );
x.swap( y, maxLevel, All );
// check if swapping was successful:
WALBERLA_CHECK_FLOAT_EQUAL( x.getMinValue( maxLevel, All ), 2. );
WALBERLA_CHECK_FLOAT_EQUAL( x.getMaxValue( maxLevel, All ), 2. );
WALBERLA_CHECK_FLOAT_EQUAL( y.getMinValue( maxLevel, All ), 1. );
WALBERLA_CHECK_FLOAT_EQUAL( y.getMaxValue( maxLevel, All ), 1. );
// check if changing x modifies y, i.e. if parts were not swapped:
x.interpolate( 3, maxLevel, All );
y.communicate< Vertex, Edge >( maxLevel );
y.communicate< Edge, Face >( maxLevel );
WALBERLA_CHECK_FLOAT_EQUAL( y.getMinValue( maxLevel, All ), 1. );
WALBERLA_CHECK_FLOAT_EQUAL( y.getMaxValue( maxLevel, All ), 1. );
return 0;
}
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