Sunday, 20 December 2015

A Quick Start to Using SMAUG

Guidelines for Using Sheffield Magnetohydrodynamics Algorithm Using GPUs (SMAUG)

Introduction

Parallel magnetohydrodynamic (MHD) algorithms are important for numerical modelling of highly inhomogeneous solar and astrophysical plasmas. SMAUG is the Sheffield Magnetohydrodynamics Algorithm Using GPUs. SMAUG is a 1-3D MHD code capable of modelling magnetised and gravitationally stratified magnetised plasma. The methods employed have been justied by performance benchmarks and validation results demonstrating that the code successfully simulates the physics for a range of test scenarios including a full 3D realistic model of wave propagation in the magnetised and stratified solar atmosphere. For details about smaug see the preprint at: smaugpreprint
SMAUG is based on the Sheffield Advanced Code (SAC), which is a novel fully non-linear MHD code, designed for simulations of linear and non-linear wave propagation in gravitationally strongly stratified magnetised plasma. See the reference at the Astronomy Abstracts Service. sacpaper
The smaug code has been developed by the Solar Wave theory group SWAT at The University of Sheffield. Researchers and users downloading the code are requested to acknowledge and give credit to the Solar Physics and Space Plasma Research Centre (SP2RC) at The University of Sheffield.

Requirements

CUDA-Enabled Tesla GPU Computing Product with at least compute capability 1.3.
See
http://developer.nvidia.com/cuda-gpus
CUDA toolkit
https://developer.nvidia.com/cuda-downloads
The SMAUG has been developed and tested on a range of different 64 bit (and 32 bit ) linux platforms.
Guidelines for correct installation of the CUDA toolkit and drivers can be found at cudagettingstarted

Installation

SMAUG can be downloaded in 3 ways
  • Download and extract the latest tarball from the google code site
  • Checkout the distribution from the user release version from the google repository. This is recommended if you require regular updates and bugfixes.
  • Checkout the distribution from the developer repository. This is recommended if you wish to participate in the development of future code versions.
Method 1:
Download the distribution Link to revision 257 source code
Copy the distribution to a suitable directory in your working area and extract the distribution tar -zxvf smaug_v1_rev255.tgz
Method 2:
Create a directory and from that directory,
using a subversion client checkout the latest distribution using the command:
svn checkout https://ccpforge.cse.rl.ac.uk/gf/project/sac/scmsvn/?action=browse&path=%2Frelease%2Fsmaug%2F
when prompted, Password for 'anonymous' just press return.

Building and running a Model

From the distribution base directory change directory to the src folder.
Building a smaug based simulation requires the use of the make utility. The make may be tuned for a particular platform by editing the include line near the top of the file.
The default input file is make_inputs. If you are building an MPI distributionthen edit this line and use make_inputs_mpi. Any particular options can be edited within the make_inputs file. It is most likely that the library path for the cuda libraries is set correctly. This can easily be changed by editing the CUDA.
The make_inputs file includes a number of compiler switches the smaug specific switches used for both the host compiler and cuda compiler are as follows.
USE_SAC            //Set this to build and compile 2D models
USE_SAC_3D         //Set this to build and compile 3D models
USE_MULTIGPU       //Set this to build for multi GPU models (e.g. if you are using MPI)
USE_MPI            //Set this if you are using MPI (need to set the host                           compiler to a suitabel MPI compiler)
USE_USERSOURCE     //Set this if you are using user provide source terms
The cuda specific switches are as follows
--ptxas-options=-v Provide verbose output when generating CUDA code -arch sm_20 Set the correct CUDA architecture (sm_20 allows printf debugging in CUDA kernels) -maxregcount=32 Set the numbe of register variables for the CUDA compiler
To make the Brio-Wu test (use the following commands)
make clean make bw make sac
Change back to the distribution base directory
Run the model
./iosmaug a
As each step is run the program outputs the current simulation time step, iteration and the time taken to compute that step. Generated configuration files are written to the out directory. These may be visualised with IDL using the procedures in the Idl directory.
For the Brio-Wu test use
visex22D_BW_test1.pro
For the Orszag-Tang test use
visex22d_cu_OT_test1.pro
The test models available are as follows. The code used with make to make the model is shown in the second column
1d Brio-Wu bw
2d Orszag-Tang ot 2d Kelvin-Helmholtz test kh
These tests have pre-prepared configuration files and should run by default. Configuration files may be generated using either SAMUG or the vacini routine with VAC or SAC. SMAUG generates binary output files but currently takes as input ascii configuration files. IDL procedures in the Idl folder are available to translate configuration data as required.

