spirit-code / spirit

Atomistic Spin Simulation Framework
http://spirit-code.github.io
MIT License
120 stars 52 forks source link

Core: unit sets/conversions #275

Open GPMueller opened 7 years ago

GPMueller commented 7 years ago

It may be a good idea to provide options to choose certain sets of units for input and UI.

Literals may be an approach to specify units or unit conversions, for example as

scalar energy_mev = 10_meV;
scalar energy_mry = energy_mev * 1_eV_Ry;

See https://stackoverflow.com/a/21868642/4069571. Also, one could use a #define to switch between unit sets, where literals _energy and _mfield could denote energy and magnetic field respectively, which would be used in API etc. to convert between a user's units and the internally used.

Alternatively, unit conversion functions could be defined, which would do a similar job as literals: converting values to internal units when reading in and converting to user units when writing out etc.

GPMueller commented 7 years ago

Added a second set of constants (energy in mRy) with 5c9075b7e08a4ec68e80da9d9f653701b1038214 and added constants to transfer between unit sets.

GPMueller commented 7 years ago

A micromagnetic unit set might be useful (containing erg etc.)

GPMueller commented 6 years ago

Maybe it would suffice to have the units in the State, e.g.

std::string units_energy   = "meV"; // milli-electron-Volt
std::string units_field    = "T";   // Tesla
std::string units_distance = "A";   // Angstrom
std::string units_time.    = "ps";  // picoseconds

Then, when values are given through input or APIs, they can be converted from their given units (the above) to the intrinsic units of the code, i.e. meV for energy and field, A for distance and ps for time.

Question: should it be allowed to specify units per volume of space, as micromagnetic codes seem to do, such as J/m^3?

Energy units:

Field units:

Distance units:

Are volume and/or area units needed?

GPMueller commented 4 years ago

A micromagnetic unit set was added on fixed-micromagnetic with 013d8aeeeff91f7f2a9c86f2c647b3b525a80b9b.