Skip to content

Commit

Permalink
v3.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
barnex committed Feb 5, 2015
1 parent 4e144a1 commit 3a65903
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions engine/demag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import (

// Demag variables
var (
Msat ScalarParam
Bsat derivedParam
M_full vSetter
B_demag vSetter
E_demag *GetScalar
Edens_demag sAdder
EnableDemag = true // enable/disable global demag field
NoDemagSpins ScalarParam // disable demag field per-cell
Msat ScalarParam
Bsat derivedParam
M_full vSetter
B_demag vSetter
E_demag *GetScalar
Edens_demag sAdder
EnableDemag = true // enable/disable global demag field
//NoDemagSpins ScalarParam // disable demag field per-cell
conv_ *cuda.DemagConvolution // does the heavy lifting and provides FFTM
DemagAccuracy = 6.0 // Demag accuracy (divide cubes in at most N^3 points)
CacheDir = "" // directory for kernel cache
)

func init() {
Msat.init("Msat", "A/m", "Saturation magnetization", []derived{&Bsat, &lex2, &din2, &dbulk2, &ku1_red, &ku2_red, &kc1_red, &kc2_red, &kc3_red, &temp_red})
NoDemagSpins.init("NoDemagSpins", "", "Disable magnetostatic interaction per-spin (set to 1 to disable)", nil)
//NoDemagSpins.init("NoDemagSpins", "", "Disable magnetostatic interaction per-spin (set to 1 to disable)", nil)
M_full.init("m_full", "A/m", "Unnormalized magnetization", SetMFull)
DeclVar("EnableDemag", &EnableDemag, "Enables/disables demag (default=true)")
DeclVar("DemagAccuracy", &DemagAccuracy, "Controls accuracy of demag kernel")
Expand All @@ -46,42 +46,42 @@ func init() {
// Sets dst to the current demag field
func SetDemagField(dst *data.Slice) {
if EnableDemag {
if NoDemagSpins.isZero() {
// Normal demag, everywhere
demagConv().Exec(dst, M.Buffer(), geometry.Gpu(), Bsat.gpuLUT1(), regions.Gpu())
} else {
setMaskedDemagField(dst)
}
//if NoDemagSpins.isZero() {
// Normal demag, everywhere
demagConv().Exec(dst, M.Buffer(), geometry.Gpu(), Bsat.gpuLUT1(), regions.Gpu())
//} else {
//setMaskedDemagField(dst)
//}
} else {
cuda.Zero(dst) // will ADD other terms to it
}
}

// Sets dst to the demag field, but cells where NoDemagSpins != 0 do not generate nor recieve field.
func setMaskedDemagField(dst *data.Slice) {
// No-demag spins: mask-out geometry with zeros where NoDemagSpins is set,
// so these spins do not generate a field

buf := cuda.Buffer(SCALAR, geometry.Gpu().Size()) // masked-out geometry
defer cuda.Recycle(buf)

// obtain a copy of the geometry mask, which we can overwrite
geom, r := geometry.Slice()
if r {
defer cuda.Recycle(geom)
}
data.Copy(buf, geom)

// mask-out
cuda.ZeroMask(buf, NoDemagSpins.gpuLUT1(), regions.Gpu())

// convolution with masked-out cells.
demagConv().Exec(dst, M.Buffer(), buf, Bsat.gpuLUT1(), regions.Gpu())

// After convolution, mask-out the field in the NoDemagSpins cells
// so they don't feel the field generated by others.
cuda.ZeroMask(dst, NoDemagSpins.gpuLUT1(), regions.Gpu())
}
//func setMaskedDemagField(dst *data.Slice) {
// // No-demag spins: mask-out geometry with zeros where NoDemagSpins is set,
// // so these spins do not generate a field
//
// buf := cuda.Buffer(SCALAR, geometry.Gpu().Size()) // masked-out geometry
// defer cuda.Recycle(buf)
//
// // obtain a copy of the geometry mask, which we can overwrite
// geom, r := geometry.Slice()
// if r {
// defer cuda.Recycle(geom)
// }
// data.Copy(buf, geom)
//
// // mask-out
// cuda.ZeroMask(buf, NoDemagSpins.gpuLUT1(), regions.Gpu())
//
// // convolution with masked-out cells.
// demagConv().Exec(dst, M.Buffer(), buf, Bsat.gpuLUT1(), regions.Gpu())
//
// // After convolution, mask-out the field in the NoDemagSpins cells
// // so they don't feel the field generated by others.
// cuda.ZeroMask(dst, NoDemagSpins.gpuLUT1(), regions.Gpu())
//}

// Sets dst to the full (unnormalized) magnetization in A/m
func SetMFull(dst *data.Slice) {
Expand Down

0 comments on commit 3a65903

Please sign in to comment.