wavesim

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: BSD-3-Clause Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GPUInitialized is true once the GPU system has been initialized.
	// Prevents multiple initializations.
	GPUInitialized bool

	// ComputeGPU is the compute gpu device.
	// Set this prior to calling GPUInit() to use an existing device.
	ComputeGPU *gpu.GPU

	// BorrowedGPU is true if our ComputeGPU is set externally,
	// versus created specifically for this system. If external,
	// we don't release it.
	BorrowedGPU bool

	// UseGPU indicates whether to use GPU vs. CPU.
	UseGPU bool
)
View Source
var (
	// Params contains the full set of simulation parameters.
	//gosl:group Params
	//gosl:read-only
	Params []Parameters

	// NeighOffs are neighborhood offsets for 3D 26 neighbors: [26][3]
	//gosl:dims 2
	NeighOffs *tensor.Int32

	// LaplacianWts are Laplacian weighting factors for 3D 26 neighbors.
	//gosl:dims 1
	LaplacianWts *tensor.Float32

	// Ctx has the Context state values.
	//gosl:group State
	Ctx []Context

	// State is the overall wave state, with inner-most index being the current
	// and previous states. [Z][Y][X][VarsN][2]
	// The display shows X-Y planes stacked in the Z dimension.
	//gosl:dims 5
	State *tensor.Float32
)

vars are all the global vars for GPU / CPU computation.

View Source
var GPUSystem *gpu.ComputeSystem

GPUSystem is a GPU compute System with kernels operating on the same set of data variables.

View Source
var MinUnitHeight = float32(1.0e-6)

MinUnitHeight ensures that there is always at least some dimensionality to the unit cubes -- affects transparency rendering etc

View Source
var NilColor = color.RGBA{0x20, 0x20, 0x20, 0x40}
View Source
var TensorStrides tensor.Uint32

Tensor stride variables

Functions

func FormDialog

func FormDialog(ctx core.Widget, v any, title string)

FormDialog opens a dialog in a new, separate window for viewing / editing the given struct object, in the context of the given ctx widget.

func GPUInit

func GPUInit()

GPUInit initializes the GPU compute system, configuring system(s), variables and kernels. It is safe to call multiple times: detects if already run.

func GPURelease

func GPURelease()

GPURelease releases the GPU compute system resources. Call this at program exit.

func Laplacian26

func Laplacian26(x, y, z, vidx, tidx int32, ctr float32) float32

Laplacian26 computes the 3D Laplacian across 26 neighbors, for given x,y,z center coordinates, variable index vidx, and cur / prev time index tidx. ctr is the center value.

func PotentialEnergy26

func PotentialEnergy26(x, y, z, vidx, tidx int32, ctr float32) float32

PotentialEnergy26 computes the 3D potential energy across 26 neighbors, for given x,y,z center coordinates, variable index vidx, and cur / prev time index tidx. ctr is the center value.

func ReadFromGPU

func ReadFromGPU(vars ...GPUVars)

ReadFromGPU starts the process of copying vars to the GPU.

func RunDone

func RunDone(syncVars ...GPUVars)

RunDone must be called after Run* calls to start compute kernels. This actually submits the kernel jobs to the GPU, and adds commands to synchronize the given variables back from the GPU to the CPU. After this function completes, the GPU results will be available in the specified variables.

func RunGPUSync

func RunGPUSync()

RunGPUSync can be called to synchronize data between CPU and GPU. Any prior ToGPU* calls will execute to send data to the GPU, and any subsequent RunDone* calls will copy data back from the GPU.

func RunOneWave1DKernel

func RunOneWave1DKernel(n int, syncVars ...GPUVars)

RunOneWave1DKernel runs the Wave1DKernel kernel with given number of elements, on either the CPU or GPU depending on the UseGPU variable. This version then calls RunDone with the given variables to sync after the Run, for a single-shot Run-and-Done call. If multiple kernels can be run in sequence, it is much more efficient to do multiple Run* calls followed by a RunDone call.

func RunOneWave3DKernel

func RunOneWave3DKernel(n int, syncVars ...GPUVars)

RunOneWave3DKernel runs the Wave3DKernel kernel with given number of elements, on either the CPU or GPU depending on the UseGPU variable. This version then calls RunDone with the given variables to sync after the Run, for a single-shot Run-and-Done call. If multiple kernels can be run in sequence, it is much more efficient to do multiple Run* calls followed by a RunDone call.

func RunWave1DKernel

func RunWave1DKernel(n int)

