engine

package
v0.0.0-...-a20b597 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2015 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

The mumax engine stores the entire simulation state and provides methods to run the simulation. An engine is typically steered by a driver, like a python program or command line interface.

Index

Constants

View Source
const (
	FINE_T     = 100  // subdivision of time interval in dispersion calculation
	B_EXT      = 1e-4 // the amplitude of excitation used in dispersion calculation
	OUT_FORMAT = "dump"
	N_TC       = 24
)
View Source
const (
	EQN_INVALID = iota // not used
	EQN_PDE1           // dy/dt=f(y,t)
)
View Source
const (
	SCALAR   = 1 // Number
	VECTOR   = 3 // Vector
	SYMMTENS = 6 // Symmetric tensor
	TENS     = 9 // General tensor
)

Number of components.

View Source
const ArgDelim = "="
View Source
const (
	T_MAGIC = 0x0A317423 // First 32-bit word of tensor blob. Identifies the format. Little-endian ASCII for "#t1\n"
)
View Source
const UPDATE_DASH = 150 * 1e6

refresh dashboard every x nanoseconds

Variables

This section is empty.

Functions

func AddTermToQuant

func AddTermToQuant(sumQuant, term *Quant)

func AtLeast1

func AtLeast1(q *Quant)

func GetVariable

func GetVariable(argMap map[string]string, name string) string

func Init

func Init()

Initializes the global simulation engine

func Int

func Int(q *Quant)

Panics if a multiplier is not an integer

func IsGoodCUFFTSize

func IsGoodCUFFTSize(n int) bool

Checks if size = 2^n * {1,3,5,7}, which is very suited as CUFFT transform size.

func IsGoodGridSize

func IsGoodGridSize(size []int) bool

func IsGoodGridSize1

func IsGoodGridSize1(direction, n int) bool

Stricter than IsGoodCUFFTSize(): Should be a good CUFFT size and meet alignment requirements.

func LoadBDFAM12

func LoadBDFAM12(e *Engine)

func LoadBDFEuler

func LoadBDFEuler(e *Engine)

func LoadEuler

func LoadEuler(e *Engine)

func LoadRK12

func LoadRK12(e *Engine)

Load the solver into the Engine

func NonNegative

func NonNegative(q *Quant)

Panics if a multiplier is < 0

func NonZero

func NonZero(q *Quant)

Panics if a multiplier is zero

func PadSize

func PadSize(size []int, periodic []int) []int

Add padding x 2 in all directions where periodic == 0, except when a dimension == 1 (no padding neccesary)

func ParseArgument

func ParseArgument(m map[string]string, v string)

func PosInt

func PosInt(q *Quant)

Panics if a multiplier is not a strictly positive integer

func Positive

func Positive(q *Quant)

Panics if a multiplier is <= 0

func ReadDump

func ReadDump(fname string) *host.Array

func ReadFile

func ReadFile(fname string) *host.Array

Reads an array from a file.

func ReadPNG

func ReadPNG(fname string) *host.Array

func RegisterInputFormat

func RegisterInputFormat(extension string, readFunc func(string) *host.Array)

func RegisterModule

func RegisterModule(name, description string, loadfunc func(e *Engine))

Registers a module in the list of known modules. Each module should register itself in its init() function.

func RegisterModuleArgs

func RegisterModuleArgs(name, description string, args Arguments, loadfuncargs func(e *Engine, args ...Arguments))

func RegisterOutputFormat

func RegisterOutputFormat(format OutputFormat)

registers an output format

func Resample

func Resample(in *host.Array, size2 []int) *host.Array

Returns a new host array of size size2, re-sized from the input array by nearest-neighbor interpolation.

func RunDot

func RunDot(infile, format string)

Executes dot -Tformat -O infile rendering the dot input file.

func TexGen

func TexGen()

INTERNAL: generates LaTeX files with documentation.

func Uint

func Uint(q *Quant)

Panics if a multiplier is not a positive or zero integer

func Write

func Write(out io.Writer, a *host.Array)

Writes the array

Types

type API

type API struct {
	Engine *Engine
}

The API methods are accessible to the end-user through scripting languages.

func (API) AddDeltaQuant

func (a API) AddDeltaQuant(src, ref string)

func (API) Add_To

func (a API) Add_To(sumQuantity, newQuantity string)

