Documentation
¶
Index ¶
- func Embed[S, C any](parent tree.Node) *S
- func Run[S, C any]()
- func RunSim[S, C any](cfg *C) error
- func ScriptFieldWidget(field string) core.Value
- type BaseConfig
- type Config
- type GUI
- func (gui *GUI) AddLooperCtrl(p *tree.Plan, loops *looper.Stacks, prefix ...string)
- func (gui *GUI) AddNetView(tabName string) *netview.NetView
- func (gui *GUI) AddToolbarItem(p *tree.Plan, item ToolbarItem)
- func (gui *GUI) FinalizeGUI(closePrompt bool)
- func (gui *GUI) GoUpdateWindow()
- func (gui *GUI) IsRunning() bool
- func (gui *GUI) MakeBody(b tree.Node, sim any, fsroot fs.FS, appname, title, about string, ...)
- func (gui *GUI) NetView() *netview.NetView
- func (gui *GUI) SetStopNow()
- func (gui *GUI) StartRun()
- func (gui *GUI) StopNow() bool
- func (gui *GUI) Stopped(mode, level enums.Enum)
- func (gui *GUI) UpdateWindow()
- type Sim
- type ToolGhosting
- func (i ToolGhosting) Desc() string
- func (i ToolGhosting) Int64() int64
- func (i ToolGhosting) MarshalText() ([]byte, error)
- func (i *ToolGhosting) SetInt64(in int64)
- func (i *ToolGhosting) SetString(s string) error
- func (i ToolGhosting) String() string
- func (i *ToolGhosting) UnmarshalText(text []byte) error
- func (i ToolGhosting) Values() []enums.Enum
- type ToolbarItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Embed ¶
Embed runs a sim with the default config, embedding it under the given parent node. It returns the resulting sim. *S must implement Sim[C] (interface Sim parameterized by config type C).
func Run ¶
func Run[S, C any]()
Run runs a sim of the given type S with config type C. *S must implement Sim[C] (interface Sim parameterized by config type C), and *C must implement Config.
This is a high-level helper function designed to be called as one-liner from the main() function of the sim's command subdirectory with package main. This subdirectory has the same name as the sim name itself, ex: sims/ra25 has the package with the sim logic, and sims/ra25/ra25 has the compilable main().
Run uses the config type C to make a new Config object and set its default values with [Config.Defaults].
func RunSim ¶
RunSim runs a sim with the given config. *S must implement Sim[C] (interface Sim parameterized by config type C).
Unlike Run, this does not handle command-line config parsing. End users should typically use Run, which uses RunSim under the hood.
func ScriptFieldWidget ¶
ScriptFieldWidget is a core FieldWidget function to use a text Editor for the Params Script (or any other field named Script).
Types ¶
type BaseConfig ¶
type BaseConfig struct {
// Name is the short name of the sim.
Name string `display:"-"`
// Title is the longer title of the sim.
Title string `display:"-"`
// URL is a link to the online README or other documentation for this sim.
URL string `display:"-"`
// Doc is brief documentation of the sim.
Doc string `display:"-"`
// Includes has a list of additional config files to include.
// After configuration, it contains list of include files added.
Includes []string
// GUI indicates to open the GUI. Otherwise it runs automatically and quits,
// saving results to log files.
GUI bool `default:"true"`
// Debug indicates to report debugging information.
Debug bool
// GPU indicates to use the GPU for computation. This is on by default, except
// on web, where it is currently off by default.
GPU bool
}
BaseConfig contains the basic configuration parameters common to all sims.
func (*BaseConfig) AsBaseConfig ¶
func (bc *BaseConfig) AsBaseConfig() *BaseConfig
func (*BaseConfig) BaseDefaults ¶
func (bc *BaseConfig) BaseDefaults()
BaseDefaults sets default values not specified by struct tags. It is called automatically by NewConfig.
func (*BaseConfig) IncludesPtr ¶
func (bc *BaseConfig) IncludesPtr() *[]string
type Config ¶
type Config interface {
// AsBaseConfig returns the embedded [BaseConfig].
AsBaseConfig() *BaseConfig
// Defaults sets default values for config fields.
// Helper functions such as [Run], [Embed], and [NewConfig] already set defaults
// based on struct tags, so you only need to set non-tag-based defaults here.
Defaults()
}
Config is an interface implemented by all Sim config types. To implement Config, you must embed BaseConfig. You must implement [Config.Defaults] yourself.
type GUI ¶
type GUI struct {
lab.Browser
// CycleUpdateInterval is number of cycles between updates of cycle-level plots.
CycleUpdateInterval int
// Active is true if the GUI is configured and running
Active bool `display:"-"`
// NetViews are the created netviews.
NetViews []*netview.NetView
// 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:"-"`
// Readme is the sim readme frame
Readme *core.Frame `display:"-"`
// OnStop is called when running is stopped through the GUI,
// via the Stopped method. It should update the network view for example.
OnStop func(mode, level enums.Enum)
// StopLevel is the enum to use when the stop button is pressed.
StopLevel enums.Enum
// contains filtered or unexported fields
}
GUI manages all standard elements of a simulation Graphical User Interface
func NewGUIBody ¶
NewGUIBody returns a new GUI, with an initialized Body by calling [gui.MakeBody].
func (*GUI) AddLooperCtrl ¶
AddLooperCtrl adds toolbar control for looper.Stacks with Init, Run, Step controls, with selector for which stack is being controlled. A prefix can optionally be provided if multiple loops are used.
func (*GUI) AddNetView ¶
AddNetView adds NetView in tab with given name
func (*GUI) AddToolbarItem ¶
func (gui *GUI) AddToolbarItem(p *tree.Plan, item ToolbarItem)
AddToolbarItem adds a toolbar item but also checks when it be active in the UI
func (*GUI) FinalizeGUI ¶
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) MakeBody ¶
func (gui *GUI) MakeBody(b tree.Node, sim any, fsroot fs.FS, appname, title, about string, readme ...embed.FS)
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. It takes an optional fs with a README.md file.
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) 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 with the given arguments, 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 Sim ¶
type Sim[C any] interface { // SetConfig sets the sim config. SetConfig(cfg *C) ConfigSim() Init() ConfigGUI(b tree.Node) // Body returns the [core.Body] used by the sim. Body() *core.Body RunNoGUI() }
Sim is an interface implemented by all sim types. It is parameterized by the config type C. *C must implement Config.
type ToolGhosting ¶
type ToolGhosting int32 //enums:enum
ToolGhosting the mode enum
const ( ActiveStopped ToolGhosting = iota ActiveRunning ActiveAlways )
The evaluation modes for when a tool bar can be clicked
const ToolGhostingN ToolGhosting = 3
ToolGhostingN is the highest valid value for type ToolGhosting, plus one.
func ToolGhostingValues ¶
func ToolGhostingValues() []ToolGhosting
ToolGhostingValues returns all possible values for the type ToolGhosting.
func (ToolGhosting) Desc ¶
func (i ToolGhosting) Desc() string
Desc returns the description of the ToolGhosting value.
func (ToolGhosting) Int64 ¶
func (i ToolGhosting) Int64() int64
Int64 returns the ToolGhosting value as an int64.
func (ToolGhosting) MarshalText ¶
func (i ToolGhosting) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*ToolGhosting) SetInt64 ¶
func (i *ToolGhosting) SetInt64(in int64)
SetInt64 sets the ToolGhosting value from an int64.
func (*ToolGhosting) SetString ¶
func (i *ToolGhosting) SetString(s string) error
SetString sets the ToolGhosting value from its string representation, and returns an error if the string is invalid.
func (ToolGhosting) String ¶
func (i ToolGhosting) String() string
String returns the string representation of this ToolGhosting value.
func (*ToolGhosting) UnmarshalText ¶
func (i *ToolGhosting) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (ToolGhosting) Values ¶
func (i ToolGhosting) Values() []enums.Enum
Values returns all possible values for the type ToolGhosting.
type ToolbarItem ¶
type ToolbarItem struct {
Label string
Icon icons.Icon
Tooltip string
Active ToolGhosting
Func func()
}
ToolbarItem holds the configuration values for a toolbar item