RunWave1DKernel runs the Wave1DKernel kernel with given number of elements, on either the CPU or GPU depending on the UseGPU variable. Can call multiple Run* kernels in a row, which are then all launched in the same command submission on the GPU, which is by far the most efficient. MUST call RunDone (with optional vars to sync) after all Run calls. Alternatively, a single-shot RunOneWave1DKernel call does Run and Done for a single run-and-sync case.

func RunWave1DKernelCPU

func RunWave1DKernelCPU(n int)

RunWave1DKernelCPU runs the Wave1DKernel kernel on the CPU.

func RunWave1DKernelGPU

func RunWave1DKernelGPU(n int)

RunWave1DKernelGPU runs the Wave1DKernel kernel on the GPU. See RunWave1DKernel for more info.

func RunWave3DKernel

func RunWave3DKernel(n int)

RunWave3DKernel runs the Wave3DKernel kernel with given number of elements, on either the CPU or GPU depending on the UseGPU variable. Can call multiple Run* kernels in a row, which are then all launched in the same command submission on the GPU, which is by far the most efficient. MUST call RunDone (with optional vars to sync) after all Run calls. Alternatively, a single-shot RunOneWave3DKernel call does Run and Done for a single run-and-sync case.

func RunWave3DKernelCPU

func RunWave3DKernelCPU(n int)

RunWave3DKernelCPU runs the Wave3DKernel kernel on the CPU.

func RunWave3DKernelGPU

func RunWave3DKernelGPU(n int)

RunWave3DKernelGPU runs the Wave3DKernel kernel on the GPU. See RunWave3DKernel for more info.

func SyncFromGPU

func SyncFromGPU(vars ...GPUVars)

SyncFromGPU synchronizes vars from the GPU to the actual variable.

func ToGPU

func ToGPU(vars ...GPUVars)

ToGPU copies given variables to the GPU for the system.

func ToGPUTensorStrides

func ToGPUTensorStrides()

ToGPUTensorStrides gets tensor strides and starts copying to the GPU.

func Wave1DKernel

func Wave1DKernel(i uint32)

Wave1DKernel is the kernel for computing the Wave1D equations.

func Wave1DViewAll added in v0.0.3

func Wave1DViewAll(view *View)

Wave1DViewAll configures the

func Wave3DKernel

func Wave3DKernel(i uint32)

Wave3DKernel is the kernel for computing the Wave3D equations.

Types

type Config

type Config struct {
	// GPU determines whether to use the GPU.
	GPU bool `default:"true"`

	// GUI determines whether to show the GUI.
	GUI bool `default:"true"`

	// Equation to run
	Equation Equations

	// Size of Universe to run. This is only the active portion, excluding
	// edges at all sizes (add 2 to each dim).
	Size math32.Vector3i

	// ViewInterval is how often to update the view
	ViewInterval int `min:"1"`

	// MaxSteps is the maximum number of steps to run.
	MaxSteps int
}

Config contains overall simulation configuration options.

func (*Config) Defaults

func (cfg *Config) Defaults()

func (*Config) SizeFull

func (cfg *Config) SizeFull() math32.Vector3i

type Context

type Context struct {
	// Size is the 3D size of the state, EXCLUSIVE of edges (add 2 to each dim).
	Size slvec.Vector3i

	// Step is the current simulation timestep.
	Step int32

	// CurState is either 0 or 1, indicating which state variables
	// are currently being updated on this compute pass.
	CurState int32
	// contains filtered or unexported fields
}

Context contains all simulation counters and other context. This is only other state shared with GPU.

func GetCtx

func GetCtx(idx uint32) *Context

GetCtx returns a pointer to the given global variable: Ctx []Context at given index. This directly processed in the GPU code, so this function call is an equivalent for the CPU.

func (*Context) Init

func (ctx *Context) Init()

func (*Context) PrevState

func (ctx *Context) PrevState() int32

PrevState returns the index for the previous state, relative to CurState.

func (*Context) SizeFull

func (ctx *Context) SizeFull() math32.Vector3i

func (*Context) StateCoords

func (ctx *Context) StateCoords(idx uint32, x, y, z *int32) bool

StateCoords returns the x,y,z coordinates for given index into the state, where index is in Size units of active states, excluding edges. Resulting coords have 1 added to each, so they are valid coordinates into actual State. returns false if the index is out of range for size.

func (*Context) StepInc

func (ctx *Context) StepInc()

StepInc increments for next step of processing.

type CurPrev

type CurPrev int32 //enums:enum

CurPrev for Current vs Previous state access.

