VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GridGeneratorTest.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#include <gmock/gmock.h>
35
38
39#include <basics/DataTypes.h>
42
43#include "Parameter/Parameter.h"
48
50
51namespace vf::gpu {
52
53namespace grid_generator_test
54{
55
57{
58private:
59 const SPtr<Grid> grid;
60 LevelGridBuilderStub() = default;
61
62public:
64
65 explicit LevelGridBuilderStub(SPtr<Grid> grid) : grid(std::move(grid)){};
66
67 uint getCommunicationProcess(int direction) override
68 {
69 uint process = 0;
70 if (direction != communication_directions::MX)
72 return process;
73 }
74
75 uint getNumberOfGridLevels() const override
76 {
77 return 2;
78 }
79
80 uint getNumberOfSendIndices(int direction, uint level) override
81 {
83 }
84
85 uint getNumberOfReceiveIndices(int direction, uint level) override
86 {
87 return 0;
88 }
89
90 void getSendIndices(uint *sendIndices, int direction, int level) override
91 {
92 }
93
94 void getReceiveIndices(uint *recvIndices, int direction, int level) override
95 {
96 }
97};
98
100{
101public:
102 explicit CudaMemoryManagerDouble(std::shared_ptr<Parameter> parameter) : CudaMemoryManager(parameter){};
103
105 void cudaCopyProcessNeighborIndex(const ProcessNeighbor27& , const ProcessNeighbor27& ) const override{};
106};
107
109{
110public:
111 IndexRearrangementForStreamsDouble(std::shared_ptr<Parameter> para, std::shared_ptr<GridBuilder> builder,
112 vf::parallel::Communicator &communicator)
113 : IndexRearrangementForStreams(para, builder, communicator){};
114
115 std::array<ProcessNeighbor27, 4> initCommunicationArraysForCommAfterFinetoCoarse(const ProcessNeighbor27& , const ProcessNeighbor27& , const ProcessNeighbor27& , const ProcessNeighbor27& , int, int) const override{
116 return {};
117 };
118};
119
120} // namespace grid_generator_test
121
122using namespace grid_generator_test;
123
125{
126public:
127 void act() const
128 {
129 gridGenerator->initalValuesDomainDecompostion();
130 }
131
132protected:
134 std::shared_ptr<LevelGridBuilderStub> builder;
135
136 const uint level = 1;
138
140
141private:
142 void SetUp() override
143 {
144 para = std::make_shared<Parameter>();
145 para->setMaxLevel(level + 1); // setMaxLevel resizes parH and parD
146 for (uint i = 0; i <= level; i++) {
147 para->parH[i] = std::make_shared<LBMSimulationParameter>();
148 para->parD[i] = std::make_shared<LBMSimulationParameter>();
149 }
150 para->setNumprocs(2);
151
152 builder = std::make_shared<LevelGridBuilderStub>(nullptr);
154
155 gridGenerator = std::make_shared<GridGenerator>(builder, para, std::make_shared<CudaMemoryManagerDouble>(para), *communicator);
156 gridGenerator->setIndexRearrangementForStreams(
157 std::make_unique<IndexRearrangementForStreamsDouble>(para, builder, *communicator));
158 }
159};
160
162{
163 act();
164 EXPECT_THAT(para->getParH(level)->sendProcessNeighborsX.size(), testing::Eq(0));
165 EXPECT_THAT(para->getParH(level)->sendProcessNeighborsY.size(), testing::Eq(0));
166 EXPECT_THAT(para->getParH(level)->sendProcessNeighborsZ.size(), testing::Eq(0));
167}
168
170{
171 builder->numberOfSendIndices = 1;
172 act();
173 EXPECT_THAT(para->getParH(level)->sendProcessNeighborsX.size(),
174 testing::Eq(1)); // one entry for communication_directions::MX
175 EXPECT_THAT(para->getParH(level)->sendProcessNeighborsY.size(), testing::Eq(0));
176 EXPECT_THAT(para->getParH(level)->sendProcessNeighborsZ.size(), testing::Eq(0));
177}
178
179}
180
class that is used to rearrange the arrays of node indices for communication between gpus....
CudaMemoryManagerDouble(std::shared_ptr< Parameter > parameter)
void cudaAllocProcessNeighbor(const ProcessNeighbor27 &, const ProcessNeighbor27 &) override
void cudaCopyProcessNeighborIndex(const ProcessNeighbor27 &, const ProcessNeighbor27 &) const override
IndexRearrangementForStreamsDouble(std::shared_ptr< Parameter > para, std::shared_ptr< GridBuilder > builder, vf::parallel::Communicator &communicator)
std::array< ProcessNeighbor27, 4 > initCommunicationArraysForCommAfterFinetoCoarse(const ProcessNeighbor27 &, const ProcessNeighbor27 &, const ProcessNeighbor27 &, const ProcessNeighbor27 &, int, int) const override
Initialize the arrays for the communication after the interpolation from fine to coarse.
void getSendIndices(uint *sendIndices, int direction, int level) override
uint getNumberOfReceiveIndices(int direction, uint level) override
uint getNumberOfSendIndices(int direction, uint level) override
void getReceiveIndices(uint *recvIndices, int direction, int level) override
An abstract class for communication between processes in parallel computation.
static std::shared_ptr< Communicator > getInstance()
std::shared_ptr< T > SPtr
unsigned int uint
Definition DataTypes.h:47
#define INVALID_INDEX
Definition DataTypes.h:48
TEST_F(GridGeneratorTests_initalValuesDomainDecompostion, whenNoCommunication_sendProcessNeighborShouldNotExist)