本文整理匯總了Golang中github.com/mumax/3/data.Slice.Size方法的典型用法代碼示例。如果您正苦於以下問題:Golang Slice.Size方法的具體用法?Golang Slice.Size怎麽用?Golang Slice.Size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mumax/3/data.Slice
的用法示例。
在下文中一共展示了Slice.Size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: crop
func crop(f *data.Slice) {
N := f.Size()
// default ranges
x1, x2 := 0, N[X]
y1, y2 := 0, N[Y]
z1, z2 := 0, N[Z]
havework := false
if *flag_cropz != "" {
z1, z2 = parseRange(*flag_cropz, N[Z])
havework = true
}
if *flag_cropy != "" {
y1, y2 = parseRange(*flag_cropy, N[Y])
havework = true
}
if *flag_cropx != "" {
x1, x2 = parseRange(*flag_cropx, N[X])
havework = true
}
if havework {
*f = *data.Crop(f, x1, x2, y1, y2, z1, z2)
}
}
示例2: writeOVF1Binary4
// Writes data in OMF Binary 4 format
func writeOVF1Binary4(out io.Writer, array *data.Slice) (err error) {
data := array.Tensors()
gridsize := array.Size()
var bytes []byte
// OOMMF requires this number to be first to check the format
var controlnumber float32 = OVF_CONTROL_NUMBER_4
// Conversion form float32 [4]byte in big-endian
// Inlined for performance, terabytes of data will pass here...
bytes = (*[4]byte)(unsafe.Pointer(&controlnumber))[:]
bytes[0], bytes[1], bytes[2], bytes[3] = bytes[3], bytes[2], bytes[1], bytes[0] // swap endianess
_, err = out.Write(bytes)
ncomp := array.NComp()
for iz := 0; iz < gridsize[Z]; iz++ {
for iy := 0; iy < gridsize[Y]; iy++ {
for ix := 0; ix < gridsize[X]; ix++ {
for c := 0; c < ncomp; c++ {
// dirty conversion from float32 to [4]byte
bytes = (*[4]byte)(unsafe.Pointer(&data[c][iz][iy][ix]))[:]
bytes[0], bytes[1], bytes[2], bytes[3] = bytes[3], bytes[2], bytes[1], bytes[0]
out.Write(bytes)
}
}
}
}
return
}
示例3: ShiftX
// shift dst by shx cells (positive or negative) along X-axis.
// new edge value is clampL at left edge or clampR at right edge.
func ShiftX(dst, src *data.Slice, shiftX int, clampL, clampR float32) {
util.Argument(dst.NComp() == 1 && src.NComp() == 1)
util.Assert(dst.Len() == src.Len())
N := dst.Size()
cfg := make3DConf(N)
k_shiftx_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftX, clampL, clampR, cfg)
}
示例4: writeOVF2DataBinary4
func writeOVF2DataBinary4(out io.Writer, array *data.Slice) {
//w.count(w.out.Write((*(*[1<<31 - 1]byte)(unsafe.Pointer(&list[0])))[0 : 4*len(list)])) // (shortcut)
data := array.Tensors()
size := array.Size()
var bytes []byte
// OOMMF requires this number to be first to check the format
var controlnumber float32 = OVF_CONTROL_NUMBER_4
bytes = (*[4]byte)(unsafe.Pointer(&controlnumber))[:]
out.Write(bytes)
ncomp := array.NComp()
for iz := 0; iz < size[Z]; iz++ {
for iy := 0; iy < size[Y]; iy++ {
for ix := 0; ix < size[X]; ix++ {
for c := 0; c < ncomp; c++ {
bytes = (*[4]byte)(unsafe.Pointer(&data[c][iz][iy][ix]))[:]
out.Write(bytes)
}
}
}
}
}
示例5: SetArray
func (b *magnetization) SetArray(src *data.Slice) {
if src.Size() != b.Mesh().Size() {
src = data.Resample(src, b.Mesh().Size())
}
data.Copy(b.Buffer(), src)
M.normalize()
}
示例6: readOVF1DataBinary8
func readOVF1DataBinary8(in io.Reader, t *data.Slice) {
size := t.Size()
data := t.Tensors()
// OOMMF requires this number to be first to check the format
var controlnumber float64
// OVF 1.0 is network byte order (MSB)
binary.Read(in, binary.BigEndian, &controlnumber)
if controlnumber != OVF_CONTROL_NUMBER_8 {
panic("invalid OVF1 control number: " + fmt.Sprint(controlnumber))
}
var tmp float64
for iz := 0; iz < size[Z]; iz++ {
for iy := 0; iy < size[Y]; iy++ {
for ix := 0; ix < size[X]; ix++ {
for c := 0; c < 3; c++ {
err := binary.Read(in, binary.BigEndian, &tmp)
if err != nil {
panic(err)
}
data[c][iz][iy][ix] = float32(tmp)
}
}
}
}
}
示例7: Write
// Write the slice to out in binary format. Add time stamp.
func Write(out io.Writer, s *data.Slice, info data.Meta) error {
w := newWriter(out)
// Writes the header.
w.writeString(MAGIC)
w.writeUInt64(uint64(s.NComp()))
size := s.Size()
w.writeUInt64(uint64(size[2])) // backwards compatible coordinates!
w.writeUInt64(uint64(size[1]))
w.writeUInt64(uint64(size[0]))
cell := info.CellSize
w.writeFloat64(cell[2])
w.writeFloat64(cell[1])
w.writeFloat64(cell[0])
w.writeString(info.MeshUnit)
w.writeFloat64(info.Time)
w.writeString("s") // time unit
w.writeString(info.Name)
w.writeString(info.Unit)
w.writeUInt64(4) // precission
// return header write error before writing data
if w.err != nil {
return w.err
}
w.writeData(s)
w.writeHash()
return w.err
}
示例8: writeVTKHeader
func writeVTKHeader(out io.Writer, q *data.Slice) (err error) {
gridsize := q.Size()
_, err = fmt.Fprintln(out, "<?xml version=\"1.0\"?>")
_, err = fmt.Fprintln(out, "<VTKFile type=\"StructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">")
_, err = fmt.Fprintf(out, "\t<StructuredGrid WholeExtent=\"0 %d 0 %d 0 %d\">\n", gridsize[0]-1, gridsize[1]-1, gridsize[2]-1)
_, err = fmt.Fprintf(out, "\t\t<Piece Extent=\"0 %d 0 %d 0 %d\">\n", gridsize[0]-1, gridsize[1]-1, gridsize[2]-1)
return
}
示例9: Exec
// Calculate the demag field of m * vol * Bsat, store result in B.
// m: magnetization normalized to unit length
// vol: unitless mask used to scale m's length, may be nil
// Bsat: saturation magnetization in Tesla
// B: resulting demag field, in Tesla
func (c *DemagConvolution) Exec(B, m, vol *data.Slice, Bsat LUTPtr, regions *Bytes) {
util.Argument(B.Size() == c.inputSize && m.Size() == c.inputSize)
if c.is2D() {
c.exec2D(B, m, vol, Bsat, regions)
} else {
c.exec3D(B, m, vol, Bsat, regions)
}
}
示例10: Exec
// Calculate the demag field of m * vol * Bsat, store result in B.
// m: magnetization normalized to unit length
// vol: unitless mask used to scale m's length, may be nil
// Bsat: saturation magnetization in Tesla
// B: resulting demag field, in Tesla
func (c *DemagConvolution) Exec(B, m, vol *data.Slice, Msat MSlice) {
util.Argument(B.Size() == c.inputSize && m.Size() == c.inputSize)
if c.is2D() {
c.exec2D(B, m, vol, Msat)
} else {
c.exec3D(B, m, vol, Msat)
}
}
示例11: sAverageUniverse
// average of slice over universe
func sAverageUniverse(s *data.Slice) []float64 {
nCell := float64(prod(s.Size()))
avg := make([]float64, s.NComp())
for i := range avg {
avg[i] = float64(cuda.Sum(s.Comp(i))) / nCell
checkNaN1(avg[i])
}
return avg
}
示例12: writeOVF2Header
func writeOVF2Header(out io.Writer, q *data.Slice, meta data.Meta) {
gridsize := q.Size()
cellsize := meta.CellSize
fmt.Fprintln(out, "# OOMMF OVF 2.0")
hdr(out, "Segment count", "1")
hdr(out, "Begin", "Segment")
hdr(out, "Begin", "Header")
hdr(out, "Title", meta.Name)
hdr(out, "meshtype", "rectangular")
hdr(out, "meshunit", "m")
hdr(out, "xmin", 0)
hdr(out, "ymin", 0)
hdr(out, "zmin", 0)
hdr(out, "xmax", cellsize[X]*float64(gridsize[X]))
hdr(out, "ymax", cellsize[Y]*float64(gridsize[Y]))
hdr(out, "zmax", cellsize[Z]*float64(gridsize[Z]))
name := meta.Name
var labels []interface{}
if q.NComp() == 1 {
labels = []interface{}{name}
} else {
for i := 0; i < q.NComp(); i++ {
labels = append(labels, name+"_"+string('x'+i))
}
}
hdr(out, "valuedim", q.NComp())
hdr(out, "valuelabels", labels...) // TODO
unit := meta.Unit
if unit == "" {
unit = "1"
}
if q.NComp() == 1 {
hdr(out, "valueunits", unit)
} else {
hdr(out, "valueunits", unit, unit, unit)
}
// We don't really have stages
//fmt.Fprintln(out, "# Desc: Stage simulation time: ", meta.TimeStep, " s") // TODO
hdr(out, "Desc", "Total simulation time: ", meta.Time, " s")
hdr(out, "xbase", cellsize[X]/2)
hdr(out, "ybase", cellsize[Y]/2)
hdr(out, "zbase", cellsize[Z]/2)
hdr(out, "xnodes", gridsize[X])
hdr(out, "ynodes", gridsize[Y])
hdr(out, "znodes", gridsize[Z])
hdr(out, "xstepsize", cellsize[X])
hdr(out, "ystepsize", cellsize[Y])
hdr(out, "zstepsize", cellsize[Z])
hdr(out, "End", "Header")
}
示例13: shiftMag
func shiftMag(m *data.Slice, dx int) {
m2 := cuda.Buffer(1, m.Size())
defer cuda.Recycle(m2)
for c := 0; c < m.NComp(); c++ {
comp := m.Comp(c)
cuda.ShiftX(m2, comp, dx, float32(ShiftMagL[c]), float32(ShiftMagR[c]))
data.Copy(comp, m2) // str0 ?
}
}
示例14: SetTopologicalCharge
// Set s to the toplogogical charge density s = m · (m/∂x ❌ ∂m/∂y)
// See topologicalcharge.cu
func SetTopologicalCharge(s *data.Slice, m *data.Slice, mesh *data.Mesh) {
cellsize := mesh.CellSize()
N := s.Size()
util.Argument(m.Size() == N)
cfg := make3DConf(N)
icxcy := float32(1.0 / (cellsize[X] * cellsize[Y]))
k_settopologicalcharge_async(s.DevPtr(X),
m.DevPtr(X), m.DevPtr(Y), m.DevPtr(Z),
icxcy, N[X], N[Y], N[Z], mesh.PBC_code(), cfg)
}
示例15: AddDMI
// Add effective field of Dzyaloshinskii-Moriya interaction to Beff (Tesla).
// According to Bagdanov and Röβler, PRL 87, 3, 2001. eq.8 (out-of-plane symmetry breaking).
// See dmi.cu
func AddDMI(Beff *data.Slice, m *data.Slice, Aex_red, Dex_red SymmLUT, regions *Bytes, mesh *data.Mesh) {
cellsize := mesh.CellSize()
N := Beff.Size()
util.Argument(m.Size() == N)
cfg := make3DConf(N)
k_adddmi_async(Beff.DevPtr(X), Beff.DevPtr(Y), Beff.DevPtr(Z),
m.DevPtr(X), m.DevPtr(Y), m.DevPtr(Z),
unsafe.Pointer(Aex_red), unsafe.Pointer(Dex_red), regions.Ptr,
float32(cellsize[X]*1e9), float32(cellsize[Y]*1e9), float32(cellsize[Z]*1e9), N[X], N[Y], N[Z], mesh.PBC_code(), cfg)
}