const (
	// Current selects the current state value (most recently updated).
	Current CurPrev = iota

	// Previous selects the previous state value.
	Previous
)
const CurPrevN CurPrev = 2

CurPrevN is the highest valid value for type CurPrev, plus one.

func CurPrevValues

func CurPrevValues() []CurPrev

CurPrevValues returns all possible values for the type CurPrev.

func (CurPrev) Desc

func (i CurPrev) Desc() string

Desc returns the description of the CurPrev value.

func (CurPrev) Int64

func (i CurPrev) Int64() int64

Int64 returns the CurPrev value as an int64.

func (CurPrev) MarshalText

func (i CurPrev) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*CurPrev) SetInt64

func (i *CurPrev) SetInt64(in int64)

SetInt64 sets the CurPrev value from an int64.

func (*CurPrev) SetString

func (i *CurPrev) SetString(s string) error

SetString sets the CurPrev value from its string representation, and returns an error if the string is invalid.

func (CurPrev) String

func (i CurPrev) String() string

String returns the string representation of this CurPrev value.

func (*CurPrev) UnmarshalText

func (i *CurPrev) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (CurPrev) Values

func (i CurPrev) Values() []enums.Enum

Values returns all possible values for the type CurPrev.

type Display

type Display struct {
	// On determines if display is updated.
	On bool

	// Interval is the number of time steps between display updates.
	Interval int
}

Display contains display parameters.

type Edges

type Edges int32 //enums:enum

Edges determines how to handle the edges.

const (
	// EdgesFixed keeps the edge values fixed at initial values
	EdgesFixed Edges = iota

	// EdgesWrap copies edge values from other side, effectively wrapping
	// the space around on itself like a torus.
	EdgesWrap
)
const EdgesN Edges = 2

EdgesN is the highest valid value for type Edges, plus one.

func EdgesValues

func EdgesValues() []Edges

EdgesValues returns all possible values for the type Edges.

func (Edges) Desc

func (i Edges) Desc() string

Desc returns the description of the Edges value.

func (Edges) Int64

func (i Edges) Int64() int64

Int64 returns the Edges value as an int64.

func (Edges) MarshalText

func (i Edges) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Edges) SetInt64

func (i *Edges) SetInt64(in int64)

SetInt64 sets the Edges value from an int64.

func (*Edges) SetString

func (i *Edges) SetString(s string) error

SetString sets the Edges value from its string representation, and returns an error if the string is invalid.

func (Edges) String

func (i Edges) String() string

String returns the string representation of this Edges value.

func (*Edges) UnmarshalText

func (i *Edges) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Edges) Values

func (i Edges) Values() []enums.Enum

Values returns all possible values for the type Edges.

type Equations

type Equations int32 //enums:enum

Equations are the different implemented equations to simulate.

const (
	// Wave1D is the basic wave equation in one dimension (X).
	Wave1D Equations = iota

	// Wave3D is the basic wave equation in three dimensions.
	Wave3D
)
const EquationsN Equations = 2

EquationsN is the highest valid value for type Equations, plus one.

func EquationsValues

func EquationsValues() []Equations

EquationsValues returns all possible values for the type Equations.

func (Equations) Desc

func (i Equations) Desc() string

Desc returns the description of the Equations value.

func (Equations) Int64

func (i Equations) Int64() int64

Int64 returns the Equations value as an int64.

func (Equations) MarshalText

func (i Equations) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Equations) SetInt64

func (i *Equations) SetInt64(in int64)

SetInt64 sets the Equations value from an int64.

func (*Equations) SetString

func (i *Equations) SetString(s string) error

SetString sets the Equations value from its string representation, and returns an error if the string is invalid.

func (Equations) String

func (i Equations) String() string

String returns the string representation of this Equations value.

func (*Equations) UnmarshalText

func (i *Equations) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Equations) Values

func (i Equations) Values() []enums.Enum

Values returns all possible values for the type Equations.

type GPUVars

type GPUVars int32 //enums:enum

GPUVars is an enum for GPU variables, for specifying what to sync.

const (
	ParamsVar       GPUVars = 0
	NeighOffsVar    GPUVars = 1
	LaplacianWtsVar GPUVars = 2
	CtxVar          GPUVars = 3
	StateVar        GPUVars = 4
)
const GPUVarsN GPUVars = 5

GPUVarsN is the highest valid value for type GPUVars, plus one.

func GPUVarsValues

func GPUVarsValues() []GPUVars

GPUVarsValues returns all possible values for the type GPUVars.

