HDF5 file Analyser

SetDirectory[NotebookDirectory[]];

Ngrid=32;

tOutputRareFreq=1; (* check your info file for the exact value of tOutputRareFreq!!! *)


tfinal=Last[ReadList["average_energy_conservation.txt",Table[Number,4]][[All,1]]];

Kinetic Energy Density Snapshots

function to plot snapshot

(* in the following you can find a function that plots the 3D kinetic energy density snapshot (you can also use it for other scalar fields) *)

PlotEkinSnapshot[fieldtype_,Nfield_,Nsnapshot_,contours_,contourStyle_]:=Block[{datasets,length,lengthperfield,ftype,tabEk,Ek,res,pos},

ftype=If[ToString[fieldtype]=="complex_scalar","E_CS_K_",If[ToString[fieldtype]=="SU2_doublet","E_SU2D_K_",If[ToString[fieldtype]=="scalar","E_S_K_",False]]];

Ek=Interpolation[Import["average_energies.txt","Data"][[All,{1,2+2*(Nfield-1)}]]];

pos=ToExpression[Position[Import["kinetic_energy_snapshot_"<>ToString[fieldtype]<>".h5","Datasets"],"/"<>ftype<>ToString[Nfield-1]<>"/"<>ToString[Nsnapshot*tOutputRareFreq]<>"."][[1,1]]];

tabEk=Import["kinetic_energy_snapshot_"<>ToString[fieldtype]<>".h5",{"Data",pos}];

res=ListContourPlot3D[tabEk/Ek[Nsnapshot*tOutputRareFreq],Contours->contours,ContourStyle->contourStyle,Mesh->None,Ticks->None];


Return[res]
]

(* in the following you can find a function that plots 2D slices of the kinetic energy density snapshot *)

PlotEkin2DSlice[fieldtype_,Nfield_,Nsnapshot_,Nslice_]:=Block[{datasets,length,lengthperfield,ftype,tabEk,Ek,res,pos},

ftype=If[ToString[fieldtype]=="complex_scalar","E_CS_K_",If[ToString[fieldtype]=="SU2_doublet","E_SU2D_K_",If[ToString[fieldtype]=="scalar","E_S_K_",False]]];

Ek=Interpolation[Import["average_energies.txt","Data"][[All,{1,2+2*(Nfield-1)}]]];

pos=ToExpression[Position[Import["kinetic_energy_snapshot_"<>ToString[fieldtype]<>".h5","Datasets"],"/"<>ftype<>ToString[Nfield-1]<>"/"<>ToString[Nsnapshot*tOutputRareFreq]<>"."][[1,1]]];

tabEk=Import["kinetic_energy_snapshot_"<>ToString[fieldtype]<>".h5",{"Data",pos}];

res=ListPlot3D[tabEk[[Nslice]]/Ek[Nsnapshot*tOutputRareFreq],PlotRange->All,PlotStyle->"AlpineColors",BaseStyle->{FontFamily->"Times",FontSize->14,Directive[Black]},AxesLabel->"(Subscript[ε, k])"];


Return[res]
]

Info

(* basic information about your HDF5 file: *)

Import["kinetic_energy_snapshot_scalar.h5","Summary"]

(* structure graph of your HDF5 file (depicts Groups and Datasets): *)

Import["kinetic_energy_snapshot_scalar.h5","StructureGraph"]

Figures

3D Snapshot

(* The function PlotEkinSlice[fieldtype_,Nfield_,Nsnapshot_,contours_,contourStyle_] plots the kinetic overdensities for scalar fields. You have to specify the type of field (fieldtype = {scalar, complex_scalar, SU2_doublet}), the number of this type of field appearing in your model (Nfield), the number of the snapshot you want to depict (Nsnapshot), the contours you want to depict (contours) and their style (contourStyle). In the following we choose some example parameters: *)


