wavesim

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: BSD-3-Clause Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Average27Sum is the sum of the AverageWts
	Average27Sum = float32(20.104084)

	// OneoAverage27Sum is 1.0/ sum of the AverageWts, for actual averaging
	OneoAverage27Sum = 0.049741138
)
View Source
const (
	Pi       = 3.14159265358979323846264338327950288419716939937510582097494459
	TwoPi    = 2 * Pi
	InvTwoPi = 1.0 / TwoPi
)

The following are constants used across many equations.

View Source
const (
	// C is the speed of light, m/s
	C = 299792458.0

	// Hbar is the normalized Planck constant h / (2 Pi) = J s = m^2 kg / s
	Hbar = 1.054571628e-34

	// E is the unit of electrical charge: C = A s
	E = 1.602176487e-19

	// EMass is the electron rest mass kg
	EMass = 9.10938215e-31

	// Mu0 is the magnetic constant, permeability of free space
	// N/A^2 = (m kg) / (s^2 A^2)
	Mu0 = 4.0 * math32.Pi * 1e-7

	// Eps0 is the electric constant, permittivity of free space = 1 / (mu0 c^2)
	// F/m = (s^4 A^2) / (m^3 kg)
	Eps0 = 1.0 / (Mu0 * C * C)

	// Alpha is the fine structure constant: e^2 / (hbar c 4pi eps0) (dimensionless)
	Alpha = 7.2973525376e-3

	// LambdaE is the Compton wavelength of the electron rest mass:
	// h / (m0 c) = (2 pi hbar) / (m0 c) = 2.42631e-12 m
	LambdaE = (2.0 * math32.Pi * Hbar) / (EMass * C)

	// LambdaBarE is the Compton wavelength of the electron rest mass in hbar
	// hbar / (m0 c) = 3.8615926771197e-13 m
	LambdaBarE = Hbar / (EMass * C)

	// A0 is the Bohr radius in hbar: hbar / (m0 c alpha) = 5.2917720859e-11 m
	A0 = Hbar / (EMass * C * Alpha)

	// Planck length, m
	Lp = 1.616252e-35

	// Planck time, s
	Tp = 5.39124e-44

	// Planck mass, kg
	Mp = 2.17644e-8

	// Planck current, A
	Ip = 3.47899e25
)

physical constants in SI units (m, s, kg, A, N, W)

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

	// FaceOffs are neighborhood offsets for 3D 18 faces: [x,y,z][-,+][9][3]
	//gosl:dims 4
	FaceOffs *tensor.Int32

	// NeighWts are weighting factors for 3D 26 neighbors.
	// [NeighWeightsN][27]
	//gosl:dims 2
	NeighWts *tensor.Float32

	// Ctx has the Context state values.
	//gosl:group State
	//gosl:read-only
	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
	//gosl:nbuffs 6
	State *tensor.Float32
)

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

View Source
var DiracShouldDisplay = []string{"Edges", "Energy", "C", "Hbar", "Mass", "Wavelength", "PacketWidth"}

DiracShouldDisplay determines which Parameters fields to display.

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 KGShouldDisplay = []string{"Edges", "Energy", "C", "Hbar", "Mass", "Wavelength", "PacketWidth"}

KGShouldDisplay determines which Parameters fields to display.

View Source
var MaxwellShouldDisplay = []string{"Edges", "C", "Mu0", "Eps0"}

MaxwellShouldDisplay determines which Parameters fields to display.

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 ParamsShouldDisplay []string

ParamsShouldDisplay should be set to an equation-specific list of Parameters field names to display. To simplify the GPU configuration, it is important to only have one struct with everything in it, so this simplifies things.

View Source
var ParticleDisplay = []string{"Edges", "Energy", "C", "Hbar", "Mass", "Wavelength", "PacketWidth", "Velocity", "Move"}

ParticleDisplay determines which Parameters fields to display.

View Source
var SchrodShouldDisplay = []string{"Edges", "Energy", "C", "Hbar", "Mass", "Wavelength", "PacketWidth"}

SchrodShouldDisplay determines which Parameters fields to display.

View Source
var TensorStrides tensor.Uint32

Tensor stride variables

View Source
var WaveShouldDisplay = []string{"Edges", "Energy", "C"}

WaveShouldDisplay determines which Parameters fields to display.

Functions

func Cab1DViewAll added in v0.0.5

func Cab1DViewAll(view *View)

Cab1DViewAll configures the View to display A and B, Cur and Prev

func Curl18 added in v0.0.5

func Curl18(x, y, z, vidx, tidx int32, cx, cy, cz *float32)

Curl18 computes the 3D curl across 18 neighbors on a field vector, for given x,y,z center coordinates, variable index vidx (to X component), and cur / prev time index tidx.

func DiracKernel added in v0.0.5

func DiracKernel(i uint32)

DiracKernel is the kernel for computing the Dirac equations, on scalar state values (WaveStates).

func Divergence18 added in v0.0.5

func Divergence18(x, y, z, vidx, tidx int32, dx, dy, dz *float32) float32

Divergence18 computes the 3D divergence across 18 neighbors, for given x,y,z center coordinates, variable index vidx, and cur / prev time index tidx. Div = sum of gradients.

func EdgeInBounds0 added in v0.0.5

func EdgeInBounds0(x, y, z, sx, sy, sz int32) bool

EdgeInBounds0 returns true if given coordinate is >= 0 and <= s.

func EdgeInBounds1 added in v0.0.5

func EdgeInBounds1(x, y, z, sx, sy, sz int32) bool

EdgeInBounds1 returns true if given coordinate is >= 1 and < s.

func EdgesWrapKernel added in v0.0.5

func EdgesWrapKernel(i uint32)

EdgesWrapKernel is the kernel for wrapping edge values

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 GetRandomNumber added in v0.0.5

func GetRandomNumber(index uint32, counter uint64, funIndex uint32) float32

GetRandomNumber returns a random number that depends on the index, counter and function index. We increment the counter after each cycle, so that we get new random numbers. This whole scheme exists to ensure equal results under different multithreading settings.

func Gradient18 added in v0.0.5

func Gradient18(x, y, z, vidx, tidx int32, dx, dy, dz *float32)

Gradient18 computes the 3D gradient across 18 neighbors, for given x,y,z center coordinates, variable index vidx, and cur / prev time index tidx.

func KleinGordonCDampKernel added in v0.0.5

