diff --git a/engine/geom.go b/engine/geom.go index 597f029a0..fa10522db 100644 --- a/engine/geom.go +++ b/engine/geom.go @@ -1,12 +1,13 @@ package engine import ( + "math/rand" + "github.com/mumax/3/cuda" "github.com/mumax/3/data" - "github.com/mumax/3/util" - "github.com/mumax/3/oommf" "github.com/mumax/3/httpfs" - "math/rand" + "github.com/mumax/3/oommf" + "github.com/mumax/3/util" ) func init() { @@ -126,17 +127,17 @@ func InitGeomFromOVF(fname string) { step := meta.CellSize //check the geometry file for sanity - if geomSlice.NComp() != 1{ + if geomSlice.NComp() != 1 { util.Fatal("Geometry initialization file should have point dimension of 1!") } - if !isNonEmpty( geomSlice ) { + if !isNonEmpty(geomSlice) { util.Fatal("InitGeomFromOVF: provided geometry is completely empty!") } //set mesh from imported file, should refresh it by itself - SetMesh( arrDim[X], arrDim[Y], arrDim[Z], - step[X], step[Y], step[Z], - 0, 0, 0 ) + SetMesh(arrDim[X], arrDim[Y], arrDim[Z], + step[X], step[Y], step[Z], + 0, 0, 0) SetBusy(true) defer SetBusy(false) @@ -149,17 +150,17 @@ func InitGeomFromOVF(fname string) { data.Copy(geometry.buffer, geomSlice) //make a makeshift function to represent imported geometry - isInterpd := false - pred := VoxelShape(geomSlice, step[0], step[1], step[2]) + isInterpd := false + pred := VoxelShape(geomSlice, step[0], step[1], step[2]) geometry.shape = func(x, y, z float64) bool { - if !isInterpd { - util.Log("Warning! Geometry imported through InitGeomFromOVF is about to be reinterpolated! Possible changes in geometry!") - isInterpd = true - } - return pred(x, y, z) + if !isInterpd { + util.Log("Warning! Geometry imported through InitGeomFromOVF is about to be reinterpolated! Possible changes in geometry!") + isInterpd = true + } + return pred(x, y, z) } - cleanMagnetization(geomSlice) + cleanMagnetization(geomSlice) } func (geometry *geom) setGeom(s Shape) { @@ -240,7 +241,7 @@ func (geometry *geom) setGeom(s Shape) { data.Copy(geometry.buffer, V) - cleanMagnetization(host) + cleanMagnetization(host) } // Sample edgeSmooth^3 points inside the cell to estimate its volume. diff --git a/engine/mesh.go b/engine/mesh.go index 40ca09487..a644885ee 100644 --- a/engine/mesh.go +++ b/engine/mesh.go @@ -38,7 +38,7 @@ func SetMesh(Nx, Ny, Nz int, cellSizeX, cellSizeY, cellSizeZ float64, pbcx, pbcy arg("PBC", pbcx >= 0 && pbcy >= 0 && pbcz >= 0) sizeChanged := globalmesh_.Size() != [3]int{Nx, Ny, Nz} - cellSizeChanged := globalmesh_.CellSize() != [3]float64{cellSizeX, cellSizeY, cellSizeZ} + cellSizeChanged := globalmesh_.CellSize() != [3]float64{cellSizeX, cellSizeY, cellSizeZ} pbc := []int{pbcx, pbcy, pbcz} if globalmesh_.Size() == [3]int{0, 0, 0} { @@ -59,21 +59,21 @@ func SetMesh(Nx, Ny, Nz int, cellSizeX, cellSizeY, cellSizeZ float64, pbcx, pbcy // resize everything globalmesh_ = *data.NewMesh(Nx, Ny, Nz, cellSizeX, cellSizeY, cellSizeZ, pbc...) - if sizeChanged || cellSizeChanged { - M.resize() - regions.resize() - geometry.buffer.Free() - geometry.buffer = data.NilSlice(1, Mesh().Size()) - geometry.setGeom(geometry.shape) - - // remove excitation extra terms if they don't fit anymore - // up to the user to add them again - B_ext.RemoveExtraTerms() - J.RemoveExtraTerms() - - B_therm.noise.Free() - B_therm.noise = nil - } + if sizeChanged || cellSizeChanged { + M.resize() + regions.resize() + geometry.buffer.Free() + geometry.buffer = data.NilSlice(1, Mesh().Size()) + geometry.setGeom(geometry.shape) + + // remove excitation extra terms if they don't fit anymore + // up to the user to add them again + B_ext.RemoveExtraTerms() + J.RemoveExtraTerms() + + B_therm.noise.Free() + B_therm.noise = nil + } } lazy_gridsize = []int{Nx, Ny, Nz} lazy_cellsize = []float64{cellSizeX, cellSizeY, cellSizeZ} diff --git a/engine/shape.go b/engine/shape.go index 94f81a815..1f390d56b 100644 --- a/engine/shape.go +++ b/engine/shape.go @@ -6,7 +6,7 @@ import ( _ "image/png" "math" - "github.com/mumax/3/data" + "github.com/mumax/3/data" "github.com/mumax/3/httpfs" "github.com/mumax/3/util" ) @@ -200,20 +200,18 @@ func VoxelShape(voxels *data.Slice, a, b, c float64) Shape { //cut FP array into bool array arrSize := voxels.Size() - voxelArr:= make([]bool, arrSize[0]*arrSize[1]*arrSize[2]) + voxelArr := make([]bool, arrSize[0]*arrSize[1]*arrSize[2]) for ix := 0; ix < arrSize[0]; ix++ { for iy := 0; iy < arrSize[1]; iy++ { for iz := 0; iz < arrSize[2]; iz++ { - voxelArr[ - iz * arrSize[0] * arrSize[1] + - iy * arrSize[0] + ix ] = voxels.Get(0, ix, iy, iz) > 0.5; + voxelArr[iz*arrSize[0]*arrSize[1]+iy*arrSize[0]+ix] = voxels.Get(0, ix, iy, iz) > 0.5 } } } //the predicate voxelSize := [3]float64{a, b, c} - return func (x, y, z float64) bool { + return func(x, y, z float64) bool { var ind [3]int coord := [3]float64{x, y, z} for c := 0; c < 3; c++ { @@ -226,9 +224,7 @@ func VoxelShape(voxels *data.Slice, a, b, c float64) Shape { } //if not fallen through check against the previous array - return voxelArr[ - ind[2] * arrSize[0] * arrSize[1] + - ind[1] * arrSize[0] + ind[0] ] + return voxelArr[ind[2]*arrSize[0]*arrSize[1]+ind[1]*arrSize[0]+ind[0]] } } diff --git a/oommf/oommf.go b/oommf/oommf.go index 267ca6050..3cc75549d 100644 --- a/oommf/oommf.go +++ b/oommf/oommf.go @@ -4,12 +4,13 @@ package oommf import ( "bufio" "fmt" - "github.com/mumax/3/data" - "github.com/mumax/3/util" "io" "os" "strconv" "strings" + + "github.com/mumax/3/data" + "github.com/mumax/3/util" ) // Read any OOMMF file, autodetect OVF1/OVF2 format