func (GPUVars) Desc

func (i GPUVars) Desc() string

Desc returns the description of the GPUVars value.

func (GPUVars) Int64

func (i GPUVars) Int64() int64

Int64 returns the GPUVars value as an int64.

func (GPUVars) MarshalText

func (i GPUVars) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*GPUVars) SetInt64

func (i *GPUVars) SetInt64(in int64)

SetInt64 sets the GPUVars value from an int64.

func (*GPUVars) SetString

func (i *GPUVars) SetString(s string) error

SetString sets the GPUVars value from its string representation, and returns an error if the string is invalid.

func (GPUVars) String

func (i GPUVars) String() string

String returns the string representation of this GPUVars value.

func (*GPUVars) UnmarshalText

func (i *GPUVars) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (GPUVars) Values

func (i GPUVars) Values() []enums.Enum

Values returns all possible values for the type GPUVars.

type GUI

type GUI struct {
	lab.Browser

	// Active is true if the GUI is configured and running
	Active bool `display:"-"`

	// SimForm displays the Sim object fields in the left panel.
	SimForm *core.Form `display:"-"`

	// Body is the entire content of the sim window.
	Body *core.Body `display:"-"`

	// view if created.
	View *View
	// contains filtered or unexported fields
}

GUI manages all standard elements of a simulation Graphical User Interface

func NewGUIBody

func NewGUIBody(b tree.Node, sim *Sim, fsroot fs.FS, appname, title, about string) *GUI

NewGUIBody returns a new GUI, with an initialized Body by calling [gui.MakeBody].

func (*GUI) AddView

func (gui *GUI) AddView(tabName string) *View

AddView adds View in tab with given name

func (*GUI) FinalizeGUI

func (gui *GUI) FinalizeGUI(closePrompt bool)

FinalizeGUI wraps the end functionality of the GUI

func (*GUI) GoUpdateWindow

func (gui *GUI) GoUpdateWindow()

GoUpdateWindow triggers an update on window body, for calling from a separate goroutine.

func (*GUI) IsRunning

func (gui *GUI) IsRunning() bool

IsRunning returns the state of the isRunning flag, under a mutex.

func (*GUI) MakeBody

func (gui *GUI) MakeBody(b tree.Node, sim *Sim, fsroot fs.FS, appname, title, about string)

MakeBody initializes default Body with a top-level core.Splits containing a core.Form editor of the given sim object, and a filetree for the data filesystem rooted at fsroot, and with given app name, title, and about information. The first arg is an optional existing core.Body to make into: if nil then a new body is made first.

func (*GUI) MakeToolbar

func (gui *GUI) MakeToolbar(p *tree.Plan)

func (*GUI) SetStopNow

func (gui *GUI) SetStopNow()

SetStopNow sets the stopNow flag to true, under a mutex.

func (*GUI) StartRun

func (gui *GUI) StartRun()

StartRun should be called whenever a process starts running. It sets stopNow = false and isRunning = true under a mutex.

func (*GUI) StopNow

func (gui *GUI) StopNow() bool

StopNow returns the state of the stopNow flag, under a mutex.

func (*GUI) Stopped

func (gui *GUI) Stopped()

Stopped is called when a run method stops running, from a separate goroutine (do not call from main event loop). Turns off the isRunning flag, calls OnStop, and calls GoUpdateWindow to update window state.

func (*GUI) UpdateWindow

func (gui *GUI) UpdateWindow()

UpdateWindow triggers an update on window body, to be called from within the normal event processing loop. See GoUpdateWindow for version to call from separate goroutine.

type NPanels

type NPanels int32 //enums:enum -trim-prefix=Panels

NPanels selects number of panels.

const (
	// One panel
	PanelsOne NPanels = iota

	// Two side-by-side panels
	PanelsTwo

	// Four bottom-top and side-by-side panels
	PanelsFour
)
const NPanelsN NPanels = 3

NPanelsN is the highest valid value for type NPanels, plus one.

func NPanelsValues

func NPanelsValues() []NPanels

NPanelsValues returns all possible values for the type NPanels.

func (NPanels) Desc

func (i NPanels) Desc() string

Desc returns the description of the NPanels value.

func (NPanels) Int64

func (i NPanels) Int64() int64

Int64 returns the NPanels value as an int64.

func (NPanels) MarshalText

func (i NPanels) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (NPanels) N

func (np NPanels) N() int

func (*NPanels) SetInt64

func (i *NPanels) SetInt64(in int64)

SetInt64 sets the NPanels value from an int64.

