Nmag cheat sheet

Mesh generation

  • Create mesh with Netgen from command line (Geometry specification to Neutral Mesh)
    netgen -geofile=in.geo -moderate -meshfiletype="Neutral Format" \
           -meshfile=out.neu -batchmode

Convert from one mesh format to the other

  • Neutral format (Netgen) to Nmag format:
    nmeshimport --netgen in.neu out.nmesh.h5
    nmeshimport --netgen in.neu out.nmesh
  • Binary Nmag format to ASCII Nmag format and viceversa:
    nmeshpp -c in.nmesh.h5 out.nmesh
    nmeshpp -c in.nmesh out.nmesh.h5
  • Binary Nmag format to AVS format (Magpar):
    nmeshpp -m in.nmesh.h5 out.inp

Inspect and visualise mesh

  • Getting generic info on the mesh
    nmeshpp in.nmesh.h5 -i   # show general information, num points, num simplices, etc
    nmeshpp in.nmesh.h5 -a   # show a distribution of lengths of the edges of the simplices
    nmeshpp in.nmesh.h5 -q   # show a distribution of simplex quality
  • Transforming the mesh to a VTK file for visualisation (with Mayavi2 or Paraview):
    nmeshpp --vtk in.nmesh.h5 out.vtk
  • Visualising the mesh from the VTK file obtained from command above (using Mayavi2 or Paraview)
    mayavi2 -d out.vtk -m Surface
    paraview --data=out.vtk # click on apply when Paraview windows is shown

Running simulations

  • Run simulation file ``mysim.py``
    nsim mysim.py
  • Run simulation and confirm that existing data files should be overridden
    nsim mysim.py --clean
  • Continue simulation from stage where it was interrupted before (only for hysteresis command)
    nsim mysim.py --restart

Running MPI simulations

  • Start a parallel run (on 2 machines):
    mpirun -np 2 nsim mysim.py
  • For MPICH2 you need to launch the daemon first (not required for Nmag VM as it is using OpenMPI):
    cd nmag-0.1 # here we assume you installed from source
    ~/lib/mpich2/bin/mpd &

    If you launch mpd for the first time take a look at the instructions in the manual

Visualise mesh partitioning

When you run the simulation in parallel you get:

nfem.ocaml:2010-07-26 15:54:50,578    INFO Processor 0: 1065 nodes
nfem.ocaml:2010-07-26 15:54:50,578    INFO Processor 1: 1052 nodes

These numbers are recorded in the log file (example simulation_log.log).
We here assume that your fields are saved in the file simulation_dat.h5.
You can produce a VTK file with the partitioning (and visualise it) using:

nmeshpp simulation_dat.h5 --partitioning=[1065,1052] partitioning.vtk
mayavi2 -d partitioning.vtk -m Surface

Postprocessing data

  • Inspect field data file simulation_dat.h5:
    nmagpp simulation --fieldlist # get the list of field stored inside the file
    nmagpp simulation --idlist    # get the list of the IDs for the stored fields
  • Convert data from mysim_dat.h5 file to vtk-files with name myvtk-000000.vtk, myvtk-000001.vtk, etc.
    nmagpp --vtk myvtk.vtk mysim
  • Write VTK files containing only the specified fields (faster than command above):
    nmagpp --vtk myvtk.vtk --fields=m,H_demag mysim
  • Visualising data from the VTK obtained above
    mayavi2 -d myvtk-000000.vtk -m Vectors
  • Get a list of fields stored in NDT file mysim.ndt
    ncol mysim
  • Get a list of the fields whose name starts with H or H_e
    ncol mysim H
    ncol mysim H_e
  • Extract external field (spatial average against time) from ``mysim.ndt`` file
    ncol mysim time H_ext_0 H_ext_1 H_ext_2
  • Extract magnetisation against time (with ncol) and plot it with Gnuplot:
    ncol mysim time m_Py_0 m_Py_1 m_Py_2 > outfile.dat
    plot "./outfile.dat" u 1:2 t "m_x" w l, "" u 1:3 t "m_y" w l, "" u 1:4 t "m_z" w l

Also available in: HTML TXT