From 8ce2f256a4a6e8d937bc371fbd54638e7ad59109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20S?= Date: Mon, 7 Nov 2022 14:47:04 +0100 Subject: [PATCH 1/8] copy the border cells when shifting M Adds a new shift mode, that copies the values at the border cells when shifting the magnetisation instead of using the values stored in ShiftMagL/R. Modified functions: engine.Shift new functions: cuda.ShiftFudgeX, cuda.ShiftFudgeY (and related .cu, .ptx files). --- engine/shift.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/engine/shift.go b/engine/shift.go index 20fea1433..3843d2873 100644 --- a/engine/shift.go +++ b/engine/shift.go @@ -9,10 +9,12 @@ var ( TotalShift, TotalYShift float64 // accumulated window shift (X and Y) in meter ShiftMagL, ShiftMagR, ShiftMagU, ShiftMagD data.Vector // when shifting m, put these value at the left/right edge. ShiftM, ShiftGeom, ShiftRegions bool = true, true, true // should shift act on magnetization, geometry, regions? + FudgeShift bool = false // Use the values of M at the border for the new cells ) func init() { DeclFunc("Shift", Shift, "Shifts the simulation by +1/-1 cells along X") + DeclVar("FudgeShift", &FudgeShift, "Whether to use the current magnetization at the border for the cells inserted by Shift") DeclVar("ShiftMagL", &ShiftMagL, "Upon shift, insert this magnetization from the left") DeclVar("ShiftMagR", &ShiftMagR, "Upon shift, insert this magnetization from the right") DeclVar("ShiftMagU", &ShiftMagU, "Upon shift, insert this magnetization from the top") @@ -47,7 +49,11 @@ func shiftMag(m *data.Slice, dx int) { defer cuda.Recycle(m2) for c := 0; c < m.NComp(); c++ { comp := m.Comp(c) - cuda.ShiftX(m2, comp, dx, float32(ShiftMagL[c]), float32(ShiftMagR[c])) + if FudgeShift { + cuda.ShiftFudgeX(m2, comp, dx); + } else { + cuda.ShiftX(m2, comp, dx, float32(ShiftMagL[c]), float32(ShiftMagR[c])) + } data.Copy(comp, m2) // str0 ? } } @@ -72,7 +78,11 @@ func shiftMagY(m *data.Slice, dy int) { defer cuda.Recycle(m2) for c := 0; c < m.NComp(); c++ { comp := m.Comp(c) - cuda.ShiftY(m2, comp, dy, float32(ShiftMagU[c]), float32(ShiftMagD[c])) + if FudgeShift { + cuda.ShiftFudgeY(m2, comp, dy); + } else { + cuda.ShiftY(m2, comp, dy, float32(ShiftMagU[c]), float32(ShiftMagD[c])) + } data.Copy(comp, m2) // str0 ? } } From dfbf3e2b9cb63be561be2f6b84b56227516e1f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20S?= Date: Mon, 7 Nov 2022 14:50:03 +0100 Subject: [PATCH 2/8] copy the border cells when shifting M Adds a new shift mode, that copies the values at the border cells when shifting the magnetisation instead of using the values stored in ShiftMagL/R. Modified functions: engine.Shift new functions: cuda.ShiftFudgeX, cuda.ShiftFudgeY (and related .cu, .ptx files). --- cuda/shiftfudgex.cu | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cuda/shiftfudgex.cu diff --git a/cuda/shiftfudgex.cu b/cuda/shiftfudgex.cu new file mode 100644 index 000000000..9101855d1 --- /dev/null +++ b/cuda/shiftfudgex.cu @@ -0,0 +1,25 @@ +#include "stencil.h" + + // shift dst by shx cells (positive or negative) along X-axis. + // new edge value is the current edge value. + extern "C" __global__ void + shiftfudgex(float* __restrict__ dst, float* __restrict__ src, + int Nx, int Ny, int Nz, int shx) { + + int ix = blockIdx.x * blockDim.x + threadIdx.x; + int iy = blockIdx.y * blockDim.y + threadIdx.y; + int iz = blockIdx.z * blockDim.z + threadIdx.z; + + if(ix < Nx && iy < Ny && iz < Nz) { + int ix2 = ix-shx; + float newval; + if (ix2 < 0) { + newval = src[idx(0, iy, iz)]; + } else if (ix2 >= Nx) { + newval = src[idx(Nx-1, iy, iz)]; + } else { + newval = src[idx(ix2, iy, iz)]; + } + dst[idx(ix, iy, iz)] = newval; + } + } From cf650b691cf30ed1a5c677bf02f634b22632a987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20S?= Date: Mon, 7 Nov 2022 14:51:07 +0100 Subject: [PATCH 3/8] copy the border cells when shifting M Adds a new shift mode, that copies the values at the border cells when shifting the magnetisation instead of using the values stored in ShiftMagL/R. Modified functions: engine.Shift new functions: cuda.ShiftFudgeX, cuda.ShiftFudgeY (and related .cu, .ptx files). --- cuda/shiftfudgey.cu | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cuda/shiftfudgey.cu diff --git a/cuda/shiftfudgey.cu b/cuda/shiftfudgey.cu new file mode 100644 index 000000000..ab43f1be7 --- /dev/null +++ b/cuda/shiftfudgey.cu @@ -0,0 +1,25 @@ +#include "stencil.h" + + // shift dst by shy cells (positive or negative) along Y-axis. + // new edge value is the current edge value. + extern "C" __global__ void + shiftfudgey(float* __restrict__ dst, float* __restrict__ src, + int Nx, int Ny, int Nz, int shy) { + + int ix = blockIdx.x * blockDim.x + threadIdx.x; + int iy = blockIdx.y * blockDim.y + threadIdx.y; + int iz = blockIdx.z * blockDim.z + threadIdx.z; + + if(ix < Nx && iy < Ny && iz < Nz) { + int iy2 = iy-shy; + float newval; + if (iy2 < 0) { + newval = src[idx(ix, 0, iz)]; + } else if (iy2 >= Ny) { + newval = src[idx(ix, Ny-1, iz)]; + } else { + newval = src[idx(ix, iy2, iz)]; + } + dst[idx(ix, iy, iz)] = newval; + } + } From c0df6a73a22106695b28f4fee0b8fc4f710e9fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20S?= Date: Mon, 7 Nov 2022 14:57:48 +0100 Subject: [PATCH 4/8] copy the border cells when shifting M Adds a new shift mode, that copies the values at the border cells when shifting the magnetisation instead of using the values stored in ShiftMagL/R. Modified functions: engine.Shift new functions: cuda.ShiftFudgeX, cuda.ShiftFudgeY (and related .cu, .ptx files). --- cuda/shift.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cuda/shift.go b/cuda/shift.go index a9ad7e886..fa7aefe7d 100644 --- a/cuda/shift.go +++ b/cuda/shift.go @@ -15,6 +15,16 @@ func ShiftX(dst, src *data.Slice, shiftX int, clampL, clampR float32) { k_shiftx_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftX, clampL, clampR, cfg) } +// shift dst by shx cells (positive or negative) along X-axis. + // new edge value is the current value at the border. + func ShiftFudgeX(dst, src *data.Slice, shiftX int) { + util.Argument(dst.NComp() == 1 && src.NComp() == 1) + util.Assert(dst.Len() == src.Len()) + N := dst.Size() + cfg := make3DConf(N) + k_shiftfudgex_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftX, cfg) + } + func ShiftY(dst, src *data.Slice, shiftY int, clampL, clampR float32) { util.Argument(dst.NComp() == 1 && src.NComp() == 1) util.Assert(dst.Len() == src.Len()) @@ -23,6 +33,14 @@ func ShiftY(dst, src *data.Slice, shiftY int, clampL, clampR float32) { k_shifty_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftY, clampL, clampR, cfg) } +func ShiftFudgeY(dst, src *data.Slice, shiftY int) { + util.Argument(dst.NComp() == 1 && src.NComp() == 1) + util.Assert(dst.Len() == src.Len()) + N := dst.Size() + cfg := make3DConf(N) + k_shiftfudgey_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftY, cfg) + } + func ShiftZ(dst, src *data.Slice, shiftZ int, clampL, clampR float32) { util.Argument(dst.NComp() == 1 && src.NComp() == 1) util.Assert(dst.Len() == src.Len()) From 1f208db743dbf37486076f5f0473058f9539dba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20S?= Date: Mon, 7 Nov 2022 15:37:34 +0100 Subject: [PATCH 5/8] test fudgeShift Tests fudgeShift, a new shift mode that copies the values at the border cells when shifting the magnetisation instead of using the values stored in ShiftMagL/R. --- test/fudgeShift.mx3 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/fudgeShift.mx3 diff --git a/test/fudgeShift.mx3 b/test/fudgeShift.mx3 new file mode 100644 index 000000000..40d699638 --- /dev/null +++ b/test/fudgeShift.mx3 @@ -0,0 +1,16 @@ +SetGridSize(128, 64, 1); +SetCellSize(4e-9, 4e-9, 4e-9); +Msat = 1e6; +Aex = 10e-12; +alpha = 1; +m = RandomMag(); +steps(300); + +fudgeShift = true; +shift(32); +ExpectV("fudgeShift = true; The added cells during shift are the same as the old border?", m.getCell(0, 20, 0), m.getCell(32, 20, 0), 1e-6); + +fudgeShift = false; +ShiftMagL = vector(0, 0, 1); +shift(32); +ExpectV("fudgeShift = false; The added cells during shift are ShiftMagL?", m.getCell(0, 20, 0), ShiftMagL, 1e-6); From c59036e7a44265c33cc6b64e25d7e23b09ec4ab9 Mon Sep 17 00:00:00 2001 From: Jonathan Maes Date: Fri, 11 Oct 2024 10:06:48 +0200 Subject: [PATCH 6/8] Fix indentation of shiftfudge blocks --- cuda/shift.go | 28 ++++++++++++++-------------- cuda/shiftfudgex.cu | 42 +++++++++++++++++++++--------------------- cuda/shiftfudgey.cu | 42 +++++++++++++++++++++--------------------- engine/shift.go | 18 +++++++++--------- 4 files changed, 65 insertions(+), 65 deletions(-) diff --git a/cuda/shift.go b/cuda/shift.go index fa7aefe7d..66941d651 100644 --- a/cuda/shift.go +++ b/cuda/shift.go @@ -16,14 +16,14 @@ func ShiftX(dst, src *data.Slice, shiftX int, clampL, clampR float32) { } // shift dst by shx cells (positive or negative) along X-axis. - // new edge value is the current value at the border. - func ShiftFudgeX(dst, src *data.Slice, shiftX int) { - util.Argument(dst.NComp() == 1 && src.NComp() == 1) - util.Assert(dst.Len() == src.Len()) - N := dst.Size() - cfg := make3DConf(N) - k_shiftfudgex_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftX, cfg) - } +// new edge value is the current value at the border. +func ShiftFudgeX(dst, src *data.Slice, shiftX int) { + util.Argument(dst.NComp() == 1 && src.NComp() == 1) + util.Assert(dst.Len() == src.Len()) + N := dst.Size() + cfg := make3DConf(N) + k_shiftfudgex_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftX, cfg) +} func ShiftY(dst, src *data.Slice, shiftY int, clampL, clampR float32) { util.Argument(dst.NComp() == 1 && src.NComp() == 1) @@ -34,12 +34,12 @@ func ShiftY(dst, src *data.Slice, shiftY int, clampL, clampR float32) { } func ShiftFudgeY(dst, src *data.Slice, shiftY int) { - util.Argument(dst.NComp() == 1 && src.NComp() == 1) - util.Assert(dst.Len() == src.Len()) - N := dst.Size() - cfg := make3DConf(N) - k_shiftfudgey_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftY, cfg) - } + util.Argument(dst.NComp() == 1 && src.NComp() == 1) + util.Assert(dst.Len() == src.Len()) + N := dst.Size() + cfg := make3DConf(N) + k_shiftfudgey_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftY, cfg) +} func ShiftZ(dst, src *data.Slice, shiftZ int, clampL, clampR float32) { util.Argument(dst.NComp() == 1 && src.NComp() == 1) diff --git a/cuda/shiftfudgex.cu b/cuda/shiftfudgex.cu index 9101855d1..ff6a7ff02 100644 --- a/cuda/shiftfudgex.cu +++ b/cuda/shiftfudgex.cu @@ -1,25 +1,25 @@ #include "stencil.h" - // shift dst by shx cells (positive or negative) along X-axis. - // new edge value is the current edge value. - extern "C" __global__ void - shiftfudgex(float* __restrict__ dst, float* __restrict__ src, - int Nx, int Ny, int Nz, int shx) { +// shift dst by shx cells (positive or negative) along X-axis. +// new edge value is the current edge value. +extern "C" __global__ void +shiftfudgex(float* __restrict__ dst, float* __restrict__ src, + int Nx, int Ny, int Nz, int shx) { - int ix = blockIdx.x * blockDim.x + threadIdx.x; - int iy = blockIdx.y * blockDim.y + threadIdx.y; - int iz = blockIdx.z * blockDim.z + threadIdx.z; + int ix = blockIdx.x * blockDim.x + threadIdx.x; + int iy = blockIdx.y * blockDim.y + threadIdx.y; + int iz = blockIdx.z * blockDim.z + threadIdx.z; - if(ix < Nx && iy < Ny && iz < Nz) { - int ix2 = ix-shx; - float newval; - if (ix2 < 0) { - newval = src[idx(0, iy, iz)]; - } else if (ix2 >= Nx) { - newval = src[idx(Nx-1, iy, iz)]; - } else { - newval = src[idx(ix2, iy, iz)]; - } - dst[idx(ix, iy, iz)] = newval; - } - } + if(ix < Nx && iy < Ny && iz < Nz) { + int ix2 = ix-shx; + float newval; + if (ix2 < 0) { + newval = src[idx(0, iy, iz)]; + } else if (ix2 >= Nx) { + newval = src[idx(Nx-1, iy, iz)]; + } else { + newval = src[idx(ix2, iy, iz)]; + } + dst[idx(ix, iy, iz)] = newval; + } +} diff --git a/cuda/shiftfudgey.cu b/cuda/shiftfudgey.cu index ab43f1be7..efb38552b 100644 --- a/cuda/shiftfudgey.cu +++ b/cuda/shiftfudgey.cu @@ -1,25 +1,25 @@ #include "stencil.h" - // shift dst by shy cells (positive or negative) along Y-axis. - // new edge value is the current edge value. - extern "C" __global__ void - shiftfudgey(float* __restrict__ dst, float* __restrict__ src, - int Nx, int Ny, int Nz, int shy) { +// shift dst by shy cells (positive or negative) along Y-axis. +// new edge value is the current edge value. +extern "C" __global__ void +shiftfudgey(float* __restrict__ dst, float* __restrict__ src, + int Nx, int Ny, int Nz, int shy) { - int ix = blockIdx.x * blockDim.x + threadIdx.x; - int iy = blockIdx.y * blockDim.y + threadIdx.y; - int iz = blockIdx.z * blockDim.z + threadIdx.z; + int ix = blockIdx.x * blockDim.x + threadIdx.x; + int iy = blockIdx.y * blockDim.y + threadIdx.y; + int iz = blockIdx.z * blockDim.z + threadIdx.z; - if(ix < Nx && iy < Ny && iz < Nz) { - int iy2 = iy-shy; - float newval; - if (iy2 < 0) { - newval = src[idx(ix, 0, iz)]; - } else if (iy2 >= Ny) { - newval = src[idx(ix, Ny-1, iz)]; - } else { - newval = src[idx(ix, iy2, iz)]; - } - dst[idx(ix, iy, iz)] = newval; - } - } + if(ix < Nx && iy < Ny && iz < Nz) { + int iy2 = iy-shy; + float newval; + if (iy2 < 0) { + newval = src[idx(ix, 0, iz)]; + } else if (iy2 >= Ny) { + newval = src[idx(ix, Ny-1, iz)]; + } else { + newval = src[idx(ix, iy2, iz)]; + } + dst[idx(ix, iy, iz)] = newval; + } +} diff --git a/engine/shift.go b/engine/shift.go index 3843d2873..7f0fd3832 100644 --- a/engine/shift.go +++ b/engine/shift.go @@ -9,7 +9,7 @@ var ( TotalShift, TotalYShift float64 // accumulated window shift (X and Y) in meter ShiftMagL, ShiftMagR, ShiftMagU, ShiftMagD data.Vector // when shifting m, put these value at the left/right edge. ShiftM, ShiftGeom, ShiftRegions bool = true, true, true // should shift act on magnetization, geometry, regions? - FudgeShift bool = false // Use the values of M at the border for the new cells + FudgeShift bool = false // Use the values of M at the border for the new cells ) func init() { @@ -50,10 +50,10 @@ func shiftMag(m *data.Slice, dx int) { for c := 0; c < m.NComp(); c++ { comp := m.Comp(c) if FudgeShift { - cuda.ShiftFudgeX(m2, comp, dx); - } else { - cuda.ShiftX(m2, comp, dx, float32(ShiftMagL[c]), float32(ShiftMagR[c])) - } + cuda.ShiftFudgeX(m2, comp, dx) + } else { + cuda.ShiftX(m2, comp, dx, float32(ShiftMagL[c]), float32(ShiftMagR[c])) + } data.Copy(comp, m2) // str0 ? } } @@ -79,10 +79,10 @@ func shiftMagY(m *data.Slice, dy int) { for c := 0; c < m.NComp(); c++ { comp := m.Comp(c) if FudgeShift { - cuda.ShiftFudgeY(m2, comp, dy); - } else { - cuda.ShiftY(m2, comp, dy, float32(ShiftMagU[c]), float32(ShiftMagD[c])) - } + cuda.ShiftFudgeY(m2, comp, dy) + } else { + cuda.ShiftY(m2, comp, dy, float32(ShiftMagU[c]), float32(ShiftMagD[c])) + } data.Copy(comp, m2) // str0 ? } } From d83f8fe3656fac5302176221a09498765374f9c2 Mon Sep 17 00:00:00 2001 From: Jonathan Maes Date: Fri, 11 Oct 2024 11:00:39 +0200 Subject: [PATCH 7/8] Rename FudgeShift to EdgeCarryShift --- cuda/shift.go | 8 ++++---- cuda/{shiftfudgex.cu => shiftedgecarryx.cu} | 2 +- cuda/{shiftfudgey.cu => shiftedgecarryy.cu} | 2 +- engine/shift.go | 12 ++++++------ test/edgeCarryShift.mx3 | 16 ++++++++++++++++ test/fudgeShift.mx3 | 16 ---------------- 6 files changed, 28 insertions(+), 28 deletions(-) rename cuda/{shiftfudgex.cu => shiftedgecarryx.cu} (91%) rename cuda/{shiftfudgey.cu => shiftedgecarryy.cu} (91%) create mode 100644 test/edgeCarryShift.mx3 delete mode 100644 test/fudgeShift.mx3 diff --git a/cuda/shift.go b/cuda/shift.go index 66941d651..6f2b8186f 100644 --- a/cuda/shift.go +++ b/cuda/shift.go @@ -17,12 +17,12 @@ func ShiftX(dst, src *data.Slice, shiftX int, clampL, clampR float32) { // shift dst by shx cells (positive or negative) along X-axis. // new edge value is the current value at the border. -func ShiftFudgeX(dst, src *data.Slice, shiftX int) { +func ShiftEdgeCarryX(dst, src *data.Slice, shiftX int) { util.Argument(dst.NComp() == 1 && src.NComp() == 1) util.Assert(dst.Len() == src.Len()) N := dst.Size() cfg := make3DConf(N) - k_shiftfudgex_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftX, cfg) + k_shiftedgecarryX_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftX, cfg) } func ShiftY(dst, src *data.Slice, shiftY int, clampL, clampR float32) { @@ -33,12 +33,12 @@ func ShiftY(dst, src *data.Slice, shiftY int, clampL, clampR float32) { k_shifty_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftY, clampL, clampR, cfg) } -func ShiftFudgeY(dst, src *data.Slice, shiftY int) { +func ShiftEdgeCarryY(dst, src *data.Slice, shiftY int) { util.Argument(dst.NComp() == 1 && src.NComp() == 1) util.Assert(dst.Len() == src.Len()) N := dst.Size() cfg := make3DConf(N) - k_shiftfudgey_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftY, cfg) + k_shiftedgecarryY_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftY, cfg) } func ShiftZ(dst, src *data.Slice, shiftZ int, clampL, clampR float32) { diff --git a/cuda/shiftfudgex.cu b/cuda/shiftedgecarryx.cu similarity index 91% rename from cuda/shiftfudgex.cu rename to cuda/shiftedgecarryx.cu index ff6a7ff02..2e952c796 100644 --- a/cuda/shiftfudgex.cu +++ b/cuda/shiftedgecarryx.cu @@ -3,7 +3,7 @@ // shift dst by shx cells (positive or negative) along X-axis. // new edge value is the current edge value. extern "C" __global__ void -shiftfudgex(float* __restrict__ dst, float* __restrict__ src, +shiftedgecarryX(float* __restrict__ dst, float* __restrict__ src, int Nx, int Ny, int Nz, int shx) { int ix = blockIdx.x * blockDim.x + threadIdx.x; diff --git a/cuda/shiftfudgey.cu b/cuda/shiftedgecarryy.cu similarity index 91% rename from cuda/shiftfudgey.cu rename to cuda/shiftedgecarryy.cu index efb38552b..1d52df68b 100644 --- a/cuda/shiftfudgey.cu +++ b/cuda/shiftedgecarryy.cu @@ -3,7 +3,7 @@ // shift dst by shy cells (positive or negative) along Y-axis. // new edge value is the current edge value. extern "C" __global__ void -shiftfudgey(float* __restrict__ dst, float* __restrict__ src, +shiftedgecarryY(float* __restrict__ dst, float* __restrict__ src, int Nx, int Ny, int Nz, int shy) { int ix = blockIdx.x * blockDim.x + threadIdx.x; diff --git a/engine/shift.go b/engine/shift.go index 7f0fd3832..b6338071b 100644 --- a/engine/shift.go +++ b/engine/shift.go @@ -9,12 +9,12 @@ var ( TotalShift, TotalYShift float64 // accumulated window shift (X and Y) in meter ShiftMagL, ShiftMagR, ShiftMagU, ShiftMagD data.Vector // when shifting m, put these value at the left/right edge. ShiftM, ShiftGeom, ShiftRegions bool = true, true, true // should shift act on magnetization, geometry, regions? - FudgeShift bool = false // Use the values of M at the border for the new cells + EdgeCarryShift bool = false // Use the values of M at the border for the new cells ) func init() { DeclFunc("Shift", Shift, "Shifts the simulation by +1/-1 cells along X") - DeclVar("FudgeShift", &FudgeShift, "Whether to use the current magnetization at the border for the cells inserted by Shift") + DeclVar("EdgeCarryShift", &EdgeCarryShift, "Whether to use the current magnetization at the border for the cells inserted by Shift") DeclVar("ShiftMagL", &ShiftMagL, "Upon shift, insert this magnetization from the left") DeclVar("ShiftMagR", &ShiftMagR, "Upon shift, insert this magnetization from the right") DeclVar("ShiftMagU", &ShiftMagU, "Upon shift, insert this magnetization from the top") @@ -49,8 +49,8 @@ func shiftMag(m *data.Slice, dx int) { defer cuda.Recycle(m2) for c := 0; c < m.NComp(); c++ { comp := m.Comp(c) - if FudgeShift { - cuda.ShiftFudgeX(m2, comp, dx) + if EdgeCarryShift { + cuda.ShiftEdgeCarryX(m2, comp, dx) } else { cuda.ShiftX(m2, comp, dx, float32(ShiftMagL[c]), float32(ShiftMagR[c])) } @@ -78,8 +78,8 @@ func shiftMagY(m *data.Slice, dy int) { defer cuda.Recycle(m2) for c := 0; c < m.NComp(); c++ { comp := m.Comp(c) - if FudgeShift { - cuda.ShiftFudgeY(m2, comp, dy) + if EdgeCarryShift { + cuda.ShiftEdgeCarryY(m2, comp, dy) } else { cuda.ShiftY(m2, comp, dy, float32(ShiftMagU[c]), float32(ShiftMagD[c])) } diff --git a/test/edgeCarryShift.mx3 b/test/edgeCarryShift.mx3 new file mode 100644 index 000000000..f8349a09b --- /dev/null +++ b/test/edgeCarryShift.mx3 @@ -0,0 +1,16 @@ +SetGridSize(128, 64, 1); +SetCellSize(4e-9, 4e-9, 4e-9); +Msat = 1e6; +Aex = 10e-12; +alpha = 1; +m = RandomMag(); +steps(300); + +edgeCarryShift = true; +shift(32); +ExpectV("edgeCarryShift = true; The added cells during shift are the same as the old border?", m.getCell(0, 20, 0), m.getCell(32, 20, 0), 1e-6); + +edgeCarryShift = false; +ShiftMagL = vector(0, 0, 1); +shift(32); +ExpectV("edgeCarryShift = false; The added cells during shift are ShiftMagL?", m.getCell(0, 20, 0), ShiftMagL, 1e-6); diff --git a/test/fudgeShift.mx3 b/test/fudgeShift.mx3 deleted file mode 100644 index 40d699638..000000000 --- a/test/fudgeShift.mx3 +++ /dev/null @@ -1,16 +0,0 @@ -SetGridSize(128, 64, 1); -SetCellSize(4e-9, 4e-9, 4e-9); -Msat = 1e6; -Aex = 10e-12; -alpha = 1; -m = RandomMag(); -steps(300); - -fudgeShift = true; -shift(32); -ExpectV("fudgeShift = true; The added cells during shift are the same as the old border?", m.getCell(0, 20, 0), m.getCell(32, 20, 0), 1e-6); - -fudgeShift = false; -ShiftMagL = vector(0, 0, 1); -shift(32); -ExpectV("fudgeShift = false; The added cells during shift are ShiftMagL?", m.getCell(0, 20, 0), ShiftMagL, 1e-6); From e968b090b2dd122475a261a171d0e0e65c992350 Mon Sep 17 00:00:00 2001 From: Jonathan Maes Date: Fri, 11 Oct 2024 11:17:05 +0200 Subject: [PATCH 8/8] remove ; from edgeCarryshift.mx3 --- test/edgeCarryShift.mx3 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/edgeCarryShift.mx3 b/test/edgeCarryShift.mx3 index f8349a09b..a2145fd18 100644 --- a/test/edgeCarryShift.mx3 +++ b/test/edgeCarryShift.mx3 @@ -1,16 +1,16 @@ -SetGridSize(128, 64, 1); -SetCellSize(4e-9, 4e-9, 4e-9); -Msat = 1e6; -Aex = 10e-12; -alpha = 1; -m = RandomMag(); -steps(300); +SetGridSize(128, 64, 1) +SetCellSize(4e-9, 4e-9, 4e-9) +Msat = 1e6 +Aex = 10e-12 +alpha = 1 +m = RandomMag() +steps(300) -edgeCarryShift = true; -shift(32); -ExpectV("edgeCarryShift = true; The added cells during shift are the same as the old border?", m.getCell(0, 20, 0), m.getCell(32, 20, 0), 1e-6); +edgeCarryShift = true +shift(32) +ExpectV("edgeCarryShift = true; The added cells during shift are the same as the old border?", m.getCell(0, 20, 0), m.getCell(32, 20, 0), 1e-6) -edgeCarryShift = false; -ShiftMagL = vector(0, 0, 1); -shift(32); -ExpectV("edgeCarryShift = false; The added cells during shift are ShiftMagL?", m.getCell(0, 20, 0), ShiftMagL, 1e-6); +edgeCarryShift = false +ShiftMagL = vector(0, 0, 1) +shift(32) +ExpectV("edgeCarryShift = false; The added cells during shift are ShiftMagL?", m.getCell(0, 20, 0), ShiftMagL, 1e-6)