Skip to content

Commit

Permalink
cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
barnex committed Sep 28, 2016
1 parent 4f0a87b commit 45fc9c5
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 67 deletions.
1 change: 1 addition & 0 deletions engine/anisotropy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func AddAnisotropyField(dst *data.Slice) {
addCubicAnisotropyFrom(dst, M, Msat, Kc1, Kc2, Kc3, AnisC1, AnisC2)
}

// Add the anisotropy energy density to dst
func AddAnisotropyEnergyDensity(dst *data.Slice) {
haveUnixial := Ku1.nonZero() || Ku2.nonZero()
haveCubic := Kc1.nonZero() || Kc2.nonZero() || Kc3.nonZero()
Expand Down
12 changes: 1 addition & 11 deletions engine/backwardeuler.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package engine

import (
//"fmt"
"github.com/mumax/3/cuda"
"github.com/mumax/3/data"
"github.com/mumax/3/util"
)

// Implicit midpoint solver.
type BackwardEuler struct {
dy1 *data.Slice
}
Expand Down Expand Up @@ -56,19 +56,9 @@ func (s *BackwardEuler) Step() {

err := cuda.MaxVecDiff(dy0, dy1) * float64(dt)

// adjust next time step
//if err < MaxErr || Dt_si <= MinDt || FixDt != 0 { // mindt check to avoid infinite loop
// step OK
NSteps++
setLastErr(err)
setMaxTorque(dy1)
//} else {
// undo bad step
// util.Assert(FixDt == 0)
// Time = t0
// data.Copy(y, y0)
// NUndone++
//}
}

func (s *BackwardEuler) Free() {
Expand Down
15 changes: 7 additions & 8 deletions engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ func init() {
// Magnetic configuration returns m vector for position (x,y,z)
type Config func(x, y, z float64) data.Vector

// Random initial magnetization.
func RandomMag() Config {
return RandomMagSeed(0)
}

// Random initial magnetization,
// generated from random seed.
func RandomMagSeed(seed int) Config {
rng := rand.New(rand.NewSource(int64(seed)))
return func(x, y, z float64) data.Vector {
Expand Down Expand Up @@ -181,16 +184,12 @@ func (c Config) RotZ(θ float64) Config {
}
}

// Returns a new magnetization equal to c + weight * other.
// E.g.:
// Uniform(1, 0, 0).Add(0.2, RandomMag())
// for a uniform state with 20% random distortion.
func (c Config) Add(weight float64, other Config) Config {
return func(x, y, z float64) data.Vector {
return c(x, y, z).MAdd(weight, other(x, y, z))
}
}

// Infinitely repeats the shape with given period in x, y, z.
// A period of 0 or infinity means no repetition.
//func (c Config) Repeat(periodX, periodY, periodZ float64) Config {
// return func(x, y, z float64) data.Vector {
// return c(fmod(x, periodX), fmod(y, periodY), fmod(z, periodZ))
// }
//}
2 changes: 2 additions & 0 deletions engine/crop.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type cropped struct {
x1, x2, y1, y2, z1, z2 int
}

// Crop quantity to a box enclosing the given region.
// Used to output a region of interest, even if the region is non-rectangular.
func CropRegion(parent Q, region int) *cropped {
n := MeshOf(parent).Size()
// use -1 for unset values
Expand Down
11 changes: 5 additions & 6 deletions engine/customfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ func AddCustomEnergyDensity(dst *data.Slice) {
}

func GetCustomEnergy() float64 {
//buf := cuda.Buffer(1, Edens_custom.Mesh().Size())
//defer cuda.Recycle(buf)
//cuda.Zero(buf)
//AddCustomEnergyDensity(buf)
//return cellVolume() * float64(cuda.Sum(buf))
return 999
buf := cuda.Buffer(1, Mesh().Size())
defer cuda.Recycle(buf)
cuda.Zero(buf)
AddCustomEnergyDensity(buf)
return cellVolume() * float64(cuda.Sum(buf))
}

type constValue struct {
Expand Down
1 change: 0 additions & 1 deletion engine/excitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

// An excitation, typically field or current,
// can be defined region-wise plus extra mask*multiplier terms.
// TODO: unify with param.
type Excitation struct {
name string
perRegion RegionwiseVector // Region-based excitation
Expand Down
12 changes: 0 additions & 12 deletions engine/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@ func log2GUI(msg string) {
// TODO: push to web ?
}

// returns log file of input commands, opening it first if needed
//func openlog() *httpfs.File {
// if logfile == nil {
// var err error
// logfile, err = fs.Create(OD + "/input.log")
// if err != nil {
// log.Println(err)
// }
// }
// return logfile
//}

// like fmt.Sprint but with spaces between args
func sprint(msg ...interface{}) string {
str := fmt.Sprintln(msg...)
Expand Down
2 changes: 1 addition & 1 deletion engine/maxangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var (
MaxAngle = NewScalarValue("MaxAngle", "rad", "maximum angle between neighboring spins", GetMaxAngle) // TODO: Max(...)
MaxAngle = NewScalarValue("MaxAngle", "rad", "maximum angle between neighboring spins", GetMaxAngle)
SpinAngle = NewScalarField("spinAngle", "rad", "Angle between neighboring spins", SetSpinAngle)
)

Expand Down
12 changes: 1 addition & 11 deletions engine/q.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"reflect"
)

// Arbitrary physical quantity.
type Q interface {
NComp() int
EvalTo(dst *data.Slice)
Expand Down Expand Up @@ -86,14 +87,3 @@ func EvalTo(q interface {
}
data.Copy(dst, v)
}

//func EvalTo(q Q, dst *data.Slice) {
// util.AssertMsg(q.NComp() == dst.NComp() && SizeOf(q) == dst.Size(), "size mismatch")
// q.EvalTo(dst)
//}

func EvalScript(q Q) (*data.Slice, bool) {
buf := cuda.Buffer(q.NComp(), SizeOf(q))
q.EvalTo(buf)
return buf, true
}
2 changes: 0 additions & 2 deletions engine/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"sync"
)

//var renderer = render{img: new(image.RGBA)}

type render struct {
mutex sync.Mutex
quant Q
Expand Down
2 changes: 0 additions & 2 deletions engine/rk4.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

// Classical 4th order RK solver.

type RK4 struct {
}

Expand Down Expand Up @@ -69,7 +68,6 @@ func (rk *RK4) Step() {
setMaxTorque(k4)
} else {
// undo bad step
//util.Println("Bad step at t=", t0, ", err=", err)
util.Assert(FixDt == 0)
Time = t0
data.Copy(m, m0)
Expand Down
2 changes: 1 addition & 1 deletion engine/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
DeclVar("FixDt", &FixDt, "Set a fixed time step, 0 disables fixed step")
DeclFunc("Exit", Exit, "Exit from the program")
SetSolver(DORMANDPRINCE)
_ = NewScalarValue("dt", "s", "Time Step", func() float64 { return Dt_si }) // TODO: fromPtr
_ = NewScalarValue("dt", "s", "Time Step", func() float64 { return Dt_si })
_ = NewScalarValue("LastErr", "", "Error of last step", func() float64 { return LastErr })
_ = NewScalarValue("PeakErr", "", "Overall maxium error per step", func() float64 { return PeakErr })
_ = NewScalarValue("NEval", "", "Total number of torque evaluations", func() float64 { return float64(NEvals) })
Expand Down
2 changes: 0 additions & 2 deletions engine/shift.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func GetShiftPos() float64 { return -TotalShift }

// shift the simulation window over dx cells in X direction
func Shift(dx int) {
//util.Argument(dx == 1 || dx == -1) // one cell at a time please

TotalShift += float64(dx) * Mesh().CellSize()[X] // needed to re-init geom, regions
if ShiftM {
shiftMag(M.Buffer(), dx) // TODO: M.shift?
Expand Down
8 changes: 0 additions & 8 deletions engine/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,6 @@ func (t *DataTable) flush() {
t.Flush()
}

// can be saved in table
//type TableData interface {
// average() []float64
// Name() string
// Unit() string
// NComp() int
//}

// Safe fmt.Fprint, will fail on error
func fprint(out io.Writer, x ...interface{}) {
_, err := fmt.Fprint(out, x...)
Expand Down
2 changes: 0 additions & 2 deletions engine/torque.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func init() {
}

// Sets dst to the current total torque
// TODO: extensible
func SetTorque(dst *data.Slice) {
SetLLTorque(dst)
AddSTTorque(dst)
Expand Down Expand Up @@ -108,7 +107,6 @@ func FreezeSpins(dst *data.Slice) {
}
}

// Gets
func GetMaxTorque() float64 {
torque := ValueOf(Torque)
defer cuda.Recycle(torque)
Expand Down

0 comments on commit 45fc9c5

Please sign in to comment.