Modifying The Run Parameters

To change the input parameters edit the file iosmaugparams.h in the include folder. At any time you can revert to the default parameters for the OT test (or a particular model) by changing to the src folder and issuing the command
make ot
As soon as the parameter files have been updated, move to the src folder and recompile the model using
make smaug
Move back to the base directory and run the model.
The following parameters can be altered in the iosmaugparams.h file
ni,nj,nk           //size of the domain (note this will be shifted by 2X the number of ghost cells)
xmax, ymax, zmax   //the physical domain size for each direction
xmin, ymin, zmin

cfgfile             //The name and path of the input configuration file
cfgout              //The name and path of the output configuration file              (each file generated will
                     //be appended with an integer denoting the step index)

dt                  //The time step (if using fixed)
nt                  //Number of iterations to perform

p->gamma            //The adiabatic constant
p->courant          //The courant parameter used to determine the time step parameter
p->moddton          //Set to 0.0 for fixed time steps setto 1  to enable
p->hyperdifmom      //Set to 1.0 to switch hyperdiffusion stabilisation on 0.0 disables
p->readini          //Set to 1.0 to read initial configuration from an input file. 
                    //The 0.0 will generate a configutation using the default if provided
                    //or written by the user.
The hypediffusion parameters may be altered slightly but it is recommended to leave them at their default tuned settings.
p->chyp[rho]=0.02;
p->chyp[energy]=0.02;
p->chyp[b1]=0.02;
p->chyp[b2]=0.02;
p->chyp[mom1]=0.4;
p->chyp[mom2]=0.4;
p->chyp[rho]=0.02;
Boundary types are also set here according to field variable, direction and top or bottom boundary. The boundary conditions may also be user configured as briefly outlined in the following section.

Guidelines for Users Developing Customised Models

Users wishing to develop customised models require a basic knowledge of C programming. An indepth knowledge of CUDA programming is not required.
The following source files may be modified by the user.
iosmaugparams.h init_user.cu boundary.cu usersource.cu initialisation_user.h
The above files can be appended with a .mymodelname and stored in the models folder. The Makefile should be updated by including the following lines.
mymodelname:
cp ../models/iosmaugparams.h.mymodelname ../include/iosmaugparams.h
cp ../models/init_user.cu.mymodelname ../src/init_user.cu
cp ../models/boundary.cu.mymodelname ../src/boundary.cu
cp ../models/usersource.cu.mymodelname ../src/usersource.cu
cp ../models/initialisation_user.h.default ../include/initialisation_user.h
The custome model can then be set using
make mymodelname
Further details about building and compiling use defined models will be provided on line.
iosmaugparams.h Contains parameter settings init_user.cu Contains code which can be used to initialise a configuration on the GPU boundary.cu Allows the user to define which boundary conditions called and how they will be called usersource.cu Allows the user to include additional source terms (for example velocity driver terms) initialisation_user.h Allows the user to provide custom code generating a configuration on the host machine.
This is useful when a user needs to generate configurations scattered across multiple GPU's

Help Support

The developers may be contacted directly

SMAUG is the Sheffield Magnetohydrodynamics Algorithm Using GPUs

Parallel magnetohydrodynamics (MHD) algorithms are important for numerical modelling of highly inhomogeneous solar and astrophysical plasmas. SMAUG is the Sheffield Magnetohydrodynamics Algorithm Using GPUs. SMAUG is a 1-3D MHD code capable of modelling magnetised and gravitationally stratified magnetised plasma.

The methods employed have been justified by performance benchmarks and validation results demonstrating that the code successfully simulates the physics for a range of test scenarios including a full 3D realistic model of wave propagation in the magnetised and stratifi ed solar atmosphere.
For details about smaug see the preprint at:smaug-preprint
 
SMAUG is based on the Sheffield Advanced Code (SAC), which is a novel fully non-linear MHD code, designed for simulations of linear and non-linear wave propagation in gravitationally strongly stratified magnetised plasma.

See the reference at the Journal of Astrophysics and Astronomy. SMAUG paper springer DOI: 10.1007/s12036-015-9328-y

See the reference at the Astronomy Abstracts Service. SMAUG paper at ADS
 
See the reference at the Astronomy Abstracts Service. SAC paper at ADS
 
