Newer
Older

Vít Hanousek
committed
/***************************************************************************
DistributedGridTest.cpp - description
-------------------
begin : Sep 6, 2017
copyright : (C) 2017 by Tomas Oberhuber et al.
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
#ifdef HAVE_GTEST
#include <gtest/gtest.h>

Vít Hanousek
committed
#ifdef HAVE_MPI

Vít Hanousek
committed
#include <TNL/Meshes/DistributedMeshes/DistributedMesh.h>

Vít Hanousek
committed
#include <TNL/Functions/MeshFunction.h>
#include <TNL/Communicators/MpiCommunicator.h>
#include <TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.h>

Vít Hanousek
committed
Tomáš Oberhuber
committed
#include "../../Functions/Functions.h"

Vít Hanousek
committed
using namespace TNL;
using namespace TNL::Containers;
using namespace TNL::Meshes;
using namespace TNL::Functions;
using namespace TNL::Devices;
using namespace TNL::Communicators;
using namespace TNL::Meshes::DistributedMeshes;

Vít Hanousek
committed
template<typename DofType>
void setDof_2D( DofType &dof, typename DofType::RealType value )

Vít Hanousek
committed
{
for( int i = 0; i < dof.getSize(); i++ )
dof[ i ] = value;

Vít Hanousek
committed
}
template<typename DofType,typename GridType>
void checkLeftEdge( GridType &grid, DofType &dof, bool with_first, bool with_last, typename DofType::RealType expectedValue )

Vít Hanousek
committed
{
int maxx = grid.getDimensions().x();
int maxy = grid.getDimensions().y();
int begin = 0;
int end = maxy;
if( !with_first ) begin++;
if( !with_last ) end--;
for( int i=begin;i<end;i++ )

Vít Hanousek
committed
EXPECT_EQ( dof[maxx*i], expectedValue) << "Left Edge test failed " << i<<" " << maxx << " "<< maxy;

Vít Hanousek
committed
}
template<typename DofType,typename GridType>
void checkRightEdge(GridType &grid, DofType &dof, bool with_first, bool with_last, typename DofType::RealType expectedValue)
{
int maxx = grid.getDimensions().x();
int maxy = grid.getDimensions().y();
int begin = 0;
int end = maxy;
if( !with_first ) begin++;
if( !with_last ) end--;
for( int i = begin; i < end; i++ )

Vít Hanousek
committed
EXPECT_EQ( dof[maxx*i+(maxx-1)], expectedValue) << "Right Edge test failed " << i <<" " << maxx << " "<< maxy;

Vít Hanousek
committed
}
template<typename DofType,typename GridType>
void checkUpEdge( GridType &grid, DofType &dof, bool with_first, bool with_last, typename DofType::RealType expectedValue )

Vít Hanousek
committed
{
int maxx = grid.getDimensions().x();
int maxy = grid.getDimensions().y();
int begin = 0;
int end = maxx;
if( !with_first ) begin++;
if( !with_last ) end--;
for( int i=begin; i<end; i++ )

Vít Hanousek
committed
EXPECT_EQ( dof[i], expectedValue) << "Up Edge test failed " << i<<" " << maxx << " "<< maxy;

Vít Hanousek
committed
}
template<typename DofType,typename GridType>
void checkDownEdge( GridType &grid, DofType &dof, bool with_first, bool with_last, typename DofType::RealType expectedValue )

Vít Hanousek
committed
{
int maxx = grid.getDimensions().x();
int maxy = grid.getDimensions().y();
int begin = 0;
int end = maxx;
if( !with_first ) begin++;
if( !with_last ) end--;
for( int i=begin; i<end; i++ )

Vít Hanousek
committed
EXPECT_EQ( dof[maxx*(maxy-1)+i], expectedValue) << "Down Edge test failed " << i<<" " << maxx << " "<< maxy;

Vít Hanousek
committed
}
template<typename DofType,typename GridType>
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
void checkLeftBoundary( GridType &grid, DofType &dof, bool with_first, bool with_last, typename DofType::RealType expectedValue )
{
int maxx = grid.getDimensions().x();
int maxy = grid.getDimensions().y();
int begin = 1;
int end = maxy - 1;
if( !with_first ) begin++;
if( !with_last ) end--;
for( int i=begin;i<end;i++ )
EXPECT_EQ( dof[ maxx * i + 1 ], expectedValue) << "Left Edge test failed " << i<<" " << maxx << " "<< maxy;
}
template<typename DofType,typename GridType>
void checkRightBoundary(GridType &grid, DofType &dof, bool with_first, bool with_last, typename DofType::RealType expectedValue)
{
int maxx = grid.getDimensions().x();
int maxy = grid.getDimensions().y();
int begin = 1;
int end = maxy - 1;
if( !with_first ) begin++;
if( !with_last ) end--;
for( int i = begin; i < end; i++ )
EXPECT_EQ( dof[ maxx * i + ( maxx - 2 ) ], expectedValue) << "Right Edge test failed " << i <<" " << maxx << " "<< maxy;
}
template<typename DofType,typename GridType>
void checkUpBoundary( GridType &grid, DofType &dof, bool with_first, bool with_last, typename DofType::RealType expectedValue )
{
int maxx = grid.getDimensions().x();
int maxy = grid.getDimensions().y();
int begin = 1;
int end = maxx - 1;
if( !with_first ) begin++;
if( !with_last ) end--;
for( int i=begin; i<end; i++ )
EXPECT_EQ( dof[ maxx + i ], expectedValue) << "Up Edge test failed " << i<<" " << maxx << " "<< maxy;
}
template<typename DofType,typename GridType>
void checkDownBoundary( GridType &grid, DofType &dof, bool with_first, bool with_last, typename DofType::RealType expectedValue )
{
int maxx = grid.getDimensions().x();
int maxy = grid.getDimensions().y();
int begin = 1;
int end = maxx - 1;
if( !with_first ) begin++;
if( !with_last ) end--;
for( int i=begin; i<end; i++ )
EXPECT_EQ( dof[ maxx * ( maxy-2 ) + i ], expectedValue) << "Down Edge test failed " << i<<" " << maxx << " "<< maxy;
}
template<typename DofType,typename GridType>
void checkCorner(GridType &grid, DofType &dof, bool up, bool left, typename DofType::RealType expectedValue )

Vít Hanousek
committed
{

Vít Hanousek
committed
int maxx=grid.getDimensions().x();
int maxy=grid.getDimensions().y();
if(up&&left)
{
EXPECT_EQ( dof[0], expectedValue) << "Up Left Conner test failed ";
}
if(up && !left)
{
EXPECT_EQ( dof[maxx-1], expectedValue) << "Up Right Conner test failed ";
}
if(!up && left)
{
EXPECT_EQ( dof[(maxy-1)*maxx], expectedValue) << "Down Left Conner test failed ";
}
if(!up && !left)
{
EXPECT_EQ( dof[(maxy-1)*maxx+maxx-1], expectedValue) << "Down right Conner test failed ";
}

Vít Hanousek
committed
}
/*expecting 9 processes*/

Vít Hanousek
committed
template<typename DofType,typename GridType>
void check_Boundary_2D(int rank, GridType &grid, DofType &dof, typename DofType::RealType expectedValue)

Vít Hanousek
committed
{
if(rank==0)//Up Left
{
checkUpEdge(grid,dof,true,false,expectedValue);//posledni je overlap
checkLeftEdge(grid,dof,true,false, expectedValue);//posledni je overlap
}
if(rank==1)//Up Center
{
checkUpEdge(grid,dof,false,false, expectedValue);//prvni a posledni je overlap
}
if(rank==2)//Up Right
{
checkUpEdge(grid,dof,false,true,expectedValue);//prvni je overlap
checkRightEdge(grid,dof,true,false,expectedValue);//posledni je overlap
}
if(rank==3)//Center Left
{
checkLeftEdge(grid,dof,false,false,expectedValue);//prvni a posledni je overlap
}
Loading
Loading full blame...