func (*NPanels) SetString

func (i *NPanels) SetString(s string) error

SetString sets the NPanels value from its string representation, and returns an error if the string is invalid.

func (NPanels) String

func (i NPanels) String() string

String returns the string representation of this NPanels value.

func (*NPanels) UnmarshalText

func (i *NPanels) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (NPanels) Values

func (i NPanels) Values() []enums.Enum

Values returns all possible values for the type NPanels.

type PanelView

type PanelView struct {
	// Variable to display.
	Var enums.Enum

	// Select which state to view
	CurPrev CurPrev

	// Mode is how the state values are displayed for this panel.
	Mode ViewModes

	// Offset is an additional offset from the global Start,
	// enforced to be within the displayable size.
	Offset math32.Vector3i
}

PanelView for what each panel in the View renders.

type Parameters

type Parameters struct {
	// Edges determines how to handle the edges.
	Edges Edges

	// DoEnergy determines if energy is computed (when not necessary).
	DoEnergy slbool.Bool

	// Units are the relevant unit factors.
	Units Units
	// contains filtered or unexported fields
}

Parameters contains the full set of simulation parameters. this is uploaded to the GPU.

func GetParams

func GetParams(idx uint32) *Parameters

GetParams returns a pointer to the given global variable: Params []Parameters at given index. This directly processed in the GPU code, so this function call is an equivalent for the CPU.

func (*Parameters) Defaults

func (pr *Parameters) Defaults()

func (*Parameters) Update

func (pr *Parameters) Update()

type PlaneMesh

type PlaneMesh struct {
	xyz.MeshBase
	// contains filtered or unexported fields
}

PlaneMesh is a xyz.Mesh that represents an X-Y plane through the state, as either a Heightfield or bars. It is dynamically updated using the Set method. The geometry is literal in the size: 0,0,0 lower-left corner and increasing X,Z in display for the X,Y plane. Display applies an overall scaling to make it fit within the larger view.

func NewPlaneMesh

func NewPlaneMesh(sc *xyz.Scene, view *View, panel int) *PlaneMesh

NewPlaneMesh adds PlaneMesh mesh to given scene for given layer

func (*PlaneMesh) MeshSize

func (pm *PlaneMesh) MeshSize() (nVtx, nIndex int, hasColor bool)

func (*PlaneMesh) Set

func (pm *PlaneMesh) Set(vtxAry, normAry, texAry, clrAry math32.ArrayF32, idxAry math32.ArrayU32)

func (*PlaneMesh) SetBars

func (pm *PlaneMesh) SetBars(vtxAry, normAry, texAry, clrAry math32.ArrayF32, idxAry math32.ArrayU32)

func (*PlaneMesh) SetPlane

func (pm *PlaneMesh) SetPlane(vtxAry, normAry, texAry, clrAry math32.ArrayF32, idxAry math32.ArrayU32)

type PlaneObj

type PlaneObj struct {
	xyz.Solid
	// contains filtered or unexported fields
}

PlaneObj is the Plane 3D object within the View

func NewPlaneObj

func NewPlaneObj(parent ...tree.Node) *PlaneObj

NewPlaneObj returns a new PlaneObj with the given optional parent: PlaneObj is the Plane 3D object within the View

type Scene

type Scene struct {
	xyzcore.Scene

	View *View
}

Scene is a Widget for managing the 3D Scene of the NetView

func NewScene

func NewScene(parent ...tree.Node) *Scene

NewScene returns a new Scene with the given optional parent: Scene is a Widget for managing the 3D Scene of the NetView

func (*Scene) Init

func (sw *Scene) Init()

func (*Scene) MouseDownEvent

func (sw *Scene) MouseDownEvent(e events.Event)

func (*Scene) SetView

func (t *Scene) SetView(v *View) *Scene

SetView sets the Scene.View

func (*Scene) WidgetTooltip

func (sw *Scene) WidgetTooltip(pos image.Point) (string, image.Point)

type Settings

type Settings struct {

	// Number of different panels, each capable of displaying a different variable, mode,
	// and location in the state.
	NPanels NPanels

	// Mode is how the state values are displayed.
	Mode ViewModes

	// Height is how high the values are, in normalized units.
	Height float32

	// Camera specifies the initial camera view to show the scene
	// 1 = default = top-down, 2 = side-long
	Camera int

	// size of a single bar element, where 1 = full width and no space.. .9 default
	BarSize float32 `min:"0.1" max:"1" step:"0.1" default:"0.9"`

	// name of color map to use
	ColorMap core.ColorMapName `display:"-"`

	// size of the labels
	LabelSize float32 `min:"0.01" max:".1" step:"0.01" default:"0.05"`

	// opacity (0-1) of zero values. greater magnitude values become increasingly
	// opaque on either side of this minimum.
	ZeroAlpha float32 `min:"0" max:"1" step:"0.1" default:"0.5"`
}

