Skip to content

Commit c0e797c

Browse files
committed
Final fix to the vector potential consistancy in serial, to do the
same as with MPI
1 parent 8984d0d commit c0e797c

3 files changed

Lines changed: 54 additions & 58 deletions

File tree

src/fluid/constrainedTransport/constrainedTransport.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class ConstrainedTransport {
102102
void EvolveVectorPotential(real, IdefixArray4D<real> &);
103103
void ComputeMagFieldFromA(IdefixArray4D<real> &Vein, IdefixArray4D<real> &Vsout);
104104
void EnforceVectorPotentialBoundary(IdefixArray4D<real> &Vein); // Enforce BCs on A
105+
void EnforceEMFBoundaryPeriodic(IdefixArray3D<real> ex,
106+
IdefixArray3D<real> ey,
107+
IdefixArray3D<real> ez);
105108

106109
#ifdef WITH_MPI
107110
// Exchange surface EMFs to remove interprocess round off errors

src/fluid/constrainedTransport/enforceEMFBoundary.hpp

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -42,70 +42,62 @@ void ConstrainedTransport<Phys>::EnforceEMFBoundary() {
4242
#endif
4343
#endif
4444

45-
IdefixArray3D<real> ex = this->ex;
46-
IdefixArray3D<real> ey = this->ey;
47-
IdefixArray3D<real> ez = this->ez;
48-
4945
// Enforce specific EMF regularisation
5046
for(int dir=0 ; dir < DIMENSIONS ; dir++ ) {
5147
if(data->lbound[dir] == shearingbox || data->rbound[dir] == shearingbox) {
5248
SymmetrizeEMFShearingBox();
5349
}
54-
#ifdef ENFORCE_EMF_CONSISTENCY
55-
if(data->lbound[dir] == periodic && data->rbound[dir] == periodic) {
56-
// If domain decomposed, periodicity is already enforced by ExchangeAll
57-
if(data->mygrid->nproc[dir] == 1) {
58-
int ioffset = (dir == IDIR) ? data->np_int[IDIR] : 0;
59-
int joffset = (dir == JDIR) ? data->np_int[JDIR] : 0;
60-
int koffset = (dir == KDIR) ? data->np_int[KDIR] : 0;
61-
62-
int ibeg = (dir == IDIR) ? data->beg[IDIR] : 0;
63-
int iend = (dir == IDIR) ? data->beg[IDIR]+1 : data->np_tot[IDIR];
64-
int jbeg = (dir == JDIR) ? data->beg[JDIR] : 0;
65-
int jend = (dir == JDIR) ? data->beg[JDIR]+1 : data->np_tot[JDIR];
66-
int kbeg = (dir == KDIR) ? data->beg[KDIR] : 0;
67-
int kend = (dir == KDIR) ? data->beg[KDIR]+1 : data->np_tot[KDIR];
68-
idefix_for("BoundaryEMFPeriodic",kbeg,kend,jbeg,jend,ibeg,iend,
69-
KOKKOS_LAMBDA (int k, int j, int i) {
70-
real em;
71-
72-
if(dir==IDIR) {
73-
em = HALF_F*(ez(k,j,i)+ez(k,j,i+ioffset));
74-
ez(k,j,i) = em;
75-
ez(k,j,i+ioffset) = em;
76-
77-
#if DIMENSIONS == 3
78-
em = HALF_F*(ey(k,j,i)+ey(k,j,i+ioffset));
79-
ey(k,j,i) = em;
80-
ey(k,j,i+ioffset) = em;
81-
#endif
82-
}
83-
84-
if(dir==JDIR) {
85-
em = HALF_F*(ez(k,j,i)+ez(k,j+joffset,i));
86-
ez(k,j,i) = em;
87-
ez(k,j+joffset,i) = em;
88-
89-
#if DIMENSIONS == 3
90-
em = HALF_F*(ex(k,j,i)+ex(k,j+joffset,i));
91-
ex(k,j,i) = em;
92-
ex(k,j+joffset,i) = em;
93-
#endif
94-
}
95-
96-
if(dir==KDIR) {
97-
em = HALF_F*(ex(k,j,i)+ex(k+koffset,j,i));
98-
ex(k,j,i) = em;
99-
ex(k+koffset,j,i) = em;
100-
101-
em = HALF_F*(ey(k,j,i)+ey(k+koffset,j,i));
102-
ey(k,j,i) = em;
103-
ey(k+koffset,j,i) = em;
104-
}
105-
});
106-
}
50+
}
51+
#ifdef ENFORCE_EMF_CONSISTENCY
52+
EnforceEMFBoundaryPeriodic(ex,ey,ez);
53+
#endif //ENFORCE_EMF_CONSISTENCY
54+
#endif // MHD==YES
55+
idfx::popRegion();
56+
}
57+
58+
template<typename Phys>
59+
void ConstrainedTransport<Phys>::EnforceEMFBoundaryPeriodic(IdefixArray3D<real> ex,
60+
IdefixArray3D<real> ey,
61+
IdefixArray3D<real> ez) {
62+
idfx::pushRegion("Emf::EnforceEMFBoundaryPeriodic");
63+
#if MHD == YES
64+
for(int dir=0 ; dir < DIMENSIONS ; dir++ ) {
65+
if(data->lbound[dir] == periodic && data->rbound[dir] == periodic) {
66+
// If domain decomposed, periodicity is already enforced by ExchangeAll
67+
if(data->mygrid->nproc[dir] == 1) {
68+
int ioffset = (dir == IDIR) ? data->np_int[IDIR] : 0;
69+
int joffset = (dir == JDIR) ? data->np_int[JDIR] : 0;
70+
int koffset = (dir == KDIR) ? data->np_int[KDIR] : 0;
71+
72+
int ibeg = (dir == IDIR) ? data->beg[IDIR] : 0;
73+
int iend = (dir == IDIR) ? data->beg[IDIR]+1 : data->np_tot[IDIR];
74+
int jbeg = (dir == JDIR) ? data->beg[JDIR] : 0;
75+
int jend = (dir == JDIR) ? data->beg[JDIR]+1 : data->np_tot[JDIR];
76+
int kbeg = (dir == KDIR) ? data->beg[KDIR] : 0;
77+
int kend = (dir == KDIR) ? data->beg[KDIR]+1 : data->np_tot[KDIR];
78+
idefix_for("BoundaryEMFPeriodic",kbeg,kend,jbeg,jend,ibeg,iend,
79+
KOKKOS_LAMBDA (int k, int j, int i) {
80+
if(dir==IDIR) {
81+
ez(k,j,i+ioffset) = ez(k,j,i);
82+
#if DIMENSIONS == 3
83+
ey(k,j,i+ioffset) = ey(k,j,i);
84+
#endif
85+
}
86+
87+
if(dir==JDIR) {
88+
ez(k,j+joffset,i) = ez(k,j,i);
89+
#if DIMENSIONS == 3
90+
ex(k,j+joffset,i) = ex(k,j,i);
91+
#endif
92+
}
93+
94+
if(dir==KDIR) {
95+
ex(k+koffset,j,i) = ex(k,j,i);
96+
ey(k+koffset,j,i) = ey(k,j,i);
97+
}
98+
});
10799
}
108-
#endif //ENFORCE_EMF_CONSISTENCY
100+
}
109101
}
110102
#endif // MHD==YES
111103
idfx::popRegion();

src/fluid/constrainedTransport/enforceVectorPotentialBoundary.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void ConstrainedTransport<Phys>::EnforceVectorPotentialBoundary(IdefixArray4D<re
2828

2929
this->ExchangeAll(Ax1, Ax2, Ax3);
3030
#endif
31+
EnforceEMFBoundaryPeriodic(Ax1, Ax2, Ax3);
3132
#endif
3233

3334
idfx::popRegion();

0 commit comments

Comments
 (0)