func KleinGordonCDampKernel(i uint32)

KleinGordonCDampKernel is the kernel for computing the KleinGordonC equations, on complex wave state, at damped edges. Does Sommerfield damping where velocity = force.

func KleinGordonCKernel added in v0.0.5

func KleinGordonCKernel(i uint32)

KleinGordonCKernel is the kernel for computing the KleinGordonC equations, on complex wave state.

func KleinGordonDampKernel added in v0.0.5

func KleinGordonDampKernel(i uint32)

KleinGordonDampKernel is the kernel for computing the KleinGordon equations, on scalar state values (WaveStates), at damped edges. Does Sommerfield damping where velocity = force.

func KleinGordonKernel added in v0.0.5

func KleinGordonKernel(i uint32)

KleinGordonKernel is the kernel for computing the KleinGordon equations, on scalar state values (WaveStates).

func Laplacian1D added in v0.0.5

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

Laplacian1D computes the 1D Laplacian across 2 X dim neighbors, for given x,y,z center coordinates, variable index vidx, and cur / prev time index tidx. ctr is the center value.

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 LaplacianEdge1D added in v0.0.5

func LaplacianEdge1D(x, y, z, sx, sy, sz, vidx, tidx int32, ctr float32) float32

LaplacianEdge1D computes the 1D Laplacian across 2 X dim neighbors, for given x,y,z center coordinates, variable index vidx, and cur / prev time index tidx. ctr is the center value. For computation at the edge, checks against given full size bounds.

func LaplacianEdge26 added in v0.0.5

func LaplacianEdge26(x, y, z, sx, sy, sz, vidx, tidx int32, ctr float32) float32

LaplacianEdge26 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. For computation at the edge, checks against given full size bounds.

func MaxwellDampKernel added in v0.0.5

func MaxwellDampKernel(i uint32)

MaxwellDampKernel is the kernel for computing the Maxwell EM equations, on EM state values (EMStates), at damped edges. Does Sommerfield damping where velocity = force.

func MaxwellKernel added in v0.0.5

func MaxwellKernel(i uint32)

MaxwellKernel is the kernel for computing the Maxwell EM equations, on EM state values (EMStates).

func NeighAverage27 added in v0.0.5

func NeighAverage27(x, y, z, vidx, tidx int32) float32

NeighAverage27 computes the 3D average across 27 neighbors, including the center, for given x,y,z center coordinates, variable index vidx, and cur / prev time index tidx. ctr is the center value.

func ParticleKGCKernel added in v0.0.5

func ParticleKGCKernel(i uint32)

ParticleKGCKernel is the kernel for computing the stochastic particle with simple harmonic oscillator velocity and rest-mass factors along positive and negative directions for each axis, based on KG on complex wave state.

func ParticleKGCViewAll added in v0.0.5

func ParticleKGCViewAll(view *View)

ParticleKGCViewAll configures the View to display ParticleKGC values

func PotentialEnergy1D added in v0.0.5

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

PotentialEnergy1D computes the 1D potential energy across 2 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 RunDiracKernel added in v0.0.5

func RunDiracKernel(n int)

RunDiracKernel runs the DiracKernel 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 RunOneDiracKernel call does Run and Done for a single run-and-sync case.

func RunDiracKernelCPU added in v0.0.5

func RunDiracKernelCPU(n int)

RunDiracKernelCPU runs the DiracKernel kernel on the CPU.

func RunDiracKernelGPU added in v0.0.5

func RunDiracKernelGPU(n int)

RunDiracKernelGPU runs the DiracKernel kernel on the GPU. See RunDiracKernel for more info.

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 RunEdgesWrapKernel added in v0.0.5

func RunEdgesWrapKernel(n int)

RunEdgesWrapKernel runs the EdgesWrapKernel 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 RunOneEdgesWrapKernel call does Run and Done for a single run-and-sync case.

func RunEdgesWrapKernelCPU added in v0.0.5

func RunEdgesWrapKernelCPU(n int)

RunEdgesWrapKernelCPU runs the EdgesWrapKernel kernel on the CPU.

func RunEdgesWrapKernelGPU added in v0.0.5

func RunEdgesWrapKernelGPU(n int)

RunEdgesWrapKernelGPU runs the EdgesWrapKernel kernel on the GPU. See RunEdgesWrapKernel for more info.

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 RunKleinGordonCDampKernel added in v0.0.5

func RunKleinGordonCDampKernel(n int)

RunKleinGordonCDampKernel runs the KleinGordonCDampKernel 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 RunOneKleinGordonCDampKernel call does Run and Done for a single run-and-sync case.

func RunKleinGordonCDampKernelCPU added in v0.0.5

func RunKleinGordonCDampKernelCPU(n int)

RunKleinGordonCDampKernelCPU runs the KleinGordonCDampKernel kernel on the CPU.

func RunKleinGordonCDampKernelGPU added in v0.0.5

func RunKleinGordonCDampKernelGPU(n int)

RunKleinGordonCDampKernelGPU runs the KleinGordonCDampKernel kernel on the GPU. See RunKleinGordonCDampKernel for more info.

func RunKleinGordonCKernel added in v0.0.5

func RunKleinGordonCKernel(n int)

RunKleinGordonCKernel runs the KleinGordonCKernel 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 RunOneKleinGordonCKernel call does Run and Done for a single run-and-sync case.

func RunKleinGordonCKernelCPU added in v0.0.5

func RunKleinGordonCKernelCPU(n int)

RunKleinGordonCKernelCPU runs the KleinGordonCKernel kernel on the CPU.

func RunKleinGordonCKernelGPU added in v0.0.5

func RunKleinGordonCKernelGPU(n int)

RunKleinGordonCKernelGPU runs the KleinGordonCKernel kernel on the GPU. See RunKleinGordonCKernel for more info.

func RunKleinGordonDampKernel added in v0.0.5

func RunKleinGordonDampKernel(n int)

RunKleinGordonDampKernel runs the KleinGordonDampKernel 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 RunOneKleinGordonDampKernel call does Run and Done for a single run-and-sync case.

func RunKleinGordonDampKernelCPU added in v0.0.5

func RunKleinGordonDampKernelCPU(n int)

RunKleinGordonDampKernelCPU runs the KleinGordonDampKernel kernel on the CPU.

func RunKleinGordonDampKernelGPU added in v0.0.5

func RunKleinGordonDampKernelGPU(n int)