A quick start guide to using smaug is available: Quickstart
 
The SMAUG code has been developed by the Solar Wave theory group SWAT at The University of Sheffield. Researchers and users downloading the code are requested to acknowledge and give credit to the Solar Physics and Space Plasma Research Centre (SP2RC) at The University of Sheffield.
For example
"Courtesy: SP2RC, University of Sheffield"

Monday, 14 December 2015

Space Weather Forecasting Using Photospheric data

This semester we have had two excellent seminars on space weather forecasting using sunspot and x-ray observations of the sun. The reported investigations have  focused on  methods for predicting solar flares using studies of X-ray emission data from satellites such as GOES and RHESSI. By investigating the  variation of the sunspot distributions using datasets such as the Debrecen Data (SDD) it is possible to forecast solar flares significantly in advance of current methods.

Solar flares and CME's are both explosions that occur on the sun the events are quite different. Solar flares are classified as A, B, C, M or X according to the peak flux (in watts per square metre, W/m2) of 100 to 800 picometre X-rays near Earth, as measured on the GOES spacecraft.

Classification Peak Flux Range at 100-800 picometre

(Watts/square metre)
A < 10−7
B 10−7 – 10−6
C 10−6 – 10−5
M 10−5 – 10−4
X > 10−4

The following SDO video provides an interesting visual overview of the different kind of events.


An example HMI magnetogram of an active region is shown below shortly after the occurence of a C2.7 class flare which occurred at 2036. We observe two groups of opposite polarity in close proximity.
The active region NOAA AR12443 gave rise to a number of flare events and a CME of class M1.0 shown in the video below