Settings for how the View is rendered.

func (*Settings) Defaults

func (nv *Settings) Defaults()

type Sim

type Sim struct {
	// Params contains the current simulation parameters.
	Params *Parameters `new-window:"+" display:"no-inline"`

	// Config contains the broader running configuration.
	Config *Config `new-window:"+" display:"no-inline"`

	// ConfigFunc is run at initial configuration, after all default configuration,
	// and can then change any parameters etc.
	ConfigFunc func(sim *Sim) `display:"-"`

	// InitFunc is run at initialization, and should be used to set
	// the initial State, using functions in init.
	InitFunc func(sim *Sim) `display:"-"`

	// Root is the root tensorfs directory, where all stats and other misc sim data goes.
	Root *tensorfs.Node `display:"-"`

	// Stats has the stats directory within Root.
	Stats *tensorfs.Node `display:"-"`

	// Current has the current stats values within Stats.
	Current *tensorfs.Node `display:"-"`

	// GUI manages all the GUI elements
	GUI GUI // `display:"-"`

	// StateVars points the current state variables in effect.
	StateVars enums.Enum `display:"-"`

	// Rand is the random number generator for the network.
	// all random calls must use this.
	// Set seed here for weight initialization values.
	Rand randx.Rand `display:"-"`

	// Random seed to be set at the start of configuring
	// the network and initializing the weights.
	// Set this to get a different set of weights.
	RandSeed int64 `display:"-"`

	// RandSeeds is a list of random seeds to use for each run.
	RandSeeds randx.Seeds `display:"-"`
	// contains filtered or unexported fields
}

Sim contains everything for the simulation.

func Embed

func Embed(parent tree.Node, configFunc, initFunc func(sim *Sim)) *Sim

func Run

func Run(configFunc, initFunc func(sim *Sim)) *Sim

func RunSim

func RunSim(cfg *Config, configFunc, initFunc func(sim *Sim)) *Sim

func (*Sim) ConfigGUI

func (ss *Sim) ConfigGUI(b tree.Node)

func (*Sim) ConfigSim

func (ss *Sim) ConfigSim()

func (*Sim) ConfigState

func (ss *Sim) ConfigState()

func (*Sim) ConfigVars

func (ss *Sim) ConfigVars()

func (*Sim) CopyCurToPrev

func (ss *Sim) CopyCurToPrev()

CopyCurToPrev copies the current values to previous values for all variables.

func (*Sim) Init

func (ss *Sim) Init()

Init initializes the state and prepares everything for running.

func (*Sim) InitRandSeed

func (ss *Sim) InitRandSeed(run int)

func (*Sim) MovingWavePacket

func (ss *Sim) MovingWavePacket(vr enums.Enum, dim math32.Dims, ctr math32.Vector3i, dir, period, width, phase, amp float32)

MovingWavePacket adds moving wave packet along given dimension, to given variable.

func (*Sim) Run

func (ss *Sim) Run()

Run runs until stopped or Step > MaxSteps. Must be called by goroutine.

func (*Sim) RunNoGUI

func (ss *Sim) RunNoGUI()

func (*Sim) Sine

func (ss *Sim) Sine(vr enums.Enum, dim math32.Dims, period, phase, amp, off float32)

Sine adds sine wave values along given dimension, to given variable.

func (*Sim) StepN

func (ss *Sim) StepN(n int)

StepN runs given number of steps. Must be called by goroutine.

func (*Sim) StepRun

func (ss *Sim) StepRun()

StepRun does one step of running. Must be called from goroutine.

func (*Sim) Stopped

func (ss *Sim) Stopped()

Stopped should be called whenever running stops.

func (*Sim) UpdateView

func (ss *Sim) UpdateView()

func (*Sim) ViewInit

func (ss *Sim) ViewInit(fun func(view *View))

ViewInit adds given function to view initialization functions. Called in reverse of order added. Equations typically set default init for specific equations (e.g., variable), added at the end.

func (*Sim) WaveConfig

func (ss *Sim) WaveConfig()

type Units