RunKleinGordonDampKernelGPU runs the KleinGordonDampKernel kernel on the GPU. See RunKleinGordonDampKernel for more info.

func RunKleinGordonKernel added in v0.0.5

func RunKleinGordonKernel(n int)

RunKleinGordonKernel runs the KleinGordonKernel 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 RunOneKleinGordonKernel call does Run and Done for a single run-and-sync case.

func RunKleinGordonKernelCPU added in v0.0.5

func RunKleinGordonKernelCPU(n int)

RunKleinGordonKernelCPU runs the KleinGordonKernel kernel on the CPU.

func RunKleinGordonKernelGPU added in v0.0.5

func RunKleinGordonKernelGPU(n int)

RunKleinGordonKernelGPU runs the KleinGordonKernel kernel on the GPU. See RunKleinGordonKernel for more info.

func RunMaxwellDampKernel added in v0.0.5

func RunMaxwellDampKernel(n int)

RunMaxwellDampKernel runs the MaxwellDampKernel 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 RunOneMaxwellDampKernel call does Run and Done for a single run-and-sync case.

func RunMaxwellDampKernelCPU added in v0.0.5

func RunMaxwellDampKernelCPU(n int)

RunMaxwellDampKernelCPU runs the MaxwellDampKernel kernel on the CPU.

func RunMaxwellDampKernelGPU added in v0.0.5

func RunMaxwellDampKernelGPU(n int)

RunMaxwellDampKernelGPU runs the MaxwellDampKernel kernel on the GPU. See RunMaxwellDampKernel for more info.

func RunMaxwellKernel added in v0.0.5

func RunMaxwellKernel(n int)

RunMaxwellKernel runs the MaxwellKernel 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 RunOneMaxwellKernel call does Run and Done for a single run-and-sync case.

func RunMaxwellKernelCPU added in v0.0.5

func RunMaxwellKernelCPU(n int)

RunMaxwellKernelCPU runs the MaxwellKernel kernel on the CPU.

func RunMaxwellKernelGPU added in v0.0.5

func RunMaxwellKernelGPU(n int)

RunMaxwellKernelGPU runs the MaxwellKernel kernel on the GPU. See RunMaxwellKernel for more info.

func RunOneDiracKernel added in v0.0.5

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

RunOneDiracKernel runs the DiracKernel 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 RunOneEdgesWrapKernel added in v0.0.5

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

RunOneEdgesWrapKernel runs the EdgesWrapKernel 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 RunOneKleinGordonCDampKernel added in v0.0.5

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

RunOneKleinGordonCDampKernel runs the KleinGordonCDampKernel 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 RunOneKleinGordonCKernel added in v0.0.5

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

RunOneKleinGordonCKernel runs the KleinGordonCKernel 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 RunOneKleinGordonDampKernel added in v0.0.5

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

RunOneKleinGordonDampKernel runs the KleinGordonDampKernel 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 RunOneKleinGordonKernel added in v0.0.5

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

RunOneKleinGordonKernel runs the KleinGordonKernel 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 RunOneMaxwellDampKernel added in v0.0.5

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

RunOneMaxwellDampKernel runs the MaxwellDampKernel 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 RunOneMaxwellKernel added in v0.0.5

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

RunOneMaxwellKernel runs the MaxwellKernel 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 RunOneParticleKGCKernel added in v0.0.5

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

RunOneParticleKGCKernel runs the ParticleKGCKernel 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 RunOneSchrodingerKernel added in v0.0.5

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

RunOneSchrodingerKernel runs the SchrodingerKernel 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 RunOneWaveDampKernel added in v0.0.5

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

RunOneWaveDampKernel runs the WaveDampKernel 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 RunOneWaveKernel added in v0.0.5

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

RunOneWaveKernel runs the WaveKernel 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 RunParticleKGCKernel added in v0.0.5

func RunParticleKGCKernel(n int)

RunParticleKGCKernel runs the ParticleKGCKernel 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 RunOneParticleKGCKernel call does Run and Done for a single run-and-sync case.

func RunParticleKGCKernelCPU added in v0.0.5

func RunParticleKGCKernelCPU(n int)

RunParticleKGCKernelCPU runs the ParticleKGCKernel kernel on the CPU.

func RunParticleKGCKernelGPU added in v0.0.5

func RunParticleKGCKernelGPU(n int)

RunParticleKGCKernelGPU runs the ParticleKGCKernel kernel on the GPU. See RunParticleKGCKernel for more info.

func RunSchrodingerKernel added in v0.0.5

func RunSchrodingerKernel(n int)

RunSchrodingerKernel runs the SchrodingerKernel 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 RunOneSchrodingerKernel call does Run and Done for a single run-and-sync case.

func RunSchrodingerKernelCPU added in v0.0.5

func RunSchrodingerKernelCPU(n int)

RunSchrodingerKernelCPU runs the SchrodingerKernel kernel on the CPU.

func RunSchrodingerKernelGPU added in v0.0.5

func RunSchrodingerKernelGPU(n int)

RunSchrodingerKernelGPU runs the SchrodingerKernel kernel on the GPU. See RunSchrodingerKernel for more info.

func RunWaveDampKernel added in v0.0.5

func RunWaveDampKernel(n int)

RunWaveDampKernel runs the WaveDampKernel 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 RunOneWaveDampKernel call does Run and Done for a single run-and-sync case.

func RunWaveDampKernelCPU added in v0.0.5

func RunWaveDampKernelCPU(n int)

RunWaveDampKernelCPU runs the WaveDampKernel kernel on the CPU.

func RunWaveDampKernelGPU added in v0.0.5

func RunWaveDampKernelGPU(n int)

RunWaveDampKernelGPU runs the WaveDampKernel kernel on the GPU. See RunWaveDampKernel for more info.

func RunWaveKernel added in v0.0.5

func RunWaveKernel(n int)

RunWaveKernel runs the WaveKernel 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 RunOneWaveKernel call does Run and Done for a single run-and-sync case.

func RunWaveKernelCPU added in v0.0.5

func RunWaveKernelCPU(n int)

RunWaveKernelCPU runs the WaveKernel kernel on the CPU.

func RunWaveKernelGPU added in v0.0.5

func RunWaveKernelGPU(n int)

RunWaveKernelGPU runs the WaveKernel kernel on the GPU. See RunWaveKernel for more info.

func SchrodingerKernel added in v0.0.5

func SchrodingerKernel(i uint32)