fieldtype="scalar";
Nfields =1;
Nsnapshot = 70;
contour ={3,8};
contourStyleEkin ={Directive[Lighter[Red],Opacity[0.4]],Directive[Darker[Red],Opacity[0.7]]};

(* plot snapshot: *)

PlotEkinSnapshot[fieldtype,Nfields,Nsnapshot,contour,contourStyleEkin]

2D slice form the snapshot

(* in the following we plot a 2D slice out of your 3D snapshot. Pick your favourite 2D slice: *)

myfavourite2Dslice=20;

(* plot slice: *)

PlotEkin2DSlice[fieldtype,Nfields,Nsnapshot,myfavourite2Dslice]

Gradient Energy Density Snapshots

function to plot snapshot

(* in the following you can find a function that plots the 3D gradient energy density snapshot (you can also use it for other scalar fields) *)

PlotEgradSnapshot[fieldtype_,Nfield_,Nsnapshot_,contours_,contourStyle_]:=Block[{datasets,length,lengthperfield,ftype,tabEg,Eg,res,pos},

ftype=If[ToString[fieldtype]=="complex_scalar","E_CS_G_",If[ToString[fieldtype]=="SU2_doublet","E_SU2D_G_",If[ToString[fieldtype]=="scalar","E_S_G_",False]]];

Eg=Interpolation[Import["average_energies.txt","Data"][[All,{1,3+2*(Nfield-1)}]]];

pos=ToExpression[Position[Import["gradient_energy_snapshot_"<>ToString[fieldtype]<>".h5","Datasets"],"/"<>ftype<>ToString[Nfield-1]<>"/"<>ToString[Nsnapshot*tOutputRareFreq]<>"."][[1,1]]];

tabEg=Import["gradient_energy_snapshot_"<>ToString[fieldtype]<>".h5",{"Data",pos}];

res=ListContourPlot3D[tabEg/Eg[Nsnapshot*tOutputRareFreq],Contours->contours,ContourStyle->contourStyle,Mesh->None,Ticks->None];


Return[res]
]

(* in the following you can find a function that plots 2D slices of the gradient energy density snapshot *)

PlotEgrad2DSlice[fieldtype_,Nfield_,Nsnapshot_,Nslice_]:=Block[{datasets,length,lengthperfield,ftype,tabEg,Eg,res,pos},

ftype=If[ToString[fieldtype]=="complex_scalar","E_CS_G_",If[ToString[fieldtype]=="SU2_doublet","E_SU2D_G_",If[ToString[fieldtype]=="scalar","E_S_G_",False]]];

Eg=Interpolation[Import["average_energies.txt","Data"][[All,{1,3+2*(Nfield-1)}]]];

pos=ToExpression[Position[Import["gradient_energy_snapshot_"<>ToString[fieldtype]<>".h5","Datasets"],"/"<>ftype<>ToString[Nfield-1]<>"/"<>ToString[Nsnapshot*tOutputRareFreq]<>"."][[1,1]]];

tabEg=Import["gradient_energy_snapshot_"<>ToString[fieldtype]<>".h5",{"Data",pos}];

res=ListPlot3D[tabEg[[Nslice]]/Eg[Nsnapshot*tOutputRareFreq],PlotRange->All,PlotStyle->"AlpineColors",BaseStyle->{FontFamily->"Times",FontSize->14,Directive[Black]},AxesLabel->"(Subscript[ε, g])"];


Return[res]
]

Info

(* basic information about your HDF5 file: *)

Import["gradient_energy_snapshot_scalar.h5","Summary"]

(* structure graph of your HDF5 file (depicts Groups and Datasets): *)

Import["gradient_energy_snapshot_scalar.h5","StructureGraph"]

Figures

3D Snapshot

