IndexFunctionVSManualVersion.cpp 4.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Copyright (c) 2017-2019 Daniel Drzisga, Dominik Thoennes, Nils Kohl.
 *
 * 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/>.
 */
20
#include "core/Environment.h"
Dominik Thoennes's avatar
Dominik Thoennes committed
21
#include "core/debug/TestSubsystem.h"
Dominik Thoennes's avatar
Dominik Thoennes committed
22

Dominik Thoennes's avatar
Dominik Thoennes committed
23
24
25
26
27
28
29
#include "hyteg/indexing/Optimization.hpp"
#include "hyteg/LikwidWrapper.hpp"
#include "hyteg/p1functionspace/P1Function.hpp"
#include "hyteg/p1functionspace/P1ConstantOperator.hpp"
#include "hyteg/p1functionspace/VertexDoFIndexing.hpp"
#include "hyteg/p1functionspace/VertexDoFMacroFace.hpp"
#include "hyteg/primitivestorage/SetupPrimitiveStorage.hpp"
Dominik Thoennes's avatar
Dominik Thoennes committed
30
31

using walberla::real_c;
32
using walberla::real_t;
33
using namespace hyteg;
Dominik Thoennes's avatar
Dominik Thoennes committed
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
std::shared_ptr< PrimitiveStorage > globalStorage;

template < size_t Level >
inline void manualApply( real_t* oprPtr, real_t* srcPtr, real_t* dstPtr, UpdateType )
{
   size_t rowsize       = levelinfo::num_microvertices_per_edge( Level );
   size_t inner_rowsize = rowsize;

   size_t br = 1;
   size_t mr = 1 + rowsize;
   size_t tr = mr + ( rowsize - 1 );
   ///This is written for the update type Replace!
   for( size_t i = 0; i < rowsize - 3; ++i )
   {
      for( size_t j = 0; j < inner_rowsize - 3; ++j )
      {
         dstPtr[mr] = oprPtr[0] * srcPtr[br] + oprPtr[1] * srcPtr[br + 1] + oprPtr[2] * srcPtr[mr - 1] + oprPtr[3] * srcPtr[mr] +
                      oprPtr[4] * srcPtr[mr + 1] + oprPtr[5] * srcPtr[tr - 1] + oprPtr[6] * srcPtr[tr];

         br += 1;
         mr += 1;
         tr += 1;
      }

      br += 3;
      mr += 2;
Dominik Thoennes's avatar
Dominik Thoennes committed
61
      tr += 1;
62
63
      --inner_rowsize;
   }
Dominik Thoennes's avatar
Dominik Thoennes committed
64
65
}

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
int main( int argc, char** argv )
{
   LIKWID_MARKER_INIT;

   walberla::debug::enterTestMode();
   walberla::mpi::Environment MPIenv( argc, argv );
   walberla::MPIManager::instance()->useWorldComm();

   LIKWID_MARKER_THREADINIT;

   MeshInfo                            meshInfo = MeshInfo::fromGmshFile( "../data/meshes/tri_1el.msh" );
   SetupPrimitiveStorage               setupStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) );
   std::shared_ptr< PrimitiveStorage > storage = std::make_shared< PrimitiveStorage >( setupStorage );
   globalStorage                               = storage;

   const size_t level = 14;

83
84
85
86
   auto                   src  = std::make_shared< hyteg::P1Function< real_t > >( "src", storage, level, level );
   auto                   dst1 = std::make_shared< hyteg::P1Function< real_t > >( "dst", storage, level, level );
   auto                   dst2 = std::make_shared< hyteg::P1Function< real_t > >( "dst", storage, level, level );
   hyteg::P1ConstantLaplaceOperator M( storage, level, level );
87
88
89

   std::shared_ptr< Face > face = storage->getFaces().begin().operator*().second;

90
   std::function< real_t( const hyteg::Point3D& ) > ones = []( const hyteg::Point3D& x ) { return x[0] * 4; };
91
92
93
94
95
96
97
98
99
100
101
102
103
104
   src->interpolate( ones, level );

   real_t* oprPtr = face->getData( M.getFaceStencilID() )->getPointer( level );
   for( uint_t i = 0; i < 7; ++i )
   {
      oprPtr[i] = real_c( i );
   }
   real_t* srcPtr  = face->getData( src->getFaceDataID() )->getPointer( level );
   real_t* dst1Ptr = face->getData( dst1->getFaceDataID() )->getPointer( level );
   real_t* dst2Ptr = face->getData( dst2->getFaceDataID() )->getPointer( level );

   walberla::WcTimer timer;
   timer.reset();
   LIKWID_MARKER_START( "IndexApply" );
105
   hyteg::vertexdof::macroface::apply< real_t >(
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
       level, *face, M.getFaceStencilID(), src->getFaceDataID(), dst1->getFaceDataID(), Replace );
   LIKWID_MARKER_STOP( "IndexApply" );
   timer.end();
   WALBERLA_LOG_INFO_ON_ROOT( std::setw( 20 ) << "Index Apply: " << timer.last() );

   timer.reset();
   LIKWID_MARKER_START( "ManualApply" );
   manualApply< level >( oprPtr, srcPtr, dst2Ptr, Replace );
   LIKWID_MARKER_STOP( "ManualApply" );
   timer.end();
   WALBERLA_LOG_INFO_ON_ROOT( std::setw( 20 ) << "Manual Apply: " << timer.last() );

   ///check calculations
   real_t sum1 = 0, sum2 = 0;
   for( uint_t i = 0; i < levelinfo::num_microvertices_per_face( level ); ++i )
   {
      WALBERLA_CHECK_FLOAT_EQUAL( dst1Ptr[i], dst2Ptr[i], "i was: " << i );
      sum1 += dst1Ptr[i];
      sum2 += dst2Ptr[i];
   }
   WALBERLA_CHECK_FLOAT_UNEQUAL( sum1, 0. );

   LIKWID_MARKER_CLOSE;
Nils Kohl's avatar
Nils Kohl committed
129
}