type Units struct {
	// C is the speed of light factor
	C float32

	// CSq = C^2
	CSq float32 `edit:"-"`

	// Inv2CSq = 1 / 2C^2
	Inv2CSq float32 `edit:"-"`
	// contains filtered or unexported fields
}

Units contains all the relevant units

func (*Units) Defaults

func (un *Units) Defaults()

func (*Units) Update

func (un *Units) Update()

type VarSettinger

type VarSettinger interface {
	SetVarSettings(vs *VarSettings)
}

VarSettinger sets variable parameters

type VarSettings

type VarSettings struct {

	// the variable
	Var enums.Enum

	// keep Min - Max centered around 0, and use negative heights for units
	// else use full min-max range for height (no negative heights)
	ZeroCtr bool

	// range to display
	Range minmax.Range32 `display:"inline"`

	// if not using fixed range, this is the actual range of data
	MinMax minmax.F32 `display:"inline"`
}

VarSettings holds parameters for display of each variable

func (*VarSettings) Defaults

func (vs *VarSettings) Defaults()

Defaults sets default values if otherwise not set

type View

type View struct {
	core.Frame

	// Var determines the set of variables being used.
	// actual variable to view is in the PanelView.
	Var enums.Enum `set:"-"`

	// Pannels are the view settings per panel (4 max).
	Panels [4]PanelView

	// Starting front-left corner location within state.
	Start math32.Vector3i

	// Size of planes
	Size math32.Vector3i

	// parameters for the list of variables to view
	VarSettings map[enums.Enum]*VarSettings

	// Settings are parameters controlling how the view is rendered
	Settings Settings

	// Counters are displayed at the bottom: time, etc.
	Counters string `set:"-" display:"-"`

	sync.Mutex
	// contains filtered or unexported fields
}

View is a Cogent Core Widget that provides a 3D view into state.

func NewView

func NewView(parent ...tree.Node) *View

NewView returns a new View with the given optional parent: View is a Cogent Core Widget that provides a 3D view into state.

func (*View) GetVarSettings added in v0.0.3

func (vw *View) GetVarSettings(vr enums.Enum) (*VarSettings, error)

func (*View) GetVarSettingsPanel added in v0.0.3

func (vw *View) GetVarSettingsPanel(panelNo int) (*VarSettings, error)

func (*View) GoUpdateView

func (vw *View) GoUpdateView()

GoUpdateView is the update call to make from another go routine it does the proper blocking to coordinate with GUI updates generated on the main GUI thread.

func (*View) Init

func (vw *View) Init()

func (*View) MakeToolbar

func (vw *View) MakeToolbar(p *tree.Plan)

func (*View) MakeViewbar

func (vw *View) MakeViewbar(p *tree.Plan)

func (*View) PlaneAtNumber

func (vw *View) PlaneAtNumber(no int) *xyz.Group

PlaneAtNumber returns the xyz.Group that represents given plane number. nil if not found.

func (*View) Planes

func (vw *View) Planes() *xyz.Group

func (*View) SceneXYZ

func (vw *View) SceneXYZ() *xyz.Scene

func (*View) SelectCamera added in v0.0.3

func (vw *View) SelectCamera(camNo int)

SelectCamera selects the given pre-configured camera view, which have different angles. 1= top-down, 2 = head-on

func (*View) SetCounters

func (vw *View) SetCounters(ctrs string)

SetCounters sets the counters widget view display at bottom of netview

func (*View) SetCurPrev

func (vw *View) SetCurPrev(curprv CurPrev, panelNo int)

SetCurPrev sets the current vs. previous state viewing

func (*View) SetMode

func (vw *View) SetMode(mode ViewModes, panelNo int)

SetMode sets the display mode for given panel number. if panelNo < 0 then sets default for all panels.

func (*View) SetPanels

func (t *View) SetPanels(v [4]PanelView) *View

SetPanels sets the View.Panels: Pannels are the view settings per panel (4 max).

func (*View) SetSettings

func (t *View) SetSettings(v Settings) *View

SetSettings sets the View.Settings: Settings are parameters controlling how the view is rendered

func (*View) SetSize

func (t *View) SetSize(v math32.Vector3i) *View

SetSize sets the View.Size: Size of planes

func (*View) SetStart

func (t *View) SetStart(v math32.Vector3i) *View

SetStart sets the View.Start: Starting front-left corner location within state.

func (*View) SetVar

func (vw *View) SetVar(vr enums.Enum, panelNo int)

SetVar sets the variable to view and updates the display, for given panel number. If panelNo is -1, then this sets the global default for all panels, and doesn't update display.