(* The function PlotEgradSlice[fieldtype_,Nfield_,Nsnapshot_,contours_,contourStyle_] plots the gradient overdensities for scalar fields. You have to specify the type of field (fieldtype = {scalar, complex_scalar, SU2_doublet}), the number of this type of field appearing in your model (Nfield), the number of the snapshot you want to depict (Nsnapshot), the contours you want to depict (contours) and their style (contourStyle). In the following we choose some example parameters: *)


fieldtype="scalar";
Nfields =1;
Nsnapshot = 70;
contour ={3,8};
contourStyleEgrad={Directive[Lighter[Blue],Opacity[0.4]],Directive[Darker[Blue],Opacity[0.7]]};

(* plot snapshot: *)

PlotEgradSnapshot[fieldtype,Nfields,Nsnapshot,contour,contourStyleEgrad]

2D slice form the snapshot

(* in the following we plot a 2D slice out of your 3D snapshot. Pick your favourite 2D slice: *)

myfavourite2Dslice=20;

(* plot slice: *)

PlotEgrad2DSlice[fieldtype,Nfields,Nsnapshot,myfavourite2Dslice]

Potential Energy Density Snapshots

function to plot snapshot

(* in the following you can find a function that plots the 3D potential energy density snapshot (you can also use it for other scalar fields) *)

PlotEpotSnapshot[Nfield_,Nsnapshot_,contours_,contourStyle_]:=Block[{datasets,length,lengthperfield,ftype,tabEp,Ep,res,pos},


length=Length[Import["average_energies.txt","Data"][[1]]];

Ep=Interpolation[Sum[Import["average_energies.txt","Data"][[All,{1,i}]],{i,4+2*(Nfield-1),Length[Import["average_energies.txt","Data"][[1]]]-1}]];

pos=ToExpression[Position[Import["potential_energy_snapshot.h5","Datasets"],"/E_V/"<>ToString[Nsnapshot*tOutputRareFreq]<>"."][[1,1]]];

tabEp=Import["potential_energy_snapshot.h5",{"Data",pos}];

res=ListContourPlot3D[tabEp/Ep[Nsnapshot*tOutputRareFreq],Contours->contours,ContourStyle->contourStyle,Mesh->None,Ticks->None];


Return[res]
]

(* in the following you can find a function that plots 2D slices of the potential energy density snapshot *)

PlotEpot2DSlice[fieldtype_,Nfield_,Nsnapshot_,Nslice_]:=Block[{datasets,length,lengthperfield,ftype,tabEp,Ep,res,pos},


length=Length[Import["average_energies.txt","Data"][[1]]];

Ep=Interpolation[Sum[Import["average_energies.txt","Data"][[All,{1,i}]],{i,4+2*(Nfield-1),Length[Import["average_energies.txt","Data"][[1]]]-1}]];

pos=ToExpression[Position[Import["potential_energy_snapshot.h5","Datasets"],"/E_V/"<>ToString[Nsnapshot*tOutputRareFreq]<>"."][[1,1]]];

tabEp=Import["potential_energy_snapshot.h5",{"Data",pos}];

res=ListPlot3D[tabEp[[Nslice]]/Ep[Nsnapshot*tOutputRareFreq],PlotRange->All,PlotStyle->"AlpineColors",BaseStyle->{FontFamily->"Times",FontSize->14,Directive[Black]},AxesLabel->"(Subscript[ε, p])"];


Return[res]
]

Info

(* basic information about your HDF5 file: *)

Import["potential_energy_snapshot.h5","Summary"]

(* structure graph of your HDF5 file (depicts Groups and Datasets): *)

Import["potential_energy_snapshot.h5","StructureGraph"]

Figures

3D Snapshot

(* The function PlotEpotSlice[Nfield_,Nsnapshot_,contours_,contourStyle_] plots the potential overdensities for scalar fields. You have to specify the number of field appearing in your model (Nfield), the number of the snapshot you want to depict (Nsnapshot), the contours you want to depict (contours) and their style (contourStyle). In the following we choose some example parameters: *)