A 171, LASCO C2 (2015-10-30 05:48:10 - 2015-11-01 05:29:10 U

This movie was produced by Helioviewer.org. See the original at http://helioviewer.org/?movieId=296d5 or download a high-quality version from http://helioviewer.org/api/?action=downloadMovie&id=296d5&format=mp4&hq=true

Understanding flaring phenomena requires a detailed study of the magnetic field configurations and the study of reconnection phenomena. Although coronal loops are remarkably stable for long periods it is a study of instability which can reveal the mechanisms resulting in the generation of solar flares. Understanding the flaring events requires a detailed study of the stability of the magnetic flux ropes participating in reconnection events, also important is the interaction of the flux rope photospheric footpoints.


The animated gif below, illustrates the change in the configuration of the magnetic field occuring during a reconnection. Such processes may be driven by huge mechanical motions of more dense plasma within the photosphere.



The discussion of the Debrecen sunspot data collection presented the new insights into pre-flare and Coronal Mass Ejection behavior and the evolution of the Active Regions (ARs). This was achieved by analysing the SOHO/MDI data and the  Debrecen Data  sunspot catalogues. This is a statistical study of the spatio-temporal distribution of precursor flares before major solar flares, how is this achieved and how does it link with the physical phenomena generating the events.

In earlier work measurements of the umbral area of sunspots and the mean magnetic field from the Debrecen data over a 10 year period produced a logarithmic distribution, as follows;


 
The curve fit is satisfied when |K1| = 265 gauss and |K2| = 1067 gauss. This function relates a Bmean magnetic field to an A umbral area.  

The proxy measure used to represent the magnetic field gradient between two spots of opposite polarities having areas A1 and A2 and at a distance d, is defined as:



The study of the sunspot magnetic fields and the associated gradient GM revealed a number of interesting features. There is a rise in GM of around 2 days prior to an event. The maximum in GM is around 3MWb/m, after the maximum and before the flare event this decreases, the fluctuations during this phase are indicative of the pre flare dynamics. Of 57 events studied, for half of them the flare occured within 10 hours after the maximum of GM.

 In the second paper the method was updated and employed the weighted horizontal gradient of the magnetic field (WG_M) defined between opposite polarity spot-groups at the polarity inversion line of active regions (ARs). This parameter provides important diagnostic information about the accurate prediction of onset time, on the flare intensity and towards CME risk assessment from C class to the X class flare.


The revised method computes the flux gradient for sunspot groups in addition to confirming the earlier results, the new method improves the information which can be obtained about flare events. If the maximum flare energy is less than 42% of the energy stored in the group further flares are more likely. The method improves the estimation of the onset time for flare events.

http://www.solarmonitor.org/index.php?date=19991127&region=08771


NOAA AR 8771


http://www.solarmonitor.org/index.php?date=20010326&region=09393


NOAA AR 9393

NOAA AR 8771, for 1999 November 23–26. Right column: continuum white-light image (top), reconstruction from SDD (middle), and magnetogram (bottom). Left column: variation of (top), distance between the area-weighted centers of the spots of opposite polarities (middle), and unsigned flux of all spots in the encircled area (bottom).
  but of NOAA AR 9393 with a single (i.e., X1.7) and multiple (i.e., X1.4 and X20) flares, for 2001 March 26 April 3.

For these studies a lot of use was made of potential field theory and non-linear force field theory to predict the fields at different levels from magnetograms  with the proxies these were then used to predict flare occurrences 10-12 hours in advance.

Further studies of the variations of solar non-axisymmetric activity have been used as predictors of geomagnetic activity. The dynamic properties of the active longitudes may be of predictive importance. The most flare-productive active regions tend to be located in or close to the active longitudinal belt. This may allow to predict the geoeffective position of the domain of enhanced flaring probability for a couple of years ahead. The magnetic flux emergence exhibits a fluctuation of 1.3 years within the active belt, this fluctuation is absent out of this belt.  The observed behaviour may allow an estimation of  the time intervals of higher geomagnetic activity for a couple of months ahead.

 Solar Flare Statistics (key presentation for mac)

Flare Prediction by Sunspot Dynamics
 http://solarwavetheory.blogspot.co.uk/2014/10/flare-prediction-by-sunspot-dynamics.html

 SOHO/MDI - Debrecen Data (SDD)

 On Flare Predictability Based on Sunspot Group Evolution  arxiv
 Dynamic Precursors of Flares in Active Region NOAA 10486 arxiv

Friday, 11 December 2015

Experiences with the TRISTAN-MP

Tristan-mp (and on TRAC ) is a massively parallel, fully relativistic, Particle-In-Cell code for plasma physics applications. Inspired by a tutorial by Rony Keppens on the induction equation and the Petschek model of magnetic reconnection  ( sample models for VAC )

This code is barely documented and this posting provides a few clues on how to get going!

Recipe for Building Tristan-MP

We built the hdf5 libraries and compiled your code in the home directory. It seems there is no error with a missing library problem mentioned by a colleague.
 
Just a brief instruction of building hdf5 libraries and compiling Tristan-MPI is here:
1- inside hdf/hdf5-1.8.9 folder
 
- make clean
- module add mpi/gcc/openmpi/1.4.4
- ./configure --prefix=/home/usr/hdf/hdf5-1.8.9 --enable-fortran --enable-parallel --enable-unsupported --enable-debug=all
- make
- make check
- make install
- make check-install
 
2- compiling Tristan-MPI
 
- inside Tristan-MPI
- module add mpi/gcc/openmpi/1.4.4
- go to source
- make clean
- make
 
* Note: We editted Makefile which is inside Tristan-MPI/source :
e.g. :
 
FC= /home/usr_dir/hdf/hdf5-1.8.9/bin/h5pfc
LD= /home/usr_dir/hdf/hdf5-1.8.9/bin/h5pfc
INCPATH= -I/usr/local/mpi/gcc/openmpi/1.4.4/include
 
and also we added LIBPATH to the Makefile
 
LIBPATH = -L/usr/local/mpi/gcc/openmpi/1.4.4/lib -L/home/usr_dir/hdf/hdf5-1.8.9/lib -lmpi -lmpi_f90  -lmpi_f77 -lhdf5_fortran -lhdf5
You can do the same for your own makefile.
 
Guidelines on building HDF5 are on the HDF5 site.
 
A link to  the Makefile we use is here

 Running the Code and Analysing the Ouput

The compiled model is run using an MPI with the following command embedded in a script file
mpirun tristan-mp2d
 
Loading the output was easy starting Matlab on our HPC cluster
h5i=h5disp('flds.tot.001','/')
densi=h5read('flds.tot.001','/densi');

The code generates a mountain of data
 
For each timestep (where xxx is the timestep)
flds.tot.xxx (bx,by,bz,dens,densi, ex,ey,ez,jx,jy,jz)
momentum.xxx (dens,dens0,dpx,dpy,dpz,p(x,y,z)bin, p(x,y,z)lim, p(x,y,z)elogsp,xshock,xsl
param.xxx
prtl.xxx  (particle data)
spect.xxx


All we need now is to complete this post with some output from one of the initial test runs!