Skip to content

Commit

Permalink
rename Slicer->Quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
barnex committed Jan 10, 2014
1 parent 8ffdb28 commit 6d9a81c
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 25 deletions.
11 changes: 1 addition & 10 deletions engine/asyncio.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@ import (
"strings"
)

// Any space-dependent quantity
type Slicer interface {
Slice() (q *data.Slice, recycle bool) // get quantity data (GPU or CPU), indicate need to recycle
NComp() int
Name() string
Unit() string
Mesh() *data.Mesh
}

// Save under given file name (transparant async I/O).
func SaveAs(q Slicer, fname string) {
func SaveAs(q Quantity, fname string) {
if !path.IsAbs(fname) && !strings.HasPrefix(fname, OD) {
fname = path.Clean(OD + "/" + fname)
}
Expand Down
8 changes: 4 additions & 4 deletions engine/autosave.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package engine
import "fmt"

var (
output = make(map[Slicer]*autosave) // when to save quantities
autonum = make(map[interface{}]int) // auto number for out file
output = make(map[Quantity]*autosave) // when to save quantities
autonum = make(map[interface{}]int) // auto number for out file
)

func init() {
Expand All @@ -28,7 +28,7 @@ func DoOutput() {

// Register quant to be auto-saved every period.
// period == 0 stops autosaving.
func AutoSave(quant Slicer, period float64) {
func AutoSave(quant Quantity, period float64) {
if period == 0 {
delete(output, quant)
} else {
Expand All @@ -37,7 +37,7 @@ func AutoSave(quant Slicer, period float64) {
}

// Save once, with auto file name
func Save(q Slicer) {
func Save(q Quantity) {
fname := fmt.Sprintf("%s%06d.ovf", q.Name(), autonum[q])
SaveAs(q, fname)
autonum[q]++
Expand Down
2 changes: 1 addition & 1 deletion engine/average.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func init() {
// Take average of quantity, taking into account the volume in which it is defined. E.g.:
// Average(m) // averges only inside magnet.
// Average(m.Region(1)) // averages only in region 1
func Average(s Slicer) []float64 {
func Average(s Quantity) []float64 {
buf, recycle := s.Slice()
if recycle {
defer cuda.Recycle(buf)
Expand Down
4 changes: 2 additions & 2 deletions engine/comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

type comp struct {
parent Slicer
parent Quantity
comp int
}

func Comp(parent Slicer, c int) *comp {
func Comp(parent Quantity, c int) *comp {
util.Argument(c >= 0 && c < parent.NComp())
return &comp{parent, c}
}
Expand Down
4 changes: 2 additions & 2 deletions engine/energy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func SetTotalEdens(dst *data.Slice) {
}

// vector dot product
func dot(a, b Slicer) float64 {
func dot(a, b Quantity) float64 {
A, recyA := a.Slice()
if recyA {
defer cuda.Recycle(A)
Expand All @@ -59,7 +59,7 @@ func cellVolume() float64 {

// returns a function that adds to dst the energy density:
// prefactor * dot (M_full, field)
func addEdens(field Slicer, prefactor float64) func(*data.Slice) {
func addEdens(field Quantity, prefactor float64) func(*data.Slice) {
return func(dst *data.Slice) {
B, r1 := field.Slice()
if r1 {
Expand Down
6 changes: 3 additions & 3 deletions engine/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// global GUI state stores what is currently shown in the web page.
var (
GUI = guistate{Quants: make(map[string]Slicer), Params: make(map[string]Param)}
GUI = guistate{Quants: make(map[string]Quantity), Params: make(map[string]Param)}
keepalive = time.Now()
keepaliveLock sync.Mutex
)
Expand All @@ -36,7 +36,7 @@ func updateKeepAlive() {

type guistate struct {
*gui.Page
Quants map[string]Slicer
Quants map[string]Quantity
Params map[string]Param
mutex sync.Mutex
_eventCacheBreaker int // changed on any event to make sure display is updated
Expand All @@ -58,7 +58,7 @@ func (g *guistate) Add(name string, value interface{}) {
if v, ok := value.(Param); ok {
g.Params[name] = v
}
if v, ok := value.(Slicer); ok {
if v, ok := value.(Quantity); ok {
g.Quants[name] = v
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/inregion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// represents a new quantity equal to q in the given region, 0 outside.
type sliceInRegion struct {
slicer Slicer
slicer Quantity
region int
}

Expand Down
14 changes: 14 additions & 0 deletions engine/quantity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package engine

import (
"github.com/mumax/3/data"
)

// Any space-dependent quantity
type Quantity interface {
Slice() (q *data.Slice, recycle bool) // get quantity data (GPU or CPU), indicate need to recycle
NComp() int
Name() string
Unit() string
Mesh() *data.Mesh
}
2 changes: 1 addition & 1 deletion engine/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (ren *render) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

func (ren *render) render(quant Slicer, comp string) {
func (ren *render) render(quant Quantity, comp string) {
// rescale and download
InjectAndWait(func() {
size := quant.Mesh().Size()
Expand Down
2 changes: 1 addition & 1 deletion engine/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func LoadFile(fname string) *data.Slice {

// Download a quantity to host,
// or just return its data when already on host.
func Download(q Slicer) *data.Slice {
func Download(q Quantity) *data.Slice {
buf, recycle := q.Slice()
if recycle {
defer cuda.Recycle(buf)
Expand Down

0 comments on commit 6d9a81c

Please sign in to comment.