diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index 5ce67661..00000000 --- a/frontend/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# create-svelte - -Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte). - -## Creating a project - -If you're seeing this, you've probably already done this step. Congrats! - -```bash -# create a new project in the current directory -npm create svelte@latest - -# create a new project in my-app -npm create svelte@latest my-app -``` - -## Developing - -Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: - -```bash -npm run dev - -# or start the server and open the app in a new browser tab -npm run dev -- --open -``` - -## Building - -To create a production version of your app: - -```bash -npm run build -``` - -You can preview the production build with `npm run preview`. - -> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. diff --git a/justfile b/justfile index 834b9750..175df77e 100644 --- a/justfile +++ b/justfile @@ -17,10 +17,10 @@ build-frontend: docker.io/node:18.20.4-alpine3.20 -c 'npm install && npm run build && mv dist ../src/api/static' build: - podman run --rm -v $PWD:/src matmoa/amumax:build + podman run --rm -v $PWD/src:/src matmoa/amumax:build test: - podman run --rm -v $PWD:/src -it --device=nvidia.com/gpu=all -p 35367:35367 matmoa/amumax:build /src/build/amumax -d -i /src/mytest/t2.mx3 + podman run --rm -v $PWD/src:/src -it --device=nvidia.com/gpu=all -p 35367:35367 matmoa/amumax:build /src/build/amumax -d -i /src/mytest/t2.mx3 release: image build_cuda build-frontend build VERSION=$(date -u +'%Y.%m.%d') && \ diff --git a/src/api/echo.go b/src/api/echo.go index 7bea6ae4..4d04346c 100644 --- a/src/api/echo.go +++ b/src/api/echo.go @@ -7,8 +7,8 @@ import ( "strconv" "time" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" ) @@ -75,9 +75,9 @@ func startGuiServer(e *echo.Echo, host string, port int, tunnel string) { // Find an available port addr, port, err := findAvailablePort(host, port) if err != nil { - util.Log.ErrAndExit("Failed to find available port: %v", err) + log.Log.ErrAndExit("Failed to find available port: %v", err) } - util.Log.Info("Serving the web UI at http://%s", addr) + log.Log.Info("Serving the web UI at http://%s", addr) if tunnel != "" { go startTunnel(tunnel) @@ -95,17 +95,17 @@ func startGuiServer(e *echo.Echo, host string, port int, tunnel string) { continue } // If the error is not related to the port being busy, exit - util.Log.Err("Failed to start server: %v", err) + log.Log.Err("Failed to start server: %v", err) break } // If the server started successfully, break out of the loop - util.Log.Info("Successfully started server at http://%s", addr) + log.Log.Info("Successfully started server at http://%s", addr) return } // If the loop completes without successfully starting the server - util.Log.Err("Failed to start server after multiple attempts") + log.Log.Err("Failed to start server after multiple attempts") } func findAvailablePort(host string, startPort int) (string, string, error) { diff --git a/src/api/sec_console.go b/src/api/sec_console.go index dee86bb3..54102966 100644 --- a/src/api/sec_console.go +++ b/src/api/sec_console.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/MathieuMoalic/amumax/src/engine" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/labstack/echo/v4" ) @@ -15,7 +15,7 @@ type Console struct { func newConsole() *Console { return &Console{ - Hist: util.Log.Hist, + Hist: log.Log.Hist, } } diff --git a/src/api/sec_parameters.go b/src/api/sec_parameters.go index b25eb0bb..05d8dcb9 100644 --- a/src/api/sec_parameters.go +++ b/src/api/sec_parameters.go @@ -4,7 +4,7 @@ import ( "net/http" "github.com/MathieuMoalic/amumax/src/engine" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/labstack/echo/v4" ) @@ -59,7 +59,7 @@ func postSelectParameterRegion(c echo.Context) error { } req := new(Request) if err := c.Bind(req); err != nil { - util.Log.Err("%v", err) + log.Log.Err("%v", err) return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"}) } diff --git a/src/api/sec_preview.go b/src/api/sec_preview.go index 1deda935..fde0e3bc 100644 --- a/src/api/sec_preview.go +++ b/src/api/sec_preview.go @@ -7,7 +7,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" "github.com/MathieuMoalic/amumax/src/engine" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/labstack/echo/v4" ) @@ -57,7 +57,7 @@ type Preview struct { func (p *Preview) GetQuantity() engine.Quantity { quantity, exists := engine.Quantities[p.Quantity] if !exists { - util.Log.Err("Quantity not found: %v", p.Quantity) + log.Log.Err("Quantity not found: %v", p.Quantity) } return quantity } @@ -215,7 +215,7 @@ func (p *Preview) UpdateScalarField(scalarField [][][]float32) { } } if len(valArray) == 0 { - util.Log.Warn("No data in scalar field") + log.Log.Warn("No data in scalar field") } p.Min = min @@ -271,7 +271,7 @@ func compStringToIndex(comp string) int { case "None": return 0 } - util.Log.ErrAndExit("Invalid component string") + log.Log.ErrAndExit("Invalid component string") return -2 } @@ -304,7 +304,7 @@ func validateComponent() { preview.Component = "3D" } default: - util.Log.Err("Invalid number of components") + log.Log.Err("Invalid number of components") // reset to default preview.Quantity = "m" preview.Component = "3D" @@ -317,7 +317,7 @@ func postPreviewComponent(c echo.Context) error { } req := new(Request) if err := c.Bind(req); err != nil { - util.Log.Err("%v", err) + log.Log.Err("%v", err) return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"}) } preview.Component = req.Component @@ -334,7 +334,7 @@ func postPreviewQuantity(c echo.Context) error { } req := new(Request) if err := c.Bind(req); err != nil { - util.Log.Err("%v", err) + log.Log.Err("%v", err) return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"}) } _, exists := engine.Quantities[req.Quantity] @@ -355,7 +355,7 @@ func postPreviewLayer(c echo.Context) error { } req := new(Request) if err := c.Bind(req); err != nil { - util.Log.Err("%v", err) + log.Log.Err("%v", err) return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"}) } @@ -371,7 +371,7 @@ func postPreviewMaxPoints(c echo.Context) error { } req := new(Request) if err := c.Bind(req); err != nil { - util.Log.Err("%v", err) + log.Log.Err("%v", err) return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"}) } if req.MaxPoints < 8 { diff --git a/src/api/sec_table_plot.go b/src/api/sec_table_plot.go index 602c9000..399acbbf 100644 --- a/src/api/sec_table_plot.go +++ b/src/api/sec_table_plot.go @@ -4,7 +4,7 @@ import ( "net/http" "github.com/MathieuMoalic/amumax/src/engine" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/labstack/echo/v4" ) @@ -189,7 +189,7 @@ func postTablePlotMaxPoints(c echo.Context) error { } req := new(Request) if err := c.Bind(req); err != nil { - util.Log.Err("%v", err) + log.Log.Err("%v", err) return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"}) } tablePlot.MaxPoints = req.MaxPoints @@ -204,7 +204,7 @@ func postTablePlotStep(c echo.Context) error { } req := new(Request) if err := c.Bind(req); err != nil { - util.Log.Err("%v", err) + log.Log.Err("%v", err) return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid request payload"}) } if req.Step < 1 { diff --git a/src/api/tunnel.go b/src/api/tunnel.go index ec81bc92..6e8c02b8 100644 --- a/src/api/tunnel.go +++ b/src/api/tunnel.go @@ -12,8 +12,8 @@ import ( "path/filepath" "github.com/MathieuMoalic/amumax/src/engine" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" "github.com/kevinburke/ssh_config" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" @@ -51,7 +51,7 @@ func loadPrivateKeys() []ssh.AuthMethod { } signer, err := ssh.ParsePrivateKey(key) if err != nil { - util.Log.Debug("Error parsing private key %s: %v", keyFile, err) + log.Log.Debug("Error parsing private key %s: %v", keyFile, err) continue } methods = append(methods, ssh.PublicKeys(signer)) @@ -85,7 +85,7 @@ func fromConfig(host string, localPort, remotePort uint16) (tunnel SSHTunnel) { // Start the SSH reverse tunnel func (tunnel *SSHTunnel) Start() { - util.Log.Debug("Starting SSH tunnel") + log.Log.Debug("Starting SSH tunnel") // Create SSH config authMethods := []ssh.AuthMethod{} @@ -99,7 +99,7 @@ func (tunnel *SSHTunnel) Start() { // If no SSH key is available, fallback to password authentication if len(authMethods) == 0 { - util.Log.Err("No SSH keys found, please add one to ~/.ssh/id_rsa, ~/.ssh/id_ed25519 or use an SSH agent") + log.Log.Err("No SSH keys found, please add one to ~/.ssh/id_rsa, ~/.ssh/id_ed25519 or use an SSH agent") } config := &ssh.ClientConfig{ @@ -111,40 +111,40 @@ func (tunnel *SSHTunnel) Start() { // Connect to the SSH server sshConn, err := ssh.Dial("tcp", tunnel.SSHHost+":"+tunnel.SSHPort, config) if err != nil { - util.Log.Err("failed to dial SSH: %v", err) + log.Log.Err("failed to dial SSH: %v", err) return } defer sshConn.Close() listener, err := sshConn.Listen("tcp", tunnel.remoteIP+":"+uint16ToString(tunnel.remotePort)) if err != nil { - util.Log.Err("failed to start reverse tunnel: %v", err) + log.Log.Err("failed to start reverse tunnel: %v", err) return } defer listener.Close() if tunnel.remotePort == 0 { tunnel.remotePort, err = stringToUint16(strings.Split(listener.Addr().String(), ":")[1]) if err != nil { - util.Log.Err("failed to parse remote port: %v", err) + log.Log.Err("failed to parse remote port: %v", err) return } } // Retrieve the dynamically assigned port from listener.Addr() - util.Log.Info("Tunnel started: http://%s:%d -> http://%s:%d", tunnel.remoteIP, tunnel.remotePort, tunnel.remoteIP, tunnel.localPort) + log.Log.Info("Tunnel started: http://%s:%d -> http://%s:%d", tunnel.remoteIP, tunnel.remotePort, tunnel.remoteIP, tunnel.localPort) // Handle connections for { clientConn, err := listener.Accept() if err != nil { - util.Log.Debug("Error accepting connection: %v", err) + log.Log.Debug("Error accepting connection: %v", err) continue } // Connect to the local WebUI (on worker) remoteConn, err := net.Dial("tcp", net.JoinHostPort(tunnel.remoteIP, uint16ToString(tunnel.localPort))) if err != nil { - util.Log.Debug("Error connecting to remote: %v", err) + log.Log.Debug("Error connecting to remote: %v", err) clientConn.Close() continue } @@ -168,18 +168,18 @@ func startTunnel(hostAndPort string) { go func() { localPort, err := getLocalPortWithRetry(5, 2*time.Second) if err != nil { - util.Log.Err("Failed to get the local port: %v", err) + log.Log.Err("Failed to get the local port: %v", err) return } remoteHost, remotePort, err := parseHostAndPort(hostAndPort) if err != nil { - util.Log.Err("Failed to parse host and port: %v", err) + log.Log.Err("Failed to parse host and port: %v", err) return } tunnel := fromConfig(remoteHost, localPort, remotePort) if tunnel.SSHHost == "" { - util.Log.Err("No SSH host found in ~/.ssh/config for %s", remoteHost) + log.Log.Err("No SSH host found in ~/.ssh/config for %s", remoteHost) return } tunnel.Start() @@ -199,7 +199,7 @@ func getLocalPortWithRetry(maxRetries int, retryInterval time.Duration) (uint16, return localPort, nil // Successfully retrieved the port } } - util.Log.Debug("Failed to get or parse port, retrying in %v...", retryInterval) + log.Log.Debug("Failed to get or parse port, retrying in %v...", retryInterval) time.Sleep(retryInterval) } diff --git a/src/api/websocket.go b/src/api/websocket.go index 64615827..cd3f139b 100644 --- a/src/api/websocket.go +++ b/src/api/websocket.go @@ -6,7 +6,7 @@ import ( "time" "github.com/MathieuMoalic/amumax/src/engine" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/gorilla/websocket" "github.com/labstack/echo/v4" "github.com/vmihailenco/msgpack/v5" @@ -33,7 +33,7 @@ type connectionManager struct { } func (cm *connectionManager) add(ws *websocket.Conn) { - util.Log.Debug("Websocket connection added") + log.Log.Debug("Websocket connection added") cm.mu.Lock() defer cm.mu.Unlock() cm.conns[ws] = struct{}{} @@ -41,7 +41,7 @@ func (cm *connectionManager) add(ws *websocket.Conn) { } func (cm *connectionManager) remove(ws *websocket.Conn) { - util.Log.Debug("Websocket connection removed") + log.Log.Debug("Websocket connection removed") cm.mu.Lock() defer cm.mu.Unlock() delete(cm.conns, ws) @@ -53,7 +53,7 @@ func (cm *connectionManager) broadcast(msg []byte) { for ws := range cm.conns { err := ws.WriteMessage(websocket.BinaryMessage, msg) if err != nil { - util.Log.Err("Error sending message via WebSocket: %v", err) + log.Log.Err("Error sending message via WebSocket: %v", err) ws.Close() delete(cm.conns, ws) } @@ -61,11 +61,11 @@ func (cm *connectionManager) broadcast(msg []byte) { } func websocketEntrypoint(c echo.Context) error { - util.Log.Debug("New WebSocket connection, upgrading...") + log.Log.Debug("New WebSocket connection, upgrading...") ws, err := upgrader.Upgrade(c.Response(), c.Request(), nil) - util.Log.Debug("New WebSocket connection upgraded") + log.Log.Debug("New WebSocket connection upgraded") if err != nil { - util.Log.Err("Error upgrading connection to WebSocket: %v", err) + log.Log.Err("Error upgrading connection to WebSocket: %v", err) return err } defer ws.Close() @@ -89,7 +89,7 @@ func websocketEntrypoint(c echo.Context) error { select { case <-done: - util.Log.Debug("Connection closed by client") + log.Log.Debug("Connection closed by client") return nil case <-broadcastStop: return nil @@ -99,7 +99,7 @@ func websocketEntrypoint(c echo.Context) error { func broadcastEngineState() { msg, err := msgpack.Marshal(NewEngineState()) if err != nil { - util.Log.Err("Error marshaling combined message: %v", err) + log.Log.Err("Error marshaling combined message: %v", err) return } diff --git a/src/cuda/alloc.go b/src/cuda/alloc.go index 76da74a1..2f368da8 100644 --- a/src/cuda/alloc.go +++ b/src/cuda/alloc.go @@ -6,7 +6,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Wrapper for cu.MemAlloc, fatal exit on out of memory. @@ -14,7 +14,7 @@ func MemAlloc(bytes int64) unsafe.Pointer { defer func() { err := recover() if err == cu.ERROR_OUT_OF_MEMORY { - util.Log.PanicIfError(fmt.Errorf("out of memory")) + log.Log.PanicIfError(fmt.Errorf("out of memory")) } if err != nil { panic(err) diff --git a/src/cuda/angles.go b/src/cuda/angles.go index 1dcc4ca6..f539700c 100644 --- a/src/cuda/angles.go +++ b/src/cuda/angles.go @@ -2,19 +2,19 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func SetPhi(s *data.Slice, m *data.Slice) { N := s.Size() - util.Argument(m.Size() == N) + log.AssertArgument(m.Size() == N) cfg := make3DConf(N) k_setPhi_async(s.DevPtr(X), m.DevPtr(X), m.DevPtr(Y), N[X], N[Y], N[Z], cfg) } func SetTheta(s *data.Slice, m *data.Slice) { N := s.Size() - util.Argument(m.Size() == N) + log.AssertArgument(m.Size() == N) cfg := make3DConf(N) k_setTheta_async(s.DevPtr(X), m.DevPtr(Z), N[X], N[Y], N[Z], cfg) } diff --git a/src/cuda/anisotropy.go b/src/cuda/anisotropy.go index 2b4510c2..9e19b8aa 100644 --- a/src/cuda/anisotropy.go +++ b/src/cuda/anisotropy.go @@ -2,13 +2,13 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Add uniaxial magnetocrystalline anisotropy field to Beff. // see uniaxialanisotropy.cu func AddCubicAnisotropy2(Beff, m *data.Slice, Msat, k1, k2, k3, c1, c2 MSlice) { - util.Argument(Beff.Size() == m.Size()) + log.AssertArgument(Beff.Size() == m.Size()) N := Beff.Len() cfg := make1DConf(N) @@ -31,7 +31,7 @@ func AddCubicAnisotropy2(Beff, m *data.Slice, Msat, k1, k2, k3, c1, c2 MSlice) { // Add uniaxial magnetocrystalline anisotropy field to Beff. // see uniaxialanisotropy.cu func AddUniaxialAnisotropy2(Beff, m *data.Slice, Msat, k1, k2, u MSlice) { - util.Argument(Beff.Size() == m.Size()) + log.AssertArgument(Beff.Size() == m.Size()) checkSize(Beff, m, k1, k2, u, Msat) diff --git a/src/cuda/buffer.go b/src/cuda/buffer.go index 12de461f..4b65ffde 100644 --- a/src/cuda/buffer.go +++ b/src/cuda/buffer.go @@ -12,7 +12,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var ( @@ -42,7 +42,7 @@ func Buffer(nComp int, size [3]int) *data.Slice { // allocate as much new memory as needed for i := nFromPool; i < nComp; i++ { if len(buf_check) >= buf_max { - util.Log.PanicIfError(fmt.Errorf("too many buffers in use, possible memory leak")) + log.Log.PanicIfError(fmt.Errorf("too many buffers in use, possible memory leak")) } ptrs[i] = MemAlloc(int64(cu.SIZEOF_FLOAT32 * N)) buf_check[ptrs[i]] = struct{}{} // mark this pointer as mine @@ -66,7 +66,7 @@ func Recycle(s *data.Slice) { continue } if _, ok := buf_check[ptr]; !ok { - util.Log.PanicIfError(fmt.Errorf("recyle: was not obtained with getbuffer")) + log.Log.PanicIfError(fmt.Errorf("recyle: was not obtained with getbuffer")) } pool = append(pool, ptr) diff --git a/src/cuda/bytes.go b/src/cuda/bytes.go index 935312bd..e60048ea 100644 --- a/src/cuda/bytes.go +++ b/src/cuda/bytes.go @@ -7,7 +7,7 @@ import ( "unsafe" "github.com/MathieuMoalic/amumax/src/cuda/cu" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // 3D byte slice, used for region lookup. @@ -26,19 +26,19 @@ func NewBytes(Len int) *Bytes { // Upload src (host) to dst (gpu). func (dst *Bytes) Upload(src []byte) { - util.Argument(dst.Len == len(src)) + log.AssertArgument(dst.Len == len(src)) MemCpyHtoD(dst.Ptr, unsafe.Pointer(&src[0]), int64(dst.Len)) } // Copy on device: dst = src. func (dst *Bytes) Copy(src *Bytes) { - util.Argument(dst.Len == src.Len) + log.AssertArgument(dst.Len == src.Len) MemCpy(dst.Ptr, src.Ptr, int64(dst.Len)) } // Copy to host: dst = src. func (src *Bytes) Download(dst []byte) { - util.Argument(src.Len == len(dst)) + log.AssertArgument(src.Len == len(dst)) MemCpyDtoH(unsafe.Pointer(&dst[0]), src.Ptr, int64(src.Len)) } @@ -46,7 +46,7 @@ func (src *Bytes) Download(dst []byte) { // data.Index can be used to find the index for x,y,z. func (dst *Bytes) Set(index int, value byte) { if index < 0 || index >= dst.Len { - util.Log.PanicIfError(fmt.Errorf("Bytes.Set: index out of range: %d", index)) + log.Log.PanicIfError(fmt.Errorf("Bytes.Set: index out of range: %d", index)) } src := value MemCpyHtoD(unsafe.Pointer(uintptr(dst.Ptr)+uintptr(index)), unsafe.Pointer(&src), 1) @@ -56,7 +56,7 @@ func (dst *Bytes) Set(index int, value byte) { // data.Index can be used to find the index for x,y,z. func (src *Bytes) Get(index int) byte { if index < 0 || index >= src.Len { - util.Log.PanicIfError(fmt.Errorf("Bytes.Set: index out of range: %v", index)) + log.Log.PanicIfError(fmt.Errorf("Bytes.Set: index out of range: %v", index)) } var dst byte MemCpyDtoH(unsafe.Pointer(&dst), unsafe.Pointer(uintptr(src.Ptr)+uintptr(index)), 1) diff --git a/src/cuda/conv_common.go b/src/cuda/conv_common.go index 17b818df..8694a97b 100644 --- a/src/cuda/conv_common.go +++ b/src/cuda/conv_common.go @@ -6,7 +6,7 @@ import ( "math" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Output size of R2C FFT with given logic size, expressed in floats. @@ -24,8 +24,8 @@ func prod(size [3]int) int { // and scale the kernel to compensate for unnormalized FFTs. // scale = 1/N, with N the FFT logical size. func scaleRealParts(dst, src *data.Slice, scale float32) { - util.Argument(2*dst.Len() == src.Len()) - util.Argument(dst.NComp() == 1 && src.NComp() == 1) + log.AssertArgument(2*dst.Len() == src.Len()) + log.AssertArgument(dst.NComp() == 1 && src.NComp() == 1) srcList := src.Host()[0] dstList := dst.Host()[0] @@ -44,7 +44,7 @@ func scaleRealParts(dst, src *data.Slice, scale float32) { // ...however, we check that the imaginary parts are nearly zero, // just to be sure we did not make a mistake during kernel creation. if maximg > FFT_IMAG_TOLERANCE { - util.Log.ErrAndExit("FFT kernel imaginary part: %v\n", maximg) + log.Log.ErrAndExit("FFT kernel imaginary part: %v\n", maximg) } } diff --git a/src/cuda/conv_copypad.go b/src/cuda/conv_copypad.go index e2f42c49..5bf709cc 100644 --- a/src/cuda/conv_copypad.go +++ b/src/cuda/conv_copypad.go @@ -2,14 +2,14 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Copies src (larger) into dst (smaller). // Used to extract demag field after convolution on padded m. func copyUnPad(dst, src *data.Slice, dstsize, srcsize [3]int) { - util.Argument(dst.NComp() == 1 && src.NComp() == 1) - util.Argument(dst.Len() == prod(dstsize) && src.Len() == prod(srcsize)) + log.AssertArgument(dst.NComp() == 1 && src.NComp() == 1) + log.AssertArgument(dst.Len() == prod(dstsize) && src.Len() == prod(srcsize)) cfg := make3DConf(dstsize) @@ -21,8 +21,8 @@ func copyUnPad(dst, src *data.Slice, dstsize, srcsize [3]int) { // The remainder of dst is not filled with zeros. // Used to zero-pad magnetization before convolution and in the meanwhile multiply m by its length. func copyPadMul(dst, src, vol *data.Slice, dstsize, srcsize [3]int, Msat MSlice) { - util.Argument(dst.NComp() == 1 && src.NComp() == 1) - util.Assert(dst.Len() == prod(dstsize) && src.Len() == prod(srcsize)) + log.AssertArgument(dst.NComp() == 1 && src.NComp() == 1) + log.Assert(dst.Len() == prod(dstsize) && src.Len() == prod(srcsize)) cfg := make3DConf(srcsize) diff --git a/src/cuda/conv_demag.go b/src/cuda/conv_demag.go index 1efa94fc..c4bffbb6 100644 --- a/src/cuda/conv_demag.go +++ b/src/cuda/conv_demag.go @@ -3,7 +3,7 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Stores the necessary state to perform FFT-accelerated convolution @@ -33,12 +33,13 @@ func NewDemag(inputSize, PBC [3]int, kernel [3][3]*data.Slice, test bool) *Demag } // Calculate the demag field of m * vol * Bsat, store result in B. -// m: magnetization normalized to unit length -// vol: unitless mask used to scale m's length, may be nil -// Bsat: saturation magnetization in Tesla -// B: resulting demag field, in Tesla +// +// m: magnetization normalized to unit length +// vol: unitless mask used to scale m's length, may be nil +// Bsat: saturation magnetization in Tesla +// B: resulting demag field, in Tesla func (c *DemagConvolution) Exec(B, m, vol *data.Slice, Msat MSlice) { - util.Argument(B.Size() == c.inputSize && m.Size() == c.inputSize) + log.AssertArgument(B.Size() == c.inputSize && m.Size() == c.inputSize) if c.is2D() { c.exec2D(B, m, vol, Msat) } else { @@ -134,7 +135,7 @@ func (c *DemagConvolution) init(realKern [3][3]*data.Slice) { // logic size of FFT(kernel): store real parts only c.fftKernLogicSize = fftR2COutputSizeFloats(c.realKernSize) - util.Assert(c.fftKernLogicSize[X]%2 == 0) + log.Assert(c.fftKernLogicSize[X]%2 == 0) c.fftKernLogicSize[X] /= 2 // physical size of FFT(kernel): store only non-redundant part exploiting Y, Z mirror symmetry diff --git a/src/cuda/conv_kernmul.go b/src/cuda/conv_kernmul.go index 1c363915..9f9381a7 100644 --- a/src/cuda/conv_kernmul.go +++ b/src/cuda/conv_kernmul.go @@ -5,12 +5,12 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // kernel multiplication for 3D demag convolution, exploiting full kernel symmetry. func kernMulRSymm3D_async(fftM [3]*data.Slice, Kxx, Kyy, Kzz, Kyz, Kxz, Kxy *data.Slice, Nx, Ny, Nz int) { - util.Argument(fftM[X].NComp() == 1 && Kxx.NComp() == 1) + log.AssertArgument(fftM[X].NComp() == 1 && Kxx.NComp() == 1) cfg := make3DConf([3]int{Nx, Ny, Nz}) k_kernmulRSymm3D_async(fftM[X].DevPtr(0), fftM[Y].DevPtr(0), fftM[Z].DevPtr(0), @@ -20,7 +20,7 @@ func kernMulRSymm3D_async(fftM [3]*data.Slice, Kxx, Kyy, Kzz, Kyz, Kxz, Kxy *dat // kernel multiplication for 2D demag convolution on X and Y, exploiting full kernel symmetry. func kernMulRSymm2Dxy_async(fftMx, fftMy, Kxx, Kyy, Kxy *data.Slice, Nx, Ny int) { - util.Argument(fftMy.NComp() == 1 && Kxx.NComp() == 1) + log.AssertArgument(fftMy.NComp() == 1 && Kxx.NComp() == 1) cfg := make3DConf([3]int{Nx, Ny, 1}) k_kernmulRSymm2Dxy_async(fftMx.DevPtr(0), fftMy.DevPtr(0), @@ -30,7 +30,7 @@ func kernMulRSymm2Dxy_async(fftMx, fftMy, Kxx, Kyy, Kxy *data.Slice, Nx, Ny int) // kernel multiplication for 2D demag convolution on Z, exploiting full kernel symmetry. func kernMulRSymm2Dz_async(fftMz, Kzz *data.Slice, Nx, Ny int) { - util.Argument(fftMz.NComp() == 1 && Kzz.NComp() == 1) + log.AssertArgument(fftMz.NComp() == 1 && Kzz.NComp() == 1) cfg := make3DConf([3]int{Nx, Ny, 1}) k_kernmulRSymm2Dz_async(fftMz.DevPtr(0), Kzz.DevPtr(0), Nx, Ny, cfg) @@ -39,7 +39,7 @@ func kernMulRSymm2Dz_async(fftMz, Kzz *data.Slice, Nx, Ny int) { // kernel multiplication for general 1D convolution. Does not assume any symmetry. // Used for MFM images. func kernMulC_async(fftM, K *data.Slice, Nx, Ny int) { - util.Argument(fftM.NComp() == 1 && K.NComp() == 1) + log.AssertArgument(fftM.NComp() == 1 && K.NComp() == 1) cfg := make3DConf([3]int{Nx, Ny, 1}) k_kernmulC_async(fftM.DevPtr(0), K.DevPtr(0), Nx, Ny, cfg) } diff --git a/src/cuda/conv_selftest.go b/src/cuda/conv_selftest.go index efd64e74..dd90140a 100644 --- a/src/cuda/conv_selftest.go +++ b/src/cuda/conv_selftest.go @@ -6,7 +6,7 @@ import ( "math/rand" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Compares FFT-accelerated convolution against brute-force on sparse data. @@ -14,10 +14,10 @@ import ( func testConvolution(c *DemagConvolution, PBC [3]int, realKern [3][3]*data.Slice) { if PBC != [3]int{0, 0, 0} { // the brute-force method does not work for pbc. - util.Log.Info("skipping convolution self-test for PBC") + log.Log.Info("skipping convolution self-test for PBC") return } - util.Log.Info("convolution self-test...") + log.Log.Info("convolution self-test...") inhost := data.NewSlice(3, c.inputSize) initConvTestInput(inhost.Vectors()) gpu := NewSlice(3, c.inputSize) @@ -46,7 +46,7 @@ func testConvolution(c *DemagConvolution, PBC [3]int, realKern [3][3]*data.Slice } } if err > CONV_TOLERANCE { - util.Log.ErrAndExit("convolution self-test tolerance: %v FAIL", err) + log.Log.ErrAndExit("convolution self-test tolerance: %v FAIL", err) } } diff --git a/src/cuda/crop.go b/src/cuda/crop.go index dd568a05..95e3fb97 100644 --- a/src/cuda/crop.go +++ b/src/cuda/crop.go @@ -2,7 +2,7 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Crop stores in dst a rectangle cropped from src at given offset position. @@ -10,8 +10,8 @@ import ( func Crop(dst, src *data.Slice, offX, offY, offZ int) { D := dst.Size() S := src.Size() - util.Argument(dst.NComp() == src.NComp()) - util.Argument(D[X]+offX <= S[X] && D[Y]+offY <= S[Y] && D[Z]+offZ <= S[Z]) + log.AssertArgument(dst.NComp() == src.NComp()) + log.AssertArgument(D[X]+offX <= S[X] && D[Y]+offY <= S[Y] && D[Z]+offZ <= S[Z]) cfg := make3DConf(D) diff --git a/src/cuda/crossproduct.go b/src/cuda/crossproduct.go index 97798751..800aa1f5 100644 --- a/src/cuda/crossproduct.go +++ b/src/cuda/crossproduct.go @@ -2,12 +2,12 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func CrossProduct(dst, a, b *data.Slice) { - util.Argument(dst.NComp() == 3 && a.NComp() == 3 && b.NComp() == 3) - util.Argument(dst.Len() == a.Len() && dst.Len() == b.Len()) + log.AssertArgument(dst.NComp() == 3 && a.NComp() == 3 && b.NComp() == 3) + log.AssertArgument(dst.Len() == a.Len() && dst.Len() == b.Len()) N := dst.Len() cfg := make1DConf(N) diff --git a/src/cuda/cuda2go.go b/src/cuda/cuda2go.go index 5d929e01..66998161 100644 --- a/src/cuda/cuda2go.go +++ b/src/cuda/cuda2go.go @@ -18,7 +18,7 @@ import ( "text/scanner" "text/template" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func main() { @@ -32,7 +32,7 @@ func main() { func cuda2go(fname string) { // open cuda file f, err := os.Open(fname) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) defer f.Close() // read tokens @@ -113,33 +113,33 @@ func wrapgen(filename, funcname string, argt, argn []string) { if ls == nil { dir, errd := os.Open(".") defer dir.Close() - util.Log.PanicIfError(errd) + log.Log.PanicIfError(errd) var errls error ls, errls = dir.Readdirnames(-1) - util.Log.PanicIfError(errls) + log.Log.PanicIfError(errls) } - // basename := util.NoExt(filename) + // basename := log.NoExt(filename) basename := filename[:len(filename)-len(".cu")] for _, f := range ls { match, e := regexp.MatchString("^"+basename+"_*[0-9]..ptx", f) - util.Log.PanicIfError(e) + log.Log.PanicIfError(e) if match { cc, ei := strconv.Atoi(f[len(f)-len("00.ptx") : len(f)-len(".ptx")]) - util.Log.PanicIfError(ei) + log.Log.PanicIfError(ei) kernel.PTX[cc] = filterptx(f) } } if len(kernel.PTX) == 0 { - util.Log.ErrAndExit("no PTX files for %v", filename) + log.Log.ErrAndExit("no PTX files for %v", filename) } wrapfname := basename + "_wrapper.go" wrapout, err := os.OpenFile(wrapfname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) defer wrapout.Close() - util.Log.PanicIfError(templ.Execute(wrapout, kernel)) + log.Log.PanicIfError(templ.Execute(wrapout, kernel)) } // wrapper code template text @@ -227,14 +227,14 @@ func filter(token string) bool { // They spoil the git history. func filterptx(fname string) string { f, err := os.Open(fname) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) defer f.Close() in := bufio.NewReader(f) var out bytes.Buffer out.Write(([]byte)("`")) line, err := in.ReadBytes('\n') for err != io.EOF { - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) if !bytes.HasPrefix(line, []byte("//")) && !bytes.HasPrefix(line, []byte(" .file")) { out.Write(line) } diff --git a/src/cuda/dmi.go b/src/cuda/dmi.go index 2ce9103f..79ed4f6b 100644 --- a/src/cuda/dmi.go +++ b/src/cuda/dmi.go @@ -4,7 +4,7 @@ import ( "unsafe" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Add effective field of Dzyaloshinskii-Moriya interaction to Beff (Tesla). @@ -13,7 +13,7 @@ import ( func AddDMI(Beff *data.Slice, m *data.Slice, Aex_red, Dex_red SymmLUT, Msat MSlice, regions *Bytes, mesh *data.Mesh, OpenBC bool) { cellsize := mesh.CellSize() N := Beff.Size() - util.Argument(m.Size() == N) + log.AssertArgument(m.Size() == N) cfg := make3DConf(N) var openBC byte if OpenBC { diff --git a/src/cuda/dmibulk.go b/src/cuda/dmibulk.go index 6a745e23..e69165c7 100644 --- a/src/cuda/dmibulk.go +++ b/src/cuda/dmibulk.go @@ -4,7 +4,7 @@ import ( "unsafe" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Add effective field due to bulk Dzyaloshinskii-Moriya interaction to Beff. @@ -12,7 +12,7 @@ import ( func AddDMIBulk(Beff *data.Slice, m *data.Slice, Aex_red, D_red SymmLUT, Msat MSlice, regions *Bytes, mesh *data.Mesh, OpenBC bool) { cellsize := mesh.CellSize() N := Beff.Size() - util.Argument(m.Size() == N) + log.AssertArgument(m.Size() == N) cfg := make3DConf(N) var openBC byte if OpenBC { diff --git a/src/cuda/dotproduct.go b/src/cuda/dotproduct.go index be508da1..987cbbb6 100644 --- a/src/cuda/dotproduct.go +++ b/src/cuda/dotproduct.go @@ -2,13 +2,13 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // dst += prefactor * dot(a, b), as used for energy density func AddDotProduct(dst *data.Slice, prefactor float32, a, b *data.Slice) { - util.Argument(dst.NComp() == 1 && a.NComp() == 3 && b.NComp() == 3) - util.Argument(dst.Len() == a.Len() && dst.Len() == b.Len()) + log.AssertArgument(dst.NComp() == 1 && a.NComp() == 3 && b.NComp() == 3) + log.AssertArgument(dst.Len() == a.Len() && dst.Len() == b.Len()) N := dst.Len() cfg := make1DConf(N) diff --git a/src/cuda/fatbin.go b/src/cuda/fatbin.go index 91f912a1..0cb4db1e 100644 --- a/src/cuda/fatbin.go +++ b/src/cuda/fatbin.go @@ -2,7 +2,7 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/cuda/cu" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // load PTX code for function name, find highest SM that matches our card. @@ -24,7 +24,7 @@ func determineCC() int { } } if UseCC == 0 { - util.Log.ErrAndExit("\nNo binary for GPU. Your nvidia driver may be out-of-date\n") + log.Log.ErrAndExit("\nNo binary for GPU. Your nvidia driver may be out-of-date\n") } return UseCC } diff --git a/src/cuda/fft3dr2c.go b/src/cuda/fft3dr2c.go index 68352d4d..8a5c6468 100644 --- a/src/cuda/fft3dr2c.go +++ b/src/cuda/fft3dr2c.go @@ -4,8 +4,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/cuda/cufft" "github.com/MathieuMoalic/amumax/src/data" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/timer" - "github.com/MathieuMoalic/amumax/src/util" ) // 3D single-precission real-to-complex FFT plan. @@ -28,14 +28,14 @@ func (p *fft3DR2CPlan) ExecAsync(src, dst *data.Slice) { Sync() timer.Start("fft") } - util.Argument(src.NComp() == 1 && dst.NComp() == 1) + log.AssertArgument(src.NComp() == 1 && dst.NComp() == 1) oksrclen := p.InputLen() if src.Len() != oksrclen { - util.Log.ErrAndExit("fft size mismatch: expecting src len %v, got %v", oksrclen, src.Len()) + log.Log.ErrAndExit("fft size mismatch: expecting src len %v, got %v", oksrclen, src.Len()) } okdstlen := p.OutputLen() if dst.Len() != okdstlen { - util.Log.ErrAndExit("fft size mismatch: expecting dst len %v, got %v", okdstlen, dst.Len()) + log.Log.ErrAndExit("fft size mismatch: expecting dst len %v, got %v", okdstlen, dst.Len()) } p.handle.ExecR2C(cu.DevicePtr(uintptr(src.DevPtr(0))), cu.DevicePtr(uintptr(dst.DevPtr(0)))) if Synchronous { diff --git a/src/cuda/init.go b/src/cuda/init.go index 1d581613..ff24bea5 100644 --- a/src/cuda/init.go +++ b/src/cuda/init.go @@ -6,7 +6,7 @@ import ( "runtime" "github.com/MathieuMoalic/amumax/src/cuda/cu" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var ( @@ -38,10 +38,10 @@ func Init(gpu int) { DevName, (TotalMem)/(1024*1024), DriverVersion/1000, (DriverVersion%1000)/10, M, m) if M < 2 { - util.Log.ErrAndExit("GPU has insufficient compute capability, need 2.0 or higher.") + log.Log.ErrAndExit("GPU has insufficient compute capability, need 2.0 or higher.") } if Synchronous { - util.Log.Info("DEBUG: synchronized CUDA calls") + log.Log.Info("DEBUG: synchronized CUDA calls") } // test PTX load so that we can catch CUDA_ERROR_NO_BINARY_FOR_GPU early @@ -53,10 +53,10 @@ func tryCuInit() { defer func() { err := recover() if err == cu.ERROR_UNKNOWN { - util.Log.ErrAndExit("\n CUDA unknown error\n") + log.Log.ErrAndExit("\n CUDA unknown error\n") } if err != nil { - util.Log.PanicIfError(fmt.Errorf("%v", fmt.Sprint(err))) + log.Log.PanicIfError(fmt.Errorf("%v", fmt.Sprint(err))) } }() cu.Init(0) diff --git a/src/cuda/madd.go b/src/cuda/madd.go index 3990eaf7..669bd668 100644 --- a/src/cuda/madd.go +++ b/src/cuda/madd.go @@ -2,7 +2,7 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // multiply: dst[i] = a[i] * b[i] @@ -10,7 +10,7 @@ import ( func Mul(dst, a, b *data.Slice) { N := dst.Len() nComp := dst.NComp() - // util.Assert(a.Len() == N && a.NComp() == nComp && b.Len() == N && b.NComp() == nComp) + // log.Assert(a.Len() == N && a.NComp() == nComp && b.Len() == N && b.NComp() == nComp) cfg := make1DConf(N) for c := 0; c < nComp; c++ { k_mul_async(dst.DevPtr(c), a.DevPtr(c), b.DevPtr(c), N, cfg) @@ -22,7 +22,7 @@ func Mul(dst, a, b *data.Slice) { func Div(dst, a, b *data.Slice) { N := dst.Len() nComp := dst.NComp() - util.Assert(a.Len() == N && a.NComp() == nComp && b.Len() == N && b.NComp() == nComp) + log.Assert(a.Len() == N && a.NComp() == nComp && b.Len() == N && b.NComp() == nComp) cfg := make1DConf(N) for c := 0; c < nComp; c++ { k_pointwise_div_async(dst.DevPtr(c), a.DevPtr(c), b.DevPtr(c), N, cfg) @@ -38,8 +38,8 @@ func Add(dst, src1, src2 *data.Slice) { func Madd2(dst, src1, src2 *data.Slice, factor1, factor2 float32) { N := dst.Len() nComp := dst.NComp() - util.Assert(src1.Len() == N && src2.Len() == N) - util.Assert(src1.NComp() == nComp && src2.NComp() == nComp) + log.Assert(src1.Len() == N && src2.Len() == N) + log.Assert(src1.NComp() == nComp && src2.NComp() == nComp) cfg := make1DConf(N) for c := 0; c < nComp; c++ { k_madd2_async(dst.DevPtr(c), src1.DevPtr(c), factor1, @@ -51,8 +51,8 @@ func Madd2(dst, src1, src2 *data.Slice, factor1, factor2 float32) { func Madd3(dst, src1, src2, src3 *data.Slice, factor1, factor2, factor3 float32) { N := dst.Len() nComp := dst.NComp() - util.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N) - util.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp) + log.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N) + log.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp) cfg := make1DConf(N) for c := 0; c < nComp; c++ { k_madd3_async(dst.DevPtr(c), src1.DevPtr(c), factor1, @@ -64,8 +64,8 @@ func Madd3(dst, src1, src2, src3 *data.Slice, factor1, factor2, factor3 float32) func Madd4(dst, src1, src2, src3, src4 *data.Slice, factor1, factor2, factor3, factor4 float32) { N := dst.Len() nComp := dst.NComp() - util.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N && src4.Len() == N) - util.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp && src4.NComp() == nComp) + log.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N && src4.Len() == N) + log.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp && src4.NComp() == nComp) cfg := make1DConf(N) for c := 0; c < nComp; c++ { k_madd4_async(dst.DevPtr(c), @@ -80,8 +80,8 @@ func Madd4(dst, src1, src2, src3, src4 *data.Slice, factor1, factor2, factor3, f func Madd5(dst, src1, src2, src3, src4, src5 *data.Slice, factor1, factor2, factor3, factor4, factor5 float32) { N := dst.Len() nComp := dst.NComp() - util.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N && src4.Len() == N && src5.Len() == N) - util.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp && src4.NComp() == nComp && src5.NComp() == nComp) + log.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N && src4.Len() == N && src5.Len() == N) + log.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp && src4.NComp() == nComp && src5.NComp() == nComp) cfg := make1DConf(N) for c := 0; c < nComp; c++ { k_madd5_async(dst.DevPtr(c), @@ -97,8 +97,8 @@ func Madd5(dst, src1, src2, src3, src4, src5 *data.Slice, factor1, factor2, fact func Madd6(dst, src1, src2, src3, src4, src5, src6 *data.Slice, factor1, factor2, factor3, factor4, factor5, factor6 float32) { N := dst.Len() nComp := dst.NComp() - util.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N && src4.Len() == N && src5.Len() == N && src6.Len() == N) - util.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp && src4.NComp() == nComp && src5.NComp() == nComp && src6.NComp() == nComp) + log.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N && src4.Len() == N && src5.Len() == N && src6.Len() == N) + log.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp && src4.NComp() == nComp && src5.NComp() == nComp && src6.NComp() == nComp) cfg := make1DConf(N) for c := 0; c < nComp; c++ { k_madd6_async(dst.DevPtr(c), @@ -115,8 +115,8 @@ func Madd6(dst, src1, src2, src3, src4, src5, src6 *data.Slice, factor1, factor2 func Madd7(dst, src1, src2, src3, src4, src5, src6, src7 *data.Slice, factor1, factor2, factor3, factor4, factor5, factor6, factor7 float32) { N := dst.Len() nComp := dst.NComp() - util.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N && src4.Len() == N && src5.Len() == N && src6.Len() == N && src7.Len() == N) - util.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp && src4.NComp() == nComp && src5.NComp() == nComp && src6.NComp() == nComp && src7.NComp() == nComp) + log.Assert(src1.Len() == N && src2.Len() == N && src3.Len() == N && src4.Len() == N && src5.Len() == N && src6.Len() == N && src7.Len() == N) + log.Assert(src1.NComp() == nComp && src2.NComp() == nComp && src3.NComp() == nComp && src4.NComp() == nComp && src5.NComp() == nComp && src6.NComp() == nComp && src7.NComp() == nComp) cfg := make1DConf(N) for c := 0; c < nComp; c++ { k_madd7_async(dst.DevPtr(c), diff --git a/src/cuda/magnetoelastic.go b/src/cuda/magnetoelastic.go index bd4ec3b0..38a3681c 100644 --- a/src/cuda/magnetoelastic.go +++ b/src/cuda/magnetoelastic.go @@ -2,19 +2,19 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Add magneto-elasticit coupling field to the effective field. // see magnetoelasticfield.cu func AddMagnetoelasticField(Beff, m *data.Slice, exx, eyy, ezz, exy, exz, eyz, B1, B2, Msat MSlice) { - util.Argument(Beff.Size() == m.Size()) - util.Argument(Beff.Size() == exx.Size()) - util.Argument(Beff.Size() == eyy.Size()) - util.Argument(Beff.Size() == ezz.Size()) - util.Argument(Beff.Size() == exy.Size()) - util.Argument(Beff.Size() == exz.Size()) - util.Argument(Beff.Size() == eyz.Size()) + log.AssertArgument(Beff.Size() == m.Size()) + log.AssertArgument(Beff.Size() == exx.Size()) + log.AssertArgument(Beff.Size() == eyy.Size()) + log.AssertArgument(Beff.Size() == ezz.Size()) + log.AssertArgument(Beff.Size() == exy.Size()) + log.AssertArgument(Beff.Size() == exz.Size()) + log.AssertArgument(Beff.Size() == eyz.Size()) N := Beff.Len() cfg := make1DConf(N) @@ -31,7 +31,7 @@ func AddMagnetoelasticField(Beff, m *data.Slice, exx, eyy, ezz, exy, exz, eyz, B // Calculate magneto-elasticit force density // see magnetoelasticforce.cu func GetMagnetoelasticForceDensity(out, m *data.Slice, B1, B2 MSlice, mesh *data.Mesh) { - util.Argument(out.Size() == m.Size()) + log.AssertArgument(out.Size() == m.Size()) cellsize := mesh.CellSize() N := mesh.Size() diff --git a/src/cuda/normalize.go b/src/cuda/normalize.go index e3732471..a799d970 100644 --- a/src/cuda/normalize.go +++ b/src/cuda/normalize.go @@ -2,12 +2,12 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Normalize vec to unit length, unless length or vol are zero. func Normalize(vec, vol *data.Slice) { - util.Argument(vol == nil || vol.NComp() == 1) + log.AssertArgument(vol == nil || vol.NComp() == 1) N := vec.Len() cfg := make1DConf(N) k_normalize_async(vec.DevPtr(X), vec.DevPtr(Y), vec.DevPtr(Z), vol.DevPtr(0), N, cfg) diff --git a/src/cuda/reduce.go b/src/cuda/reduce.go index 6ddb7c44..db158ade 100644 --- a/src/cuda/reduce.go +++ b/src/cuda/reduce.go @@ -6,7 +6,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) //#include "reduce.h" @@ -17,7 +17,7 @@ const REDUCE_BLOCKSIZE = C.REDUCE_BLOCKSIZE // Sum of all elements. func Sum(in *data.Slice) float32 { - util.Argument(in.NComp() == 1) + log.AssertArgument(in.NComp() == 1) out := reduceBuf(0) k_reducesum_async(in.DevPtr(0), out, 0, in.Len(), reducecfg) return copyback(out) @@ -26,7 +26,7 @@ func Sum(in *data.Slice) float32 { // Dot product. func Dot(a, b *data.Slice) float32 { nComp := a.NComp() - util.Argument(nComp == b.NComp()) + log.AssertArgument(nComp == b.NComp()) out := reduceBuf(0) // not async over components for c := 0; c < nComp; c++ { @@ -37,14 +37,15 @@ func Dot(a, b *data.Slice) float32 { // Maximum of absolute values of all elements. func MaxAbs(in *data.Slice) float32 { - util.Argument(in.NComp() == 1) + log.AssertArgument(in.NComp() == 1) out := reduceBuf(0) k_reducemaxabs_async(in.DevPtr(0), out, 0, in.Len(), reducecfg) return copyback(out) } // Maximum of the norms of all vectors (x[i], y[i], z[i]). -// max_i sqrt( x[i]*x[i] + y[i]*y[i] + z[i]*z[i] ) +// +// max_i sqrt( x[i]*x[i] + y[i]*y[i] + z[i]*z[i] ) func MaxVecNorm(v *data.Slice) float64 { out := reduceBuf(0) k_reducemaxvecnorm2_async(v.DevPtr(0), v.DevPtr(1), v.DevPtr(2), out, 0, v.Len(), reducecfg) @@ -52,10 +53,11 @@ func MaxVecNorm(v *data.Slice) float64 { } // Maximum of the norms of the difference between all vectors (x1,y1,z1) and (x2,y2,z2) -// (dx, dy, dz) = (x1, y1, z1) - (x2, y2, z2) -// max_i sqrt( dx[i]*dx[i] + dy[i]*dy[i] + dz[i]*dz[i] ) +// +// (dx, dy, dz) = (x1, y1, z1) - (x2, y2, z2) +// max_i sqrt( dx[i]*dx[i] + dy[i]*dy[i] + dz[i]*dz[i] ) func MaxVecDiff(x, y *data.Slice) float64 { - util.Argument(x.Len() == y.Len()) + log.AssertArgument(x.Len() == y.Len()) out := reduceBuf(0) k_reducemaxvecdiff2_async(x.DevPtr(0), x.DevPtr(1), x.DevPtr(2), y.DevPtr(0), y.DevPtr(1), y.DevPtr(2), diff --git a/src/cuda/reduce_test.go b/src/cuda/reduce_test.go index f71f58cf..f377843f 100644 --- a/src/cuda/reduce_test.go +++ b/src/cuda/reduce_test.go @@ -5,7 +5,7 @@ import ( "unsafe" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // test input data @@ -85,7 +85,7 @@ func TestReduceMaxAbs(t *testing.T) { func sliceFromList(arr [][]float32, size [3]int) *data.Slice { ptrs := make([]unsafe.Pointer, len(arr)) for i := range ptrs { - util.Argument(len(arr[i]) == prod(size)) + log.AssertArgument(len(arr[i]) == prod(size)) ptrs[i] = unsafe.Pointer(&arr[i][0]) } return data.SliceFromPtrs(size, data.CPUMemory, ptrs) diff --git a/src/cuda/region.go b/src/cuda/region.go index 5ba33cef..0e1b5c88 100644 --- a/src/cuda/region.go +++ b/src/cuda/region.go @@ -4,12 +4,12 @@ import ( "unsafe" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // dst += LUT[region], for vectors. Used to add terms to excitation. func RegionAddV(dst *data.Slice, lut LUTPtrs, regions *Bytes) { - util.Argument(dst.NComp() == 3) + log.AssertArgument(dst.NComp() == 3) N := dst.Len() cfg := make1DConf(N) k_regionaddv_async(dst.DevPtr(X), dst.DevPtr(Y), dst.DevPtr(Z), @@ -18,7 +18,7 @@ func RegionAddV(dst *data.Slice, lut LUTPtrs, regions *Bytes) { // dst += LUT[region], for scalar. Used to add terms to scalar excitation. func RegionAddS(dst *data.Slice, lut LUTPtr, regions *Bytes) { - util.Argument(dst.NComp() == 1) + log.AssertArgument(dst.NComp() == 1) N := dst.Len() cfg := make1DConf(N) k_regionadds_async(dst.DevPtr(0), unsafe.Pointer(lut), regions.Ptr, N, cfg) @@ -33,7 +33,7 @@ func RegionDecode(dst *data.Slice, lut LUTPtr, regions *Bytes) { // select the part of src within the specified region, set 0's everywhere else. func RegionSelect(dst, src *data.Slice, regions *Bytes, region byte) { - util.Argument(dst.NComp() == src.NComp()) + log.AssertArgument(dst.NComp() == src.NComp()) N := dst.Len() cfg := make1DConf(N) diff --git a/src/cuda/resize.go b/src/cuda/resize.go index d94705dc..347ba49c 100644 --- a/src/cuda/resize.go +++ b/src/cuda/resize.go @@ -2,19 +2,19 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Select and resize one layer for interactive output func Resize(dst, src *data.Slice, layer int) { dstsize := dst.Size() srcsize := src.Size() - util.Assert(dstsize[Z] == 1) - util.Assert(dst.NComp() == 1 && src.NComp() == 1) + log.Assert(dstsize[Z] == 1) + log.Assert(dst.NComp() == 1 && src.NComp() == 1) scalex := srcsize[X] / dstsize[X] scaley := srcsize[Y] / dstsize[Y] - util.Assert(scalex > 0 && scaley > 0) + log.Assert(scalex > 0 && scaley > 0) cfg := make3DConf(dstsize) diff --git a/src/cuda/shift.go b/src/cuda/shift.go index 24fab36f..93df5a72 100644 --- a/src/cuda/shift.go +++ b/src/cuda/shift.go @@ -2,30 +2,30 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // shift dst by shx cells (positive or negative) along X-axis. // new edge value is clampL at left edge or clampR at right edge. func ShiftX(dst, src *data.Slice, shiftX int, clampL, clampR float32) { - util.Argument(dst.NComp() == 1 && src.NComp() == 1) - util.Assert(dst.Len() == src.Len()) + log.AssertArgument(dst.NComp() == 1 && src.NComp() == 1) + log.Assert(dst.Len() == src.Len()) N := dst.Size() cfg := make3DConf(N) k_shiftx_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftX, clampL, clampR, cfg) } func ShiftY(dst, src *data.Slice, shiftY int, clampL, clampR float32) { - util.Argument(dst.NComp() == 1 && src.NComp() == 1) - util.Assert(dst.Len() == src.Len()) + log.AssertArgument(dst.NComp() == 1 && src.NComp() == 1) + log.Assert(dst.Len() == src.Len()) N := dst.Size() cfg := make3DConf(N) k_shifty_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftY, clampL, clampR, cfg) } func ShiftZ(dst, src *data.Slice, shiftZ int, clampL, clampR float32) { - util.Argument(dst.NComp() == 1 && src.NComp() == 1) - util.Assert(dst.Len() == src.Len()) + log.AssertArgument(dst.NComp() == 1 && src.NComp() == 1) + log.Assert(dst.Len() == src.Len()) N := dst.Size() cfg := make3DConf(N) k_shiftz_async(dst.DevPtr(0), src.DevPtr(0), N[X], N[Y], N[Z], shiftZ, clampL, clampR, cfg) diff --git a/src/cuda/slice.go b/src/cuda/slice.go index 965f7ea5..2f9229df 100644 --- a/src/cuda/slice.go +++ b/src/cuda/slice.go @@ -6,8 +6,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/data" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/timer" - "github.com/MathieuMoalic/amumax/src/util" ) // Make a GPU Slice with nComp components each of size length. @@ -67,7 +67,7 @@ func Memset(s *data.Slice, val ...float32) { Sync() timer.Start("memset") } - util.Argument(len(val) == s.NComp()) + log.AssertArgument(len(val) == s.NComp()) for c, v := range val { cu.MemsetD32Async(cu.DevicePtr(uintptr(s.DevPtr(c))), math.Float32bits(v), int64(s.Len()), stream0) } diff --git a/src/cuda/temperature.go b/src/cuda/temperature.go index 926b68d6..7c611880 100644 --- a/src/cuda/temperature.go +++ b/src/cuda/temperature.go @@ -2,13 +2,13 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Set Bth to thermal noise (Brown). // see temperature.cu func SetTemperature(Bth, noise *data.Slice, k2mu0_Mu0VgammaDt float64, Msat, Temp, Alpha MSlice) { - util.Argument(Bth.NComp() == 1 && noise.NComp() == 1) + log.AssertArgument(Bth.NComp() == 1 && noise.NComp() == 1) N := Bth.Len() cfg := make1DConf(N) diff --git a/src/cuda/topologicalcharge.go b/src/cuda/topologicalcharge.go index 01a1bfee..55818af0 100644 --- a/src/cuda/topologicalcharge.go +++ b/src/cuda/topologicalcharge.go @@ -2,7 +2,7 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Set s to the toplogogical charge density s = m · (∂m/∂x ❌ ∂m/∂y) @@ -10,7 +10,7 @@ import ( func SetTopologicalCharge(s *data.Slice, m *data.Slice, mesh *data.Mesh) { cellsize := mesh.CellSize() N := s.Size() - util.Argument(m.Size() == N) + log.AssertArgument(m.Size() == N) cfg := make3DConf(N) icxcy := float32(1.0 / (cellsize[X] * cellsize[Y])) diff --git a/src/cuda/topologicalchargelattice.go b/src/cuda/topologicalchargelattice.go index 34f3f2d2..4a1a7db5 100644 --- a/src/cuda/topologicalchargelattice.go +++ b/src/cuda/topologicalchargelattice.go @@ -2,14 +2,14 @@ package cuda import ( "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Topological charge according to Berg and Lüscher func SetTopologicalChargeLattice(s *data.Slice, m *data.Slice, mesh *data.Mesh) { cellsize := mesh.CellSize() N := s.Size() - util.Argument(m.Size() == N) + log.AssertArgument(m.Size() == N) cfg := make3DConf(N) icxcy := float32(1.0 / (cellsize[X] * cellsize[Y])) diff --git a/src/data/resample.go b/src/data/resample.go index fcc2db15..6eec8a86 100644 --- a/src/data/resample.go +++ b/src/data/resample.go @@ -1,7 +1,7 @@ package data import ( - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Resample returns a slice of new size N, @@ -54,7 +54,7 @@ func Downsample(In [][][][]float32, N [3]int) [][][][]float32 { scalex := Sx / Dx scaley := Sy / Dy scalez := Sz / Dz - util.Assert(scalex > 0 && scaley > 0) + log.Assert(scalex > 0 && scaley > 0) for c := range Out { diff --git a/src/data/slice.go b/src/data/slice.go index 5da245e1..49673efe 100644 --- a/src/data/slice.go +++ b/src/data/slice.go @@ -3,11 +3,10 @@ package data // Slice stores N-component GPU or host data. import ( - "bytes" "fmt" "unsafe" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Slice is like a [][]float32, but may be stored in GPU or host memory. @@ -72,7 +71,7 @@ func NilSlice(nComp int, size [3]int) *Slice { func SliceFromPtrs(size [3]int, memType int8, ptrs []unsafe.Pointer) *Slice { length := prod(size) nComp := len(ptrs) - util.Argument(nComp > 0 && length > 0) + log.AssertArgument(nComp > 0 && length > 0) s := new(Slice) s.ptrs = make([]unsafe.Pointer, nComp) s.size = size @@ -186,7 +185,7 @@ const SIZEOF_FLOAT32 = 4 // It should have CPUAccess() == true. func (s *Slice) Host() [][]float32 { if !s.CPUAccess() { - util.Log.PanicIfError(fmt.Errorf("slice not accessible by CPU")) + log.Log.PanicIfError(fmt.Errorf("slice not accessible by CPU")) } list := make([][]float32, s.NComp()) for c := range list { @@ -273,15 +272,6 @@ func (s *Slice) IsNil() bool { return s.ptrs[0] == nil } -func (s *Slice) String() string { - if s == nil { - return "nil" - } - var buf bytes.Buffer - util.Fprint(&buf, s.Tensors()) - return buf.String() -} - func (s *Slice) Set(comp, ix, iy, iz int, value float64) { s.checkComp(comp) s.Host()[comp][s.Index(ix, iy, iz)] = float32(value) diff --git a/src/draw/arrows.go b/src/draw/arrows.go index 7116755f..f87a7b73 100644 --- a/src/draw/arrows.go +++ b/src/draw/arrows.go @@ -10,7 +10,7 @@ import ( ) func drawArrows(img *image.RGBA, arr [3][][][]float32, sub int) { - c := NewCanvas(img) + c := newCanvas(img) Na := data.SizeOf(arr[0]) // number of arrows h := Na[Y] // orignal image height @@ -44,7 +44,7 @@ type Canvas struct { } // Make a new canvas of size w x h. -func NewCanvas(img *image.RGBA) *Canvas { +func newCanvas(img *image.RGBA) *Canvas { c := new(Canvas) c.RGBA = img c.RGBAPainter = raster.NewRGBAPainter(c.RGBA) diff --git a/src/draw/colorscale.go b/src/draw/colorscale.go index 31776a31..86541891 100644 --- a/src/draw/colorscale.go +++ b/src/draw/colorscale.go @@ -1,14 +1,16 @@ package draw -import "image/color" -import "fmt" +import ( + "fmt" + "image/color" +) type ColorMapSpec struct { Cmap []color.RGBA Ccomp int } -func ColorMap(min, max, value float32, colormap ...color.RGBA) color.RGBA { +func colorMap(min, max, value float32, colormap ...color.RGBA) color.RGBA { // default colormap: black-white if len(colormap) < 1 { colormap = []color.RGBA{{0, 0, 0, 255}, {255, 255, 255, 255}} diff --git a/src/draw/doc.go b/src/draw/doc.go deleted file mode 100644 index 07d978ac..00000000 --- a/src/draw/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// 2D rendering of data slices. -package draw diff --git a/src/draw/encode.go b/src/draw/encode.go index fcf3a16c..0644a84e 100644 --- a/src/draw/encode.go +++ b/src/draw/encode.go @@ -8,45 +8,35 @@ import ( "image/jpeg" "image/png" "io" - "os" "path" "strings" "github.com/MathieuMoalic/amumax/src/data" ) -func RenderFile(fname string, f *data.Slice, min, max string, arrowSize int, colormap ...ColorMapSpec) error { - out, err := os.Create(fname) - if err != nil { - return err - } - defer out.Close() - return RenderFormat(out, f, min, max, arrowSize, fname, colormap...) -} - func RenderFormat(out io.Writer, f *data.Slice, min, max string, arrowSize int, format string, colormap ...ColorMapSpec) error { - var codecs = map[string]codec{".png": PNG, ".jpg": JPEG100, ".gif": GIF256} + var codecs = map[string]codec{".png": pngfull, ".jpg": jpeg100, ".gif": GIF256} ext := strings.ToLower(path.Ext(format)) enc := codecs[ext] if enc == nil { return fmt.Errorf("render: unhandled image type: %s", ext) } - return Render(out, f, min, max, arrowSize, enc, colormap...) + return render(out, f, min, max, arrowSize, enc, colormap...) } // encodes an image type codec func(io.Writer, image.Image) error -// Render data and encode with arbitrary codec. -func Render(out io.Writer, f *data.Slice, min, max string, arrowSize int, encode codec, colormap ...ColorMapSpec) error { - img := Image(f, min, max, arrowSize, colormap...) +// render data and encode with arbitrary codec. +func render(out io.Writer, f *data.Slice, min, max string, arrowSize int, encode codec, colormap ...ColorMapSpec) error { + img := createRGBAImage(f, min, max, arrowSize, colormap...) buf := bufio.NewWriter(out) defer buf.Flush() return encode(buf, img) } // full-quality jpeg codec, passable to Render() -func JPEG100(w io.Writer, img image.Image) error { +func jpeg100(w io.Writer, img image.Image) error { return jpeg.Encode(w, img, &jpeg.Options{Quality: 100}) } @@ -56,6 +46,6 @@ func GIF256(w io.Writer, img image.Image) error { } // png codec, passable to Render() -func PNG(w io.Writer, img image.Image) error { +func pngfull(w io.Writer, img image.Image) error { return png.Encode(w, img) } diff --git a/src/draw/hslscale.go b/src/draw/hslscale.go index 461a434a..6252b037 100644 --- a/src/draw/hslscale.go +++ b/src/draw/hslscale.go @@ -6,15 +6,15 @@ import ( ) // Colormap for 3D vector data. -func HSLMap(x, y, z float32) color.RGBA { +func hslmap(x, y, z float32) color.RGBA { s := sqrtf(x*x + y*y + z*z) l := 0.5*z + 0.5 h := float32(math.Atan2(float64(y), float64(x))) - return HSLtoRGB(h, s, l) + return hls2rgb(h, s, l) } // h = 0..2pi, s=0..1, l=0..1 -func HSLtoRGB(h, s, l float32) color.RGBA { +func hls2rgb(h, s, l float32) color.RGBA { if s > 1 { s = 1 } diff --git a/src/draw/image.go b/src/draw/image.go index 312cc072..f32a5301 100644 --- a/src/draw/image.go +++ b/src/draw/image.go @@ -6,22 +6,22 @@ import ( "strconv" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Renders an image of slice. fmin, fmax = "auto" or a number to set the min/max color scale. -func Image(f *data.Slice, fmin, fmax string, arrowSize int, colormap ...ColorMapSpec) *image.RGBA { +func createRGBAImage(f *data.Slice, fmin, fmax string, arrowSize int, colormap ...ColorMapSpec) *image.RGBA { img := new(image.RGBA) - On(img, f, fmin, fmax, arrowSize, colormap...) + on(img, f, fmin, fmax, arrowSize, colormap...) return img } // Render on existing image buffer. Resize it if needed -func On(img *image.RGBA, f *data.Slice, fmin, fmax string, arrowSize int, colormap ...ColorMapSpec) { +func on(img *image.RGBA, f *data.Slice, fmin, fmax string, arrowSize int, colormap ...ColorMapSpec) { dim := f.NComp() switch dim { default: - util.Log.ErrAndExit("unsupported number of components: %v", dim) + log.Log.ErrAndExit("unsupported number of components: %v", dim) case 3: if colormap == nil { drawVectors(img, f.Vectors(), arrowSize) @@ -53,14 +53,14 @@ func parseMinMax(f *data.Slice, fmin, fmax string) (min, max float32) { if fmin != "auto" { m, err := strconv.ParseFloat(fmin, 32) if err != nil { - util.Log.ErrAndExit("draw: scale: %v", err) + log.Log.ErrAndExit("draw: scale: %v", err) } min = float32(m) } if fmax != "auto" { m, err := strconv.ParseFloat(fmax, 32) if err != nil { - util.Log.ErrAndExit("draw: scale: %v", err) + log.Log.ErrAndExit("draw: scale: %v", err) } max = float32(m) } @@ -89,7 +89,7 @@ func drawVectors(img *image.RGBA, arr [3][][][]float32, arrowSize int) { x /= norm y /= norm z /= norm - img.Set(ix, (h-1)-iy, HSLMap(x, y, z)) + img.Set(ix, (h-1)-iy, hslmap(x, y, z)) } } if arrowSize > 0 { @@ -127,7 +127,7 @@ func drawFloats(img *image.RGBA, arr [][][]float32, min, max float32, colormap . } v /= float32(d) - img.Set(ix, (h-1)-iy, ColorMap(min, max, v, colormap...)) + img.Set(ix, (h-1)-iy, colorMap(min, max, v, colormap...)) } } } diff --git a/src/draw/svg.go b/src/draw/svg.go deleted file mode 100644 index b5999b9a..00000000 --- a/src/draw/svg.go +++ /dev/null @@ -1,67 +0,0 @@ -package draw - -import ( - "fmt" - "github.com/MathieuMoalic/amumax/src/svgo" - "io" - "math" -) - -// Renders svg image of vector data. -func SVG(out io.Writer, arr [3][][][]float32) { - - h, w := len(arr[0][0]), len(arr[0][0][0]) - - const ( - r1 = 1. / 2. // arrow half length - r2 = 1. / 4. // arrow half width - ) - - canvas := svg.New(out) - canvas.Start(w, h) - - for slice := 0; slice < len(arr[0]); slice++ { - Mx := arr[X][slice] - My := arr[Y][slice] - Mz := arr[Z][slice] - - for i := 0; i < h; i++ { - y := float64(h) - (float64(i) + 1./2.) - for j := 0; j < w; j++ { - x := float64(j) + 1./2. - - mx := Mx[i][j] - my := My[i][j] - mz := Mz[i][j] - - // skip zero-length vectors - if mx*mx+my*my+mz*mz == 0 { - continue - } - - theta := math.Atan2(float64(my), float64(mx)) - c := math.Cos(theta) - s := math.Sin(theta) - r1 := r1 * math.Cos(math.Asin(float64(mz))) - - xs := []float64{(r1 * c) + x, (r2*s - r1*c) + x, (-r2*s - r1*c) + x} - ys := []float64{-(r1 * s) + y, -(-r2*c - r1*s) + y, -(r2*c - r1*s) + y} - - col := HSLMap(mx, my, mz) - style := "fill:#" + hex(col.R) + hex(col.G) + hex(col.B) - - canvas.Polygon(xs, ys, style) - } - } - } - - canvas.End() -} - -func hex(i uint8) string { - j := int(i) - 32 // make it a bit darker - if j < 0 { - j = 0 - } - return fmt.Sprintf("%02X", j) -} diff --git a/src/engine/asyncio.go b/src/engine/asyncio.go index 5f5238d6..ba69fae1 100644 --- a/src/engine/asyncio.go +++ b/src/engine/asyncio.go @@ -1,11 +1,11 @@ package engine import ( + "sync/atomic" "time" "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/timer" - "github.com/MathieuMoalic/amumax/src/util" ) // Asynchronous I/O queue flushes data to disk while simulation keeps running. @@ -13,7 +13,7 @@ import ( var ( saveQue chan func() // passes save requests to runSaver for asyc IO - queLen util.Atom // # tasks in queue + queLen Atom // # tasks in queue ) func init() { @@ -23,6 +23,17 @@ func init() { go runSaver() } +// Atomic int +type Atom int32 + +func (a *Atom) Add(v int32) { + atomic.AddInt32((*int32)(a), v) +} + +func (a *Atom) Load() int32 { + return atomic.LoadInt32((*int32)(a)) +} + func queOutput(f func()) { if cuda.Synchronous { timer.Start("io") diff --git a/src/engine/backwardeuler.go b/src/engine/backwardeuler.go index 5afebd9e..e58e5b63 100644 --- a/src/engine/backwardeuler.go +++ b/src/engine/backwardeuler.go @@ -3,7 +3,7 @@ package engine import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Implicit midpoint solver. @@ -13,7 +13,7 @@ type BackwardEuler struct { // Euler method, can be used as solver.Step. func (s *BackwardEuler) Step() { - util.AssertMsg(MaxErr > 0, "Backward euler solver requires MaxErr > 0") + log.AssertMsg(MaxErr > 0, "Backward euler solver requires MaxErr > 0") t0 := Time @@ -32,7 +32,7 @@ func (s *BackwardEuler) Step() { Dt_si = FixDt dt := float32(Dt_si * GammaLL) - util.AssertMsg(dt > 0, "Backward Euler solver requires fixed time step > 0") + log.AssertMsg(dt > 0, "Backward Euler solver requires fixed time step > 0") // Fist guess Time = t0 + 0.5*Dt_si // 0.5 dt makes it implicit midpoint method diff --git a/src/engine/chunk.go b/src/engine/chunk.go index 538a9cf9..7e669605 100644 --- a/src/engine/chunk.go +++ b/src/engine/chunk.go @@ -3,7 +3,7 @@ package engine import ( "math" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func init() { @@ -46,11 +46,11 @@ func NewChunks(q Quantity, c RequestedChunking) Chunks { func NewChunk(length, nb_of_chunks, N_index int) Chunk { name := []string{"Nx", "Ny", "Nz", "comp"}[N_index] if nb_of_chunks < 1 || (nb_of_chunks > length) { - util.Log.ErrAndExit("Error: The number of chunks must be between 1 and %v", name) + log.Log.ErrAndExit("Error: The number of chunks must be between 1 and %v", name) } new_nb_of_chunks := closestDivisor(length, nb_of_chunks) if new_nb_of_chunks != nb_of_chunks { - util.Log.Info("Warning: The number of chunks for %v has been automatically resized from %v to %v", name, nb_of_chunks, new_nb_of_chunks) + log.Log.Info("Warning: The number of chunks for %v has been automatically resized from %v to %v", name, nb_of_chunks, new_nb_of_chunks) } nb_of_chunks = new_nb_of_chunks return Chunk{length / nb_of_chunks, nb_of_chunks} diff --git a/src/engine/comp.go b/src/engine/comp.go index 77edd047..bbaf5ac8 100644 --- a/src/engine/comp.go +++ b/src/engine/comp.go @@ -4,9 +4,10 @@ package engine import ( "fmt" + "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) type component struct { @@ -16,7 +17,7 @@ type component struct { // Comp returns vector component c of the parent Quantity func Comp(parent Quantity, c int) ScalarField { - util.Argument(c >= 0 && c < parent.NComp()) + log.AssertArgument(c >= 0 && c < parent.NComp()) return AsScalarField(&component{parent, c}) } diff --git a/src/engine/crop.go b/src/engine/crop.go index e8a57b42..6bb81e86 100644 --- a/src/engine/crop.go +++ b/src/engine/crop.go @@ -7,7 +7,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func init() { @@ -89,9 +89,9 @@ func CropZ(parent Quantity, z1, z2 int) *cropped { func Crop(parent Quantity, x1, x2, y1, y2, z1, z2 int) *cropped { n := MeshOf(parent).Size() - util.Argument(x1 < x2 && y1 < y2 && z1 < z2) - util.Argument(x1 >= 0 && y1 >= 0 && z1 >= 0) - util.Argument(x2 <= n[X] && y2 <= n[Y] && z2 <= n[Z]) + log.AssertArgument(x1 < x2 && y1 < y2 && z1 < z2) + log.AssertArgument(x1 >= 0 && y1 >= 0 && z1 >= 0) + log.AssertArgument(x2 <= n[X] && y2 <= n[Y] && z2 <= n[Z]) name := NameOf(parent) if x1 != 0 || x2 != n[X] { diff --git a/src/engine/customfield.go b/src/engine/customfield.go index dfc2d091..5cc0ba3d 100644 --- a/src/engine/customfield.go +++ b/src/engine/customfield.go @@ -7,7 +7,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var ( @@ -143,7 +143,7 @@ type mulmv struct { // MulMV returns a new Quantity that evaluates to the // matrix-vector product (Ax·b, Ay·b, Az·b). func MulMV(Ax, Ay, Az, b Quantity) Quantity { - util.Argument(Ax.NComp() == 3 && + log.AssertArgument(Ax.NComp() == 3 && Ay.NComp() == 3 && Az.NComp() == 3 && b.NComp() == 3) @@ -151,7 +151,7 @@ func MulMV(Ax, Ay, Az, b Quantity) Quantity { } func (q *mulmv) EvalTo(dst *data.Slice) { - util.Argument(dst.NComp() == 3) + log.AssertArgument(dst.NComp() == 3) cuda.Zero(dst) b := ValueOf(q.b) defer cuda.Recycle(b) @@ -293,8 +293,8 @@ func mulNN(dst, a, b *data.Slice) { // mul1N pointwise multiplies a scalar (1-component) with an N-component vector, // yielding an N-component vector stored in dst. func mul1N(dst, a, b *data.Slice) { - util.Assert(a.NComp() == 1) - util.Assert(dst.NComp() == b.NComp()) + log.Assert(a.NComp() == 1) + log.Assert(dst.NComp() == b.NComp()) for c := 0; c < dst.NComp(); c++ { cuda.Mul(dst.Comp(c), a, b.Comp(c)) } @@ -340,8 +340,8 @@ func divNN(dst, a, b *data.Slice) { } func divN1(dst, a, b *data.Slice) { - util.Assert(dst.NComp() == a.NComp()) - util.Assert(b.NComp() == 1) + log.Assert(dst.NComp() == a.NComp()) + log.Assert(b.NComp() == 1) for c := 0; c < dst.NComp(); c++ { cuda.Div(dst.Comp(c), a.Comp(c), b) } @@ -355,7 +355,7 @@ type shifted struct { // Shifted returns a new Quantity that evaluates to // the original, shifted over dx, dy, dz cells. func Shifted(q Quantity, dx, dy, dz int) Quantity { - util.Assert(dx != 0 || dy != 0 || dz != 0) + log.Assert(dx != 0 || dy != 0 || dz != 0) return &shifted{q, dx, dy, dz} } @@ -448,7 +448,7 @@ func (q *normalized) NComp() int { } func (q *normalized) EvalTo(dst *data.Slice) { - util.Assert(dst.NComp() == q.NComp()) + log.Assert(dst.NComp() == q.NComp()) q.orig.EvalTo(dst) cuda.Normalize(dst, nil) } diff --git a/src/engine/engine.go b/src/engine/engine.go index 610af7f0..44dace9e 100644 --- a/src/engine/engine.go +++ b/src/engine/engine.go @@ -15,9 +15,9 @@ import ( "sync" "time" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" "github.com/MathieuMoalic/amumax/src/timer" - "github.com/MathieuMoalic/amumax/src/util" ) var VERSION = "dev" @@ -49,12 +49,12 @@ func CleanExit() { return } drainOutput() - util.Log.Info("**************** Simulation Ended ****************** //") + log.Log.Info("**************** Simulation Ended ****************** //") Table.Flush() if SyncAndLog { timer.Print(os.Stdout) } script.MMetadata.Add("steps", NSteps) script.MMetadata.End() - util.Log.FlushToFile() + log.Log.FlushToFile() } diff --git a/src/engine/euler.go b/src/engine/euler.go index 1392a5cd..a142b72f 100644 --- a/src/engine/euler.go +++ b/src/engine/euler.go @@ -2,7 +2,7 @@ package engine import ( "github.com/MathieuMoalic/amumax/src/cuda" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) type Euler struct{} @@ -26,7 +26,7 @@ func (*Euler) Step() { dt = float32(MaxErr / LastTorque) Dt_si = float64(dt) / GammaLL } - util.AssertMsg(dt > 0, "Euler solver requires fixed time step > 0") + log.AssertMsg(dt > 0, "Euler solver requires fixed time step > 0") setLastErr(float64(dt) * LastTorque) cuda.Madd2(y, y, dy0, 1, dt) // y = y + dt * dy diff --git a/src/engine/exchange.go b/src/engine/exchange.go index 58e4364e..97f84a1b 100644 --- a/src/engine/exchange.go +++ b/src/engine/exchange.go @@ -10,7 +10,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var ( @@ -61,7 +61,7 @@ func AddExchangeField(dst *data.Slice) { cuda.AddDMIBulk(dst, M.Buffer(), lex2.Gpu(), dbulk2.Gpu(), ms, Regions.Gpu(), M.Mesh(), OpenBC) // dmi+exchange // TODO: add ScaleInterDbulk and InterDbulk case inter && bulk: - util.Log.ErrAndExit("Cannot have interfacial-induced DMI and bulk DMI at the same time") + log.Log.ErrAndExit("Cannot have interfacial-induced DMI and bulk DMI at the same time") } } diff --git a/src/engine/excitation.go b/src/engine/excitation.go index 4be91808..c2238db2 100644 --- a/src/engine/excitation.go +++ b/src/engine/excitation.go @@ -7,8 +7,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" ) // An excitation, typically field or current, @@ -35,7 +35,7 @@ func NewExcitation(name, unit, desc string) *Excitation { func (p *Excitation) MSlice() cuda.MSlice { buf, r := p.Slice() - util.Assert(r) + log.Assert(r) return cuda.ToMSlice(buf) } @@ -72,7 +72,7 @@ func (e *Excitation) RemoveExtraTerms() { return } - // util.Log.Comment("REMOVING EXTRA TERMS FROM", e.Name()) + // log.Log.Comment("REMOVING EXTRA TERMS FROM", e.Name()) for _, m := range e.extraTerms { m.mask.Free() } @@ -141,7 +141,7 @@ func checkNaN(s *data.Slice, name string) { for _, h := range h { for _, v := range h { if math.IsNaN(float64(v)) || math.IsInf(float64(v), 0) { - util.Log.ErrAndExit("NaN or Inf in %v", name) + log.Log.ErrAndExit("NaN or Inf in %v", name) } } } diff --git a/src/engine/ext_magnetoelastic.go b/src/engine/ext_magnetoelastic.go index b2c69c80..54609395 100644 --- a/src/engine/ext_magnetoelastic.go +++ b/src/engine/ext_magnetoelastic.go @@ -5,7 +5,7 @@ package engine import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var ( @@ -76,7 +76,7 @@ func GetMagnetoelasticForceDensity(dst *data.Slice) { return } - util.AssertMsg(B1.IsUniform() && B2.IsUniform(), "Magnetoelastic: B1, B2 must be uniform") + log.AssertMsg(B1.IsUniform() && B2.IsUniform(), "Magnetoelastic: B1, B2 must be uniform") b1 := B1.MSlice() defer b1.Recycle() diff --git a/src/engine/ext_rmsurfacecharge.go b/src/engine/ext_rmsurfacecharge.go index cdc89ffe..e11e4b26 100644 --- a/src/engine/ext_rmsurfacecharge.go +++ b/src/engine/ext_rmsurfacecharge.go @@ -5,8 +5,8 @@ import ( "math" "github.com/MathieuMoalic/amumax/src/data" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/mag" - "github.com/MathieuMoalic/amumax/src/util" ) func init() { @@ -20,10 +20,10 @@ func init() { func RemoveLRSurfaceCharge(region int, mxLeft, mxRight float64) { SetBusy(true) defer SetBusy(false) - util.Argument(mxLeft == 1 || mxLeft == -1) - util.Argument(mxRight == 1 || mxRight == -1) + log.AssertArgument(mxLeft == 1 || mxLeft == -1) + log.AssertArgument(mxRight == 1 || mxRight == -1) bsat := Msat.GetRegion(region) * mag.Mu0 - util.AssertMsg(bsat != 0, "RemoveSurfaceCharges: Msat is zero in region "+fmt.Sprint(region)) + log.AssertMsg(bsat != 0, "RemoveSurfaceCharges: Msat is zero in region "+fmt.Sprint(region)) B_ext.Add(compensateLRSurfaceCharges(GetMesh(), mxLeft, mxRight, bsat), nil) } diff --git a/src/engine/geom.go b/src/engine/geom.go index c057dd3e..0be35843 100644 --- a/src/engine/geom.go +++ b/src/engine/geom.go @@ -5,7 +5,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func init() { @@ -89,7 +89,7 @@ func (geometry *geom) setGeom(s Shape) { c := geometry.Mesh().CellSize() cx, cy, cz := c[X], c[Y], c[Z] - util.Log.Info("Initializing geometry") + log.Log.Info("Initializing geometry") var ok bool for iz := 0; iz < n[Z]; iz++ { for iy := 0; iy < n[Y]; iy++ { @@ -135,7 +135,7 @@ func (geometry *geom) setGeom(s Shape) { } if !ok { - util.Log.ErrAndExit("SetGeom: geometry completely empty") + log.Log.ErrAndExit("SetGeom: geometry completely empty") } data.Copy(geometry.Buffer, V) @@ -255,7 +255,7 @@ func (g *geom) shiftY(dy int) { // x range that needs to be refreshed after shift over dx func shiftDirtyRange(dx int) (x1, x2 int) { nx := GetMesh().Size()[X] - util.Argument(dx != 0) + log.AssertArgument(dx != 0) if dx < 0 { x1 = nx + dx x2 = nx diff --git a/src/engine/heun.go b/src/engine/heun.go index f7698c30..c925b0c7 100644 --- a/src/engine/heun.go +++ b/src/engine/heun.go @@ -1,9 +1,10 @@ package engine import ( - "github.com/MathieuMoalic/amumax/src/cuda" - "github.com/MathieuMoalic/amumax/src/util" "math" + + "github.com/MathieuMoalic/amumax/src/cuda" + "github.com/MathieuMoalic/amumax/src/log" ) // Adaptive Heun solver. @@ -20,7 +21,7 @@ func (*Heun) Step() { } dt := float32(Dt_si * GammaLL) - util.Assert(dt > 0) + log.Assert(dt > 0) // stage 1 torqueFn(dy0) @@ -45,7 +46,7 @@ func (*Heun) Step() { setMaxTorque(dy) } else { // undo bad step - util.Assert(FixDt == 0) + log.Assert(FixDt == 0) Time -= Dt_si cuda.Madd2(y, y, dy0, 1, -dt) NUndone++ diff --git a/src/engine/lutdata.go b/src/engine/lutdata.go index 57175649..2f117cc7 100644 --- a/src/engine/lutdata.go +++ b/src/engine/lutdata.go @@ -6,7 +6,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // look-up table for region based parameters @@ -51,7 +51,7 @@ func (p *lut) gpuLUT() cuda.LUTPtrs { // utility for LUT of single-component data func (p *lut) gpuLUT1() cuda.LUTPtr { - util.Assert(len(p.gpu_buf) == 1) + log.Assert(len(p.gpu_buf) == 1) return cuda.LUTPtr(p.gpuLUT()[0]) } diff --git a/src/engine/magnetization.go b/src/engine/magnetization.go index 0faec666..799ef157 100644 --- a/src/engine/magnetization.go +++ b/src/engine/magnetization.go @@ -6,7 +6,6 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" ) var M magnetization // reduced magnetization (unit length) @@ -75,8 +74,6 @@ func (m *magnetization) EvalTo(dst *data.Slice) { func (m *magnetization) Region(r int) *vOneReg { return vOneRegion(m, r) } -func (m *magnetization) String() string { return util.Sprint(m.Buffer().HostCopy()) } - // Set the value of one cell. func (m *magnetization) SetCell(ix, iy, iz int, v data.Vector) { r := Index2Coord(ix, iy, iz) diff --git a/src/engine/mesh.go b/src/engine/mesh.go index abfd2d73..df043f40 100644 --- a/src/engine/mesh.go +++ b/src/engine/mesh.go @@ -6,9 +6,9 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/mag" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" ) var ( @@ -79,12 +79,12 @@ func closestSevenSmooth(n int) int { func SmoothMesh() { if Nx*Ny*Nz < 10000 { - util.Log.Info("No optimization to be made for small meshes") + log.Log.Info("No optimization to be made for small meshes") return } - util.Log.Info("Original mesh: ") - util.Log.Info("Cell size: %e, %e, %e", Dx, Dy, Dz) - util.Log.Info("Grid Size: %d, %d, %d", Nx, Ny, Nz) + log.Log.Info("Original mesh: ") + log.Log.Info("Cell size: %e, %e, %e", Dx, Dy, Dz) + log.Log.Info("Grid Size: %d, %d, %d", Nx, Ny, Nz) if AutoMeshx { NewNx := closestSevenSmooth(Nx) Dx = Dx * float64(Nx) / float64(NewNx) @@ -100,9 +100,9 @@ func SmoothMesh() { Dz = Dz * float64(Nz) / float64(NewNz) Nz = NewNz } - util.Log.Info("Smoothed mesh: ") - util.Log.Info("Cell size: %e, %e, %e", Dx, Dy, Dz) - util.Log.Info("Grid Size: %d, %d, %d", Nx, Ny, Nz) + log.Log.Info("Smoothed mesh: ") + log.Log.Info("Cell size: %e, %e, %e", Dx, Dy, Dz) + log.Log.Info("Grid Size: %d, %d, %d", Nx, Ny, Nz) } func IsValidCellSize(cellSizeX, cellSizeY, cellSizeZ float64) bool { @@ -119,9 +119,9 @@ func ValidateGridSize() { names := []string{"Nx", "Ny", "Nz"} for i, N := range []int{Nx, Ny, Nz} { if N == 0.0 { - util.Log.ErrAndExit("Error: You have to specify %v", names[i]) + log.Log.ErrAndExit("Error: You have to specify %v", names[i]) } else if N > max_threshold { - util.Log.ErrAndExit("Error: %s shouldn't be more than %d", names[i], max_threshold) + log.Log.ErrAndExit("Error: %s shouldn't be more than %d", names[i], max_threshold) } } } @@ -132,11 +132,11 @@ func ValidateCellSize() { names := []string{"dx", "dy", "dz"} for i, d := range []float64{Dx, Dy, Dz} { if d == 0.0 { - util.Log.ErrAndExit("Error: You have to specify %v", names[i]) + log.Log.ErrAndExit("Error: You have to specify %v", names[i]) } else if d < min_threshold { - util.Log.ErrAndExit("Error: %s shouldn't be less than %f", names[i], min_threshold) + log.Log.ErrAndExit("Error: %s shouldn't be less than %f", names[i], min_threshold) } else if d > max_threshold { - util.Log.ErrAndExit("Error: %s shouldn't be more than %f", names[i], max_threshold) + log.Log.ErrAndExit("Error: %s shouldn't be more than %f", names[i], max_threshold) } } } @@ -147,7 +147,7 @@ func IsMeshCreated() bool { func SetTiDiNi(Ti, di *float64, Ni *int, comp string) { if (*Ti != 0.0) && (*di != 0.0) && (*Ni != 0) { - util.Log.ErrAndExit("Error: Only 2 of [N%s,d%s,T%s] are needed to define the mesh, you can't define all 3 of them.", comp, comp, comp) + log.Log.ErrAndExit("Error: Only 2 of [N%s,d%s,T%s] are needed to define the mesh, you can't define all 3 of them.", comp, comp, comp) } else if (*Ti != 0.0) && (*di != 0.0) { *Ni = int(math.Round(*Ti / *di)) } else if (*Ni != 0) && (*di != 0.0) { @@ -160,7 +160,7 @@ func SetTiDiNi(Ti, di *float64, Ni *int, comp string) { // check if mesh is set, otherwise, it creates it func CreateMesh() { if !IsMeshCreated() { - util.Log.Info("Creating mesh") + log.Log.Info("Creating mesh") SetBusy(true) defer SetBusy(false) SetTiDiNi(&Tx, &Dx, &Nx, "x") diff --git a/src/engine/minimizer.go b/src/engine/minimizer.go index d52ee308..3b21ec12 100644 --- a/src/engine/minimizer.go +++ b/src/engine/minimizer.go @@ -7,7 +7,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var ( @@ -174,10 +174,10 @@ func Minimize() { maxDmReached := mini.lastDm.Max() > StopMaxDm out := !(maxStepsReached || maxTimeReached || !(maxDmSamplesReached || maxDmReached)) if maxStepsReached { - util.Log.Info("Stopping `Minimize()`: Maximum time steps reached ( MinimizeMaxSteps= %v steps", MinimizeMaxSteps) + log.Log.Info("Stopping `Minimize()`: Maximum time steps reached ( MinimizeMaxSteps= %v steps", MinimizeMaxSteps) } if maxTimeReached { - util.Log.Info("Stopping `Minimize()`: Maximum time reached ( MinimizeMaxTimeSeconds= %vs )", MinimizeMaxTimeSeconds) + log.Log.Info("Stopping `Minimize()`: Maximum time reached ( MinimizeMaxTimeSeconds= %vs )", MinimizeMaxTimeSeconds) } return out } diff --git a/src/engine/od.go b/src/engine/od.go index 44b7ffc5..b7983da2 100644 --- a/src/engine/od.go +++ b/src/engine/od.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/MathieuMoalic/amumax/src/httpfs" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/zarr" ) @@ -54,16 +54,16 @@ func InitIO(mx3Path, od, cachedir string, skipexists, forceclean, showprogressba if httpfs.IsDir(od) { // if directory exists and --skip-exist flag is set, skip the directory if SkipExists { - util.Log.Warn("Directory `%s` exists, skipping `%s` because of --skip-exist flag.", od, mx3Path) + log.Log.Warn("Directory `%s` exists, skipping `%s` because of --skip-exist flag.", od, mx3Path) os.Exit(0) // if directory exists and --force-clean flag is set, remove the directory } else if ForceClean { - util.Log.Warn("Cleaning `%s`", od) - util.Log.PanicIfError(httpfs.Remove(od)) - util.Log.PanicIfError(httpfs.Mkdir(od)) + log.Log.Warn("Cleaning `%s`", od) + log.Log.PanicIfError(httpfs.Remove(od)) + log.Log.PanicIfError(httpfs.Mkdir(od)) } } else { - util.Log.PanicIfError(httpfs.Mkdir(od)) + log.Log.PanicIfError(httpfs.Mkdir(od)) } zarr.InitZgroup(OD()) } diff --git a/src/engine/oneregion.go b/src/engine/oneregion.go index acbebf6e..03ebcc3b 100644 --- a/src/engine/oneregion.go +++ b/src/engine/oneregion.go @@ -5,16 +5,16 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func sOneRegion(q Quantity, r int) *sOneReg { - util.Argument(q.NComp() == 1) + log.AssertArgument(q.NComp() == 1) return &sOneReg{oneReg{q, r}} } func vOneRegion(q Quantity, r int) *vOneReg { - util.Argument(q.NComp() == 3) + log.AssertArgument(q.NComp() == 3) return &vOneReg{oneReg{q, r}} } diff --git a/src/engine/parameter.go b/src/engine/parameter.go index a8d23d71..334b3035 100644 --- a/src/engine/parameter.go +++ b/src/engine/parameter.go @@ -13,8 +13,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" ) func init() { @@ -88,7 +88,7 @@ func (p *regionwise) MSlice() cuda.MSlice { return cuda.MakeMSlice(data.NilSlice(p.NComp(), GetMesh().Size()), p.getRegion(0)) } else { buf, r := p.Slice() - util.Assert(r) + log.Assert(r) return cuda.ToMSlice(buf) } } @@ -150,8 +150,8 @@ func (p *regionwise) setUniform(v []float64) { // set in regions r1..r2(excl) func (p *regionwise) setRegions(r1, r2 int, v []float64) { - util.Argument(len(v) == len(p.cpu_buf)) - util.Argument(r1 < r2) // exclusive upper bound + log.AssertArgument(len(v) == len(p.cpu_buf)) + log.AssertArgument(r1 < r2) // exclusive upper bound for r := r1; r < r2; r++ { p.upd_reg[r] = nil p.bufset_(r, v) @@ -166,7 +166,7 @@ func (p *regionwise) bufset_(region int, v []float64) { } func (p *regionwise) setFunc(r1, r2 int, f func() []float64) { - util.Argument(r1 < r2) // exclusive upper bound + log.AssertArgument(r1 < r2) // exclusive upper bound for r := r1; r < r2; r++ { p.upd_reg[r] = f } diff --git a/src/engine/regions.go b/src/engine/regions.go index dc160c1d..710e4063 100644 --- a/src/engine/regions.go +++ b/src/engine/regions.go @@ -5,7 +5,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var Regions = RegionsState{info: info{1, "regions", ""}, Indices: make(map[int]bool)} // global regions map @@ -142,7 +142,7 @@ func (r *RegionsState) GetCell(ix, iy, iz int) int { func defRegionId(id int) { if id < 0 || id > NREGION { - util.Log.ErrAndExit("region id should be 0 -%d, have: %d", NREGION, id) + log.Log.ErrAndExit("region id should be 0 -%d, have: %d", NREGION, id) } CreateMesh() Regions.AddIndex(id) @@ -191,7 +191,9 @@ var _ Quantity = &Regions // Re-interpret a contiguous array as a multi-dimensional array of given size. func reshapeBytes(array []byte, size [3]int) [][][]byte { Nx, Ny, Nzz := size[X], size[Y], size[Z] - util.Argument(Nx*Ny*Nzz == len(array)) + if Nx*Ny*Nzz != len(array) { + log.Log.ErrAndExit("reshapeBytes: size mismatch") + } sliced := make([][][]byte, Nzz) for i := range sliced { sliced[i] = make([][]byte, Ny) diff --git a/src/engine/rk23.go b/src/engine/rk23.go index c3d8c7e1..ad7e4861 100644 --- a/src/engine/rk23.go +++ b/src/engine/rk23.go @@ -1,21 +1,23 @@ package engine import ( + "math" + "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" - "math" + "github.com/MathieuMoalic/amumax/src/log" ) // Bogacki-Shampine solver. 3rd order, 3 evaluations per step, adaptive step. -// http://en.wikipedia.org/wiki/Bogacki-Shampine_method // -// k1 = f(tn, yn) -// k2 = f(tn + 1/2 h, yn + 1/2 h k1) -// k3 = f(tn + 3/4 h, yn + 3/4 h k2) -// y{n+1} = yn + 2/9 h k1 + 1/3 h k2 + 4/9 h k3 // 3rd order -// k4 = f(tn + h, y{n+1}) -// z{n+1} = yn + 7/24 h k1 + 1/4 h k2 + 1/3 h k3 + 1/8 h k4 // 2nd order +// http://en.wikipedia.org/wiki/Bogacki-Shampine_method +// +// k1 = f(tn, yn) +// k2 = f(tn + 1/2 h, yn + 1/2 h k1) +// k3 = f(tn + 3/4 h, yn + 3/4 h k2) +// y{n+1} = yn + 2/9 h k1 + 1/3 h k2 + 4/9 h k3 // 3rd order +// k4 = f(tn + h, y{n+1}) +// z{n+1} = yn + 7/24 h k1 + 1/4 h k2 + 1/3 h k3 + 1/8 h k4 // 2nd order type RK23 struct { k1 *data.Slice // torque at end of step is kept for beginning of next step } @@ -96,8 +98,8 @@ func (rk *RK23) Step() { data.Copy(rk.k1, k4) // FSAL } else { // undo bad step - //util.Println("Bad step at t=", t0, ", err=", err) - util.Assert(FixDt == 0) + //log.Println("Bad step at t=", t0, ", err=", err) + log.Assert(FixDt == 0) Time = t0 data.Copy(m, m0) NUndone++ diff --git a/src/engine/rk4.go b/src/engine/rk4.go index b51fb4b4..d2600a32 100644 --- a/src/engine/rk4.go +++ b/src/engine/rk4.go @@ -5,7 +5,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Classical 4th order RK solver. @@ -69,7 +69,7 @@ func (rk *RK4) Step() { setMaxTorque(k4) } else { // undo bad step - util.Assert(FixDt == 0) + log.Assert(FixDt == 0) Time = t0 data.Copy(m, m0) NUndone++ diff --git a/src/engine/rk45dp.go b/src/engine/rk45dp.go index d92c4bfc..eeacf63e 100644 --- a/src/engine/rk45dp.go +++ b/src/engine/rk45dp.go @@ -1,10 +1,11 @@ package engine import ( + "math" + "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" - "math" + "github.com/MathieuMoalic/amumax/src/log" ) type RK45DP struct { @@ -110,8 +111,8 @@ func (rk *RK45DP) Step() { data.Copy(rk.k1, k7) // FSAL } else { // undo bad step - //util.Println("Bad step at t=", t0, ", err=", err) - util.Assert(FixDt == 0) + //log.Println("Bad step at t=", t0, ", err=", err) + log.Assert(FixDt == 0) Time = t0 data.Copy(m, m0) NUndone++ diff --git a/src/engine/rk56.go b/src/engine/rk56.go index a5dc0ea0..792aa9a9 100644 --- a/src/engine/rk56.go +++ b/src/engine/rk56.go @@ -1,10 +1,11 @@ package engine import ( + "math" + "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" - "math" + "github.com/MathieuMoalic/amumax/src/log" ) type RK56 struct { @@ -108,8 +109,8 @@ func (rk *RK56) Step() { adaptDt(math.Pow(MaxErr/err, 1./6.)) } else { // undo bad step - //util.Println("Bad step at t=", t0, ", err=", err) - util.Assert(FixDt == 0) + //log.Println("Bad step at t=", t0, ", err=", err) + log.Assert(FixDt == 0) Time = t0 data.Copy(m, m0) NUndone++ diff --git a/src/engine/run.go b/src/engine/run.go index 349531b9..1c4a51fd 100644 --- a/src/engine/run.go +++ b/src/engine/run.go @@ -8,8 +8,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/mag" - "github.com/MathieuMoalic/amumax/src/util" "github.com/MathieuMoalic/amumax/src/zarr" ) @@ -80,7 +80,7 @@ func SetSolver(typ int) { } switch typ { default: - util.Log.ErrAndExit("SetSolver: unknown solver type: %v", typ) + log.Log.ErrAndExit("SetSolver: unknown solver type: %v", typ) case BACKWARD_EULER: stepper = new(BackwardEuler) case EULER: @@ -130,7 +130,7 @@ func adaptDt(corr float64) { corr = 1 } - util.AssertMsg(corr != 0, "Time step too small, check if parameters are sensible") + log.AssertMsg(corr != 0, "Time step too small, check if parameters are sensible") corr *= Headroom if corr > 2 { corr = 2 @@ -146,7 +146,7 @@ func adaptDt(corr float64) { Dt_si = MaxDt } if Dt_si == 0 { - util.Log.ErrAndExit("time step too small") + log.Log.ErrAndExit("time step too small") } // do not cross alarm time @@ -154,7 +154,7 @@ func adaptDt(corr float64) { Dt_si = alarm - Time } - util.AssertMsg(Dt_si > 0, fmt.Sprint("Time step too small: ", Dt_si)) + log.AssertMsg(Dt_si > 0, fmt.Sprint("Time step too small: ", Dt_si)) } // Run the simulation for a number of seconds. @@ -261,10 +261,10 @@ func InjectAndWait(task func()) { func SanityCheck() { if Msat.isZero() { - util.Log.Info("Note: Msat = 0") + log.Log.Info("Note: Msat = 0") } if Aex.isZero() { - util.Log.Info("Note: Aex = 0") + log.Log.Info("Note: Aex = 0") } } @@ -284,15 +284,15 @@ func checkExchangeLenght() { lex := math.Sqrt(2 * Aex_r / (mag.Mu0 * Msat_r * Msat_r)) if !exchangeLenghtWarned { if Dx > lex { - util.Log.Warn("Warning: Exchange length (%.3g nm) smaller than dx (%.3g nm) in region %d", lex*1e9, Dx*1e9, region) + log.Log.Warn("Warning: Exchange length (%.3g nm) smaller than dx (%.3g nm) in region %d", lex*1e9, Dx*1e9, region) exchangeLenghtWarned = true } if Dy > lex { - util.Log.Warn("Warning: Exchange length (%.3g nm) smaller than dy (%.3g nm) in region %d", lex*1e9, Dy*1e9, region) + log.Log.Warn("Warning: Exchange length (%.3g nm) smaller than dy (%.3g nm) in region %d", lex*1e9, Dy*1e9, region) exchangeLenghtWarned = true } if Dz > lex && Nz > 1 { - util.Log.Warn("Warning: Exchange length (%.3g nm) smaller than dz (%.3g nm) in region %d", lex*1e9, Dz*1e9, region) + log.Log.Warn("Warning: Exchange length (%.3g nm) smaller than dz (%.3g nm) in region %d", lex*1e9, Dz*1e9, region) exchangeLenghtWarned = true } } diff --git a/src/engine/run_python.go b/src/engine/run_python.go index f43777a8..683a02bd 100644 --- a/src/engine/run_python.go +++ b/src/engine/run_python.go @@ -3,7 +3,7 @@ package engine import ( "os/exec" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func init() { @@ -16,14 +16,14 @@ var Insecure bool // runPython executes a Python script with optional arguments after the simulation completes. func runShell(cmd_str string) { if !Insecure { - util.Log.Err("Insecure mode is disabled. To run shell commands, use the --insecure flag.") + log.Log.Err("Insecure mode is disabled. To run shell commands, use the --insecure flag.") return } output, err := exec.Command(cmd_str).CombinedOutput() if err != nil { - util.Log.Err("Error running shell commands: %v\nOutput: %s", err, output) + log.Log.Err("Error running shell commands: %v\nOutput: %s", err, output) } - util.Log.Info("%s", output) + log.Log.Info("%s", output) } diff --git a/src/engine/save.go b/src/engine/save.go index 956afacb..72b71f0d 100644 --- a/src/engine/save.go +++ b/src/engine/save.go @@ -10,8 +10,8 @@ import ( "github.com/MathieuMoalic/amumax/src/data" "github.com/MathieuMoalic/amumax/src/draw" "github.com/MathieuMoalic/amumax/src/httpfs" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/oommf" - "github.com/MathieuMoalic/amumax/src/util" ) func init() { @@ -102,19 +102,19 @@ func SnapshotAs(q Quantity, fname string) { // synchronous snapshot func snapshot_sync(fname string, output *data.Slice) { f, err := httpfs.Create(fname) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) defer f.Close() arrowSize := 16 err = draw.RenderFormat(f, output, "auto", "auto", arrowSize, path.Ext(fname)) if err != nil { - util.Log.Warn("Error while rendering snapshot: %v", err) + log.Log.Warn("Error while rendering snapshot: %v", err) } } // synchronous save func saveAs_sync(fname string, s *data.Slice, info data.Meta, format OutputFormat) { f, err := httpfs.Create(fname) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) defer f.Close() switch format { diff --git a/src/engine/scalar_excitation.go b/src/engine/scalar_excitation.go index 0c771807..c8f6fd5a 100644 --- a/src/engine/scalar_excitation.go +++ b/src/engine/scalar_excitation.go @@ -6,8 +6,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" ) // An excitation, typically field or current, @@ -31,7 +31,7 @@ func (e *ScalarExcitation) GetRegionToString(region int) string { func (p *ScalarExcitation) MSlice() cuda.MSlice { buf, r := p.Slice() - util.Assert(r) + log.Assert(r) return cuda.ToMSlice(buf) } @@ -64,7 +64,7 @@ func (e *ScalarExcitation) RemoveExtraTerms() { return } - // util.Log.Comment("REMOVING EXTRA TERMS FROM", e.Name()) + // log.Log.Comment("REMOVING EXTRA TERMS FROM", e.Name()) for _, m := range e.extraTerms { m.mask.Free() } diff --git a/src/engine/script.go b/src/engine/script.go index a8812cfc..5ae05684 100644 --- a/src/engine/script.go +++ b/src/engine/script.go @@ -6,8 +6,8 @@ import ( "reflect" "github.com/MathieuMoalic/amumax/src/httpfs" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" ) func CompileFile(fname string) (*script.BlockStmt, error) { @@ -22,7 +22,7 @@ func EvalTryRecover(code string) { defer func() { if err := recover(); err != nil { if userErr, ok := err.(UserErr); ok { - util.Log.Err("%v", userErr) + log.Log.Err("%v", userErr) } else { panic(err) } @@ -34,22 +34,22 @@ func EvalTryRecover(code string) { func Eval(code string) { tree, err := World.Compile(code) if err != nil { - util.Log.Command(code) - util.Log.Err("%v", err.Error()) + log.Log.Command(code) + log.Log.Err("%v", err.Error()) return } - util.Log.Command(rmln(tree.Format())) + log.Log.Command(rmln(tree.Format())) tree.Eval() } func Eval1Line(code string) interface{} { tree, err := World.Compile(code) if err != nil { - util.Log.Err("%v", err.Error()) + log.Log.Err("%v", err.Error()) return nil } if len(tree.Children) != 1 { - util.Log.Err("expected single statement:%v", code) + log.Log.Err("expected single statement:%v", code) return nil } return tree.Children[0].Eval() @@ -114,7 +114,7 @@ type LValue interface { func EvalFile(code *script.BlockStmt) { for i := range code.Children { formatted := rmln(script.Format(code.Node[i])) - util.Log.Command(formatted) + log.Log.Command(formatted) code.Children[i].Eval() } } diff --git a/src/engine/shape.go b/src/engine/shape.go index 7c8cf59b..36b81f94 100644 --- a/src/engine/shape.go +++ b/src/engine/shape.go @@ -7,7 +7,7 @@ import ( "math" "github.com/MathieuMoalic/amumax/src/httpfs" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func init() { @@ -177,7 +177,7 @@ func ZRange(a, b float64) Shape { func Layers(a, b int) Shape { Nz := GetMesh().Size()[Z] if a < 0 || a > Nz || b < 0 || b < a { - util.Log.ErrAndExit("layers %d:%d out of bounds (0 - %d)", a, b, Nz) + log.Log.ErrAndExit("layers %d:%d out of bounds (0 - %d)", a, b, Nz) } c := GetMesh().CellSize()[Z] z1 := Index2Coord(0, 0, a)[Z] - c/2 diff --git a/src/engine/torque.go b/src/engine/torque.go index b6c2ff34..25e74754 100644 --- a/src/engine/torque.go +++ b/src/engine/torque.go @@ -5,7 +5,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var ( @@ -65,7 +65,7 @@ func AddSTTorque(dst *data.Slice) { if J.isZero() { return } - util.AssertMsg(!Pol.isZero(), "spin polarization should not be 0") + log.AssertMsg(!Pol.isZero(), "spin polarization should not be 0") jspin, rec := J.Slice() if rec { defer cuda.Recycle(jspin) diff --git a/src/engine/util.go b/src/engine/util.go index 9cd2dd8f..b862bbca 100644 --- a/src/engine/util.go +++ b/src/engine/util.go @@ -10,9 +10,9 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" "github.com/MathieuMoalic/amumax/src/httpfs" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/mag" "github.com/MathieuMoalic/amumax/src/oommf" - "github.com/MathieuMoalic/amumax/src/util" "github.com/MathieuMoalic/amumax/src/zarr" ) @@ -60,11 +60,11 @@ func Vector(x, y, z float64) data.Vector { // and print suited message. func Expect(msg string, have, want, maxError float64) { if math.IsNaN(have) || math.IsNaN(want) || math.Abs(have-want) > maxError { - util.Log.Info(msg, ":", " have: ", have, " want: ", want, "±", maxError) + log.Log.Info(msg, ":", " have: ", have, " want: ", want, "±", maxError) CleanExit() os.Exit(1) } else { - util.Log.Info(msg, ":", have, "OK") + log.Log.Info(msg, ":", have, "OK") } // note: we also check "want" for NaN in case "have" and "want" are switched. } @@ -81,23 +81,23 @@ func Fprintln(filename string, msg ...interface{}) { filename = OD() + filename } err := httpfs.Touch(filename) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) err = httpfs.Append(filename, []byte(fmt.Sprintln(CustomFmt(msg)))) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } func LoadFile(fname string) *data.Slice { var s *data.Slice s, err := zarr.Read(fname, OD()) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) return s } func LoadOvfFile(fname string) *data.Slice { in, err := httpfs.Open(fname) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) var s *data.Slice s, _, err = oommf.Read(in) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) return s } @@ -116,7 +116,7 @@ func Download(q Quantity) *data.Slice { // print with special formatting for some known types func myprint(msg ...interface{}) { - util.Log.Info("%v", CustomFmt(msg)) + log.Log.Info("%v", CustomFmt(msg)) } // mumax specific formatting (Slice -> average, etc). @@ -165,7 +165,7 @@ func slice(v [3]float64) []float64 { } func unslice(v []float64) [3]float64 { - util.Assert(len(v) == 3) + log.Assert(len(v) == 3) return [3]float64{v[0], v[1], v[2]} } diff --git a/src/engine/zarr_save.go b/src/engine/zarr_save.go index 12eb1e50..77b5d4d9 100644 --- a/src/engine/zarr_save.go +++ b/src/engine/zarr_save.go @@ -10,7 +10,7 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" "github.com/MathieuMoalic/amumax/src/httpfs" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/zarr" ) @@ -70,11 +70,11 @@ func (a *zArray) SaveAttrs() { // it's stupid and wasteful but it works // keeping the whole array of times wastes a few MB of RAM u, err := json.Marshal(zarr.Zattrs{Buffer: a.times}) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) err = httpfs.Remove(OD() + a.name + "/.zattrs") - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) err = httpfs.Put(OD()+a.name+"/.zattrs", []byte(string(u))) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } func (a *zArray) Save() { @@ -100,10 +100,10 @@ func zVerifyAndSave(q Quantity, name string, rchunks RequestedChunking, period f } else { if httpfs.Exists(OD() + name) { err := httpfs.Remove(OD() + name) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } err := httpfs.Mkdir(OD() + name) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) var b []float64 a := zArray{name, q, period, Time, -1, b, NewChunks(q, rchunks), rchunks} zArrays = append(zArrays, &a) @@ -115,9 +115,9 @@ func zArrayExists(q Quantity, name string, rchunks RequestedChunking) bool { for _, z := range zArrays { if z.name == name { if z.rchunks != rchunks { - util.Log.ErrAndExit("Error: The dataset %v has already been initialized with different chunks.", name) + log.Log.ErrAndExit("Error: The dataset %v has already been initialized with different chunks.", name) } else if z.q != q { - util.Log.ErrAndExit("Error: The dataset %v has already been initialized with a different quantity.", name) + log.Log.ErrAndExit("Error: The dataset %v has already been initialized with a different quantity.", name) } else { return true } @@ -141,7 +141,7 @@ func SyncSave(array *data.Slice, qname string, time int, chunks Chunks) { for icc := 0; icc < chunks.c.nb; icc++ { bdata := []byte{} f, err := httpfs.Create(fmt.Sprintf(OD()+"%s/%d.%d.%d.%d.%d", qname, time+1, icz, icy, icx, icc)) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) defer f.Close() for iz := 0; iz < chunks.z.len; iz++ { z := icz*chunks.z.len + iz @@ -150,7 +150,7 @@ func SyncSave(array *data.Slice, qname string, time int, chunks Chunks) { for ix := 0; ix < chunks.x.len; ix++ { x := icx*chunks.x.len + ix for ic := 0; ic < chunks.c.len; ic++ { - // util.Log.Comment(ic,icc) + // log.Log.Comment(ic,icc) c := icc*chunks.c.len + ic bytes = (*[4]byte)(unsafe.Pointer(&data[c][z][y][x]))[:] for k := 0; k < 4; k++ { @@ -161,9 +161,9 @@ func SyncSave(array *data.Slice, qname string, time int, chunks Chunks) { } } compressedData, err := zstd.Compress(nil, bdata) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) _, err = f.Write(compressedData) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } } } diff --git a/src/engine/zarr_table.go b/src/engine/zarr_table.go index b58edcc0..ecc05a38 100644 --- a/src/engine/zarr_table.go +++ b/src/engine/zarr_table.go @@ -7,8 +7,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/data" "github.com/MathieuMoalic/amumax/src/httpfs" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" "github.com/MathieuMoalic/amumax/src/zarr" ) @@ -67,7 +67,7 @@ func (ts *TableStruct) WriteToBuffer() { func (ts *TableStruct) Flush() { for i := range ts.Columns { _, err := ts.Columns[i].io.Write(ts.Columns[i].buffer) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) ts.Columns[i].buffer = []byte{} // saving .zarray before the data might help resolve some unsync // errors when the simulation is running and the user loads data @@ -100,20 +100,20 @@ func (ts *TableStruct) Exists(q Quantity, name string) bool { func (ts *TableStruct) AddColumn(name, unit string) { err := httpfs.Mkdir(OD() + "table/" + name) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) f, err := httpfs.Create(OD() + "table/" + name + "/0") - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) ts.Columns = append(ts.Columns, Column{Name: name, Unit: unit, buffer: []byte{}, io: f}) } func TableInit() { err := httpfs.Remove(OD() + "table") - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) zarr.MakeZgroup("table", OD(), &zGroups) err = httpfs.Mkdir(OD() + "table/t") - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) f, err := httpfs.Create(OD() + "table/t/0") - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) Table.Columns = append(Table.Columns, Column{"t", "s", []byte{}, f}) TableAdd(&M) go TablesAutoFlush() @@ -142,14 +142,14 @@ func TableAdd(q Quantity) { func TableAddAs(q Quantity, name string) { suffixes := []string{"x", "y", "z"} if Table.Step != -1 { - util.Log.Warn("You cannot add a new quantity to the table after the simulation has started. Ignoring.") + log.Log.Warn("You cannot add a new quantity to the table after the simulation has started. Ignoring.") } if len(Table.Columns) == 0 { TableInit() } if Table.Exists(q, name) { - util.Log.Warn("%s is already in the table. Ignoring.", name) + log.Log.Warn("%s is already in the table. Ignoring.", name) return } Table.quantities = append(Table.quantities, q) diff --git a/src/entrypoint/cli.go b/src/entrypoint/cli.go index 5fe404fa..25817071 100644 --- a/src/entrypoint/cli.go +++ b/src/entrypoint/cli.go @@ -6,8 +6,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/engine" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/timer" - "github.com/MathieuMoalic/amumax/src/util" "github.com/fatih/color" "github.com/spf13/cobra" ) @@ -42,7 +42,7 @@ func init() { } func cliEntrypoint(cmd *cobra.Command, args []string) { - util.Log.SetDebug(flags.debug) + log.Log.SetDebug(flags.debug) if flags.update { showUpdateMenu() return @@ -78,6 +78,6 @@ func cliEntrypoint(cmd *cobra.Command, args []string) { } else if len(args) > 1 { RunQueue(args) } else { - util.Log.ErrAndExit("No input files") + log.Log.ErrAndExit("No input files") } } diff --git a/src/entrypoint/main.go b/src/entrypoint/main.go index f1da4920..2c993548 100644 --- a/src/entrypoint/main.go +++ b/src/entrypoint/main.go @@ -13,8 +13,8 @@ import ( "github.com/MathieuMoalic/amumax/src/cuda" "github.com/MathieuMoalic/amumax/src/cuda/cu" "github.com/MathieuMoalic/amumax/src/engine" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" ) func Entrypoint() { @@ -29,15 +29,15 @@ type Release struct { } func runInteractive() { - util.Log.Info("No input files: starting interactive session") + log.Log.Info("No input files: starting interactive session") // setup outut dir now := time.Now() outdir := fmt.Sprintf("/tmp/amumax-%v-%02d-%02d_%02dh%02d.zarr", now.Year(), int(now.Month()), now.Day(), now.Hour(), now.Minute()) engine.InitIO(outdir, outdir, flags.cacheDir, flags.skipExists, flags.forceClean, flags.progress, flags.selfTest, flags.sync) - util.Log.Info("Input file: %s", "none") - util.Log.Info("Output directory: %s", engine.OD()) - util.Log.Init(engine.OD()) + log.Log.Info("Input file: %s", "none") + log.Log.Info("Output directory: %s", engine.OD()) + log.Log.Init(engine.OD()) // set up some sensible start configuration engine.Eval(` @@ -59,7 +59,7 @@ m = RandomMag()`) func runFileAndServe(mx3Path string) { if _, err := os.Stat(mx3Path); errors.Is(err, os.ErrNotExist) { - util.Log.ErrAndExit("Error: File `%s` does not exist", mx3Path) + log.Log.ErrAndExit("Error: File `%s` does not exist", mx3Path) } outputdir := strings.TrimSuffix(mx3Path, ".mx3") + ".zarr" @@ -67,11 +67,11 @@ func runFileAndServe(mx3Path string) { outputdir = flags.outputDir } engine.InitIO(mx3Path, outputdir, flags.cacheDir, flags.skipExists, flags.forceClean, flags.progress, flags.selfTest, flags.sync) - util.Log.Info("Input file: %s", mx3Path) - util.Log.Info("Output directory: %s", engine.OD()) + log.Log.Info("Input file: %s", mx3Path) + log.Log.Info("Output directory: %s", engine.OD()) - util.Log.Init(engine.OD()) - go util.Log.AutoFlushToFile() + log.Log.Init(engine.OD()) + go log.Log.AutoFlushToFile() mx3Path = engine.InputFile @@ -81,9 +81,9 @@ func runFileAndServe(mx3Path string) { // first we compile the entire file into an executable tree code, err2 = engine.CompileFile(mx3Path) if err2 != nil { - util.Log.ErrAndExit("Error while parsing `%s`: %v", mx3Path, err2) + log.Log.ErrAndExit("Error while parsing `%s`: %v", mx3Path, err2) } - util.Log.PanicIfError(err2) + log.Log.PanicIfError(err2) } // now the parser is not used anymore so it can handle web requests @@ -100,9 +100,9 @@ func runFileAndServe(mx3Path string) { // print version to stdout func printVersion() { - util.Log.Info("Version: %s", engine.VERSION) - util.Log.Info("Platform: %s_%s", runtime.GOOS, runtime.GOARCH) - util.Log.Info("Go Version: %s (%s)", runtime.Version(), runtime.Compiler) - util.Log.Info("CUDA Version: %d.%d (CC=%d PTX)", cu.CUDA_VERSION/1000, (cu.CUDA_VERSION%1000)/10, cuda.UseCC) - util.Log.Info("GPU Information: %s", cuda.GPUInfo) + log.Log.Info("Version: %s", engine.VERSION) + log.Log.Info("Platform: %s_%s", runtime.GOOS, runtime.GOARCH) + log.Log.Info("Go Version: %s (%s)", runtime.Version(), runtime.Compiler) + log.Log.Info("CUDA Version: %d.%d (CC=%d PTX)", cu.CUDA_VERSION/1000, (cu.CUDA_VERSION%1000)/10, cuda.UseCC) + log.Log.Info("GPU Information: %s", cuda.GPUInfo) } diff --git a/src/entrypoint/queue.go b/src/entrypoint/queue.go index 78ac9ac1..4b130312 100644 --- a/src/entrypoint/queue.go +++ b/src/entrypoint/queue.go @@ -13,7 +13,7 @@ import ( "sync/atomic" "github.com/MathieuMoalic/amumax/src/cuda/cu" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) var ( @@ -121,7 +121,7 @@ func run(inFile string, gpu int) { func initGPUs(nGpu int) chan int { if nGpu == 0 { - util.Log.ErrAndExit("no GPUs available") + log.Log.ErrAndExit("no GPUs available") } idle := make(chan int, nGpu) for i := 0; i < nGpu; i++ { @@ -203,7 +203,7 @@ func (s *stateTab) RenderHTML(w io.Writer) { func (s *stateTab) ListenAndServe(addr string) { http.Handle("/", s) go func() { - util.Log.PanicIfError(http.ListenAndServe(addr, nil)) + log.Log.PanicIfError(http.ListenAndServe(addr, nil)) }() } diff --git a/src/entrypoint/slurm.go b/src/entrypoint/slurm.go index b7d0e482..90a47d7b 100644 --- a/src/entrypoint/slurm.go +++ b/src/entrypoint/slurm.go @@ -8,8 +8,8 @@ import ( "time" "github.com/MathieuMoalic/amumax/src/engine" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/script" - "github.com/MathieuMoalic/amumax/src/util" ) // Parse HH:MM:SS format into time.Duration @@ -72,7 +72,7 @@ func setEndTimerIfSlurm() { getSlurmMetadata() endTime, err := getSlurmEndTime() if err != nil { - util.Log.Warn("Error getting SLURM end time: %v", err) + log.Log.Warn("Error getting SLURM end time: %v", err) return } @@ -81,8 +81,8 @@ func setEndTimerIfSlurm() { remaining := time.Until(endTime) if remaining <= 30*time.Second && remaining > 0 { // If 30 seconds or less are remaining, print the message - util.Log.Warn("30 seconds remaining until the job ends!") - util.Log.Warn("Cleanly exiting the simulation early...") + log.Log.Warn("30 seconds remaining until the job ends!") + log.Log.Warn("Cleanly exiting the simulation early...") engine.Exit() } // Sleep for a short while before checking again diff --git a/src/entrypoint/template_test.go b/src/entrypoint/template_test.go index 11419d17..caf643a0 100644 --- a/src/entrypoint/template_test.go +++ b/src/entrypoint/template_test.go @@ -236,8 +236,8 @@ func TestFormatError(t *testing.T) { // Parse template err := template(templatePath) - if err != nil { - t.Fatalf("Error processing template: %v", err) + if err.Error() != `error finding expressions: only the %f format is allowed: %d` { + t.Fatalf("Expected error: %v", err) } // check if no file is generated _, err = os.ReadFile("test_output/1.mx3") diff --git a/src/entrypoint/update.go b/src/entrypoint/update.go index 1cbcf842..9f8ad90f 100644 --- a/src/entrypoint/update.go +++ b/src/entrypoint/update.go @@ -3,12 +3,11 @@ package entrypoint import ( "encoding/json" "fmt" - "log" "net/http" "os" "github.com/MathieuMoalic/amumax/src/engine" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/fatih/color" "github.com/manifoldco/promptui" "github.com/minio/selfupdate" @@ -18,7 +17,7 @@ func doUpdate(tag string) { color.Green("Downloading version %s", tag) resp, err := http.Get(fmt.Sprintf("https://github.com/MathieuMoalic/amumax/src/releases/download/%s/amumax", tag)) if err != nil { - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } defer resp.Body.Close() err = selfupdate.Apply(resp.Body, selfupdate.Options{}) @@ -35,17 +34,17 @@ func getTags() (tags []string) { } resp, err := http.Get("https://api.github.com/repos/mathieumoalic/amumax/tags") if err != nil { - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - log.Panicf("Error: HTTP %v", resp.StatusCode) + log.Log.PanicIfError(fmt.Errorf("unexpected status code: %d", resp.StatusCode)) } tempTags := []Tag{} if err := json.NewDecoder(resp.Body).Decode(&tempTags); err != nil { - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } for _, tag := range tempTags { diff --git a/src/entrypoint/vet.go b/src/entrypoint/vet.go index 0d039098..6cc3e94a 100644 --- a/src/entrypoint/vet.go +++ b/src/entrypoint/vet.go @@ -6,7 +6,7 @@ import ( "os" "github.com/MathieuMoalic/amumax/src/engine" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // check all input files for errors, don't run. @@ -14,7 +14,7 @@ func vet() { status := 0 for _, f := range flag.Args() { src, ioerr := os.ReadFile(f) - util.Log.PanicIfError(ioerr) + log.Log.PanicIfError(ioerr) engine.World.EnterScope() // avoid name collisions between separate files _, err := engine.World.Compile(string(src)) engine.World.ExitScope() diff --git a/src/util/log.go b/src/log/log.go similarity index 85% rename from src/util/log.go rename to src/log/log.go index 5bac7066..83cd0e8f 100644 --- a/src/util/log.go +++ b/src/log/log.go @@ -1,4 +1,4 @@ -package util +package log // Logging and error reporting utility functions @@ -117,3 +117,24 @@ func (l *Logs) ErrAndExit(msg string, args ...interface{}) { l.Err(msg, args...) os.Exit(1) } + +// Panics with "illegal argument" if test is false. +func AssertArgument(test bool) { + if !test { + Log.ErrAndExit("illegal argument") + } +} + +// Panics with msg if test is false +func AssertMsg(test bool, msg interface{}) { + if !test { + Log.ErrAndExit("%v", msg) + } +} + +// Panics with "assertion failed" if test is false. +func Assert(test bool) { + if !test { + Log.ErrAndExit("assertion failed") + } +} diff --git a/src/mag/demagkernel.go b/src/mag/demagkernel.go index d7b8c57b..43f40de8 100644 --- a/src/mag/demagkernel.go +++ b/src/mag/demagkernel.go @@ -9,8 +9,8 @@ import ( "github.com/DataDog/zstd" "github.com/MathieuMoalic/amumax/src/data" "github.com/MathieuMoalic/amumax/src/httpfs" + "github.com/MathieuMoalic/amumax/src/log" "github.com/MathieuMoalic/amumax/src/timer" - "github.com/MathieuMoalic/amumax/src/util" "github.com/MathieuMoalic/amumax/src/zarr" ) @@ -26,7 +26,7 @@ func DemagKernel(gridsize, pbc [3]int, cellsize [3]float64, accuracy float64, ca sanityCheck(cellsize) // Cache disabled if cacheDir == "" { - util.Log.Warn(`Kernel cache disabled.`) + log.Log.Warn(`Kernel cache disabled.`) kernel = calcDemagKernel(gridsize, pbc, cellsize, accuracy, showMagnets) // return without saving return @@ -35,32 +35,32 @@ func DemagKernel(gridsize, pbc [3]int, cellsize [3]float64, accuracy float64, ca if !httpfs.Exists(cacheDir) { err := httpfs.Mkdir(cacheDir) if err != nil { - util.Log.Warn("Unable to create kernel cache directory: %v", err) + log.Log.Warn("Unable to create kernel cache directory: %v", err) } } defer func() { if err := recover(); err != nil { - util.Log.Warn("Unable to use kernel cache: %v", err) + log.Log.Warn("Unable to use kernel cache: %v", err) kernel = calcDemagKernel(gridsize, pbc, cellsize, accuracy, showMagnets) } }() basename := kernelName(gridsize, pbc, cellsize, accuracy, cacheDir) if httpfs.Exists(basename) { - util.Log.Info("Loading kernel from cache") + log.Log.Info("Loading kernel from cache") var err error kernel, err = loadKernel(basename, padSize(gridsize, pbc)) if err != nil { - util.Log.Warn("Couldn't load kernel from cache: %v", err) + log.Log.Warn("Couldn't load kernel from cache: %v", err) kernel = calcDemagKernel(gridsize, pbc, cellsize, accuracy, showMagnets) } return kernel } else { - util.Log.Info("Calculating kernel and saving to cache") + log.Log.Info("Calculating kernel and saving to cache") kernel = calcDemagKernel(gridsize, pbc, cellsize, accuracy, showMagnets) err := saveKernel(basename, kernel) if err != nil { - util.Log.Warn("Couldn't save kernel to cache: %v \n %v", basename, err.Error()) + log.Log.Warn("Couldn't save kernel to cache: %v \n %v", basename, err.Error()) } return } @@ -175,10 +175,10 @@ func calcDemagKernel(gridsize, pbc [3]int, cellsize [3]float64, accuracy float64 // Sanity check { - util.Assert(size[Z] > 0 && size[Y] > 0 && size[X] > 0) - util.Assert(cellsize[X] > 0 && cellsize[Y] > 0 && cellsize[Z] > 0) - util.Assert(pbc[X] >= 0 && pbc[Y] >= 0 && pbc[Z] >= 0) - util.Assert(accuracy > 0) + log.Assert(size[Z] > 0 && size[Y] > 0 && size[X] > 0) + log.Assert(cellsize[X] > 0 && cellsize[Y] > 0 && cellsize[Z] > 0) + log.Assert(pbc[X] >= 0 && pbc[Y] >= 0 && pbc[Z] >= 0) + log.Assert(accuracy > 0) } // Allocate only upper diagonal part. The rest is symmetric due to reciprocity. @@ -271,7 +271,7 @@ func calcDemagKernel(gridsize, pbc [3]int, cellsize [3]float64, accuracy float64 nv *= 2 nw *= 2 - util.Assert(nv > 0 && nw > 0 && nx > 0 && ny > 0 && nz > 0) + log.Assert(nv > 0 && nw > 0 && nx > 0 && ny > 0 && nz > 0) scale := 1 / float64(nv*nw*nx*ny*nz) surface := cellsize[v] * cellsize[w] // the two directions perpendicular to direction s @@ -450,7 +450,7 @@ func sanityCheck(cellsize [3]float64) { aMin := math.Min(a1, math.Min(a2, a3)) if aMax > maxAspect || aMin < 1./maxAspect { - util.Log.PanicIfError(fmt.Errorf("unrealistic cell aspect ratio %v", cellsize)) + log.Log.PanicIfError(fmt.Errorf("unrealistic cell aspect ratio %v", cellsize)) } } diff --git a/src/mag/mfmkernel.go b/src/mag/mfmkernel.go index 82614d0c..928a5422 100644 --- a/src/mag/mfmkernel.go +++ b/src/mag/mfmkernel.go @@ -5,7 +5,7 @@ import ( "math" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func MFMKernel(mesh *data.Mesh, lift, tipsize float64, cacheDir string) (kernel [3]*data.Slice) { @@ -19,7 +19,7 @@ func CalcMFMKernel(mesh *data.Mesh, lift, tipsize float64) (kernel [3]*data.Slic const TipCharge = 1 / Mu0 // tip charge const Δ = 1e-9 // tip oscillation, take 2nd derivative over this distance - util.AssertMsg(lift > 0, "MFM tip crashed into sample, please lift the new one higher") + log.AssertMsg(lift > 0, "MFM tip crashed into sample, please lift the new one higher") { // Kernel mesh is 2x larger than input, instead in case of PBC pbc := mesh.PBC() @@ -37,11 +37,11 @@ func CalcMFMKernel(mesh *data.Mesh, lift, tipsize float64) (kernel [3]*data.Slic // Sanity check { - util.Assert(size[Z] >= 1 && size[Y] >= 2 && size[X] >= 2) - util.Assert(cellsize[X] > 0 && cellsize[Y] > 0 && cellsize[Z] > 0) - util.AssertMsg(size[X]%2 == 0 && size[Y]%2 == 0, "MFM must have even cellsize on the X and Y axis") + log.Assert(size[Z] >= 1 && size[Y] >= 2 && size[X] >= 2) + log.Assert(cellsize[X] > 0 && cellsize[Y] > 0 && cellsize[Z] > 0) + log.AssertMsg(size[X]%2 == 0 && size[Y]%2 == 0, "MFM must have even cellsize on the X and Y axis") if size[Z] > 1 { - util.AssertMsg(size[Z]%2 == 0, "MFM only supports one cell thickness on the Z axis") + log.AssertMsg(size[Z]%2 == 0, "MFM only supports one cell thickness on the Z axis") } } diff --git a/src/oommf/oommf.go b/src/oommf/oommf.go index fd4fe524..72ac5333 100644 --- a/src/oommf/oommf.go +++ b/src/oommf/oommf.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // Read any OOMMF file, autodetect OVF1/OVF2 format @@ -53,7 +53,7 @@ func ReadFile(fname string) (*data.Slice, data.Meta, error) { func MustReadFile(fname string) (*data.Slice, data.Meta) { s, t, err := ReadFile(fname) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) return s, t } @@ -233,9 +233,9 @@ func writeOVFText(out io.Writer, tens *data.Slice) (err error) { // # Key: Value func hdr(out io.Writer, key string, value ...interface{}) { _, err := fmt.Fprint(out, "# ", key, ": ") - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) _, err = fmt.Fprintln(out, value...) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } func dsc(out io.Writer, k, v interface{}) { diff --git a/src/oommf/ovf1.go b/src/oommf/ovf1.go index 0cd94b20..297f1b80 100644 --- a/src/oommf/ovf1.go +++ b/src/oommf/ovf1.go @@ -8,12 +8,12 @@ import ( "unsafe" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func WriteOVF1(out io.Writer, q *data.Slice, meta data.Meta, dataformat string) { if q.NComp() != 3 { - util.Log.ErrAndExit("Cannot save the quantity: the OVF1 format only supports 3D-vector fields.") + log.Log.ErrAndExit("Cannot save the quantity: the OVF1 format only supports 3D-vector fields.") } writeOVF1Header(out, q, meta) writeOVF1Data(out, q, dataformat) @@ -26,13 +26,13 @@ func writeOVF1Data(out io.Writer, q *data.Slice, dataformat string) { case "text": canonicalFormat = "Text" hdr(out, "Begin", "Data "+canonicalFormat) - util.Log.PanicIfError(writeOVFText(out, q)) + log.Log.PanicIfError(writeOVFText(out, q)) case "binary", "binary 4": canonicalFormat = "Binary 4" hdr(out, "Begin", "Data "+canonicalFormat) - util.Log.PanicIfError(writeOVF1Binary4(out, q)) + log.Log.PanicIfError(writeOVF1Binary4(out, q)) default: - util.Log.ErrAndExit("Illegal OVF data format: %v. Options are: Text, Binary 4", dataformat) + log.Log.ErrAndExit("Illegal OVF data format: %v. Options are: Text, Binary 4", dataformat) } hdr(out, "End", "Data "+canonicalFormat) } @@ -99,7 +99,7 @@ func writeOVF1Binary4(out io.Writer, array *data.Slice) (err error) { bytes = (*[4]byte)(unsafe.Pointer(&data[c][iz][iy][ix]))[:] bytes[0], bytes[1], bytes[2], bytes[3] = bytes[3], bytes[2], bytes[1], bytes[0] _, err := out.Write(bytes) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } } } @@ -114,7 +114,7 @@ func readOVF1DataBinary4(in io.Reader, t *data.Slice) { // OOMMF requires this number to be first to check the format var controlnumber float32 // OVF 1.0 is network byte order (MSB) - util.Log.PanicIfError(binary.Read(in, binary.BigEndian, &controlnumber)) + log.Log.PanicIfError(binary.Read(in, binary.BigEndian, &controlnumber)) if controlnumber != OVF_CONTROL_NUMBER_4 { panic("invalid OVF1 control number: " + fmt.Sprint(controlnumber)) } @@ -142,7 +142,7 @@ func readOVF1DataBinary8(in io.Reader, t *data.Slice) { // OOMMF requires this number to be first to check the format var controlnumber float64 // OVF 1.0 is network byte order (MSB) - util.Log.PanicIfError(binary.Read(in, binary.BigEndian, &controlnumber)) + log.Log.PanicIfError(binary.Read(in, binary.BigEndian, &controlnumber)) if controlnumber != OVF_CONTROL_NUMBER_8 { panic("invalid OVF1 control number: " + fmt.Sprint(controlnumber)) diff --git a/src/oommf/ovf2.go b/src/oommf/ovf2.go index 11de104e..146316ab 100644 --- a/src/oommf/ovf2.go +++ b/src/oommf/ovf2.go @@ -7,7 +7,7 @@ import ( "unsafe" "github.com/MathieuMoalic/amumax/src/data" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func WriteOVF2(out io.Writer, q *data.Slice, meta data.Meta, dataformat string) { @@ -80,13 +80,13 @@ func writeOVF2Data(out io.Writer, q *data.Slice, dataformat string) { case "text": canonicalFormat = "Text" hdr(out, "Begin", "Data "+canonicalFormat) - util.Log.PanicIfError(writeOVFText(out, q)) + log.Log.PanicIfError(writeOVFText(out, q)) case "binary", "binary 4": canonicalFormat = "Binary 4" hdr(out, "Begin", "Data "+canonicalFormat) writeOVF2DataBinary4(out, q) default: - util.Log.ErrAndExit("Illegal OMF data format: %v. Options are: Text, Binary 4", dataformat) + log.Log.ErrAndExit("Illegal OMF data format: %v. Options are: Text, Binary 4", dataformat) } hdr(out, "End", "Data "+canonicalFormat) } @@ -104,7 +104,7 @@ func writeOVF2DataBinary4(out io.Writer, array *data.Slice) { var controlnumber float32 = OVF_CONTROL_NUMBER_4 bytes = (*[4]byte)(unsafe.Pointer(&controlnumber))[:] _, err := out.Write(bytes) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) ncomp := array.NComp() for iz := 0; iz < size[Z]; iz++ { @@ -113,7 +113,7 @@ func writeOVF2DataBinary4(out io.Writer, array *data.Slice) { for c := 0; c < ncomp; c++ { bytes = (*[4]byte)(unsafe.Pointer(&data[c][iz][iy][ix]))[:] _, err := out.Write(bytes) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } } } diff --git a/src/script/blockstmt.go b/src/script/blockstmt.go index f02e5bf3..172bf5b6 100644 --- a/src/script/blockstmt.go +++ b/src/script/blockstmt.go @@ -9,7 +9,7 @@ import ( "reflect" "strings" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) // block statement is a list of statements. @@ -50,7 +50,7 @@ func (b *BlockStmt) Child() []Expr { func Format(n ast.Node) string { var buf bytes.Buffer fset := token.NewFileSet() - util.Log.PanicIfError(format.Node(&buf, fset, n)) + log.Log.PanicIfError(format.Node(&buf, fset, n)) str := buf.String() str = strings.TrimSuffix(str, "\n") return str @@ -60,7 +60,7 @@ func (b *BlockStmt) Format() string { var buf bytes.Buffer fset := token.NewFileSet() for i := range b.Children { - util.Log.PanicIfError(format.Node(&buf, fset, b.Node[i])) + log.Log.PanicIfError(format.Node(&buf, fset, b.Node[i])) fmt.Fprintln(&buf) } return buf.String() diff --git a/src/script/script_test.go b/src/script/script_test.go index 1e9fcb50..b116d3fd 100644 --- a/src/script/script_test.go +++ b/src/script/script_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) func TestEval(t *testing.T) { @@ -67,7 +67,7 @@ func TestTypes(t *testing.T) { w.Var("x", &x) w.MustExec("x=7") - w.Func("printInt", func(x int) { util.Log.Info("%v", x) }) + w.Func("printInt", func(x int) { log.Log.Info("%v", x) }) w.MustExec("printInt(7)") } @@ -210,7 +210,7 @@ func TestFail(test *testing.T) { if err == nil { test.Error(t, "should not compile") } else { - util.Log.Info(t, ":", err, ":OK") + log.Log.Info(t, ":", err, ":OK") } } } diff --git a/src/util/assert.go b/src/util/assert.go deleted file mode 100644 index cac0f842..00000000 --- a/src/util/assert.go +++ /dev/null @@ -1,34 +0,0 @@ -package util - -// Panics with "illegal argument" if test is false. -func Argument(test bool) { - if !test { - Log.ErrAndExit("illegal argument") - } -} - -// Panics with msg if test is false -func AssertMsg(test bool, msg interface{}) { - if !test { - Log.ErrAndExit("%v", msg) - } -} - -// Panics with "assertion failed" if test is false. -func Assert(test bool) { - if !test { - Log.ErrAndExit("assertion failed") - } -} - -// Special error that is not fatal when paniced on and called from GUI -// E.g.: try to set bad grid size: panic on UserErr, recover, print error, carry on. -type UserErr string - -func (e UserErr) Error() string { return string(e) } - -func CheckRecoverable(err error) { - if err != nil { - panic(UserErr(err.Error())) - } -} diff --git a/src/util/atom.go b/src/util/atom.go deleted file mode 100644 index b14f0b09..00000000 --- a/src/util/atom.go +++ /dev/null @@ -1,14 +0,0 @@ -package util - -import "sync/atomic" - -// Atomic int -type Atom int32 - -func (a *Atom) Add(v int32) { - atomic.AddInt32((*int32)(a), v) -} - -func (a *Atom) Load() int32 { - return atomic.LoadInt32((*int32)(a)) -} diff --git a/src/util/format.go b/src/util/format.go deleted file mode 100644 index 91c6ed03..00000000 --- a/src/util/format.go +++ /dev/null @@ -1,77 +0,0 @@ -package util - -import ( - "bytes" - "fmt" - "io" - "os" -) - -// Produces nicely formatted output for multi-dimensional arrays. -func Println(array ...interface{}) { - Fprint(os.Stdout, array...) - fmt.Fprintln(os.Stdout) -} - -// Produces nicely formatted output for multi-dimensional arrays. -func Print(array ...interface{}) { - Fprint(os.Stdout, array...) -} - -// Produces nicely formatted output for multi-dimensional arrays. -func Printf(format string, array ...interface{}) { - Fprintf(os.Stdout, format, array...) -} - -// Produces nicely formatted output for multi-dimensional arrays. -func Fprint(out io.Writer, array ...interface{}) { - Fprintf(out, "%v", array...) -} - -func Sprint(array ...interface{}) string { - var buf bytes.Buffer - Fprint(&buf, array...) - return buf.String() -} - -// Produces nicely formatted output for multi-dimensional arrays. -func Fprintf(out io.Writer, format string, array ...interface{}) { - for _, arr := range array { - switch a := arr.(type) { - case [][][]float32: - FprintfFloats(out, format, a) - case [][][][]float32: - FprintfTensors(out, format, a) - case [3][][][]float32: - FprintfTensors(out, format, a[:]) - case [3][3][][][]float32: - Fprintf(out, format, a[0][:]) - Fprintf(out, format, a[1][:]) - Fprintf(out, format, a[2][:]) - default: - fmt.Fprintf(out, format, a) - } - } -} - -// Produces nicely formatted output. -func FprintfTensors(out io.Writer, format string, a [][][][]float32) { - for i := range a { - FprintfFloats(out, format, a[i]) - fmt.Fprintln(out) - } -} - -// Produces nicely formatted output. -func FprintfFloats(out io.Writer, format string, a [][][]float32) { - format += " " - for i := range a { - for j := range a[i] { - for _, v := range a[i][j] { - fmt.Fprintf(out, format, v) - } - fmt.Fprintln(out) - } - fmt.Fprintln(out) - } -} diff --git a/src/zarr/metadata.go b/src/zarr/metadata.go index 51cd5a4a..76c728d1 100644 --- a/src/zarr/metadata.go +++ b/src/zarr/metadata.go @@ -7,7 +7,7 @@ import ( "time" "github.com/MathieuMoalic/amumax/src/httpfs" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) type Metadata struct { @@ -60,7 +60,7 @@ func (m *Metadata) Add(key string, val interface{}) { // ignore functions return default: - util.Log.Debug("Metadata key %s has invalid type %s: %v", key, val_type, val) + log.Log.Debug("Metadata key %s has invalid type %s: %v", key, val_type, val) } } @@ -86,11 +86,11 @@ func (m *Metadata) NeedSave() bool { func (m *Metadata) Save() { if m.Path != "" { zattrs, err := httpfs.Create(m.Path) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) defer zattrs.Close() json_meta, err := json.MarshalIndent(m.Fields, "", "\t") - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) _, err = zattrs.Write([]byte(json_meta)) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) } } diff --git a/src/zarr/read.go b/src/zarr/read.go index dc6899b3..d6beeea8 100644 --- a/src/zarr/read.go +++ b/src/zarr/read.go @@ -10,7 +10,7 @@ import ( "github.com/MathieuMoalic/amumax/src/data" "github.com/MathieuMoalic/amumax/src/httpfs" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" "github.com/DataDog/zstd" ) @@ -19,28 +19,28 @@ func Read(binary_path string, pwd string) (s *data.Slice, err error) { if !path.IsAbs(binary_path) { wd := "" wd, err = os.Getwd() - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) binary_path = wd + "/" + path.Dir(pwd) + "/" + binary_path } binary_path = path.Clean(binary_path) // loop and wait until the file is saved for IsSaving { - util.Log.Info("Waiting for all the files to be saved before reading...") + log.Log.Info("Waiting for all the files to be saved before reading...") time.Sleep(1 * time.Second) } zarray_path := path.Dir(binary_path) + "/.zarray" - util.Log.Info("Reading: %v", binary_path) + log.Log.Info("Reading: %v", binary_path) io_reader, err := httpfs.Open(binary_path) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) content, err := os.ReadFile(zarray_path) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) var zarray zarrayFile err = json.Unmarshal([]byte(content), &zarray) - util.Log.PanicIfError(err) + log.Log.PanicIfError(err) if zarray.Compressor.ID != "zstd" { - util.Log.PanicIfError(errors.New("LoadFile: Only the Zstd compressor is supported")) + log.Log.PanicIfError(errors.New("LoadFile: Only the Zstd compressor is supported")) } sizez := zarray.Chunks[1] sizey := zarray.Chunks[2] diff --git a/src/zarr/save_table.go b/src/zarr/save_table.go index 637e057b..c599b21c 100644 --- a/src/zarr/save_table.go +++ b/src/zarr/save_table.go @@ -6,7 +6,7 @@ import ( "os" "github.com/MathieuMoalic/amumax/src/httpfs" - "github.com/MathieuMoalic/amumax/src/util" + "github.com/MathieuMoalic/amumax/src/log" ) type ztableFile struct { @@ -22,7 +22,7 @@ type ztableFile struct { func SaveFileTableZarray(path string, zTableAutoSaveStep int) { if !pathExists(path) { - util.Log.PanicIfError(errors.New("error: `%s` does not exist")) + log.Log.PanicIfError(errors.New("error: `%s` does not exist")) } z := ztableFile{} z.Dtype = `