Documentation ¶
Overview ¶
This package provides common functions used by all other mumax packages. Other source files will typically import this package anonymously:
import . "hotspin-core/common"
Index ¶
- Constants
- Variables
- func Abs32(x float64) float64
- func ArrayOffset(array uintptr, index int) uintptr
- func Assert(test bool)
- func AssertEqual(a, b []int)
- func AssertMsg(test bool, msg string)
- func Atob(str string) bool
- func Atof32(s string) float64
- func Atof64(str string) float64
- func Atoi(s string) int
- func Atoi64(str string) int64
- func Buffer(out io.Writer) *bufio.Writer
- func CheckBug(err error)
- func CheckErr(err error, code int)
- func CheckIO(err error)
- func CheckInput(err error)
- func CheckSize(a, b []int)
- func CheckSize3(a, b, c []int)
- func DashExit()
- func Dashboard(msg ...interface{})
- func Debug(msg ...interface{})
- func DivUp(x, y int) int
- func EnableTimers(enable bool)
- func EqualSize(a, b []int) bool
- func Err(msg ...interface{})
- func ErrCat(a, b error) error
- func FileExists(file string) bool
- func GetExecDir() string
- func GetTime(tag string) float64
- func IdxToIJ(idx int) (i, j int)
- func InitLogger(logfile string, options ...LogOption)
- func IsFinite(f float64) bool
- func IsInf(f float64) bool
- func IsReal(f float64) bool
- func Log(msg ...interface{})
- func LogFile(msg ...interface{})
- func Mkdir(filename string)
- func Nanoseconds() int64
- func OpenRDONLY(filename string) *os.File
- func OpenWRAPPENDONLY(filename string) *os.File
- func OpenWRONLY(filename string) *os.File
- func Parent(filename string) string
- func PrintProgress(prog, total int, msg string)
- func PrintTimers()
- func Prod(a []int) int
- func Progress(progress, total int, msg string)
- func Readlink(name string) string
- func ReplaceExt(filename, newext string) string
- func ResetTimer(tag string)
- func SetDebugHook(f func())
- func SetProgress(f func(int, int, string))
- func ShortPrint(a interface{}) string
- func Sqrt32(x float64) float64
- func Start(tag string)
- func Stop(tag string)
- func SwapIndex(index, dim int) int
- func SwapXYZ(array []float64)
- func Warn(msg ...interface{})
- type Bug
- type IOErr
- type InputErr
- type LogOption
- type Logger
- type Size
- type Timer
Constants ¶
const ( ESC = "\033[" BOLD = "\033[1m" BLACK = "\033[30m" RED = "\033[31m" GREEN = "\033[32m" YELLOW = "\033[33m" BLUE = "\033[34m" MAGENTA = "\033[35m" CYAN = "\033[36m" WHITE = "\033[37m" RESET = "\033[0m" // No formatting ERASE = "\033[K" // Erase rest of line LINEUP = "\033[1A" LINEDOWN = "\033[1B" LINEBEGIN = "\033[?0E" HIDECURSOR = "\033[?25l" SHOWCURSOR = "\033[?25h" )
ANSI escape sequences
const ( PI = 3.14159265358979323846264338327950288 Mu0 = 4.0 * PI * 1e-7 // Permeability of vacuum in J/Am2 Gamma0 = 2.211E5 // Gyromagnetic ratio in m/As (actually γ*µ0) Kb = 1.38064881313131313E-23 // Boltzmann's constant in J/K MuB = 9.27400968202020202E-24 // Bohr magneton in Am^2 H_bar = 1.05457172647474747E-34 // Reduced Planck's Constant in J*s Na = 6.02214129272727272e23 //Avogadro constant )
Physical constants
const ( ERR_NONE = iota // Successful exit, no error. ERR_IO // IO error ERR_INPUT // Illegal input ERR_CUDA // CUDA error ERR_BUG // Bug ERR_PANIC // Unspecified panic )
Exit error code
const ( X = 0 Y = 1 Z = 2 )
Indices for vector components
const ( XX = 0 YY = 1 ZZ = 2 YZ = 3 XZ = 4 XY = 5 ZY = 6 ZX = 7 YX = 8 )
Linear indices for matrix components. E.g.: matrix[Y]Z is stored as list[YZ]
const ( LOG_DEBUG_COL = GREEN LOG_WARN_COL = RED LOG_ERR_COL = BOLD + RED LOG_NORMAL_COL = RESET )
const MSG_ASSERTIONFAILED = "Assertion failed: %v line %v"
const MSG_WARNING = "Warning:"
const (
SIZEOF_FLOAT = 8
)
C data type size in bytes.
Variables ¶
var DEBUG bool = true
Global debug flag. Typical use: if DEBUG {Debug(...)}
var ErrString []string = []string{"Success", "I/O error", "Illegal input", "CUDA error", "Bug", "Unexpected panic"}
Human readable description of exit codes
var FullTensorIdx [3][3]int = [3][3]int{ [3]int{XX, XY, XZ}, [3]int{YX, YY, YZ}, [3]int{ZX, ZY, ZZ}}
Maps the 3x3 indices of a matrix (K_ij) onto linear indices (Kxx, Kyy, Kzz, Kyz, Kxz, Kxy, Kzy, Kzx, Kyx)
var SymmTensorIdx [3][3]int = [3][3]int{ [3]int{XX, XY, XZ}, [3]int{XY, YY, YZ}, [3]int{XZ, YZ, ZZ}}
Maps the 3x3 indices of a symmetric matrix (K_ij) onto a length 6 array containing the upper triangular part: (Kxx, Kyy, Kzz, Kyz, Kxz, Kxy)
var TensorIndex map[string]int = map[string]int{"XX": XX, "YY": YY, "ZZ": ZZ, "YZ": YZ, "XZ": XZ, "XY": XY, "ZY": ZY, "ZX": ZX, "YX": YX}
Maps string to tensor index
var TensorIndexStr []string = []string{"XX", "YY", "ZZ", "YZ", "XZ", "XY", "ZY", "ZX", "YX"}
Maps tensor index to string
Maps sting to vector index
var VectorIndexStr []string = []string{"X", "Y", "Z"}
Maps vector index to string
Functions ¶
func ArrayOffset ¶
Go equivalent of &array[index] (for a float array).
func AssertEqual ¶
func AssertEqual(a, b []int)
Panics if the slice are not equal. Used to check for equal tensor sizes.
func AssertMsg ¶
Panics if test is false, printing the message. NOTE: msg is string, not ...inteface{} to avoid spurious allocations
func Buffer ¶
Makes sure the Writer is buffered. If it is already a bufio.Writer, just return it. Otherwise, wrap it into a bufio.Writer
func CheckSize ¶
func CheckSize(a, b []int)
Check if array sizes are equal. Panics if arrays a and b are different.
func CheckSize3 ¶
func CheckSize3(a, b, c []int)
Check if array sizes are equal. Panics if arrays a and b are different.
func Dashboard ¶
func Dashboard(msg ...interface{})
Used for showing "live" progress in the terminal. Prints the message but does not move the cursor down. The next call will replace the previous line. To resume normal printing, call DashExit() once.
func ErrCat ¶
Combines two Errors into one. If a and b are nil, the returned error is nil. If either is not nil, it is returned. If both are not nil, the first one is returned.
func FileExists ¶
Checks if the file exists. TODO: use Stat() instead of Open()
func InitLogger ¶
Initiates the logger and sets the log file. logfile == "" disables logging to file.
func Mkdir ¶
func Mkdir(filename string)
Makes a directory. The permission is the same as the parent directory.
func Nanoseconds ¶
func Nanoseconds() int64
Substitute for the old time.Nanoseconds(). Does not start from Epoch so only suited to measure durations.
func OpenWRAPPENDONLY ¶
Opens the file, panics on error
func PrintProgress ¶
func ReplaceExt ¶
Replaces the extension of filename by a new one.
func SetProgress ¶
Sets the function to be used internally by Progress. Avoids cyclic dependency on engine.
func ShortPrint ¶
func ShortPrint(a interface{}) string
Like fmt.Sprint with a maximum length. Used to limit the length of error messages that contain, e.g., a large array.
func SwapIndex ¶
Transforms the index between user and program space, unless it is a scalar:
X <-> Z Y <-> Y Z <-> X XX <-> ZZ YY <-> YY ZZ <-> XX YZ <-> XY XZ <-> XZ XY <-> YZ
Types ¶
type InputErr ¶
type InputErr string
The input file contains illegal input
func InputErrF ¶
func InputErrF(msg ...interface{}) InputErr
Shorthand for InputErr(fmt.Sprint(msg...))
type Logger ¶
type Logger struct { ShowDebug bool // Include debug messages in stderr output? ShowWarn bool // Include warnings in stderr output? ShowPrint bool // Include normal output in stderr output? Screen *log.Logger // Logs to the screen (stderr), usually prints only limited output File *log.Logger // Logs to a log file, usually prints all output (including debug) Initialized bool // If the logger is not initialized, dump output to stderr. }
INTERNAL