SchrodingerKernel is the kernel for computing the Schrodinger equations.

func StateSum added in v0.0.5

func StateSum(sz math32.Vector3i, vr enums.Enum, curPrv int32) float64

StateSum computes the sum of given variable at given cur vs. prev state with given non-edge size.

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 Wave1DViewAll added in v0.0.3

func Wave1DViewAll(view *View)

Wave1DViewAll configures the View to display Pos and Vel, Cur and Prev

func WaveDampKernel added in v0.0.5

func WaveDampKernel(i uint32)

WaveDampKernel is the kernel for computing the Wave equations at damped edges. Does Sommerfield damping where velocity = force.

func WaveKernel added in v0.0.5

func WaveKernel(i uint32)

WaveKernel is the kernel for computing the Wave equations.

func WavePacket added in v0.0.4

func WavePacket(x, d, wavelength, width, phase, amp float32) float32

WavePacket returns value for a gaussian * cosine wave packet for given linear dimension value x and 3D distance d.

Types

type CabStates added in v0.0.5

type CabStates int32 //enums:enum -trim-prefix=Cab

CabStates are the state variables for wave equations on a wave state with a single complex value, where A = real and B = complex components.

const (
	// CabPosA is the position (height) wave state variable
	// for the real complex component A.
	CabPosA CabStates = iota

	// CabPosB is the position (height) wave state variable
	// for the imaginary complex component B.
	CabPosB

	// CabVelA is the velocity of wave state variable
	// for the real complex component A.
	CabVelA

	// CabVelB is the velocity of wave state variable
	// for the imaginary complex component B.
	CabVelB

	// CabForceA is the net force computed from neighbors
	// for the real complex component A.
	CabForceA

	// CabForceB is the net force computed from neighbors
	// for the imaginary complex component B.
	CabForceB

	// CabV is an external potential energy factor, that
	// can be used to push particles around.
	CabV

	// CabCC is the complex conjugate ("squared") wave
	// value, which represents the total probability or a conserved
	// charge value.
	CabCC

	// CabCharge is the charge density.
	CabCharge

	// CabCurrentX is the current density.
	CabCurrentX

	// CabCurrentY is the current density.
	CabCurrentY

	// CabCurrentZ is the current density.
	CabCurrentZ

	// CabKinetic is the total kinetic energy across components.
	CabKinetic

	// CabPotential is the total potential energy across components (only for KGC).
	CabPotential

	// CabEnergy is the total kinetic + potential energy.
	CabEnergy
)
const CabStatesN CabStates = 15

CabStatesN is the highest valid value for type CabStates, plus one.

func CabStatesValues added in v0.0.5

func CabStatesValues() []CabStates

CabStatesValues returns all possible values for the type CabStates.

func (CabStates) Desc added in v0.0.5

func (i CabStates) Desc() string

Desc returns the description of the CabStates value.

func (CabStates) Int64 added in v0.0.5

func (i CabStates) Int64() int64

Int64 returns the CabStates value as an int64.

func (CabStates) MarshalText added in v0.0.5

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

MarshalText implements the encoding.TextMarshaler interface.

func (*CabStates) SetInt64 added in v0.0.5

func (i *CabStates) SetInt64(in int64)

SetInt64 sets the CabStates value from an int64.

func (*CabStates) SetString added in v0.0.5

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

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

func (CabStates) String added in v0.0.5

func (i CabStates) String() string

String returns the string representation of this CabStates value.

func (*CabStates) UnmarshalText added in v0.0.5

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (CabStates) Values added in v0.0.5

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

Values returns all possible values for the type CabStates.

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 `edit:"-"`

	// 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"`

	// Wavelength is the wavelength to use for functions that use it
	// (Config suffix). Allows user to manipulate the wavelength easily,
	// e.g., for KG and other matter waves.
	Wavelength float32

	// PacketWidth is the wave packet width to use for functions that use it
	// (Config suffix). Allows user to manipulate the wave parameters easily,
	// e.g., for KG and other matter waves.
	PacketWidth float32

	// Velocity provides the default particle velocity.
	Velocity math32.Vector3

	// 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

	// NVars is the number of state variables.
	NVars int32

	// 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

	// RandCounter is the random counter, incremented by maximum number of
	// possible random numbers generated per cycle, regardless of how
	// many are actually used. This is shared across all layers so must
	// encompass all possible param settings.
	RandCounter slrand.Counter
	// 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) EdgeCoords added in v0.0.5

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

EdgeCoords returns the x,y,z coordinates for given index into the edge state, using non-shared edge patterns per above. returns the face / corner number we're at (0-6) or -1 for none

func (*Context) EdgeCoordsWrap added in v0.0.5

func (ctx *Context) EdgeCoordsWrap(idx uint32, x, y, z, xs, ys, zs *int32) int32

EdgeCoordsWrap returns the x,y,z coordinates for given index into the edge state, using non-shared edge patterns per above, and also the source state for wrapping the value around as in a torus. returns the face / corner number we're at (0-6) or -1 for none

func (*Context) EdgesN added in v0.0.5

func (ctx *Context) EdgesN() int32

EdgesN returns the number of points along the edges (and corners).

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

SizeFull returns the full size of the state, including edges on either side.

func (*Context) SizePlus1 added in v0.0.5

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

SizePlus1 returns Size + 1. Used for edge bounds checking.

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 CurPrevBoth added in v0.0.5

type CurPrevBoth int32 //enums:enum

CurPrevBoth allows selecting current only, previous only, or both.

const (
	// CurOnly sets only current states.
	CurOnly CurPrevBoth = iota

	// PrevOnly sets only previous states.
	PrevOnly

	// Both sets both current and previous states.
	Both
)
const CurPrevBothN CurPrevBoth = 3

CurPrevBothN is the highest valid value for type CurPrevBoth, plus one.

func CurPrevBothValues added in v0.0.5

func CurPrevBothValues() []CurPrevBoth

CurPrevBothValues returns all possible values for the type CurPrevBoth.

func (CurPrevBoth) Desc added in v0.0.5

func (i CurPrevBoth) Desc() string

Desc returns the description of the CurPrevBoth value.

func (CurPrevBoth) Int64 added in v0.0.5

func (i CurPrevBoth) Int64() int64

Int64 returns the CurPrevBoth value as an int64.

func (CurPrevBoth) MarshalText added in v0.0.5

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

MarshalText implements the encoding.TextMarshaler interface.