func (*View) SetVarMinMax added in v0.0.3

func (vw *View) SetVarMinMax(vr enums.Enum, mn, mx float32)

SetVarMinMax sets the min and max range for given variable.

func (*View) SetVarSettings

func (t *View) SetVarSettings(v map[enums.Enum]*VarSettings) *View

SetVarSettings sets the View.VarSettings: parameters for the list of variables to view

func (*View) UpdateImpl

func (vw *View) UpdateImpl()

UpdateImpl does the guts of updating -- backend for Update or GoUpdate

func (*View) UpdatePlanes

func (vw *View) UpdatePlanes()

UpdatePlanes updates the planes display with any structural or current data changes. Very fast if no structural changes.

func (*View) UpdateView

func (vw *View) UpdateView()

UpdateView updates the display based on last recorded state of network.

func (*View) ValColor

func (vw *View) ValColor(raw float32, panelNo int) (scaled float32, clr color.RGBA)

ValColor returns the raw value, scaled value, and color representation for given raw value

func (*View) VarsListUpdate

func (vw *View) VarsListUpdate()

VarsListUpdate updates the list of network variables

func (*View) ViewDefaults

func (vw *View) ViewDefaults(se *xyz.Scene)

ViewDefaults are the default 3D view params

type ViewModes

type ViewModes int32 //enums:enum

ViewModes are different ways of displaying wave states.

const (
	// Plane displays a contiguous plane of values -- best for smooth states.
	Plane ViewModes = iota

	// Bars displays discrete bars at each point -- best for more discontinuous states.
	Bars
)
const ViewModesN ViewModes = 2

ViewModesN is the highest valid value for type ViewModes, plus one.

func ViewModesValues

func ViewModesValues() []ViewModes

ViewModesValues returns all possible values for the type ViewModes.

func (ViewModes) Desc

func (i ViewModes) Desc() string

Desc returns the description of the ViewModes value.

func (ViewModes) Int64

func (i ViewModes) Int64() int64

Int64 returns the ViewModes value as an int64.

func (ViewModes) MarshalText

func (i ViewModes) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*ViewModes) SetInt64

func (i *ViewModes) SetInt64(in int64)

SetInt64 sets the ViewModes value from an int64.

func (*ViewModes) SetString

func (i *ViewModes) SetString(s string) error

SetString sets the ViewModes value from its string representation, and returns an error if the string is invalid.

func (ViewModes) String

func (i ViewModes) String() string

String returns the string representation of this ViewModes value.

func (*ViewModes) UnmarshalText

func (i *ViewModes) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (ViewModes) Values

func (i ViewModes) Values() []enums.Enum

Values returns all possible values for the type ViewModes.

type WaveStates

type WaveStates int32 //enums:enum -trim-prefix=Wave

WaveStates are the state variables for Wave equations.

const (
	// WavePos is the position (height) wave state variable.
	WavePos WaveStates = iota

	// WaveVel is the velocity of wave state variable.
	WaveVel

	// WaveForce is the net force computed from neighbors.
	WaveForce

	// WaveKinetic is the kinetic energy.
	WaveKinetic

	// WavePotential is the potential energy.
	WavePotential

	// WaveEnergy is the total kinetic + potential energy.
	WaveEnergy
)
const WaveStatesN WaveStates = 6

WaveStatesN is the highest valid value for type WaveStates, plus one.

func WaveStatesValues

func WaveStatesValues() []WaveStates

WaveStatesValues returns all possible values for the type WaveStates.

func (WaveStates) Desc

func (i WaveStates) Desc() string

Desc returns the description of the WaveStates value.

func (WaveStates) Int64

func (i WaveStates) Int64() int64

Int64 returns the WaveStates value as an int64.

func (WaveStates) MarshalText

func (i WaveStates) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*WaveStates) SetInt64

func (i *WaveStates) SetInt64(in int64)

SetInt64 sets the WaveStates value from an int64.

func (*WaveStates) SetString

func (i *WaveStates) SetString(s string) error

SetString sets the WaveStates value from its string representation, and returns an error if the string is invalid.

func (WaveStates) SetVarSettings

func (ws WaveStates) SetVarSettings(vs *VarSettings)

func (WaveStates) String

func (i WaveStates) String() string

String returns the string representation of this WaveStates value.

func (*WaveStates) UnmarshalText

func (i *WaveStates) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (WaveStates) Values

func (i WaveStates) Values() []enums.Enum

Values returns all possible values for the type WaveStates.

Jump to

Keyboard shortcuts

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