Commit 2d302bc0 authored by Andreas Wagner's avatar Andreas Wagner
Browse files

work in progress for add function

parent d3ce92d1
Pipeline #33749 failed with stages
in 37 minutes and 57 seconds
......@@ -527,6 +527,32 @@ inline void
std::cout << std::string( 100, '*' ) << std::endl;
}
template < typename ValueType >
inline void add( const uint_t& level,
Edge& edge,
const ValueType scalar,
const PrimitiveDataID< FunctionMemory< ValueType >, Edge >& dstId )
{
ValueType* dstPtr = edge.getData( dstId )->getPointer( level );
size_t rowsize = levelinfo::num_microvertices_per_edge( level );
// gray south cells
for ( uint_t i = 1; i < rowsize - 2; ++i )
{
uint_t index = facedof::macroedge::indexFaceFromVertex( level, i, stencilDirection::CELL_GRAY_SE );
dstPtr[index] += scalar;
}
if ( edge.getNumNeighborFaces() == 2 )
{
for ( uint_t i = 1; i < rowsize - 2; ++i )
{
uint_t index = facedof::macroedge::indexFaceFromVertex( level, i, stencilDirection::CELL_GRAY_NE );
dstPtr[index] += scalar;
}
}
}
}//namespace DGEdge
}//namespace hyteg
......@@ -659,5 +659,40 @@ inline void multElementwise( const uint_t&
}
}
template < typename ValueType >
inline void add( const uint_t& level,
Face& face,
const ValueType scalar,
const PrimitiveDataID< FunctionMemory< ValueType >, Face >& dstId )
{
ValueType* dstPtr = face.getData( dstId )->getPointer( level );
size_t rowsize = levelinfo::num_microvertices_per_edge( level );
size_t inner_rowsize = rowsize;
// gray cells
for ( size_t j = 1; j < rowsize - 2; ++j )
{
for ( size_t i = 1; i < inner_rowsize - 3; ++i )
{
auto cellIndex = facedof::macroface::indexFaceFromGrayFace( level, i, j, stencilDirection::CELL_GRAY_C );
dstPtr[cellIndex] += scalar;
}
--inner_rowsize;
}
// blue cells
inner_rowsize = rowsize;
for ( size_t j = 0; j < rowsize - 2; ++j )
{
for ( size_t i = 0; i < inner_rowsize - 2; ++i )
{
auto cellIndex = facedof::macroface::indexFaceFromGrayFace( level, i, j, stencilDirection::CELL_GRAY_C );
dstPtr[cellIndex] += scalar;
}
--inner_rowsize;
}
}
} //namespace DGFace
} //namespace hyteg
......@@ -146,12 +146,7 @@ class DGFunction final : public Function< DGFunction< ValueType > >
uint_t level,
DoFType flag = All ) const;
/// @name Unimplemented methods (see other kinds of functions)
/// @{
void add( const ValueType scalar, uint_t level, DoFType flag = All ) const
{
WALBERLA_ABORT( "DGFunction::add not implemented!" )
}
void add( const ValueType scalar, uint_t level, DoFType flag = All ) const;
void copyFrom( const DGFunction< ValueType >& other, const uint_t& level ) const
{
......@@ -629,4 +624,44 @@ void DGFunction< ValueType >::multElementwise(
this->stopTiming( "Multiply elementwise" );
}
template < typename ValueType >
void DGFunction< ValueType >::add( const ValueType scalar, uint_t level, DoFType flag ) const
{
this->startTiming( "Add scalar" );
if ( this->getStorage()->hasGlobalCells() )
{
WALBERLA_ABORT( "DGFunction::add() not implemented for 3D!" );
}
for ( auto& it : this->getStorage()->getVertices() )
{
Vertex& vertex = *it.second;
if ( testFlag( boundaryCondition_.getBoundaryType( vertex.getMeshBoundaryFlag() ), flag ) )
{
DGVertex::add( level, vertex, scalar, vertexDataID_ );
}
}
for ( auto& it : this->getStorage()->getEdges() )
{
Edge& edge = *it.second;
if ( testFlag( boundaryCondition_.getBoundaryType( edge.getMeshBoundaryFlag() ), flag ) )
{
DGEdge::add( level, edge, scalar, edgeDataID_ );
}
}
for ( auto& it : this->getStorage()->getFaces() )
{
Face& face = *it.second;
if ( testFlag( boundaryCondition_.getBoundaryType( face.getMeshBoundaryFlag() ), flag ) )
{
DGFace::add( level, face, scalar, faceDataID_ );
}
}
this->stopTiming( "Add scalar" );
}
} // namespace hyteg
......@@ -119,7 +119,16 @@ inline void multElementwise( const uint_t&
}
}
template < typename ValueType >
inline void add( const uint_t& level,
Vertex& vertex,
const ValueType scalar,
const PrimitiveDataID< FunctionMemory< ValueType >, Vertex >& dstId )
{
ValueType* dstPtr = vertex.getData( dstId )->getPointer( level );
for ( uint_t i = 0; i < vertex.getNumNeighborFaces(); ++i )
dstPtr[i * 2] += scalar;
}
template< typename ValueType >
inline void upwind(const uint_t & Level, Vertex &vertex,
......
......@@ -508,6 +508,9 @@ waLBerla_execute_test(NAME VectorOperatorBasicTest)
waLBerla_compile_test(FILES DGInterpolateTest.cpp DEPENDS hyteg core)
waLBerla_execute_test(NAME DGInterpolateTest)
waLBerla_compile_test(FILES DGAddTest.cpp DEPENDS hyteg core)
waLBerla_execute_test(NAME DGAddTest)
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 );
x.interpolate( 0., maxLevel, All );
// check adding on the whole domain
{
WALBERLA_CHECK_FLOAT_EQUAL( x.getMinValue( maxLevel, All ), 0. );
WALBERLA_CHECK_FLOAT_EQUAL( x.getMaxValue( maxLevel, All ), 0. );
x.add( 1., maxLevel, All );
// the min/max value functions
x.communicate< hyteg::Vertex, hyteg::Edge >( maxLevel );
x.communicate< hyteg::Edge, hyteg::Face >( maxLevel );
WALBERLA_CHECK_FLOAT_EQUAL( x.getMinValue( maxLevel, All ), 1. );
WALBERLA_CHECK_FLOAT_EQUAL( x.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