Add a new quantity to the multi-physics engine, its value is added to the (existing) sumQuantity. E.g.: Add_To("H", "H_1") adds a new external field H_1 that will be added to H.

func (API) Add_To_Weighted

func (a API) Add_To_Weighted(sumQuantity, newQuantity string, weight float64)

func (API) AutoSave

func (a API) AutoSave(quantity string, format string, options []string, period float64) (handle int)

Saves a space-dependent quantity periodically, every period (expressed in seconds). Output appears in the output directory with automatically generated file names. E.g., for a quantity named "m", and format "txt" the generated files will be:

m00000.txt m00001.txt m00002.txt...

See FilenameFormat() for setting the number of zeros. Returns an integer handle that can be used to manipulate the auto-save entry. E.g. remove(handle) stops auto-saving it. @see filenumberfomat

func (API) AutoTabulate

func (a API) AutoTabulate(quantities []string, filename string, period float64) (handle int)

Saves any number of space-independent quantities periodically, every period (expressed in seconds). The values are appended to the file. Returns an integer handle that can be used to manipulate the auto-save entry. E.g. remove(handle) stops auto-saving it.

func (API) DebugField

func (a API) DebugField(quantity string) *host.Array

DEBUG: does not update

func (API) DebugV

func (a API) DebugV(quantity string) []float64

DEBUG: Does not update.

func (API) Debug_DisableUpdate

func (a API) Debug_DisableUpdate(quantity string)

DEBUG: removes the updater of this quantity

func (API) Debug_GC

func (a API) Debug_GC()

func (API) Debug_GetArray

func (a API) Debug_GetArray(quant string) *host.Array

FOR DEBUG ONLY. Gets the quantity's array, raw.

func (API) Debug_Invalidate

func (a API) Debug_Invalidate(quantity string)

DEBUG: manually update the quantity state

func (API) Debug_Update

func (a API) Debug_Update(quantity string)

DEBUG: manually update the quantity state

func (API) Debug_VerifyAll

func (a API) Debug_VerifyAll()

DEBUG: verify all quanties' values

func (API) Echo

func (a API) Echo(str string)

DEBUG: echos a string, can be used for synchronous output

func (API) FileNumberFormat

func (a API) FileNumberFormat(format string)

Sets a global C-style printf format string used to generate file names for automatically saved files. The default "%06d" generates, e.g., "m000001.txt". "%d" would generate, e.g., "m1.txt".

func (API) GetArray

func (a API) GetArray(quantity string) *host.Array

Gets a space-dependent quantity. If the quantity uses a mask, the result is equal to GetMask() * GetValue()

func (API) GetCell

func (a API) GetCell(quant string, x, y, z int) []float64

Gets the value of the quantity at cell position x,y,z

func (API) GetCellSize

func (a API) GetCellSize() (x, y, z float64)

Get the cell size. WARNING: convert to ZYX, internal units

func (API) GetGridSize

func (a API) GetGridSize() (x, y, z int)

Get the grid size. WARNING: convert to ZYX

func (API) GetMask

func (a API) GetMask(quantity string) *host.Array

Gets a space-dependent quantity. If the quantity uses a mask, the result is equal to GetMask() * GetValue()

func (API) GetPeriodic

func (a API) GetPeriodic() (x, y, z int)

Get the periodicity WARNING: convert to ZYX, internal units

func (API) GetS

func (a API) GetS(quantity string) float64

Get the value of a scalar, space-independent quantity. Similar to GetValue, but returns a single number.

func (API) GetTime

func (a API) GetTime(tag string) float64

DEBUG: Gets the time, in seconds, recorded by the timer with this tag.

func (API) GetV

func (a API) GetV(quantity string) []float64

Get the value of a space-independent or masked quantity. Returns an array with vector components or an array with just one element in case of a scalar quantity.

func (API) GetWorldSize

func (a API) GetWorldSize() (x, y, z float64)

Get the toal size, in meters, of the simulated world.

func (API) Load

func (a API) Load(name string)

Load a physics module.

func (API) LoadArgs

func (a API) LoadArgs(name string, ins, deps, outs []string)

Load a physics module with user-defined variables.

func (API) New_MaxAbs

func (a API) New_MaxAbs(newQuantity, inputQuantity string)

