10template <MInt nDim, MInt nDist,
class SysEqn>
17template <MInt nDim, MInt nDist,
class SysEqn>
24template <MInt nDim, MInt nDist,
class SysEqn>
26 m_sourceSolverId = sourceSolver().solverId();
27 m_destSolverId = destSolver().solverId();
30template <MInt nDim, MInt nDist,
class SysEqn>
33 if(sourceSolver().m_updateMacroscopicLocation != destSolver().m_updateMacroscopicLocation) {
34 mTerm(1, AT_,
"updateAfterPropagation has to be consistent between solvers");
36 if(sourceSolver().m_isThermal != destSolver().m_isThermal) {
37 mTerm(1, AT_,
"isThermal has to be consistent between solvers");
41 for(
MInt sourceId = 0; sourceId < sourceSolver().a_noCells(); sourceId++) {
42 if(source2DestId(sourceId) < 0)
continue;
43 MBool isInside =
true;
44 for(
MInt i = 0; i < nDim; i++) {
45 MFloat coordinate = sourceSolver().a_coordinate(sourceId, i);
46 if(coordinate < m_transferBox[i] || coordinate > m_transferBox[i + nDim]) {
52 m_transferCellIds.push_back(sourceId);
57 if(sourceSolver().m_isThermal) {
59 mAlloc(m_dataBlockSizes, m_noVarsTransfer,
"m_dataBlockSizes", 0, AT_);
60 mAlloc(m_sourceBaseAddresses, m_noVarsTransfer,
"m_sourceBaseAddresses", AT_);
61 mAlloc(m_destBaseAddresses, m_noVarsTransfer,
"m_destBaseAddresses", AT_);
63 m_dataBlockSizes[0] = nDim + 1;
64 m_dataBlockSizes[1] = nDim + 1;
65 m_dataBlockSizes[2] = nDist;
66 m_dataBlockSizes[3] = nDist;
68 m_sourceBaseAddresses[0] = &sourceSolver().a_variable(0, 0);
69 m_sourceBaseAddresses[1] = &sourceSolver().a_oldVariable(0, 0);
70 m_sourceBaseAddresses[2] = &sourceSolver().a_oldDistribution(0, 0);
71 m_sourceBaseAddresses[3] = &sourceSolver().a_oldDistributionThermal(0, 0);
72 m_destBaseAddresses[0] = &destSolver().a_variable(0, 0);
73 m_destBaseAddresses[1] = &destSolver().a_oldVariable(0, 0);
74 m_destBaseAddresses[2] = &destSolver().a_oldDistribution(0, 0);
75 m_destBaseAddresses[3] = &destSolver().a_oldDistributionThermal(0, 0);
78 mAlloc(m_dataBlockSizes, m_noVarsTransfer,
"m_noDataBlockSizes", 0, AT_);
79 mAlloc(m_sourceBaseAddresses, m_noVarsTransfer,
"m_sourceBaseAddresses", AT_);
80 mAlloc(m_destBaseAddresses, m_noVarsTransfer,
"m_destBaseAddresses", AT_);
81 m_dataBlockSizes[0] = nDim + 1;
82 m_dataBlockSizes[1] = nDim + 1;
83 m_dataBlockSizes[2] = nDist;
85 m_sourceBaseAddresses[0] = &sourceSolver().a_variable(0, 0);
86 m_sourceBaseAddresses[1] = &sourceSolver().a_oldVariable(0, 0);
87 m_sourceBaseAddresses[2] = &sourceSolver().a_oldDistribution(0, 0);
88 m_destBaseAddresses[0] = &destSolver().a_variable(0, 0);
89 m_destBaseAddresses[1] = &destSolver().a_oldVariable(0, 0);
90 m_destBaseAddresses[2] = &destSolver().a_oldDistribution(0, 0);
93 if(sourceSolver().m_isThermal) {
95 mAlloc(m_dataBlockSizes, m_noVarsTransfer,
"m_noDataBlockSizes", 0, AT_);
96 mAlloc(m_sourceBaseAddresses, m_noVarsTransfer,
"m_sourceBaseAddresses", AT_);
97 mAlloc(m_destBaseAddresses, m_noVarsTransfer,
"m_destBaseAddresses", AT_);
99 m_dataBlockSizes[0] = nDim + 1;
100 m_dataBlockSizes[1] = nDist;
101 m_dataBlockSizes[2] = nDist;
103 m_sourceBaseAddresses[0] = &sourceSolver().a_variable(0, 0);
104 m_sourceBaseAddresses[1] = &sourceSolver().a_oldDistribution(0, 0);
105 m_sourceBaseAddresses[2] = &sourceSolver().a_oldDistributionThermal(0, 0);
106 m_destBaseAddresses[0] = &destSolver().a_variable(0, 0);
107 m_destBaseAddresses[1] = &destSolver().a_oldDistribution(0, 0);
108 m_destBaseAddresses[2] = &destSolver().a_oldDistributionThermal(0, 0);
110 m_noVarsTransfer = 2;
111 mAlloc(m_dataBlockSizes, m_noVarsTransfer,
"m_noDataBlockSizes", 0, AT_);
112 mAlloc(m_sourceBaseAddresses, m_noVarsTransfer,
"m_sourceBaseAddresses", AT_);
113 mAlloc(m_destBaseAddresses, m_noVarsTransfer,
"m_destBaseAddresses", AT_);
115 m_dataBlockSizes[0] = nDim + 1;
116 m_dataBlockSizes[1] = nDist;
118 m_sourceBaseAddresses[0] = &sourceSolver().a_variable(0, 0);
119 m_sourceBaseAddresses[1] = &sourceSolver().a_oldDistribution(0, 0);
120 m_destBaseAddresses[0] = &destSolver().a_variable(0, 0);
121 m_destBaseAddresses[1] = &destSolver().a_oldDistribution(0, 0);
127 for(
const auto& sourceId : m_transferCellIds) {
128 const MInt destId = source2DestId(sourceId);
129 MBool isCorrect =
true;
130 for(
MInt i = 0; i < nDim; i++) {
131 if(fabs(sourceSolver().a_coordinate(sourceId, i) - destSolver().a_coordinate(destId, i)) > 1e-10) {
136 std::cerr <<
"source:" << sourceId <<
" " << sourceSolver().a_coordinate(sourceId, 0) <<
" "
137 << sourceSolver().a_coordinate(sourceId, 1) <<
" " << sourceSolver().a_coordinate(sourceId, 2) <<
" "
138 <<
"dest:" << destId <<
" " << destSolver().a_coordinate(destId, 0) <<
" "
139 << destSolver().a_coordinate(destId, 1) <<
" " << destSolver().a_coordinate(destId, 2) << std::endl;
143 for(
MInt destId = 0; destId < destSolver().a_noCells(); destId++) {
144 MBool isInside =
true;
145 for(
MInt i = 0; i < nDim; i++) {
146 MFloat coordinate = destSolver().a_coordinate(destId, i);
147 if(coordinate < m_transferBox[i] || coordinate > m_transferBox[i + nDim]) {
153 const MInt sourceId = dest2SourceId(destId);
154 if(std::find(m_transferCellIds.begin(), m_transferCellIds.end(), sourceId) == m_transferCellIds.end()) {
155 std::cerr <<
"missed cell dest:" << destId <<
" " << destSolver().a_coordinate(destId, 0) <<
" "
156 << destSolver().a_coordinate(destId, 1) <<
" " << destSolver().a_coordinate(destId, 2) <<
" "
157 <<
"source:" << sourceId <<
" " << sourceSolver().a_coordinate(sourceId, 0) <<
" "
158 << sourceSolver().a_coordinate(sourceId, 1) <<
" " << sourceSolver().a_coordinate(sourceId, 2)
166template <MInt nDim, MInt nDist,
class SysEqn>
169 for(
MInt i = 0; i < nDim * 2; i++) {
176 m_transferBox[i] = Context::getSolverProperty<MFloat>(
"lbBox", 0, AT_, i);
179 mTerm(1, AT_,
"Property lbBox required for coupler LBLb!");
183template <MInt nDim, MInt nDist,
class SysEqn>
185 for(
const auto& sourceId : m_transferCellIds) {
186 const MInt destId = source2DestId(sourceId);
187 for(
MInt var = 0; var < m_noVarsTransfer; var++) {
188 memcpy(m_destBaseAddresses[var] + (m_dataBlockSizes[var] * destId),
189 m_sourceBaseAddresses[var] + (m_dataBlockSizes[var] * sourceId),
190 m_dataBlockSizes[var] *
sizeof(
MFloat));
void mAlloc(T *&a, const MLong N, const MString &objectName, MString function)
allocates memory for one-dimensional array 'a' of size N
MBool mDeallocate(T *&a)
deallocates the memory previously allocated for element 'a'
static MBool propertyExists(const MString &name, MInt solver=m_noSolvers)
This function checks if a property exists in general.
CouplerLbLb(const MInt couplingId, std::vector< LbSolver * > solvers)
virtual void readProperties()
virtual void postCouple(MInt)
void mTerm(const MInt errorCode, const MString &location, const MString &message)