forked from mpusz/mp-units
Total energy example extended with Natural Units
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#include <units/physical/natural/constants.h>
|
||||||
#include <units/physical/si/energy.h>
|
#include <units/physical/si/energy.h>
|
||||||
#include <units/physical/si/momentum.h>
|
#include <units/physical/si/momentum.h>
|
||||||
#include <units/physical/si/velocity.h>
|
#include <units/physical/si/velocity.h>
|
||||||
@@ -36,7 +37,7 @@ Energy AUTO total_energy(Momentum AUTO p, Mass AUTO m, Velocity AUTO c)
|
|||||||
return sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)));
|
return sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void example()
|
void si_example()
|
||||||
{
|
{
|
||||||
using namespace si;
|
using namespace si;
|
||||||
|
|
||||||
@@ -58,12 +59,29 @@ void example()
|
|||||||
<< "E_GeV = " << quantity_cast<gigaelectronvolt>(E_si) << "\n";
|
<< "E_GeV = " << quantity_cast<gigaelectronvolt>(E_si) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void natural_example()
|
||||||
|
{
|
||||||
|
using namespace natural;
|
||||||
|
|
||||||
|
const momentum<gigaelectronvolt> p(4);
|
||||||
|
const mass<gigaelectronvolt> m(3);
|
||||||
|
const Velocity AUTO c = speed_of_light;
|
||||||
|
const Energy AUTO E = total_energy(p, m, c);
|
||||||
|
|
||||||
|
std::cout << "\nNatural units:\n"
|
||||||
|
<< "p = " << p << "\n"
|
||||||
|
<< "m = " << m << "\n"
|
||||||
|
<< "c = " << c << "\n"
|
||||||
|
<< "E = " << E << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
example();
|
si_example();
|
||||||
|
natural_example();
|
||||||
}
|
}
|
||||||
catch (const std::exception& ex) {
|
catch (const std::exception& ex) {
|
||||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||||
|
Reference in New Issue
Block a user