MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
couplingutils.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef COUPLINGUTILS_H_
8#define COUPLINGUTILS_H_
9
10#include <string>
11
12#include <INCLUDE/maiatypes.h>
13#include <UTIL/functions.h>
14
15// Collection of functions which are useful for coupling multiple solvers
16
20template <class SolverA, class SolverB>
21MInt convertId(SolverA& solverA, SolverB& solverB, const MInt solverAId) {
22 if(solverAId >= solverA.c_noCells() || solverAId < 0) return -1;
23 solverA.assertValidGridCellId(solverAId);
24
25 const MInt gridId = solverA.grid().tree().solver2grid(solverAId);
26 ASSERT(solverA.grid().solverFlag(gridId, solverA.solverId()), "");
27
28 if(!solverB.grid().solverFlag(gridId, solverB.solverId())) return -1;
29
30 const MInt solverBId = solverB.grid().tree().grid2solver(gridId);
31
32 if(solverBId > 0) {
33 ASSERT(solverA.a_level(solverAId) == solverB.a_level(solverBId),
34 std::to_string(solverAId) + " " + std::to_string(solverA.a_level(solverAId)) + " "
35 + std::to_string(solverB.a_level(solverBId)));
36 }
37
38 return solverBId;
39}
40
45template <class SolverA, class SolverB>
46MInt convertIdParent(SolverA& solverA, SolverB& solverB, const MInt solverAId) {
47 if(solverAId >= solverA.c_noCells() || solverAId < 0) return -1; // not even a grid-cell, still return -1
48 solverA.assertValidGridCellId(solverAId);
49
50 MInt gridId = solverA.grid().tree().solver2grid(solverAId);
51 ASSERT(solverA.grid().solverFlag(gridId, solverA.solverId()), "");
52
53 if(solverB.grid().solverFlag(gridId, solverB.solverId())) { // connection on the same level!
54 return solverB.grid().tree().grid2solver(gridId);
55
56 } else { // going through all parents! to find a connection
57
58 MInt solverAParentId = solverA.c_parentId(solverAId);
59 MInt solverBParentId = convertId(solverA, solverB, solverAParentId);
60
61 while(solverBParentId < 0 && solverAParentId > -1 && solverAParentId < solverA.c_noCells()) {
62 solverAParentId = solverA.c_parentId(solverAParentId);
63 solverBParentId = convertId(solverA, solverB, solverAParentId);
64 }
65 return solverBParentId;
66 }
67}
68
69#endif // COUPLINGUTILS_H_
MInt convertId(SolverA &solverA, SolverB &solverB, const MInt solverAId)
Conversion from solverA id to the solverB id on the same-level only!
Definition: couplingutils.h:21
MInt convertIdParent(SolverA &solverA, SolverB &solverB, const MInt solverAId)
Conversion from solverA id to the solverB id If no cell on the same level is found,...
Definition: couplingutils.h:46
int32_t MInt
Definition: maiatypes.h:62