func (*CurPrevBoth) SetInt64 added in v0.0.5

func (i *CurPrevBoth) SetInt64(in int64)

SetInt64 sets the CurPrevBoth value from an int64.

func (*CurPrevBoth) SetString added in v0.0.5

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

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

func (CurPrevBoth) String added in v0.0.5

func (i CurPrevBoth) String() string

String returns the string representation of this CurPrevBoth value.

func (*CurPrevBoth) UnmarshalText added in v0.0.5

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (CurPrevBoth) Values added in v0.0.5

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

Values returns all possible values for the type CurPrevBoth.

type DiracStates added in v0.0.5

type DiracStates EMStates //enums:enum -trim-prefix=Dirac

DiracStates are the state variables for wave equations on a wave state with two complex values (1, 2), where A = real and B = complex components.

const (
	// DiracPos1A is the position (height) wave state variable
	// 1 for the real complex component A.
	DiracPos1A DiracStates = DiracStates(EMStatesN) + iota

	// DiracPos1B is the position (height) wave state variable
	// 1 for the imaginary complex component B.
	DiracPos1B

	// DiracPos2A is the position (height) wave state variable
	// 2 for the real complex component A.
	DiracPos2A

	// DiracPos2B is the position (height) wave state variable
	// 2 for the imaginary complex component B.
	DiracPos2B

	// DiracVel1A is the velocity of wave state variable
	// 1 for the real complex component A.
	DiracVel1A

	// DiracVel1B is the velocity of wave state variable
	// 1 for the imaginary complex component B.
	DiracVel1B

	// DiracVel2A is the velocity of wave state variable
	// 2 for the real complex component A.
	DiracVel2A

	// DiracVel2B is the velocity of wave state variable
	// 2 for the imaginary complex component B.
	DiracVel2B

	// DiracCC is the complex conjugate ("squared") wave
	// value, which represents the total probability or a conserved
	// charge value.
	DiracCC
)
const DiracStatesN DiracStates = 27

DiracStatesN is the highest valid value for type DiracStates, plus one.

func DiracStatesValues added in v0.0.5

func DiracStatesValues() []DiracStates

DiracStatesValues returns all possible values for the type DiracStates.

func (DiracStates) Desc added in v0.0.5

func (i DiracStates) Desc() string

Desc returns the description of the DiracStates value.

func (DiracStates) Int64 added in v0.0.5

func (i DiracStates) Int64() int64

Int64 returns the DiracStates value as an int64.

func (DiracStates) MarshalText added in v0.0.5

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

MarshalText implements the encoding.TextMarshaler interface.

func (*DiracStates) SetInt64 added in v0.0.5

func (i *DiracStates) SetInt64(in int64)

SetInt64 sets the DiracStates value from an int64.

func (*DiracStates) SetString added in v0.0.5

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

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

func (DiracStates) String added in v0.0.5

func (i DiracStates) String() string

String returns the string representation of this DiracStates value.

func (*DiracStates) UnmarshalText added in v0.0.5

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (DiracStates) Values added in v0.0.5

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

Values returns all possible values for the type DiracStates.

type EMStates added in v0.0.5

type EMStates int32 //enums:enum

EMStates are the state variables for EM wave equations.

const (
	// A0Pos is the position (height) wave state variable
	// for the EM A0 electrical (scalar) potential field.
	A0Pos EMStates = iota

	// AXPos is the position (height) wave state variable
	// for the EM AX magnetic (vector) potential field, X component.
	AXPos

	// AYPos is the position (height) wave state variable
	// for the EM AY magnetic (vector) potential field, Y component.
	AYPos

	// AZPos is the position (height) wave state variable
	// for the EM AZ magnetic (vector) potential field, Z component.
	AZPos

	// A0Vel is the velocity of wave state variable
	// for the EM A0 electrical (scalar) potential field.
	A0Vel

	// AXVel is the velocity of wave state variable
	// for the EM AX magnetic (vector) potential field, X component.
	AXVel

	// AYVel is the velocity of wave state variable
	// for the EM AY magnetic (vector) potential field, Y component.
	AYVel

	// AZVel is the velocity of wave state variable
	// for the EM AZ magnetic (vector) potential field, Z component.
	AZVel

	// EX is the electrical vector field, X component: -grad A_0 - d \vec{A}/dt
	EX

	// EY is the electrical vector field, Y component: -grad A_0 - d \vec{A}/dt
	EY

	// EZ is the electrical vector field, Z component: -grad A_0 - d \vec{A}/dt
	EZ

	// BX is the magnetic vector field, X component: curl \vec{A}
	BX

	// BY is the magnetic vector field, Y component: curl \vec{A}
	BY

	// BZ is the magnetic vector field, Z component: curl \vec{A}
	BZ

	// Charge is the density of charge, drives A0.
	Charge

	// CurrentX is the density of current, X component, drives AX.
	CurrentX

	// CurrentY is the density of current, Y component, drives AY.
	CurrentY

	// CurrentZ is the density of current, Z component, drives AZ.
	CurrentZ
)
const EMStatesN EMStates = 18

EMStatesN is the highest valid value for type EMStates, plus one.

func EMStatesValues added in v0.0.5

func EMStatesValues() []EMStates

EMStatesValues returns all possible values for the type EMStates.

func (EMStates) Desc added in v0.0.5

func (i EMStates) Desc() string

Desc returns the description of the EMStates value.

func (EMStates) Int64 added in v0.0.5

func (i EMStates) Int64() int64

Int64 returns the EMStates value as an int64.

func (EMStates) MarshalText added in v0.0.5

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

MarshalText implements the encoding.TextMarshaler interface.

func (*EMStates) SetInt64 added in v0.0.5

func (i *EMStates) SetInt64(in int64)

SetInt64 sets the EMStates value from an int64.

func (*EMStates) SetString added in v0.0.5

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

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

func (EMStates) String added in v0.0.5

func (i EMStates) String() string

String returns the string representation of this EMStates value.

func (*EMStates) UnmarshalText added in v0.0.5

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (EMStates) Values added in v0.0.5

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

Values returns all possible values for the type EMStates.

type Edges

