Skip to content

Commit

Permalink
https://github.com/mumax/3/pull/335
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuMoalic committed Oct 4, 2024
1 parent ffca9e7 commit 2785aaa
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/engine/ext_make3dgrains.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,32 @@ func (t *tesselation3d) tabulateCells() []cellLocs {
return cells
}

var grainCutShape = false

// Find the nearest Voronoi center to the point (x, y, z). Only points inside the given shape will be
// assigned a region.
func (t *tesselation3d) RegionOf(x, y, z float64) int {
if t.shape(x, y, z) {
nearest := center3d{}
mindist := math.Inf(1)
for _, c := range t.centers {
dist := sqr(x-c.x) + sqr(y-c.y) + sqr(z-c.z)
if dist < mindist {
nearest = c
mindist = dist
}
if !(t.shape(x, y, z) || grainCutShape) {
return -1 // Regions < 0 won't be rastered
}

// Find the nearest center point to the (x, y, z) position
nearest := center3d{x, y, z, 0}
mindist := math.Inf(1)
for _, c := range t.centers {
dist := sqr(x-c.x) + sqr(y-c.y) + sqr(z-c.z)
if dist < mindist {
nearest = c
mindist = dist
}
}

// Check if the nearest point's region should be returned
if (t.shape(x, y, z) && !grainCutShape) || (t.shape(nearest.x, nearest.y, nearest.z) && grainCutShape) {
return int(nearest.region)
} else {
return -1 //When the regions are rendered, any region < 0 will not be rastered.
}

return -1
}

// Generate normally distributed numbers; mean = lambda, variance = lambda. If generated number < 0, return 1.
Expand Down
32 changes: 32 additions & 0 deletions src/test/make3dgrains_shape_edge.mx3
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
N:=32
SetMesh(N, N, N, 1e-9,1e-9,1e-9, 0, 0, 0)

//set material params
alpha=1.
Msat=350e3
Aex=10e-12
Ku1=1.0e6

//define a spherical shape
diam:=16e-9
sphere := Ellipsoid(diam,diam,diam)
defregion(1, sphere)

seed:=238948790
randSeed(seed)
GrainCutShape=true
ext_make3Dgrains(8e-9, 2, 250, sphere, seed)

for i:=2; i<254; i+=1 {
anisU.setregion(i, vector(randNorm(),randNorm(),randNorm()))
}


//a cell in the sphere for which the nearest voronoi centre also lies in the sphere: nonzero region nr expected
expect("region", regions.getcell(15,15,15), 191, 0)

//a cell in the sphere for which the nearest voronoi centre lies outside the sphere: region nr 1 expected as it is not affected by make3Dgrains
expect("region", regions.getcell(9,15,15), 1, 0)

//a cell outside of the sphere for which the nearest voronoi centre lies inside the sphere: nonzero region nr expected as it was completed by make3Dgrains
expect("region", regions.getcell(16,4,15), 64, 0)

0 comments on commit 2785aaa

Please sign in to comment.