Add a new quantity to the multi-physics engine, its value is the maximum of the absolute value of inputQuantity. E.g.: New_MaxAbs("max_torque", "torque") adds a new quantity "max_torque" whose value is max(abs(torque)). For vector quantities, the maximum is taken over all components.

func (API) New_MaxNorm

func (a API) New_MaxNorm(newQuantity, inputQuantity string)

Add a new quantity to the multi-physics engine, its value is the maximum norm of inputQuantity (a 3-component vector). E.g.: New_MaxNorm("maxnorm_torque", "torque") adds a new quantity "maxnorm_torque" whose value is max(norm(torque)).

func (API) New_Peak

func (a API) New_Peak(newQuantity, inputQuantity string)

func (API) OutputDirectory

func (a API) OutputDirectory() string

Returns the output directory for the running simulation.

func (API) OutputID

func (a API) OutputID() int

Returns the output ID corresponding to the current simulation time. All automatic output uses this number to identify the time corresponding to the saved quantity.

func (API) PrintStats

func (a API) PrintStats()

DEBUG

func (API) ReadFile

func (a API) ReadFile(filename string) *host.Array

DEBUG: reads an array from a file.

func (API) RecoverState

func (a API) RecoverState(dst, src string)

func (API) Remove

func (a API) Remove(handle int)

Removes the object with given handle. E.g.:

handle = autosave(...)
remove(handle) # stops auto-saving

func (API) ResetTimer

func (a API) ResetTimer(tag string)

DEBUG: Resets the timer with this tag.

func (API) Run

func (a API) Run(duration float64)

Runs for a duration given in seconds. TODO: precise stopping time

func (API) Run_Until_Larger

func (a API) Run_Until_Larger(quantity string, value float64)

Runs the simulation until quantity a > quantity b

func (API) Run_Until_Smaller

func (a API) Run_Until_Smaller(quantity string, value float64)

Runs the simulation until quantity a < value

func (API) Save

func (a API) Save(quantity string, format string, options []string)

Saves a space-dependent quantity, once. Uses the specified format and gives an automatic file name (like "m000001.png"). See also: Save()

func (API) SaveAs

func (a API) SaveAs(quantity string, format string, options []string, filename string)

Saves a space-dependent quantity, once. Uses the specified format and file name.

func (API) SaveGraph

func (a API) SaveGraph(file string)

Saves an image file of the physics graph using the given file name. The extension determines the output format. E.g.: .png, .svg, ... A file with a .dot extension will be written as well. Rendering requires the package "graphviz" to be installed.

func (API) SaveState

func (a API) SaveState(dst, src string)

func (API) SetArray

func (a API) SetArray(quantity string, field *host.Array)

Sets a space-dependent field quantity, like the magnetization.

func (API) SetArray_File

func (a API) SetArray_File(quantity string, filename string)

Like SetArray but reads the array from a file.

func (API) SetCell

func (a API) SetCell(quant string, x, y, z int, value []float64)

Sets the value of the quantity at cell position x,y,z

func (API) SetCellSize

func (a API) SetCellSize(x, y, z float64)

Set the cell size. WARNING: convert to ZYX

func (API) SetGridSize

func (a API) SetGridSize(x, y, z int)

Set the grid size. WARNING: convert to ZYX

func (API) SetMask

func (a API) SetMask(quantity string, mask *host.Array)

Sets a space-dependent multiplier mask for the quantity. The value of the quantity (set by SetValue), will be multiplied by the mask value in each point of space. The mask is dimensionless and typically contains values between 0 and 1.

func (API) SetMask_File

func (a API) SetMask_File(quantity string, filename string)

Like SetMask but reads the mask from a file.

func (API) SetPeriodic

func (a API) SetPeriodic(x, y, z int)

Set periodic boundary conditions in each direction. A value of 0 means no periodicity in that direction (the default). A nonzero value means the system is infinitely reproduced in that direction. The magnitude of the nonzero value is a hint of how accurately the infinite character should be approached, if applicable. E.g.: for the ferromagnetic exchange interaction, any nonzero value will give the same result: perfect infinite periodicity. But for the magnetostatic interaction, the magnitude of the nonzero value may be used as a hint where to cut off the magnetic field.

func (API) SetS

func (a API) SetS(quantity string, value float64)

Set scalar. Convenience method for SetValue() with only one number. REDUNDANT?

func (API) SetV