type Edges int32 //enums:enum -trim-prefix=Edges

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

	// EdgesDamp implements damping of edge values.
	EdgesDamp
)
const EdgesN Edges = 3

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 (
	// Wave is the basic wave equation in one dimension (X).
	Wave Equations = iota

	// KleinGordon is the Klein-Gordon massive particle wave function,
	// on a scalar wave state.
	KleinGordon

	// KleinGordonC is the Klein-Gordon massive particle wave function,
	// on a complex wave state.
	KleinGordonC

	// Schrodinger is the Schrodinger wave function on complex state.
	Schrodinger

	// Maxwell is Maxwell's equations for electromagnetic (EM) waves.
	Maxwell

	// Dirac is Dirac's wave equation coupled with electromagnetic (EM) waves.
	Dirac

	// ParticleKGC is the Klein-Gordon complex version of stochastic particles.
	ParticleKGC
)
const EquationsN Equations = 7

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
	FaceOffsVar  GPUVars = 2
	NeighWtsVar  GPUVars = 3
	CtxVar       GPUVars = 4
	StateVar     GPUVars = 5
)
const GPUVarsN GPUVars = 6

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 MinusPlusOne added in v0.0.5

type MinusPlusOne int32 //enums:enum

MinusPlusOne is minus1 and plus1

const (
	Minus1 MinusPlusOne = iota
	Plus1
)
const MinusPlusOneN MinusPlusOne = 2

MinusPlusOneN is the highest valid value for type MinusPlusOne, plus one.

func MinusPlusOneValues added in v0.0.5

func MinusPlusOneValues() []MinusPlusOne

MinusPlusOneValues returns all possible values for the type MinusPlusOne.

func (MinusPlusOne) Desc added in v0.0.5

func (i MinusPlusOne) Desc() string

Desc returns the description of the MinusPlusOne value.

func (MinusPlusOne) Int64 added in v0.0.5

func (i MinusPlusOne) Int64() int64

Int64 returns the MinusPlusOne value as an int64.

func (MinusPlusOne) MarshalText added in v0.0.5

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

MarshalText implements the encoding.TextMarshaler interface.

func (*MinusPlusOne) SetInt64 added in v0.0.5

func (i *MinusPlusOne) SetInt64(in int64)

SetInt64 sets the MinusPlusOne value from an int64.

func (*MinusPlusOne) SetString added in v0.0.5

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

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

func (MinusPlusOne) String added in v0.0.5

func (i MinusPlusOne) String() string

String returns the string representation of this MinusPlusOne value.

func (*MinusPlusOne) UnmarshalText added in v0.0.5

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (MinusPlusOne) Values added in v0.0.5

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

Values returns all possible values for the type MinusPlusOne.

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 NeighWeights added in v0.0.5

type NeighWeights int32 //enums:enum

NeighWeights

const (
	// LaplacianWts are weighting factors for 3D Laplacian = 3 / (13 * d^2)
	LaplacianWts NeighWeights = iota

	// AverageWts are 26 + 1 ctr average weights = 1 / d
	AverageWts

	// Grad18Wts are 18 neighbor gradaients
	Grad18Wts
)
const NeighWeightsN NeighWeights = 3

NeighWeightsN is the highest valid value for type NeighWeights, plus one.

func NeighWeightsValues added in v0.0.5

func NeighWeightsValues() []NeighWeights

NeighWeightsValues returns all possible values for the type NeighWeights.

func (NeighWeights) Desc added in v0.0.5

func (i NeighWeights) Desc() string

Desc returns the description of the NeighWeights value.

func (NeighWeights) Int64 added in v0.0.5

func (i NeighWeights) Int64() int64

Int64 returns the NeighWeights value as an int64.

func (NeighWeights) MarshalText added in v0.0.5

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

MarshalText implements the encoding.TextMarshaler interface.

func (*NeighWeights) SetInt64 added in v0.0.5

func (i *NeighWeights) SetInt64(in int64)

SetInt64 sets the NeighWeights value from an int64.

func (*NeighWeights) SetString added in v0.0.5

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

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

func (NeighWeights) String added in v0.0.5

func (i NeighWeights) String() string

String returns the string representation of this NeighWeights value.

func (*NeighWeights) UnmarshalText added in v0.0.5

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (NeighWeights) Values added in v0.0.5

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

Values returns all possible values for the type NeighWeights.

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 {
	// ThreeD runs the 3D version of wave equations, else 1D.
	ThreeD slbool.Bool

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

	// Move determines if particles actually move according to their momentums.
	Move slbool.Bool

	// C is the speed of light factor. Generally should not exceed 1!
	C float32

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

	// Inv2CSq = 1 / 2C^2
	Inv2CSq float32 `display:"-"`

	// Hbar = h / 2pi = reduced Planck constant.
	Hbar float32

	// Mass is a general mass term, e.g., for the KleinGordon equations.
	Mass float32

	// MCOverHSq = Mass^2 C^2 / Hbar^2 is the mass drag factor
	// in KleinGordon and related equations.
	MCOverHSq float32 `display:"-"`

	// HSqOver2M = Hbar^2 / 2 Mass is the factor for Schrodinger's equation.
	HSqOver2M float32 `display:"-"`

	// HEOver2MCSq = (Hbar*e) / (2 Mass * CSq) for computing charge.
	HEOver2MCSq float32 `display:"-"`

	// HOverMC = (Hbar) / (Mass * C) for computing particle momentum from phase.
	HOverMC float32 `display:"-"`

	// MOver2 = Mass / 2 for computing kinetic energy.
	MOver2 float32 `display:"-"`

	// MCSq = (Mass^2 * C^2) for computing total momentum squared
	MCSq float32 `display:"-"`

	// C6M2= (C^6 * Mass^2) is the numerator for computing total particle energy
	C6M2 float32 `display:"-"`

	// E is the electric charge constant, which determines the
	// electric potential units, C = A s
	// 0.302822 causes Mu0 and Eps0 to both be 1, if C and Hbar are both 1
	E float32

	// Mu0 is mu_0, or the permeability of free space, which weights
	// the impact of current on the magnetic vector potential.
	Mu0 float32

	// Eps0 is epsilon_0, or the permittivity of free space, which weights
	// the impact of charge on the electrical scalar potential = 1 / (mu0 c^2)
	Eps0 float32 `edit:"-"`

	// OneoEps0 = 1 / Eps0
	OneoEps0 float32 `display:"-"`

	// Edges determines how to handle the edges.
	Edges Edges
}

Parameters contains the full set of simulation parameters, for all equations. These are the bare computational values, uploaded to the GPU. Use Units to set values relative to a particular set of units.

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) ShouldDisplay added in v0.0.4

