MaMiCo 1.2
Loading...
Searching...
No Matches
LBCouetteSolverInterface.h
1// Copyright (C) 2016 Technische Universitaet Muenchen
2// This file is part of the Mamico project. For conditions of distribution
3// and use, please see the copyright notice in Mamico's main folder, or at
4// www5.in.tum.de/mamico
5
6#ifndef _MOLECULARDYNAMICS_COUPLING_SOLVERS_LBCOUETTESOLVERINTERFACE_H_
7#define _MOLECULARDYNAMICS_COUPLING_SOLVERS_LBCOUETTESOLVERINTERFACE_H_
8
9#include "coupling/interface/MacroscopicSolverInterface.h"
10
11namespace coupling {
12namespace solvers {
14}
15} // namespace coupling
16
27public:
39 tarch::la::Vector<3, int> offsetMDDomain, tarch::la::Vector<3, unsigned int> globalNumberCouplingCells, unsigned int outerRegion = 1)
40 : _avgNumberLBCells(avgNumberLBCells), _numberProcesses(numberProcesses), _offsetMDDomain(offsetMDDomain), _outerRegion(outerRegion),
41 _globalNumberCouplingCells(globalNumberCouplingCells) {}
43
44 unsigned int getOuterRegion() override { return _outerRegion; }
45
50 std::vector<unsigned int> getRanks(I01 idx) override {
51 std::vector<unsigned int> ranks;
52 // determine global index of cell in LB simulation
53 tarch::la::Vector<3, int> globalLBCellIndex(idx.get() + _offsetMDDomain);
54 // modify global LB cell index due to ghost layer
55 for (int d = 0; d < 3; d++) {
56#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
57 std::cout << "LB cell index for global cell index " << idx << ": " << globalLBCellIndex << std::endl;
58#endif
59 globalLBCellIndex[d]--;
60 }
61 // loop over all neighbouring cells within a one-cell surrounding and detect
62 // the respective ranks. IMPROVE: This currently only allows for simulations
63 // with MD located inside the domain (no simulation across boundary)
64 for (int z = -1; z < 2; z++) {
65 for (int y = -1; y < 2; y++) {
66 for (int x = -1; x < 2; x++) {
67 // neighbour cell index
68 const tarch::la::Vector<3, unsigned int> nbIndex(globalLBCellIndex[0] + x, globalLBCellIndex[1] + y, globalLBCellIndex[2] + z);
69 // coordinates of process of neighbour celll
70 const tarch::la::Vector<3, unsigned int> processCoordinates((nbIndex[0] / _avgNumberLBCells[0]), (nbIndex[1] / _avgNumberLBCells[1]),
71 (nbIndex[2] / _avgNumberLBCells[2]));
72 if (processCoordinates[0] < 0 || processCoordinates[0] > _numberProcesses[0] - 1)
73 continue;
74 if (processCoordinates[1] < 0 || processCoordinates[1] > _numberProcesses[1] - 1)
75 continue;
76 if (processCoordinates[2] < 0 || processCoordinates[2] > _numberProcesses[2] - 1)
77 continue;
78 // corresponding rank
79 const unsigned int rank = processCoordinates[0] + _numberProcesses[0] * (processCoordinates[1] + processCoordinates[2] * _numberProcesses[1]);
80
81 // if this rank is not part of the vector, push it back
82 bool found = false;
83 for (unsigned int i = 0; i < ranks.size(); i++) {
84 found = found || (rank == ranks[i]);
85 }
86 if (!found) {
87 ranks.push_back(rank);
88 }
89 }
90 }
91 }
92#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
93 std::cout << "Ranks for cell " << idx << ":";
94 for (unsigned int i = 0; i < ranks.size(); i++) {
95 std::cout << " " << ranks[i];
96 }
97 std::cout << std::endl;
98#endif
99 return ranks;
100 }
101
112 std::vector<unsigned int> getSourceRanks(I01 idx) override {
113 // determine global index of cell in LB simulation
114 tarch::la::Vector<3, int> globalLBCellIndex(idx.get() + _offsetMDDomain);
115 // modify global LB cell index due to ghost layer
116 for (int d = 0; d < 3; d++) {
117#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
118 std::cout << "LB cell index for global cell index " << idx << ": " << globalLBCellIndex << std::endl;
119#endif
120 globalLBCellIndex[d]--;
121 }
122 std::vector<unsigned int> ranks;
123 // determine process coordinates and respective rank
124 const tarch::la::Vector<3, unsigned int> processCoordinates(globalLBCellIndex[0] / _avgNumberLBCells[0], globalLBCellIndex[1] / _avgNumberLBCells[1],
125 globalLBCellIndex[2] / _avgNumberLBCells[2]);
126 // if idx is outside of LB domain, return no ranks
127 for (int d = 0; d < 3; d++)
128 if (processCoordinates[d] < 0 || processCoordinates[d] > _numberProcesses[d] - 1)
129 return ranks;
130
131 const unsigned int rank = processCoordinates[0] + _numberProcesses[0] * (processCoordinates[1] + processCoordinates[2] * _numberProcesses[1]);
132 ranks.push_back(rank);
133#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
134 std::cout << "Source rank for cell " << idx << ": " << ranks[0] << std::endl;
135#endif
136 return ranks;
137 }
138
139private:
149 const unsigned int _outerRegion;
152};
153
154#endif // _MOLECULARDYNAMICS_COUPLING_SOLVERS_LBCOUETTESOLVERINTERFACE_H_
value_T get() const
Definition CellIndex.h:138
interface for the macroscopic, i.e. continuum solver
Definition MacroscopicSolverInterface.h:23
interface for the LBCouetteSolver
Definition LBCouetteSolverInterface.h:26
LBCouetteSolverInterface(tarch::la::Vector< 3, unsigned int > avgNumberLBCells, tarch::la::Vector< 3, unsigned int > numberProcesses, tarch::la::Vector< 3, int > offsetMDDomain, tarch::la::Vector< 3, unsigned int > globalNumberCouplingCells, unsigned int outerRegion=1)
a simple constructor
Definition LBCouetteSolverInterface.h:38
std::vector< unsigned int > getRanks(I01 idx) override
returns for a given coupling cell index, which rank holds the correct data @oaram idx global dimensio...
Definition LBCouetteSolverInterface.h:50
const tarch::la::Vector< 3, int > _offsetMDDomain
offset of MD domain (excl. any ghost layers on MD or LB side)
Definition LBCouetteSolverInterface.h:146
const tarch::la::Vector< 3, unsigned int > _globalNumberCouplingCells
global number of coupling cells
Definition LBCouetteSolverInterface.h:151
const tarch::la::Vector< 3, unsigned int > _avgNumberLBCells
avg. number of LB cells per LB process (must be same for Interface and LBCouetteSolver)
Definition LBCouetteSolverInterface.h:142
std::vector< unsigned int > getSourceRanks(I01 idx) override
returns for a given coupling cell index, which source rank holds the correct data
Definition LBCouetteSolverInterface.h:112
const tarch::la::Vector< 3, unsigned int > _numberProcesses
number of processes used by LB solver
Definition LBCouetteSolverInterface.h:144
const unsigned int _outerRegion
defines an offset of cells which is considered to be the outer region
Definition LBCouetteSolverInterface.h:149
Definition Vector.h:25
all numerical solvers are defined in the namespace, and their interfaces
Definition CouetteSolver.h:14
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15