fieldtype="scalar";
Nfields =1;
Nsnapshot = 70;
contour ={3,8};
contourStyleEpot={Directive[Lighter[Yellow],Opacity[0.4]],Directive[Darker[Yellow],Opacity[0.7]]};

(* plot snapshot: *)

PlotEpotSnapshot[Nfields,Nsnapshot,contour,contourStyleEpot]

2D slice form the snapshot

(* in the following we plot a 2D slice out of your 3D snapshot. Pick your favourite 2D slice: *)

myfavourite2Dslice=20;

(* plot slice: *)

PlotEpot2DSlice[fieldtype,Nfields,Nsnapshot,myfavourite2Dslice]

Movie

(* in the following we want to produce a movie of the ratio of the sum of the energy density components and the average of the total energy density, i.e. ((Subscript[E, kin]) + (Subscript[E, grad]) + (Subscript[E, pot]))/⟨(Subscript[E, tot])⟩: *)



(* in case you have not done it yet, pick the correct directory: *)

SetDirectory[NotebookDirectory[]];


(*also, you may want to set the number of grid points of your simulation once more: *)

Ngrid=32;

import files

number of datasets

(* number of datasets in h5 file: *)

length=Length[Import["kinetic_energy_snapshot_scalar.h5","Datasets"]];

total averaged energy density

(* number of energy density components: *)

NEcomp=3;


(* import the total averaged energy: *)

Etot=Interpolation[ReadList["average_energies.txt",Table[Number,NEcomp+2]][[All,{1,NEcomp+2}]]];

import HDF5 files

(* import the kinetic (tabEK), gradient (tabEG) and potential (tabEV) energy snapshots: *)

(* for each 'i', the first entry in the table gives the time of the snapshot, which is also used to sort all snapshots in the correct time order. The second entry in the table is the corresponding snapshot *)


tabEK=Sort[Table[{ToExpression[StringDelete[Import["kinetic_energy_snapshot_scalar.h5","Datasets"],"/E_S_K_0/"]][[i]],Import["kinetic_energy_snapshot_scalar.h5",{"Data",i}]},{i,1,length}]];

tabEG=Sort[Table[{ToExpression[StringDelete[Import["gradient_energy_snapshot_scalar.h5","Datasets"],"/E_S_G_0/"]][[i]],Import["gradient_energy_snapshot_scalar.h5",{"Data",i}]},{i,1,length}]];

tabEV=Sort[Table[{ToExpression[StringDelete[Import["potential_energy_snapshot.h5","Datasets"],"/E_V/"]][[i]],Import["potential_energy_snapshot.h5",{"Data",i}]},{i,1,length}]];

become a film maker

(* pick the contours you want to plot *)

ContourA=3;
ContourB=8;

(* pick the contours you want to plot *)

ContourStyleA=Directive[Lighter[Green],Opacity[0.4]];
ContourStyleB=Directive[Darker[Green],Opacity[0.7]];

(* produce your film reel: *)

reel=Table[ListContourPlot3D[(((tabEK[[i,2]]+tabEG[[i,2]]+tabEV[[i,2]]))/(Etot[tabEV[[i,1]]])),Contours->{ContourA,ContourB},ContourStyle->{ContourStyleA,ContourStyleB},PlotRange->All,Mesh->None,Ticks->None],{i,1,length}];

(* become a movie producer by exporting your reel: *)

Export["movie.avi",reel,"FrameRate"->4,ImageResolution->100]

movie of a 2D slice

(* if you prefer to make a movie of a 2D slice through your 3D box, feel free: *)

(* pick your prefered slice: *)

Nslice=6; (* mine is 6,
but can you pick anything between 1 and Ngrid *)

reel2D=Table[ListPlot3D[(tabEK[[i,2,Nslice]]+tabEG[[i,2,Nslice]]+tabEV[[i,2,Nslice]])/Etot[tabEK[[i,1]]],PlotRange->All],{i,1,length}];