Skip to content

Commit

Permalink
Add units for energy and time and fixed typo in GetLength (second att…
Browse files Browse the repository at this point in the history
…empt)
  • Loading branch information
nscepi committed Dec 20, 2024
1 parent ba5eac8 commit c941342
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void idfx::Units::ShowConfig() {
idfx::cout << "Units: [Length] = " << this->_length << " cm" << std::endl;
idfx::cout << "Units: [Velocity] = " << this->_velocity << " cm/s" << std::endl;
idfx::cout << "Units: [Density] = " << this->_density << " g/cm3" << std::endl;
idfx::cout << "Units: [Energy] = " << this->_energy << " erg/cm3" << std::endl;
idfx::cout << "Units: [Time] = " << this->_time << " s" << std::endl;
idfx::cout << "Units: [Temperature] = " << this->_Kelvin << " K" << std::endl;
idfx::cout << "Units: [Mag. Field] = " << this->_magField << " G" << std::endl;
}
Expand All @@ -46,4 +48,7 @@ void idfx::Units::ComputeUnits() {
this->_isInitialized = true;
this->_magField = std::sqrt(4*M_PI*_density*_velocity*_velocity);
this->_Kelvin = u * _velocity*_velocity/k_B;
this->_energy = _density*_velocity*_velocity;
this->_time = _length/_velocity;
}

12 changes: 9 additions & 3 deletions src/units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class Units {
void Init(Input &input);


const real u {1.6605390666e-24}; // Atomic mass unit (g)
const real u{1.6605390666e-24}; // Atomic mass unit (g)
const real m_p{1.67262192369e-24}; // Proton mass unit (g)
const real m_n{1.67492749804e-24}; // neutron mass unit (g)
const real m_e{9.1093837015e-28}; // electron mass unit (g)
const real k_B{1.380649e-16}; // Boltzmann constant (erg/K)
const real sigma_sb{5.6703744191844314e-05}; // Stephan Boltzmann constant (g/(K^4 s^3))
const real ar{7.5646e-15}; // Radiation constant = 4*sigma_sb/c (g/(K^4 s^2 cm))
const real c{29979245800.0}; // Speed of light (cm/s)
const real M_sun{1.988409870698051e+33}; // Solar mass (g)
const real R_sun{69570000000.0}; // Solar radius (cm)
Expand All @@ -33,18 +34,20 @@ class Units {
const real G{6.674299999999999e-8}; // Gravitatonal constant (cm3 / (g s2))
const real h{6.62607015e-27}; // Planck constant (erg.s)
const real pc{3.08568e+18}; // Parsec (cm)
const real au{1.49598e+13}; // Astronomical unit (cm)
const real au{1.49597892e13}; // Astronomical unit (cm)


// User-defined units, non user-modifiable
KOKKOS_INLINE_FUNCTION real GetLength() const {return _density;} // L (cm) = L (code) * Units::length
KOKKOS_INLINE_FUNCTION real GetLength() const {return _length;} // L (cm) = L (code) * Units::length
KOKKOS_INLINE_FUNCTION real GetVelocity() const {return _velocity;} // V(cm/s) = V(code) * Units::velocity
KOKKOS_INLINE_FUNCTION real GetDensity() const {return _density;} // density (g/cm^3) = density(code)
// * Units::density

// Deduced units from user-defined units
KOKKOS_INLINE_FUNCTION real GetKelvin() const {return _Kelvin;} // T(K) = P(code)/rho(code) * mu * Units::Kelvin
KOKKOS_INLINE_FUNCTION real GetMagField() const {return _magField;} // B(G) = B(code) * Units::MagField
KOKKOS_INLINE_FUNCTION real GetEnergy() const {return _energy;} // energy(erg/cm3) = energy(code) * Units::energy
KOKKOS_INLINE_FUNCTION real GetTime() const {return _time;} // time(s) = time(code) * Units::time

KOKKOS_INLINE_FUNCTION bool GetIsInitialized() const {return _isInitialized;}

Expand All @@ -66,9 +69,12 @@ class Units {
// Deduced units from user-defined units
real _Kelvin{1.0};
real _magField{1.0};
real _time{1.0};
real _energy{1.0};

// Recompute deduced user-units
void ComputeUnits();
};
} // namespace idfx
#endif // UNITS_HPP_

0 comments on commit c941342

Please sign in to comment.