From 6fcfc1ca2f5f766d2961768c865da5fa175402d2 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Mon, 24 Nov 2025 18:02:38 +0100 Subject: [PATCH 1/6] Example fix when using pydefix in a python environement --- test/IO/pydefix/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/IO/pydefix/README.md b/test/IO/pydefix/README.md index 820a0958..7dbd8ed8 100644 --- a/test/IO/pydefix/README.md +++ b/test/IO/pydefix/README.md @@ -42,3 +42,10 @@ export pybind11_DIR=env/lib/python3.10/site-packages/pybind11 ``` you can then run cmake which should be able to find pybind11, and compile the code. + +If while running the code using a python interpreter in an envionement, you might run into errors stating that some module +installed in your environement is not present. This is because pybind11 does not always capture your venv. You need to force the following environement variables (replace XX by your python version) + +```bash +export PYTHONPATH=$VIRTUAL_ENV/lib/python3.XX/site-packages +``` From f1b96dacfdba8289602d0b5874930b4998df0be0 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Mon, 24 Nov 2025 18:10:03 +0100 Subject: [PATCH 2/6] - Ensure Ex1 regularisation is applied even when azimuthal domain is non-2pi (as Ex1 can be non-zero on the axis in non-ideal MHD) - Ensure Jx1 regularisation on the axis (circulation around the axis) is compatible with the discretisation used to compute the electrical current in calcCurrent. --- src/fluid/boundary/axis.cpp | 53 +++++++++++++++---------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/fluid/boundary/axis.cpp b/src/fluid/boundary/axis.cpp index e447aefc..e2e524d5 100644 --- a/src/fluid/boundary/axis.cpp +++ b/src/fluid/boundary/axis.cpp @@ -28,39 +28,31 @@ void Axis::SymmetrizeEx1Side(int jref) { IdefixArray3D Ex1 = this->ex; IdefixArray1D Ex1Avg = this->Ex1Avg; - if(isTwoPi) { - idefix_for("Ex1_ini",0,data->np_tot[IDIR], - KOKKOS_LAMBDA(int i) { - Ex1Avg(i) = ZERO_F; - }); - - idefix_for("Ex1_Symmetrize",data->beg[KDIR],data->end[KDIR],0,data->np_tot[IDIR], - KOKKOS_LAMBDA(int k,int i) { - Kokkos::atomic_add(&Ex1Avg(i), Ex1(k,jref,i)); + idefix_for("Ex1_ini",0,data->np_tot[IDIR], + KOKKOS_LAMBDA(int i) { + Ex1Avg(i) = ZERO_F; }); - if(needMPIExchange) { - #ifdef WITH_MPI - Kokkos::fence(); - // sum along all of the processes on the same r - MPI_Allreduce(MPI_IN_PLACE, Ex1Avg.data(), data->np_tot[IDIR], realMPI, - MPI_SUM, data->mygrid->AxisComm); - #endif - } - - int ncells=data->mygrid->np_int[KDIR]; - idefix_for("Ex1_Store",0,data->np_tot[KDIR],0,data->np_tot[IDIR], + idefix_for("Ex1_Symmetrize",data->beg[KDIR],data->end[KDIR],0,data->np_tot[IDIR], KOKKOS_LAMBDA(int k,int i) { - Ex1(k,jref,i) = Ex1Avg(i)/((real) ncells); - }); - } else { - // if we're not doing full two pi, the flow is symmetric with respect to the axis, and the axis - // EMF is simply zero - idefix_for("Ex1_Store",0,data->np_tot[KDIR],0,data->np_tot[IDIR], - KOKKOS_LAMBDA(int k,int i) { - Ex1(k,jref,i) = ZERO_F; + Kokkos::atomic_add(&Ex1Avg(i), Ex1(k,jref,i)); }); + if(needMPIExchange) { + #ifdef WITH_MPI + Kokkos::fence(); + // sum along all of the processes on the same r + MPI_Allreduce(MPI_IN_PLACE, Ex1Avg.data(), data->np_tot[IDIR], realMPI, + MPI_SUM, data->mygrid->AxisComm); + #endif } + + int ncells=data->mygrid->np_int[KDIR]; + + idefix_for("Ex1_Store",0,data->np_tot[KDIR],0,data->np_tot[IDIR], + KOKKOS_LAMBDA(int k,int i) { + Ex1(k,jref,i) = Ex1Avg(i)/((real) ncells); + }); + #endif } @@ -100,9 +92,9 @@ void Axis::RegularizeCurrentSide(int side) { sign = -1; } IdefixArray1D BAvg = this->Ex1Avg; - IdefixArray1D x2 = data->x[JDIR]; IdefixArray1D x1 = data->x[IDIR]; IdefixArray1D dx3 = data->dx[KDIR]; + IdefixArray1D dx2 = data->dx[JDIR]; idefix_for("B_ini",0,data->np_tot[IDIR], KOKKOS_LAMBDA(int i) { @@ -132,8 +124,7 @@ void Axis::RegularizeCurrentSide(int side) { idefix_for("fixJ",0,data->np_tot[KDIR],0,data->np_tot[IDIR], KOKKOS_LAMBDA(int k,int i) { - real th = x2(jc); - real fact = 2*sign/(deltaPhi*x1(i)*sin(th)); + real fact = 2*sign/(deltaPhi*x1(i)*dx2(jc)); J(IDIR, k,js,i) = BAvg(i)*fact; }); From bdcbd212bce65e36ed1d5449b47914d91da60a14 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Mon, 24 Nov 2025 18:10:50 +0100 Subject: [PATCH 3/6] Ensure Bphi evolution in 2.5D is computed exactly as the evolution using full CT in 3D. --- src/fluid/calcRightHandSide.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fluid/calcRightHandSide.hpp b/src/fluid/calcRightHandSide.hpp index 7777d1c2..0a0d3e19 100644 --- a/src/fluid/calcRightHandSide.hpp +++ b/src/fluid/calcRightHandSide.hpp @@ -363,7 +363,7 @@ struct Fluid_CalcRHSFunctor { #if (GEOMETRY == SPHERICAL) && (COMPONENTS == 3) rhs[iMPHI] /= FABS(sinx2(j)); if constexpr(Phys::mhd) { - rhs[iBPHI] = -dt / (rt(i)*dx(j)) * (Flux(iBPHI, k, j+1, i) - Flux(iBPHI, k, j, i)); + rhs[iBPHI] = -dt / (x1(i)*dx(j)) * (Flux(iBPHI, k, j+1, i) - Flux(iBPHI, k, j, i)); } // MHD #endif // GEOMETRY } From 72c7149943fdf83da6a85e301da5e45471d42c71 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Mon, 24 Nov 2025 18:22:40 +0100 Subject: [PATCH 4/6] fix linting errors --- src/fluid/boundary/axis.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fluid/boundary/axis.cpp b/src/fluid/boundary/axis.cpp index e2e524d5..afdeb865 100644 --- a/src/fluid/boundary/axis.cpp +++ b/src/fluid/boundary/axis.cpp @@ -52,7 +52,7 @@ void Axis::SymmetrizeEx1Side(int jref) { KOKKOS_LAMBDA(int k,int i) { Ex1(k,jref,i) = Ex1Avg(i)/((real) ncells); }); - + #endif } From f64484db7eec3626ec28c7515679aa8a34db1647 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Mon, 24 Nov 2025 20:14:30 +0100 Subject: [PATCH 5/6] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Robert --- test/IO/pydefix/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/IO/pydefix/README.md b/test/IO/pydefix/README.md index 7dbd8ed8..51ffa339 100644 --- a/test/IO/pydefix/README.md +++ b/test/IO/pydefix/README.md @@ -43,7 +43,7 @@ export pybind11_DIR=env/lib/python3.10/site-packages/pybind11 you can then run cmake which should be able to find pybind11, and compile the code. -If while running the code using a python interpreter in an envionement, you might run into errors stating that some module +If while running the code using a python interpreter in an environment, you run into errors stating that some module installed in your environement is not present. This is because pybind11 does not always capture your venv. You need to force the following environement variables (replace XX by your python version) ```bash From 9ba17f0e0a8b8904493cae53db10dcba56459a9a Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Mon, 24 Nov 2025 20:14:56 +0100 Subject: [PATCH 6/6] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Robert --- test/IO/pydefix/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/IO/pydefix/README.md b/test/IO/pydefix/README.md index 51ffa339..8dd3f5b4 100644 --- a/test/IO/pydefix/README.md +++ b/test/IO/pydefix/README.md @@ -47,5 +47,5 @@ If while running the code using a python interpreter in an environment, you run installed in your environement is not present. This is because pybind11 does not always capture your venv. You need to force the following environement variables (replace XX by your python version) ```bash -export PYTHONPATH=$VIRTUAL_ENV/lib/python3.XX/site-packages +export PYTHONPATH=$VIRTUAL_ENV/lib/python3.XX/site-packages:$PYTHONPATH ```