57#
if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
59 MPI_Comm comm = MPI_COMM_WORLD
64 for (
unsigned int i = 0; i < dim; i++) {
65 subdomainWeights[i].reserve(numberProcesses[i]);
66 for (
unsigned int j = 0; j < numberProcesses[i]; j++) {
67 subdomainWeights[i].push_back(1);
70 initWithCells(subdomainWeights, globalNumberCouplingCells, numberProcesses, parallelTopologyType, outerRegion, rank
71#
if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
80 unsigned int outerRegion,
const unsigned int rank
81#
if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
83 MPI_Comm comm = MPI_COMM_WORLD
90#
if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
92 MPI_Comm comm = MPI_COMM_WORLD
97 for (
unsigned int i = 0; i < dim; i++) {
98 subdomainWeights[i].reserve(mdNumberProcesses[i]);
99 for (
unsigned int j = 0; j < mdNumberProcesses[i]; j++) {
100 subdomainWeights[i].push_back(1);
104 initWithMDSize(subdomainWeights, globalMDDomainSize, globalMDDomainOffset, mdNumberProcesses, couplingCellSize, parallelTopologyType, outerRegion, rank
105#
if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
114 unsigned int outerRegion,
unsigned int rank
115#
if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
117 MPI_Comm comm = MPI_COMM_WORLD
120 _globalMDDomainSize = globalMDDomainSize;
121 _globalMDDomainOffset = globalMDDomainOffset;
122 _couplingCellSize = couplingCellSize;
123 _initedWithMDSize =
true;
127 for (
unsigned int d = 0; d < dim; d++) {
128 globalNumberCouplingCells[d] = (
unsigned int)floor(globalMDDomainSize[d] / couplingCellSize[d] + 0.5);
130 if (fabs((globalNumberCouplingCells[d]) * couplingCellSize[d] - globalMDDomainSize[d]) > 1e-13)
131 std::cout <<
"IndexingService: Deviation of domain size > 1e-13!" << std::endl;
134 initWithCells(subdomainWeights, globalNumberCouplingCells, mdNumberProcesses, parallelTopologyType, outerRegion, rank
135#
if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
143#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
144 _isInitialized =
false;
157 std::vector<unsigned int>
getRanksForGlobalIndex(
const BaseIndex<dim>& globalCellIndex,
unsigned int topologyOffset)
const;
159 unsigned int getUniqueRankForCouplingCell(
const BaseIndex<dim>& globalCellIndex,
unsigned int topologyOffset)
const;
161#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
162 MPI_Comm getComm()
const {
163#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
164 if (!_isInitialized) {
165 throw std::runtime_error(std::string(
"IndexingService: Called index system getComm() before initialization! "));
173 unsigned int getRank()
const {
174#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
175 if (!_isInitialized) {
176 throw std::runtime_error(std::string(
"IndexingService: Called index system getRank() before initialization! "));
183#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
184 bool isInitialized()
const {
return _isInitialized; }
191#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
192 if (!_isInitialized) {
193 throw std::runtime_error(std::string(
"IndexingService: Called getGlobalMDDomainSize() before initalization! "));
195 if (!_initedWithMDSize) {
196 throw std::runtime_error(std::string(
"IndexingService: Called getGlobalMDDomainSize() without calling initWithMDSize()! "));
199 return _globalMDDomainSize;
206#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
207 if (!_isInitialized) {
208 throw std::runtime_error(std::string(
"IndexingService: Called getGlobalMDDomainOffset() before initalization! "));
210 if (!_initedWithMDSize) {
211 throw std::runtime_error(std::string(
"IndexingService: Called getGlobalMDDomainOffset() without calling initWithMDSize()! "));
214 return _globalMDDomainOffset;
220#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
221 if (!_isInitialized) {
222 throw std::runtime_error(std::string(
"IndexingService: Called getCouplingCellSize() before initalization! "));
224 if (!_initedWithMDSize) {
225 throw std::runtime_error(std::string(
"IndexingService: Called getCouplingCellSize() without calling initWithMDSize()! "));
228 return _couplingCellSize;
231 unsigned int getScalarNumberProcesses()
const {
232#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
233 if (!_isInitialized) {
234 throw std::runtime_error(std::string(
"IndexingService: Called getScalarNumberProcesses() before initalization! "));
237 return _scalarNumberProcesses;
241#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
242 if (!_isInitialized) {
243 throw std::runtime_error(std::string(
"IndexingService: Called getCellIndex() before initalization! "));
245 if (!_initedWithMDSize) {
246 throw std::runtime_error(std::string(
"IndexingService: Called getCellIndex() without calling initWithMDSize()! "));
250 tarch::la::Vector<dim, int> res_raw;
251 for (
unsigned int d = 0; d < dim; d++) {
252 const double buf = position[d] - (_globalMDDomainOffset[d] - _couplingCellSize[d]);
253 res_raw[d] = buf / _couplingCellSize[d];
256 BaseIndex<dim> res{res_raw};
257#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
259 throw std::runtime_error(std::string(
"IndexingService::getCellIndex(): Invalid conversion!"));
266 unsigned int getUniqueRankForCouplingCell(tarch::la::Vector<dim, unsigned int> globalCellIndex,
267 const tarch::la::Vector<dim, unsigned int>& globalNumberCouplingCells,
unsigned int topologyOffset)
const;
269 tarch::la::Vector<dim, unsigned int> _numberProcesses;
270 unsigned int _scalarNumberProcesses;
271 const coupling::paralleltopology::ParallelTopology<dim>* _parallelTopology;
272#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
276#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
277 bool _isInitialized =
false;
279 bool _initedWithMDSize =
false;
280 tarch::la::Vector<dim, std::vector<unsigned int>> _subdomainOwnership;
281 tarch::la::Vector<dim, double> _globalMDDomainSize;
282 tarch::la::Vector<dim, double> _globalMDDomainOffset;
283 tarch::la::Vector<dim, double> _couplingCellSize;
285 friend IndexingServiceTest;