func (pr *Parameters) ShouldDisplay(field string) bool

func (*Parameters) Update

func (pr *Parameters) Update()

type ParticleKGCStates added in v0.0.5

type ParticleKGCStates CabStates //enums:enum -trim-prefix=PKGC

ParticleKGCStates are the state variables for particles in context of KGC complex wave equations on a wave state with two complex values (1, 2), where A = real and B = complex components.

const (
	// PKGCParticle indicates the type of particle present at this cell.
	// zero indicates no particle.
	PKGCParticle ParticleKGCStates = ParticleKGCStates(CabStatesN) + iota

	// PKGCPvelX is the particle velocity (proportion of c, [-1..1]) along X axis
	PKGCPvelX

	// PKGCPvelY is the particle velocity (proportion of c, [-1..1]) along Y axis
	PKGCPvelY

	// PKGCPvelZ is the particle velocity (proportion of c, [-1..1]) along Z axis
	PKGCPvelZ

	// PKGCPvelSq is the squared total particle velocity across all axes:
	// X^2 + Y^2 + Z^2
	PKGCPvelSq

	// PKGCLorentz is the Lorentz factor for particle: 1 / sqrt(1-v^2) (v = PvelSq)
	PKGCLorentz

	// PKGCPESq is the square of the particle energy.
	PKGCPESq

	// PKGCHoP0 is the central time-like SHO position for particle velocity,
	// which provides the reference against which the 3 axis phases are computed.
	PKGCHoP0

	// PKGCHoV0 is the central time-like SHO velocity for particle velocity,
	// which provides the reference against which the 3 axis phases are computed.
	PKGCHoV0

	// PKGCHoPX is the SHO position for particle velocity along X axis,
	// with phase relative to central HoV0 driving normalized velocity value.
	PKGCHoPX

	// PKGCHoVX is the SHO velocity for particle velocity along X axis,
	// with phase relative to central HoV0 driving normalized velocity value.
	PKGCHoVX

	// PKGCHoPY is the SHO position for particle velocity along Y axis,
	// with phase relative to central HoV0 driving normalized velocity value.
	PKGCHoPY

	// PKGCHoVY is the SHO velocity for particle velocity along Y axis,
	// with phase relative to central HoV0 driving normalized velocity value.
	PKGCHoVY

	// PKGCHoPZ is the SHO position for particle velocity along Z axis,
	// with phase relative to central HoV0 driving normalized velocity value.
	PKGCHoPZ

	// PKGCHoVZ is the SHO velocity for particle velocity along Z axis,
	// with phase relative to central HoV0 driving normalized velocity value.
	PKGCHoVZ
)
const ParticleKGCStatesN ParticleKGCStates = 30

ParticleKGCStatesN is the highest valid value for type ParticleKGCStates, plus one.

func ParticleKGCStatesValues added in v0.0.5

func ParticleKGCStatesValues() []ParticleKGCStates

ParticleKGCStatesValues returns all possible values for the type ParticleKGCStates.

func (ParticleKGCStates) Desc added in v0.0.5

func (i ParticleKGCStates) Desc() string

Desc returns the description of the ParticleKGCStates value.

func (ParticleKGCStates) Int64 added in v0.0.5

func (i ParticleKGCStates) Int64() int64

Int64 returns the ParticleKGCStates value as an int64.

func (ParticleKGCStates) MarshalText added in v0.0.5

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

MarshalText implements the encoding.TextMarshaler interface.

func (*ParticleKGCStates) SetInt64 added in v0.0.5

func (i *ParticleKGCStates) SetInt64(in int64)

SetInt64 sets the ParticleKGCStates value from an int64.

func (*ParticleKGCStates) SetString added in v0.0.5

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

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

func (ParticleKGCStates) String added in v0.0.5

func (i ParticleKGCStates) String() string

String returns the string representation of this ParticleKGCStates value.

func (*ParticleKGCStates) UnmarshalText added in v0.0.5

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (ParticleKGCStates) Values added in v0.0.5

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