func (a API) SetV(quantity string, value []float64)

Set value of a quantity. The quantity must be of type VALUE or MASK. If the quantity is a MASK, the value will be multiplied by a space-dependent mask which typically contains dimensionless numbers between 0 and 1.

func (API) SetVMap

func (a API) SetVMap(yName, xName string, yValue [][]float64, xValue []float64)

func (API) StartTimer

func (a API) StartTimer(tag string)

DEBUG: start a timer with a given identifier tag

func (API) Step

func (a API) Step()

Take one solver step

func (API) Steps

func (a API) Steps(N int)

Takes N solver steps

func (API) StopTimer

func (a API) StopTimer(tag string)

DEBUG: stop a timer with a given identifier tag. It must be started first.

func (API) Sync

func (a API) Sync()

Should be called at the end of each input file to make sure the input script does not terminate too early.

func (API) Tabulate

func (a API) Tabulate(quantities []string, filename string)

Saves these space-independent quantities, once. Their values are appended to the file, on one line.

func (API) Unit

func (a API) Unit(quantity string) string

Gets the quantities unit.

type AddTermUpdater

type AddTermUpdater struct {
	SumUpdater
	// contains filtered or unexported fields
}

func NewAddTermUpdater

func NewAddTermUpdater(orig *Quant) *AddTermUpdater

func (*AddTermUpdater) Update

func (u *AddTermUpdater) Update()

type Arguments

type Arguments struct {
	InsMap  map[string]string // the string-to-string map of the input quantities
	DepsMap map[string]string // the string-to-string map of the dependencies
	OutsMap map[string]string // the string-to-string map of the output quantities
}

A physics module. Loading it adds various quantity nodes to the engine.

func GetParsedArgumentsMap

func GetParsedArgumentsMap(module Module, in, deps, out []string) Arguments

func (*Arguments) Deps

func (t *Arguments) Deps(name string) string

func (*Arguments) Ins

func (t *Arguments) Ins(name string) string

func (*Arguments) Outs

func (t *Arguments) Outs(name string) string

type ArrayPool

type ArrayPool struct {
}
var Pool ArrayPool

the global array pool

func (*ArrayPool) Get

func (p *ArrayPool) Get(nComp int, size []int) *gpu.Array

func (*ArrayPool) Recycle

func (p *ArrayPool) Recycle(array **gpu.Array)

type AutoSave

type AutoSave struct {
	// contains filtered or unexported fields
}

Saves a field (scalar field, vector field, etc) periodically.

func (*AutoSave) Notify

func (a *AutoSave) Notify(e *Engine)

Called by the eninge

type AutoTabulate

type AutoTabulate struct {
	// contains filtered or unexported fields
}

Saves a value (scalar field, vector field, etc) periodically.

func (*AutoTabulate) Notify

func (a *AutoTabulate) Notify(e *Engine)

Called by the eninge

type AverageUpdater

type AverageUpdater ReduceUpdater

Updates an average quantity

func (*AverageUpdater) Update

func (this *AverageUpdater) Update()

type BDFAM12

type BDFAM12 struct {
	// contains filtered or unexported fields
}

The adaptive implicit method, predictor: Implicit Euler, corrector: Trapezoidal

func (*BDFAM12) Dependencies

func (s *BDFAM12) Dependencies() (children, parents []string)

func (*BDFAM12) Step

func (s *BDFAM12) Step()

type BDFEuler

type BDFEuler struct {
	// contains filtered or unexported fields
}

Naive Backward Euler solver

func (*BDFEuler) Dependencies

func (s *BDFEuler) Dependencies() (children, parents []string)

func (*BDFEuler) Step

func (s *BDFEuler) Step()

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is the heart of a multiphysics simulation. The engine stores named quantities like "m", "B", "alpha", ... An acyclic graph structure consisting of interconnected quantities determines what should be calculated and when.

func GetEngine

func GetEngine() *Engine

Returns the global simulation engine

func (*Engine) AddDeltaQuant

func (e *Engine) AddDeltaQuant(in, ref string)

func (*Engine) AddNewQuant

func (e *Engine) AddNewQuant(name string, nComp int, kind QuantKind, unit Unit, desc ...string) *Quant

