#include "simulation/unit_converter.h" #include "constants/physical_constants.h" #include "simulation/errors.h" namespace unitConvertion { double lengthPrefactor(const std::string& unit) { if (unit == "cm") { return 1E-2; } else if (unit == "m") { return 1; } else if (unit == "mm") { return 1E-3; } else { ERROR("I dont know this length unit: " + unit); return 0; } } double length(double value, const std::string& unit_from, const std::string& unit_to) { double prefactor_from = lengthPrefactor(unit_from); double prefactor_to = lengthPrefactor(unit_to); return value * prefactor_from / prefactor_to; } double energyPrefactor(const std::string& unit) { if (unit == "eV") { return 1.; } else if (unit == "J") { return 1 / SI::e; } else { ERROR("I dont know this energy unit: " + unit); return 0; } } double energy(double value, const std::string& unit_from, const std::string& unit_to) { double prefactor_from = energyPrefactor(unit_from); double prefactor_to = energyPrefactor(unit_to); return value * prefactor_from / prefactor_to; } }; // namespace unitConvertion