Values returns all possible values for the type ParticleKGCStates.

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 `display:"add-fields"`

	// Config contains the broader running configuration.
	Config *Config `display:"add-fields"`

	// Units convert between real-world SI units and per-cube computational units.
	Units Units `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:"-"`

	// StatFuncs are the stats functions that have been added.
	StatFuncs []func(init bool) `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) AddStat added in v0.0.5

func (ss *Sim) AddStat(fun func(init bool))

AddStat adds given stat function.

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) DiracConfig added in v0.0.5

func (ss *Sim) DiracConfig()

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) InvR added in v0.0.5

func (ss *Sim) InvR(vr enums.Enum, ctr math32.Vector3i, val float32)

InvR adds 1/r values radiating from given center point, with peak point as given value.

func (*Sim) KleinGordonCConfig added in v0.0.5

func (ss *Sim) KleinGordonCConfig()

func (*Sim) KleinGordonConfig added in v0.0.4

func (ss *Sim) KleinGordonConfig()

func (*Sim) MaxwellConfig added in v0.0.5

func (ss *Sim) MaxwellConfig()

func (*Sim) MovingWavePacket

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

MovingWavePacket adds a gaussian * cosine wave packet along given dimension, with given parameters, to both the position and velocity variables in current and previous states, which results in a single wave packet moving in given direction.

func (*Sim) MovingWavePacketConfig added in v0.0.5

func (ss *Sim) MovingWavePacketConfig(posVar, velVar enums.Enum, dim math32.Dims, ctr math32.Vector3i, dir, phase, amp float32)

MovingWavePacketConfig is a version of [MovingWavePacket] that takes its wavelength and width variables from Config

func (*Sim) OpenState added in v0.0.4

func (ss *Sim) OpenState(filename fsx.Filename) error

OpenState opens the state from given file. If filename ends in .gz, it is un-gzipped.

func (*Sim) ParticleAt added in v0.0.5

func (ss *Sim) ParticleAt(c math32.Vector3i, pvel math32.Vector3, partType float32)

ParticleAt adds a particle at given point, setting the normalized particle velocity factors.

func (*Sim) ParticleAtConfig added in v0.0.5

func (ss *Sim) ParticleAtConfig(c math32.Vector3i, partType float32)

ParticleAtConfig is a version of ParticleAt that sets Velocity from Config

func (*Sim) ParticleKGCConfig added in v0.0.5

func (ss *Sim) ParticleKGCConfig()

func (*Sim) ParticleKGCStats added in v0.0.5

func (ss *Sim) ParticleKGCStats()

func (*Sim) Point added in v0.0.5

func (ss *Sim) Point(vr enums.Enum, curPrev CurPrevBoth, c math32.Vector3i, val float32)

Point adds value to individual point, optionally for both cur and previous values.

func (*Sim) PosWavePacket added in v0.0.4

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

PosWavePacket adds a gaussian * cosine wave packet along given dimension, with given parameters, to just the current and previous position variables. This will produce two moving wave packets that split off into opposite directions.

func (*Sim) PosWavePacketConfig added in v0.0.5

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

PosWavePacketConfig is a version of [PosWavePacket] that gets parameters from Config

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) RunStats added in v0.0.5

func (ss *Sim) RunStats(init bool)

RunStats runs all the stats functions, with given init flag.

func (*Sim) SaveState added in v0.0.4

func (ss *Sim) SaveState(filename fsx.Filename) error

SaveState saves the state to given file. If filename ends in .gz, it is gzipped.

func (*Sim) SchrodingerConfig added in v0.0.4

func (ss *Sim) SchrodingerConfig()

func (*Sim) SchrodingerStats added in v0.0.5

func (ss *Sim) SchrodingerStats()

func (*Sim) Sine

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

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

func (*Sim) StatStep added in v0.0.5

func (ss *Sim) StatStep() func(init bool)

StatStep is a stats function that records current time step

func (*Sim) StatSum added in v0.0.5

func (ss *Sim) StatSum(vr enums.Enum) func(init bool)

StatSum is a stats function that records sum of given variable for current state.

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) UpdateUnits added in v0.0.5

func (ss *Sim) UpdateUnits()

UpdateUnits updates Units from Params and vice-versa.

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()

func (*Sim) WaveStats added in v0.0.5

func (ss *Sim) WaveStats()

type Units

type Units struct {
	// ComptonE is the compton hbar wavelength of an electron in cubic elements,
	// i.e., how many cubes long is the Compton wavelength of the electron.
	// This fixes the length dimension of a cube, as the inverse of this times
	// the numerical value of this quantity (LambdaBarE).
	ComptonE float64 `default:"16" min:"4"`

	// C is the speed of light in a vacuum in units of cube length / time step.
	// For Dirac waves, 0.5 is the maximum stable value. This fixes the time
	// scale given the length scale from ComptonE.
	C float64

	// Hbar = h / 2pi = reduced Planck constant, which determines the mass scale
	// given length (from ComptonE) and time (from C).
	Hbar float64

	// E is the electric charge constant in cubic units, which determines the
	// electric potential units, C = A s
	// 0.302822 causes Mu0 and Eps0 to both be 1, if C and Hbar are both 1
	E float64

	// EMass is the rest mass of the electron, in cubic units.
	EMass float64 `edit:"-"`

	// Mu0 is the computed Mu0 magnetic constant, permeability of free space
	// N/A^2 = m kg / s^2 A^2
	Mu0 float64 `edit:"-"`

	// Eps0 is the computed Eps0 electric constant, permittivity of free space
	// F/m = (s^4 A^2) / (m^3 kg)
	Eps0 float64 `edit:"-"`

	// CuM is the computed length of a cubic element, in meters.
	CuM float64 `edit:"-"`

	// CuS is the computed duration of a time step update, in seconds.
	CuS float64 `edit:"-"`

	// CuKg is the computed cube unit of mass, in Kg.
	CuKg float64 `edit:"-"`

	// CuN is the computed unit of force, in Newtons: kg m / s^2.
	CuN float64 `edit:"-"`

	// CuJ is the computed unit of energy, in Joules: N m = kg m^2 / s^2.
	CuJ float64 `edit:"-"`

	// CuW is the computed unit of power, in Watts: J / s = kg m^2 / s^3.
	CuW float64 `edit:"-"`

	// CuA is the computed unit of current, in Ampheres: A = C / s; Esi / (E * S).
	CuA float64 `edit:"-"`

	// CuC is the computed cube unit of charge, in Coulombs: C = A * s.
	CuC float64 `edit:"-"`

	// CuV is the computed unit of electrical potential, in Volts: V = W / A = kg m^2.
	CuV float64 `edit:"-"`

	// CuF is the computed unit of capacitance, in Farads = C / V: 1/kg 1/m^2 s^4 A^2
	CuF float64 `edit:"-"`

	// Csi is the speed of light, m/s
	Csi float64 `edit:"-"`

	// Hbar is the normalized Planck constant h / (2 Pi) = J s = m^2 kg / s
	HbarSi float64 `edit:"-"`

	// Esi is the unit of electrical charge: C = A s
	Esi float64 `edit:"-"`

	// EMassSi is the electron rest mass kg
	EMassSi float64 `edit:"-"`

	// Mu0 is the magnetic constant, permeability of free space
	// N/A^2 = (m kg) / (s^2 A^2)
	Mu0si float64 `edit:"-"`

	// Eps0 is the electric constant, permittivity of free space = 1 / (mu0 c^2)
	// F/m = (s^4 A^2) / (m^3 kg)
	Eps0si float64 `edit:"-"`

	// Alpha is the fine structure constant: e^2 / (hbar c 4pi eps0) (dimensionless)
	Alpha float64 `edit:"-"`

	// LambdaEsi is the Compton wavelength of the electron rest mass:
	// h / (m0 c) = (2 pi hbar) / (m0 c) = 2.42631e-12 m
	LambdaEsi float64 `edit:"-"`

	// LambdaBarEsi is the Compton wavelength of the electron rest mass in hbar
	// hbar / (m0 c) = 3.8615926771197e-13 m
	LambdaBarEsi float64 `edit:"-"`

	// A0 is the Bohr radius in hbar: hbar / (m0 c alpha) = 5.2917720859e-11 m
	A0si float64 `edit:"-"`
}

Units establishes a consistent set of units for computing physics-based [Parameter] factors. Length units are in terms of individual cubic elements.

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) MoveStart added in v0.0.5

func (vw *View) MoveStart(mv math32.Vector3i)

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) RebuildView added in v0.0.5

func (vw *View) RebuildView()

RebuildView does a full update and then rebuild of view data

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

func (*View) ZoomInSize added in v0.0.5

func (vw *View) ZoomInSize()

func (*View) ZoomOutSize added in v0.0.5

func (vw *View) ZoomOutSize()

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