Constructs and adds an arbitrary quantity. (Also returns it, but it's not necessarily used further) Name tag is case-independent. TODO: refactor AddQuant(q*Quant) TODO: NewQuant should take size from global engine.

func (*Engine) AddPDE1

func (e *Engine) AddPDE1(y, diff string)

Add a 1st order partial differential equation:

d y / d t = diff

E.g.: ODE1("m", "torque") No direct dependency should be declared between the arguments.

func (*Engine) AddQuant

func (e *Engine) AddQuant(q *Quant)

Add a quantity.

func (*Engine) AddTimeDerivative

func (e *Engine) AddTimeDerivative(q *Quant)

Load time derivative of quant if not yet present

func (*Engine) AutoFilename

func (e *Engine) AutoFilename(quant, format string) string

Generates an automatic file name for the quantity, given the output format. E.g., "dir.out/m000007.omf" see: outputDir, filenameFormat

func (*Engine) AutoSave

func (e *Engine) AutoSave(quant string, format string, options []string, period float64) (handle int)

Saves the quantity periodically.

func (*Engine) AutoTabulate

func (e *Engine) AutoTabulate(quants []string, filename string, period float64) (handle int)

See api.go

func (*Engine) CellSize

func (e *Engine) CellSize() []float64

Gets the FD cell size

func (*Engine) CellVolume

func (e *Engine) CellVolume() float64

FD cell volume in m³

func (*Engine) Close

func (e *Engine) Close()

Shuts down the engine. Closes all open files, etc.

func (*Engine) Depends

func (e *Engine) Depends(childQuantity string, parentQuantities ...string)

Mark childQuantity to depend on parentQuantity. Multiply adding the same dependency has no effect.

func (*Engine) GridSize

func (e *Engine) GridSize() []int

Gets the FD grid size

func (*Engine) HasModule

func (e *Engine) HasModule(name string) bool

Returns true if the named module is already loaded.

func (*Engine) HasQuant

func (e *Engine) HasQuant(name string) bool

Returns whether a quantity is already defined in the engine.

func (*Engine) LoadModule

func (e *Engine) LoadModule(name string)

Low-level module load, not aware of dependencies

func (*Engine) LoadModuleArgs

func (e *Engine) LoadModuleArgs(name string, ins, deps, outs []string)

Low-level module load, not aware of dependencies

func (*Engine) NCell

func (e *Engine) NCell() int

Gets the total number of FD cells

func (*Engine) NewHandle

func (e *Engine) NewHandle() int

Returns ++_handleCount. Used to identify objects like crontabs so they can later by manipulated through this ID.

func (*Engine) OutputID

func (e *Engine) OutputID() int

Gets an ID number to identify the current time. Used to number output files. E.g. the 7 in "m000007.omf". Files with the same OutputID correspond to the same simulation time.

func (*Engine) PaddedSize

func (e *Engine) PaddedSize() []int

Returns the grid size after zero padding

func (*Engine) Periodic

func (e *Engine) Periodic() []int

Gets the FD grid size

func (*Engine) Quant

func (e *Engine) Quant(name string) *Quant

Retrieve a quantity by its name. Lookup is case-independent

func (*Engine) RecoverState

func (e *Engine) RecoverState(out, in string)

func (*Engine) Relative

func (e *Engine) Relative(filename string) string

Resolves a file name relative to the output directory, unless the name begins with a /.

func (*Engine) RemoveHandle

func (e *Engine) RemoveHandle(handle int)

Looks for an object with the handle number and removes it. Currently only looks in the crontabs.

func (*Engine) Run

func (e *Engine) Run(duration float64)

Runs for a certain duration specified in seconds

func (*Engine) SaveAs

func (e *Engine) SaveAs(q *Quant, format string, options []string, filename string)

Saves the quantity once in the specified format and file name

func (*Engine) SaveAsAppend

func (e *Engine) SaveAsAppend(q *Quant, format string, options []string, filename string)

Append the quantity once in the specified format and file name

func (*Engine) SaveState

func (e *Engine) SaveState(out, in string)

func (*Engine) SetCellSize

func (e *Engine) SetCellSize(size []float64)

Sets the FD cell size

func (*Engine) SetGridSize

func (e *Engine) SetGridSize(size3D []int)

Sets the FD grid size

func (*Engine) SetOutputDirectory

func (e *Engine) SetOutputDirectory(dir string)

INTERNAL: Used by frontend to set the output dir

func (*Engine) SetPeriodic

func (e *Engine) SetPeriodic(p []int)

Sets the periodicity in each dimension

func (*Engine) SetSolver

func (e *Engine) SetSolver(s Solver)

func (*Engine) Stats

func (e *Engine) Stats() string

DEBUG: statistics

func (*Engine) Step

func (e *Engine) Step()

Takes one time step. It is the solver's responsibility to Update/Invalidate its dependencies as needed.

func (*Engine) Steps

func (e *Engine) Steps(N int)

Takes N time steps

func (*Engine) String

func (e *Engine) String() string

String representation

func (*Engine) Tabulate

func (e *Engine) Tabulate(quants []string, filename string)

See api.go

func (*Engine) UpdateEqRHS

func (e *Engine) UpdateEqRHS()

func (*Engine) WorldSize

func (e *Engine) WorldSize() []float64

Size of total simulated world, in meters.

func (*Engine) WriteDot

func (e *Engine) WriteDot(out io.Writer)

Write .dot file for graphviz, representing the physics graph.

type Equation

type Equation struct {
	// contains filtered or unexported fields
}

Type representing a differential equation

func PDE1

func PDE1(output, input *Quant) Equation

d output / d t = input

func (*Equation) LHS

func (e *Equation) LHS() *Quant

func (*Equation) RHS

func (e *Equation) RHS() *Quant

func (*Equation) String

func (e *Equation) String() string

func (*Equation) UpdateRHS

func (e *Equation) UpdateRHS()

type EulerSolver

type EulerSolver struct {
}

Euler solver

func (*EulerSolver) Dependencies

func (s *EulerSolver) Dependencies() (children, parents []string)

func (*EulerSolver) Step

func (s *EulerSolver) Step()

type FFTUpdater

type FFTUpdater struct {
	// contains filtered or unexported fields
}

Update FFT of quantity

func NewFFTUpdater

func NewFFTUpdater(qin, qout *Quant) *FFTUpdater

func (*FFTUpdater) Update

func (u *FFTUpdater) Update()

type FormatDump

type FormatDump struct{}

func (*FormatDump) Name

func (f *FormatDump) Name() string

func (*FormatDump) Write

func (f *FormatDump) Write(out io.Writer, q *Quant, options []string)

type HeunSolver

type HeunSolver struct {
	// contains filtered or unexported fields
}

func NewHeun

func NewHeun(e *Engine) *HeunSolver

func (*HeunSolver) Step

func (s *HeunSolver) Step()

type Invalidator

type Invalidator interface {
	Invalidate()
}

Invalidate() is called after each invalidation of a Quant.

type MaxAbsUpdater

type MaxAbsUpdater ReduceUpdater

Updates a maximum of absolute values

func (*MaxAbsUpdater) Update

func (this *MaxAbsUpdater) Update()

type MaxNormUpdater

type MaxNormUpdater ReduceUpdater

Updates the maximum norm of a 3-vector array

func (*MaxNormUpdater) Update

func (this *MaxNormUpdater) Update()

type Module

type Module struct {
	Name        string                             // Name to identify to module to the machine
	Description string                             // Human-readable description of what the module does
	Args        Arguments                          // The map of arguments and their default values
	LoadFunc    func(e *Engine, args ...Arguments) // Loads this module's quantities and dependencies into the engine
}

func GetModule

func GetModule(name string) Module

type Notifier

type Notifier interface {
	Notify(e *Engine) // Notifies the crontab that a step has been taken, so it can take action if needed
}

type OutputFormat

type OutputFormat interface {
	Name() string                                    // Name to register the format under. E.g. "txt". Also used as file extension
	Write(out io.Writer, q *Quant, options []string) // Writes the quantity buffer to out
}

A general output format for space-dependent quantities.

func GetOutputFormat

func GetOutputFormat(name string) OutputFormat

Retrieves an output format from its name. E.g. "txt", "omf"

type PeakUpdater

type PeakUpdater struct {
	// contains filtered or unexported fields
}

func (*PeakUpdater) Update

func (u *PeakUpdater) Update()

type PointwiseOfUpdater

type PointwiseOfUpdater struct {
	// contains filtered or unexported fields
}

Updates a quantity according to a point-wise defined function of argument.

func (*PointwiseOfUpdater) AppendMap

func (p *PointwiseOfUpdater) AppendMap(x []float64, y [][]float64)

func (*PointwiseOfUpdater) Update

func (field *PointwiseOfUpdater) Update()

type Quant

type Quant struct {
	// contains filtered or unexported fields
}

A quantity represents a scalar/vector/tensor field,value or mask.

* By "value" we mean a single, space-independent scalar,vector or tensor. * By "field" we mean a space-dependent field of scalars, vectors or tensors. * By "mask" we mean the point-wise multiplication of a field by a value.

Typically a mask represents A(r) * f(t), a pointwise multiplication of an N-vector function of space A(r) by an N-vector function of time f(t). A(r) is an array, f(t) is the multiplier which will be updated every time step. When a mask's array contains NULL pointers for each gpu, the mask is independent of space. The array is then interpreted as 1(r), the unit field. In this way, masks that happen to be constant values in space (homogeneous) can be efficiently represented. TODO: deduplicate identical mask arrays by setting identical pointers?

Quantities are the nodes of an acyclic graph representing the differential equation to be solved.

func NewQuant

func NewQuant(name string, nComp int, size3D []int, kind QuantKind, unit Unit, cpuOnly bool, desc ...string) *Quant

Returns a new quantity. See Quant.init(). TODO: make desc obligatory

func (*Quant) Add

func (sum *Quant) Add(parent *Quant)

sum += parent

func (*Quant) Array

func (q *Quant) Array() *gpu.Array

Gets the GPU array.

func (*Quant) Buffer

func (q *Quant) Buffer(kind QuantKind) *host.Array

Transfers the quantity from GPU to host. The quantities host buffer is allocated when needed. The transfer is only done when needed, i.e., when bufferUpToDate == false. Multiplies by the multiplier and handles masks correctly. Does not Update().

func (*Quant) Component

func (orig *Quant) Component(comp int) *Quant

Quantity representing a single component of the original, with shared underlying storage. The returned Quant's name and dependencies still have to be set.

func (*Quant) CopyFromQuant

func (q *Quant) CopyFromQuant(qin *Quant)

func (*Quant) FullName

func (q *Quant) FullName() string

Gets the name + [unit]

func (*Quant) GetUpdater

func (q *Quant) GetUpdater() Updater

Gets the updater

func (*Quant) Invalidate

func (q *Quant) Invalidate()

Opposite of Update. Sets upToDate flag of this node and all its children (which depend on this node) to false.

func (*Quant) IsSpaceDependent

func (q *Quant) IsSpaceDependent() bool

True if the quantity varies in space.

func (*Quant) Kind

func (q *Quant) Kind() QuantKind

func (*Quant) Multiplier

func (q *Quant) Multiplier() []float64

func (*Quant) NComp

func (q *Quant) NComp() int

Gets the number of components

func (*Quant) Name

func (q *Quant) Name() string

Gets the name

func (*Quant) Scalar

func (q *Quant) Scalar() float64

Assuming the quantity represent a scalar value, return it as a number.

func (*Quant) SetComponent

func (q *Quant) SetComponent(comp int, val float64)

Sets one component of a VALUE quantity.

func (*Quant) SetField

func (q *Quant) SetField(field *host.Array)

Sets a space-dependent field.

func (*Quant) SetMask

func (q *Quant) SetMask(field *host.Array)

Sets the space-dependent mask array. Allocates GPU storage when needed.

func (*Quant) SetScalar

func (q *Quant) SetScalar(val float64)

Convenience method for SetValue([]float64{val})

func (*Quant) SetUpToDate

func (q *Quant) SetUpToDate(status bool)

func (*Quant) SetUpdater

func (q *Quant) SetUpdater(u Updater)

Safely sets the updater.

func (*Quant) SetValue

func (q *Quant) SetValue(val []float64)

Set the multiplier of a MASK or the value of a VALUE

func (*Quant) SetVerifier

func (q *Quant) SetVerifier(f func(*Quant))

Sets a verifier func, called each time the user attempts to set the quantity.

func (*Quant) Size3D

func (q *Quant) Size3D() []int

Grid size of the quantity, not necessarily the engine's grid size

func (*Quant) String

func (q *Quant) String() string

func (*Quant) Unit

func (q *Quant) Unit() Unit

The quantities unit.

func (*Quant) Update

func (q *Quant) Update()

If q.upToDate is false, update this node recursively. First Update all parents (on which this node depends), and then call Quant.updateSelf.Update(). upToDate is set true. See: Invalidate()

func (*Quant) Updater

func (q *Quant) Updater() Updater

Gets the updater

func (*Quant) Verify

func (q *Quant) Verify()

Verifies if the quantity's value makes sense. Called, e.g., after the user set a value. TODO: not used consistently

type QuantKind

type QuantKind int

Kind of quantity: VALUE, FIELD or MASK

const (
	VALUE QuantKind = 1 << (1 + iota) // A value is constant in space. Has a multiplier (to store the value) but a nil *array.
	FIELD                             // A field is space-dependent. Has no multiplier but allocated array.
	MASK                              // A mask is a point-wise multiplication of a field with a value. Has an array (possibly with NULL parts) and a multiplier.
)

func (QuantKind) String

func (k QuantKind) String() string

Human-readable string.

type RK12Solver

type RK12Solver struct {
	// contains filtered or unexported fields
}

func (*RK12Solver) Dependencies

func (s *RK12Solver) Dependencies() (children, parents []string)

Declares this solver's special dependencies

func (*RK12Solver) Step

func (s *RK12Solver) Step()

Take one time step

type ReduceUpdater

type ReduceUpdater struct {
	// contains filtered or unexported fields
}

Superclass for all reduce updaters.

func NewReduceUpdater

func NewReduceUpdater(in, out *Quant) *ReduceUpdater

New reducing updater. Automatically sets the dependency in -> out.

type SDotUpdater

type SDotUpdater struct {
	// contains filtered or unexported fields
}

func (*SDotUpdater) Update

func (u *SDotUpdater) Update()

type Solver

type Solver interface {
	Step()                                      // Takes one time step
	Dependencies() (children, parents []string) // Reports dependencies apart from the normal input/output. E.g.: time, dt,maxerror
}

type SumNode

type SumNode interface {
	MAddParent(name string, weight float64)
	AddParent(name string)
}

Quantities can be added to a SumNode

type SumReduceUpdater

type SumReduceUpdater ReduceUpdater

Updates an average quantity

func (*SumReduceUpdater) Update

func (this *SumReduceUpdater) Update()

type SumUpdater

type SumUpdater struct {
	// contains filtered or unexported fields
}

func (*SumUpdater) AddParent

func (u *SumUpdater) AddParent(name string)

Add parent with weight 1.

func (*SumUpdater) MAddParent

func (u *SumUpdater) MAddParent(name string, weight float64)

Adds a parent to the sum, i.e., its value*weight will be added to the sum

func (*SumUpdater) Update

func (u *SumUpdater) Update()

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table refers to an open data table to which space-independent output is appended during the simulation.

func NewTable

func NewTable(fname string) *Table

New table that will write in the file.

func (*Table) Close

func (t *Table) Close()

func (*Table) Tabulate

func (t *Table) Tabulate(quants []string)

Append the quantities value to the table.

type Unit

type Unit string

func (Unit) String

func (u Unit) String() string

type Updater

type Updater interface {
	Update()
}

Update() is called to update the value of a Quant.

func NewAverageUpdater

func NewAverageUpdater(in, out *Quant) Updater

Returns an updater that writes the average of in to out

func NewMaxAbsUpdater

func NewMaxAbsUpdater(in, out *Quant) Updater

Returns an updater that writes the maximum of absolute values of in to out

func NewMaxNormUpdater

func NewMaxNormUpdater(in, out *Quant) Updater

Returns an updater that writes the maximum of absolute values of in to out

func NewPeakUpdater

func NewPeakUpdater(input, peak *Quant) Updater

func NewSDotUpdater

func NewSDotUpdater(sum, parent1, parent2 *Quant, scaling float64) Updater

takes dot product

func NewSumReduceUpdater

func NewSumReduceUpdater(in, out *Quant) Updater

Returns an updater that writes the average of in to out

func NewSumUpdater

func NewSumUpdater(sum *Quant) Updater

type ΔUpdater

type ΔUpdater struct {
	// contains filtered or unexported fields
}

Update Δ of quantity

func NewΔUpdater

func NewΔUpdater(in, ref, out *Quant) *ΔUpdater

func (*ΔUpdater) Update

func (u *ΔUpdater) Update()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL