Skip to content

Commit

Permalink
go fmt PR #311
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMaes committed Oct 11, 2024
1 parent a801abf commit b898d7d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 44 deletions.
35 changes: 18 additions & 17 deletions engine/geom.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
32 changes: 16 additions & 16 deletions engine/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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} {
Expand All @@ -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}
Expand Down
14 changes: 5 additions & 9 deletions engine/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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++ {
Expand All @@ -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]]
}
}

Expand Down
5 changes: 3 additions & 2 deletions oommf/oommf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b898d7d

Please sign in to comment.