Open GPMueller opened 7 years ago
Related to #31, #79 and part of #220.
A more wholesome solution might be to use cereal. It supports serialization of stl
types, i.e. vectorfield
s to binary, xml and json and it seems that cereal's Archive
class can be derived from to create also plaintext and OVF serializations.
It would be desirable to have a generic archive
, at least for vectorfield
s, which can be read or written in various data formats.
CSV support for vectorfield data might be added with PR #319
Vectorfield data is a separate issue (#336 for CSV), where it does not make much sense to use JSON (or e.g. XML). This issue will instead focus on input configs, where a JSON representation may actually be quite useful.
TOML is more versatile and readable than JSON and libraries in various languages exist to parse it.
TOML input example:
############## Spirit Configuration ##############
[general]
output_file_tag = "<time>"
# Save input parameters on State creation/deletion
save_input_initial = false
save_input_final = false
# Save atom positions on State creation/deletion
save_positions_initial = false
save_positions_final = false
################## Hamiltonian ###################
[hamiltonian]
# Hamiltonian Type:
# (heisenberg_neighbours, heisenberg_pairs, gaussian)
type = "heisenberg_pairs"
# Boundary_conditions (a b c): 0(open), 1(periodical)
boundary_conditions = [1, 1, 0]
[hamiltonian.external_field]
magnitude = 25.0 # units: [T]
normal = [0.0, 0.0, 1.0]
[hamiltonian.anisotropy]
magnitude = 0.0 # units: [meV]
normal = [0.0, 0.0, 1.0]
# Dipole-Dipole radius
[hamiltonian.dipole_dipole]
cutoff_radius = 0.0 # units: [a]
###### How to do the following?
# Interaction pairs
[hamiltonian]
pairs = [["i", "j", "da", "db", "dc", "Jij", "Dij", "Dijx", "Dijy", "Dijz"],
[ 0.0, 0.0, 1.0, 0.0, 0.0, 10.0, 6.0, 1.0, 0.0, 0.0],
[ 0.0, 0.0, 0.0, 1.0, 0.0, 10.0, 6.0, 0.0, 1.0, 0.0]]
[hamiltonian.pairs]
i = [0, 0]
j = [0, 0]
da = [1, 0]
db = [0, 1]
dc = [0, 0]
Jij = [10.0, 10.0]
Dij = [6.0, 6.0]
DijVec = [[1,0,0], [0,1,0]]
# Quadruplets
[hamiltonian.quadruplets]
n = 0
################ End Hamiltonian #################
############### Logging Parameters ###############
[log]
# Where to put the log file
output_folder = "."
# Levels of information:
# 0 = ALL - Anything
# 1 = SEVERE - Severe error
# 2 = ERROR - Error which can be handled
# 3 = WARNING - Possible unintended behaviour etc
# 4 = PARAMETER - Input parameter logging
# 5 = INFO - Status information etc
# 6 = DEBUG - Deeper status, eg numerical
# Print log messages to the console
write_to_console = true
# Print messages up to (including) log_console_level
console_level = 5
# Save the log as a file
write_to_file = true
# Save messages up to (including) log_file_level
file_level = 4
############# End Logging Parameters #############
################### Geometry #####################
[geometry]
# Lattice constant for basis and translations
lattice_constant = 1.0
# The bravais lattice type
bravais_lattice = "sc"
# µSpin
mu_s = [2.0] # units: [mu_B] - one value per basis atom
# Number of basis cells along principal directions (a b c)
n_basis_cells = [100, 100, 1]
################# End Geometry ###################
################ LLG Parameters ##################
[llg]
# Maximum wall time for single simulation:
# hh:mm:ss, where 0:0:0 is infinity
max_walltime = "0:0:0"
# Seed for Random Number Generator
seed = 20006
# Number of iterations
n_iterations = 2000000
# Number of iterations after which to save
n_iterations_log = 2000
# Force convergence parameter
force_convergence = 1e-9
temperature = 0 # units: [K]
damping = 0.3
beta = 0.1 # non-adiabatic
dt = 1e-3 # time step, units: [ps]
[llg.stt]
# false: use the pinned monolayer approximation
# true: use the gradient approximation
use_gradient = false
# Spin transfer torque parameter proportional
# to injected current density
magnitude = 0.0
# Spin current polarisation normal vector
# or current flow direction
polarisation_normal = [1.0, 0.0, 0.0]
[llg.output]
folder = "output"
any = true
initial = true
final = true
[llg.output.energy]
save_step = false
save_archive = true
save_spin_resolved = false
divide_by_nspins = true
[llg.output.configuration]
save_step = true
save_archive = false
############## End LLG Parameters ################
################# MC Parameters ##################
[mc]
# Maximum wall time for single simulation
# hh:mm:ss, where 0:0:0 is infinity
max_walltime = "0:0:0"
# Seed for Random Number Generator
seed = 20006
# Number of iterations
n_iterations = 2000000
# Number of iterations after which to save
n_iterations_log = 2000
temperature = 0 # units: [K]
acceptance_ratio = 0.5
[mc.output]
any = true
initial = true
final = true
[mc.output.energy]
save_step = false
save_archive = true
save_spin_resolved = false
divide_by_nspins = true
[mc.output.configuration]
save_step = true
save_archive = false
############### End MC Parameters ################
Note: https://github.com/nlohmann/json is already being used by the IMGUI implemented on feature-imgui
(PR #583).
The main problem remaining, however, as with toml or script input files, is that the pairs and quadruplets are not nice to represent (i.e. they would become harder to read).
Suggestions: https://github.com/nlohmann/json https://github.com/ben-strasser/fast-cpp-csv-parser