From ac93b44dc14e0c863c86c0ad6650cccb47287106 Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 14 Dec 2019 17:38:48 +0900 Subject: [PATCH 01/18] [add] environment/earth dir --- src/environment/{earth.hpp => earth/ellipsoid.hpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/environment/{earth.hpp => earth/ellipsoid.hpp} (100%) diff --git a/src/environment/earth.hpp b/src/environment/earth/ellipsoid.hpp similarity index 100% rename from src/environment/earth.hpp rename to src/environment/earth/ellipsoid.hpp From 50972b6c6d2ab70a6b996b5e2d6b8e6489390307 Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 14 Dec 2019 17:47:29 +0900 Subject: [PATCH 02/18] [fix] include path --- src/coordinate/earth.hpp | 2 +- src/environment.hpp | 31 +++++++++++++++++++++++++++++ src/environment/earth/ellipsoid.hpp | 6 +++--- src/simulation.cpp | 3 +-- 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 src/environment.hpp diff --git a/src/coordinate/earth.hpp b/src/coordinate/earth.hpp index 6df1a63..e1324ba 100644 --- a/src/coordinate/earth.hpp +++ b/src/coordinate/earth.hpp @@ -22,7 +22,7 @@ #ifndef COORDINATE_EARTH_HPP_ #define COORDINATE_EARTH_HPP_ -#include "../environment/earth.hpp" +#include "../environment/earth/ellipsoid.hpp" namespace trochia::coordinate::earth { using namespace environment::earth; diff --git a/src/environment.hpp b/src/environment.hpp new file mode 100644 index 0000000..044622b --- /dev/null +++ b/src/environment.hpp @@ -0,0 +1,31 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright (C) 2019 sksat + * + * This file is part of Trochia. + * + * Trochia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Trochia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You Should have received a copy of the GNU General Public License + * along with Trochia. If not, see . + * + * ----------------------------------------------------------------------- */ + +#ifndef ENVIRONMENT_HPP_ +#define ENVIRONMENT_HPP_ + +#include "environment/air.hpp" +#include "environment/earth/ellipsoid.hpp" +//#include "environment/earth/geodesy.hpp" +#include "environment/gravity.hpp" +#include "environment/launcher.hpp" + +#endif diff --git a/src/environment/earth/ellipsoid.hpp b/src/environment/earth/ellipsoid.hpp index 0ba84ff..2a43399 100644 --- a/src/environment/earth/ellipsoid.hpp +++ b/src/environment/earth/ellipsoid.hpp @@ -19,10 +19,10 @@ * * ----------------------------------------------------------------------- */ -#ifndef ENVIRONMENT_EARTH_HPP_ -#define ENVIRONMENT_EARTH_HPP_ +#ifndef ENVIRONMENT_EARTH_ELLIPSOID_HPP_ +#define ENVIRONMENT_EARTH_ELLIPSOID_HPP_ -#include "../math.hpp" +#include "../../math.hpp" namespace trochia::environment::earth { namespace ellipsoid { diff --git a/src/simulation.cpp b/src/simulation.cpp index 0e38782..51ce786 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -23,8 +23,7 @@ #include "math.hpp" #include "simulation.hpp" #include "solver.hpp" -#include "environment/launcher.hpp" -#include "environment/gravity.hpp" +#include "environment.hpp" auto trochia::do_simulation(Simulation &sim) -> void { const auto &timeout = sim.timeout; From 9970a80400f762ddd9936895c1c63dc4b224daf2 Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 14 Dec 2019 19:37:03 +0900 Subject: [PATCH 03/18] [add] Fundamental Physical Constants header --- src/environment.hpp | 1 + src/environment/gravity.hpp | 9 ++--- src/environment/physics.hpp | 67 +++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 src/environment/physics.hpp diff --git a/src/environment.hpp b/src/environment.hpp index 044622b..1756518 100644 --- a/src/environment.hpp +++ b/src/environment.hpp @@ -22,6 +22,7 @@ #ifndef ENVIRONMENT_HPP_ #define ENVIRONMENT_HPP_ +#include "environment/physics.hpp" // fundamental physical constants #include "environment/air.hpp" #include "environment/earth/ellipsoid.hpp" //#include "environment/earth/geodesy.hpp" diff --git a/src/environment/gravity.hpp b/src/environment/gravity.hpp index bf9a17d..42bbd5a 100644 --- a/src/environment/gravity.hpp +++ b/src/environment/gravity.hpp @@ -23,15 +23,10 @@ #define ENVIRONMENT_GRAVITY_HPP_ #include "../math.hpp" +#include "physics.hpp" namespace trochia::environment { namespace constant { - // 2018 CODATA recommended values - constexpr math::Float G = 6.6743015e-11; - - // standard acceleration of gravity(definition) - constexpr math::Float gn = 9.80665; - // Chronological Scientific Tables 2014 constexpr math::Float re = 6.3781366e6; } @@ -43,7 +38,7 @@ namespace trochia::environment { inline auto gravity(const math::Float &altitude) -> const math::Float { const auto tmp = constant::re / (constant::re + altitude); - return constant::gn * tmp * tmp; + return physics::g0 * tmp * tmp; } } diff --git a/src/environment/physics.hpp b/src/environment/physics.hpp new file mode 100644 index 0000000..3f0ceb2 --- /dev/null +++ b/src/environment/physics.hpp @@ -0,0 +1,67 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright (C) 2019 sksat + * + * This file is part of Trochia. + * + * Trochia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Trochia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You Should have received a copy of the GNU General Public License + * along with Trochia. If not, see . + * + * ----------------------------------------------------------------------- */ + +#ifndef ENVIRONMENT_PHYSICS_HPP_ +#define ENVIRONMENT_PHYSICS_HPP_ + +#include "../math.hpp" + +namespace trochia::environment::physics { + using math::Float; + + // standard acceleration of gravity(definition value) + // The third General Conference on Weights and Mesures(1901) + constexpr Float g0 = 9.80665; + + inline namespace CODATA2018 { + // 2018 CODATA recommended values + // https://physics.nist.gov/cuu/pdf/wall_2018.pdf + + // speed of light in vacuum + constexpr Float c = 299792458; + + // Newtonian constant of gravitation + constexpr Float G = 6.6743015e-11; + + // molar gas constant + constexpr Float R = 8.314462618; + } + + namespace CODATA2014 { + // 2014 CODATA recommended values + // https://physics.nist.gov/cuu/pdf/wallet_2014.pdf + + constexpr Float c = 299792458; + constexpr Float G = 6.6740831e-11; + constexpr Float R = 8.314459848; + } + + namespace CODATA2010 { + // 2010 CODATA recommended values + // https://physics.nist.gov/cuu/pdf/all_2010.pdf + + constexpr Float c = 299792458; + constexpr Float G = 6.6738480e-11; + constexpr Float R = 8.314462175; + } +} + +#endif From 4fff1c888879d9d2ad8966625076721e082029f1 Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 14 Dec 2019 19:58:43 +0900 Subject: [PATCH 04/18] [add] environment/earth.hpp --- src/environment.hpp | 5 ++-- src/environment/earth.hpp | 36 +++++++++++++++++++++++++++++ src/environment/earth/ellipsoid.hpp | 4 +--- src/environment/gravity.hpp | 8 ++----- 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 src/environment/earth.hpp diff --git a/src/environment.hpp b/src/environment.hpp index 1756518..5b0849e 100644 --- a/src/environment.hpp +++ b/src/environment.hpp @@ -23,10 +23,9 @@ #define ENVIRONMENT_HPP_ #include "environment/physics.hpp" // fundamental physical constants -#include "environment/air.hpp" -#include "environment/earth/ellipsoid.hpp" -//#include "environment/earth/geodesy.hpp" +#include "environment/earth.hpp" #include "environment/gravity.hpp" +#include "environment/air.hpp" #include "environment/launcher.hpp" #endif diff --git a/src/environment/earth.hpp b/src/environment/earth.hpp new file mode 100644 index 0000000..d661d67 --- /dev/null +++ b/src/environment/earth.hpp @@ -0,0 +1,36 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright (C) 2019 sksat + * + * This file is part of Trochia. + * + * Trochia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Trochia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You Should have received a copy of the GNU General Public License + * along with Trochia. If not, see . + * + * ----------------------------------------------------------------------- */ + +#ifndef ENVIRONMENT_EARTH_HPP_ +#define ENVIRONMENT_EARTH_HPP_ + +#include "../math.hpp" + +namespace trochia::environment::earth { + using math::Float; + + // Chronological Scientific Tables 2014 + constexpr Float re = 6.3781366e6; +} + +#include "earth/ellipsoid.hpp" + +#endif diff --git a/src/environment/earth/ellipsoid.hpp b/src/environment/earth/ellipsoid.hpp index 2a43399..50ea1c2 100644 --- a/src/environment/earth/ellipsoid.hpp +++ b/src/environment/earth/ellipsoid.hpp @@ -22,12 +22,10 @@ #ifndef ENVIRONMENT_EARTH_ELLIPSOID_HPP_ #define ENVIRONMENT_EARTH_ELLIPSOID_HPP_ -#include "../../math.hpp" +#include "../earth.hpp" namespace trochia::environment::earth { namespace ellipsoid { - using math::Float; - class Ellipsoid { public: constexpr Ellipsoid(Float a, Float f_inv) : a(a), f_inv(f_inv), diff --git a/src/environment/gravity.hpp b/src/environment/gravity.hpp index 42bbd5a..9f1f240 100644 --- a/src/environment/gravity.hpp +++ b/src/environment/gravity.hpp @@ -24,20 +24,16 @@ #include "../math.hpp" #include "physics.hpp" +#include "earth.hpp" namespace trochia::environment { - namespace constant { - // Chronological Scientific Tables 2014 - constexpr math::Float re = 6.3781366e6; - } - // TODO // latitude model(Helmert equation, WGS-84) // gravitation model // other planet inline auto gravity(const math::Float &altitude) -> const math::Float { - const auto tmp = constant::re / (constant::re + altitude); + const auto tmp = earth::re / (earth::re + altitude); return physics::g0 * tmp * tmp; } } From a887a037aa0810ac61940b5d12812c08b0f2636f Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 14 Dec 2019 20:39:05 +0900 Subject: [PATCH 05/18] [fix] --- src/environment/earth.hpp | 4 +--- src/environment/earth/ellipsoid.hpp | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/environment/earth.hpp b/src/environment/earth.hpp index d661d67..00cfc08 100644 --- a/src/environment/earth.hpp +++ b/src/environment/earth.hpp @@ -25,10 +25,8 @@ #include "../math.hpp" namespace trochia::environment::earth { - using math::Float; - // Chronological Scientific Tables 2014 - constexpr Float re = 6.3781366e6; + constexpr math::Float re = 6.3781366e6; } #include "earth/ellipsoid.hpp" diff --git a/src/environment/earth/ellipsoid.hpp b/src/environment/earth/ellipsoid.hpp index 50ea1c2..2a43399 100644 --- a/src/environment/earth/ellipsoid.hpp +++ b/src/environment/earth/ellipsoid.hpp @@ -22,10 +22,12 @@ #ifndef ENVIRONMENT_EARTH_ELLIPSOID_HPP_ #define ENVIRONMENT_EARTH_ELLIPSOID_HPP_ -#include "../earth.hpp" +#include "../../math.hpp" namespace trochia::environment::earth { namespace ellipsoid { + using math::Float; + class Ellipsoid { public: constexpr Ellipsoid(Float a, Float f_inv) : a(a), f_inv(f_inv), From d7e760883b3f91e28bb202f88408cc97934f226e Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 14 Dec 2019 21:20:10 +0900 Subject: [PATCH 06/18] [add] geodesy header --- src/environment/earth.hpp | 1 + src/environment/earth/geodesy.hpp | 41 +++++++++++++++++++++++++++++++ src/simulation.cpp | 3 ++- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/environment/earth/geodesy.hpp diff --git a/src/environment/earth.hpp b/src/environment/earth.hpp index 00cfc08..e14dae3 100644 --- a/src/environment/earth.hpp +++ b/src/environment/earth.hpp @@ -30,5 +30,6 @@ namespace trochia::environment::earth { } #include "earth/ellipsoid.hpp" +#include "earth/geodesy.hpp" #endif diff --git a/src/environment/earth/geodesy.hpp b/src/environment/earth/geodesy.hpp new file mode 100644 index 0000000..33538d4 --- /dev/null +++ b/src/environment/earth/geodesy.hpp @@ -0,0 +1,41 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright (C) 2019 sksat + * + * This file is part of Trochia. + * + * Trochia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Trochia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You Should have received a copy of the GNU General Public License + * along with Trochia. If not, see . + * + * ----------------------------------------------------------------------- */ + +#ifndef ENVIRONMENT_EARTH_GEODESY_HPP_ +#define ENVIRONMENT_EARTH_GEODESY_HPP_ + +#include "../earth.hpp" + +namespace trochia::environment::earth::geodesy { + // geopotential height + // U.S. Standard Atmosphere, 1976: https://ntrs.nasa.gov/search.jsp?R=19770009539 + auto potential_height(const math::Float &height) -> math::Float { + // the adopted, effective earth's radius, 6356.766km + // used for computing g(Z) for 45-degree north latitude, + // and used for relating H and Z at that latitude + constexpr math::Float r0 = 6356766; + constexpr math::Float gamma = 1.0; + + return (r0 * height) / (gamma * r0 - height); + } +} + +#endif diff --git a/src/simulation.cpp b/src/simulation.cpp index 51ce786..f3d7704 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -88,7 +88,8 @@ auto trochia::do_simulation(Simulation &sim) -> void { if(step % output_rate == 0){ std::cout << time << " " << rocket.pos.altitude() << " " - << environment::gravity(rocket.pos.altitude()) << std::endl; + << environment::earth::geodesy::potential_height(rocket.pos.altitude()) + << std::endl; } if(step > 100 && rocket.pos.altitude() <= 0.0) From d10104e9d63e64a1790d50eb6db94de84647978c Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 00:48:04 +0900 Subject: [PATCH 07/18] [add] temperature header --- src/environment.hpp | 1 + src/environment/temperature.hpp | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/environment/temperature.hpp diff --git a/src/environment.hpp b/src/environment.hpp index 5b0849e..82fc587 100644 --- a/src/environment.hpp +++ b/src/environment.hpp @@ -23,6 +23,7 @@ #define ENVIRONMENT_HPP_ #include "environment/physics.hpp" // fundamental physical constants +#include "environment/temperature.hpp" #include "environment/earth.hpp" #include "environment/gravity.hpp" #include "environment/air.hpp" diff --git a/src/environment/temperature.hpp b/src/environment/temperature.hpp new file mode 100644 index 0000000..79ae5de --- /dev/null +++ b/src/environment/temperature.hpp @@ -0,0 +1,52 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright (C) 2019 sksat + * + * This file is part of Trochia. + * + * Trochia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Trochia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You Should have received a copy of the GNU General Public License + * along with Trochia. If not, see . + * + * ----------------------------------------------------------------------- */ + +#ifndef ENVIRONMENT_TEMPERATURE_HPP_ +#define ENVIRONMENT_TEMPERATURE_HPP_ + +#include "../math.hpp" + +namespace trochia::environment::temperature { + class thermodynamic { + public: + constexpr thermodynamic() : t(0.0) {} + constexpr thermodynamic(const math::Float &t) : t(t) {} + + virtual operator math::Float() { + return t; + } + protected: + math::Float t; + }; + + using kelvin = thermodynamic; + + class celsius : public thermodynamic { + constexpr celsius(const thermodynamic &t) : thermodynamic(t) {} + constexpr celsius(const math::Float &t) : thermodynamic(t + 273.15) {} + + operator math::Float() { + return this->t - 273.15; + } + }; +} + +#endif From f964d45af156794afb284922bf8305b82b96f200 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 00:59:44 +0900 Subject: [PATCH 08/18] [fix] --- src/environment/temperature.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/environment/temperature.hpp b/src/environment/temperature.hpp index 79ae5de..b13cc79 100644 --- a/src/environment/temperature.hpp +++ b/src/environment/temperature.hpp @@ -40,6 +40,8 @@ namespace trochia::environment::temperature { using kelvin = thermodynamic; class celsius : public thermodynamic { + public: + constexpr celsius() : thermodynamic(273.15) {} constexpr celsius(const thermodynamic &t) : thermodynamic(t) {} constexpr celsius(const math::Float &t) : thermodynamic(t + 273.15) {} From cd430607a7197687567e8aaf007a993dda87eb59 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 01:29:22 +0900 Subject: [PATCH 09/18] [add] simple temperature change --- src/environment/air.hpp | 7 ++++++- src/simulation.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/environment/air.hpp b/src/environment/air.hpp index 55718f9..32d819d 100644 --- a/src/environment/air.hpp +++ b/src/environment/air.hpp @@ -23,8 +23,13 @@ #define ENVIRONMENT_AIR_HPP_ #include "../math.hpp" +#include "temperature.hpp" -namespace environment::air { +namespace trochia::environment::air { + auto temperature(const math::Float &height) -> temperature::kelvin { + const auto height_km = height * 0.001; + return environment::temperature::celsius(15.0 - 6.5*height_km); + } } #endif diff --git a/src/simulation.cpp b/src/simulation.cpp index f3d7704..d1a130f 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -86,9 +86,14 @@ auto trochia::do_simulation(Simulation &sim) -> void { // log if(step % output_rate == 0){ + const auto altitude = rocket.pos.altitude(); + const auto geo_height = environment::earth::geodesy::potential_height(altitude); + const auto temperature = environment::air::temperature(geo_height); + std::cout << time << " " - << rocket.pos.altitude() << " " - << environment::earth::geodesy::potential_height(rocket.pos.altitude()) + << altitude << " " + << geo_height << " " + << (math::Float)environment::temperature::celsius(temperature) << std::endl; } From 64c484867f67ea06416f882133155de2f28e0f1b Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 01:51:49 +0900 Subject: [PATCH 10/18] [fix] enable cast if temperature is const --- src/environment/temperature.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/environment/temperature.hpp b/src/environment/temperature.hpp index b13cc79..11b93b3 100644 --- a/src/environment/temperature.hpp +++ b/src/environment/temperature.hpp @@ -30,7 +30,7 @@ namespace trochia::environment::temperature { constexpr thermodynamic() : t(0.0) {} constexpr thermodynamic(const math::Float &t) : t(t) {} - virtual operator math::Float() { + virtual operator math::Float() const { return t; } protected: @@ -45,7 +45,7 @@ namespace trochia::environment::temperature { constexpr celsius(const thermodynamic &t) : thermodynamic(t) {} constexpr celsius(const math::Float &t) : thermodynamic(t + 273.15) {} - operator math::Float() { + operator math::Float() const { return this->t - 273.15; } }; From a0d4438a5101c8d15de078620a6ee1a5e65e30a7 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 01:56:06 +0900 Subject: [PATCH 11/18] [add] pressure --- src/environment/air.hpp | 10 +++++++++- src/simulation.cpp | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/environment/air.hpp b/src/environment/air.hpp index 32d819d..bcb5fa0 100644 --- a/src/environment/air.hpp +++ b/src/environment/air.hpp @@ -26,9 +26,17 @@ #include "temperature.hpp" namespace trochia::environment::air { + // from FROGS (return kelvin) auto temperature(const math::Float &height) -> temperature::kelvin { const auto height_km = height * 0.001; - return environment::temperature::celsius(15.0 - 6.5*height_km); + return temperature::celsius(15.0 - 6.5*height_km); + } + + // from FROGS (return Pa) + auto pressure(const temperature::kelvin &t) -> math::Float { + math::Float tmp = (math::Float)t; + tmp = 288.15 / tmp; + return 101325.0 * std::pow(tmp, -5.256); } } diff --git a/src/simulation.cpp b/src/simulation.cpp index d1a130f..caeac62 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -93,7 +93,8 @@ auto trochia::do_simulation(Simulation &sim) -> void { std::cout << time << " " << altitude << " " << geo_height << " " - << (math::Float)environment::temperature::celsius(temperature) + << (math::Float)environment::temperature::celsius(temperature) << " " + << environment::air::pressure(temperature) / 100.0 << std::endl; } From db68cb7fff05afbd53714533c4aef2cccd8e241e Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 02:03:11 +0900 Subject: [PATCH 12/18] [add] density --- src/environment/air.hpp | 11 ++++++++--- src/simulation.cpp | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/environment/air.hpp b/src/environment/air.hpp index bcb5fa0..21f1753 100644 --- a/src/environment/air.hpp +++ b/src/environment/air.hpp @@ -34,9 +34,14 @@ namespace trochia::environment::air { // from FROGS (return Pa) auto pressure(const temperature::kelvin &t) -> math::Float { - math::Float tmp = (math::Float)t; - tmp = 288.15 / tmp; - return 101325.0 * std::pow(tmp, -5.256); + const math::Float t_ = t; + return 101325.0 * std::pow((288.15 / t_), -5.256); + } + + // from FROGS (Don't use this equation over 11km) + auto density(const temperature::kelvin &t) -> math::Float { + const math::Float t_ = t; + return (0.0034837 * pressure(t)) / t_; } } diff --git a/src/simulation.cpp b/src/simulation.cpp index caeac62..9eefb2c 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -94,7 +94,8 @@ auto trochia::do_simulation(Simulation &sim) -> void { << altitude << " " << geo_height << " " << (math::Float)environment::temperature::celsius(temperature) << " " - << environment::air::pressure(temperature) / 100.0 + << environment::air::pressure(temperature) / 100.0 << " " + << environment::air::density(temperature) << std::endl; } From 30cfdd6f9e2689415e559bcde9ad0ced11e6a972 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 02:46:43 +0900 Subject: [PATCH 13/18] [fix] function return type --- src/coordinate/local.hpp | 62 ++++++++++++++--------------- src/engine.hpp | 6 +-- src/environment/earth/ellipsoid.hpp | 6 +-- src/environment/gravity.hpp | 2 +- src/environment/launcher.hpp | 2 +- src/math.hpp | 10 ++--- src/object.hpp | 18 ++++----- src/rocket.hpp | 4 +- 8 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/coordinate/local.hpp b/src/coordinate/local.hpp index c711a07..66473a5 100644 --- a/src/coordinate/local.hpp +++ b/src/coordinate/local.hpp @@ -29,42 +29,42 @@ namespace trochia::coordinate::local { Vector3 vec; - inline auto operator+(const Base &b) const -> const Base { + inline auto operator+(const Base &b) const -> Base { Base ret; ret.vec = this->vec + b.vec; return ret; } - inline auto operator-(const Base &b) const -> const Base { + inline auto operator-(const Base &b) const -> Base { Base ret; ret.vec = this->vec - b.vec; return ret; } - inline auto operator*(const math::Float &b) const -> const Base { + inline auto operator*(const math::Float &b) const -> Base { Base ret; ret.vec = this->vec * b; return ret; } - inline auto operator/(const math::Float &b) const -> const Base { + inline auto operator/(const math::Float &b) const -> Base { Base ret; ret.vec = this->vec / b; return ret; } - inline auto operator+=(const Base &b) -> const Base& { + inline auto operator+=(const Base &b) -> Base& { this->vec += b.vec; return *this; } - inline auto operator-=(const Base &b) -> const Base& { + inline auto operator-=(const Base &b) -> Base& { this->vec -= b.vec; return *this; } - inline auto operator*=(const math::Float &b) -> const Base& { + inline auto operator*=(const math::Float &b) -> Base& { this->vec *= b; return *this; } - inline auto operator/=(const math::Float &b) -> const Base& { + inline auto operator/=(const math::Float &b) -> Base& { this->vec /= b; return *this; } @@ -74,23 +74,23 @@ namespace trochia::coordinate::local { public: NED() : Base() {} - auto north() const -> const Float { return vec.x(); } - auto east() const -> const Float { return vec.y(); } - auto down() const -> const Float { return vec.z(); } + auto north() const -> Float { return vec.x(); } + auto east() const -> Float { return vec.y(); } + auto down() const -> Float { return vec.z(); } - auto south() const -> const Float { return -1.0*north(); } - auto west() const -> const Float { return -1.0*east(); } - auto up() const -> const Float { return -1.0*down(); } + auto south() const -> Float { return -1.0*north(); } + auto west() const -> Float { return -1.0*east(); } + auto up() const -> Float { return -1.0*down(); } - auto altitude() const -> const Float { return up(); } + auto altitude() const -> Float { return up(); } - auto north(const Float &n) -> void{ vec.x() = n; } - auto east(const Float &e) -> void{ vec.y() = e; } - auto down(const Float &d) -> void{ vec.z() = d; } + auto north(const Float &n) -> void { vec.x() = n; } + auto east(const Float &e) -> void { vec.y() = e; } + auto down(const Float &d) -> void { vec.z() = d; } - auto south(const Float &s) -> void{ north(-1.0*s); } - auto west(const Float &w) -> void{ east(-1.0*w); } - auto up(const Float &u) -> void{ down(-1.0*u); } + auto south(const Float &s) -> void { north(-1.0*s); } + auto west(const Float &w) -> void { east(-1.0*w); } + auto up(const Float &u) -> void { down(-1.0*u); } template operator Frame() { @@ -106,19 +106,19 @@ namespace trochia::coordinate::local { public: ENU() : Base() {} - auto east() const -> const Float { return vec.x(); } - auto north() const -> const Float { return vec.y(); } - auto up() const -> const Float { return vec.z(); } + auto east() const -> Float { return vec.x(); } + auto north() const -> Float { return vec.y(); } + auto up() const -> Float { return vec.z(); } - auto west() const -> const Float { return -1.0*east(); } - auto south() const -> const Float { return -1.0*north(); } - auto down() const -> const Float { return -1.0*up(); } + auto west() const -> Float { return -1.0*east(); } + auto south() const -> Float { return -1.0*north(); } + auto down() const -> Float { return -1.0*up(); } - auto altitude() const -> const Float { return up(); } + auto altitude() const -> Float { return up(); } - auto east(const Float &e) -> void{ vec.x() = e; } - auto north(const Float &n) -> void{ vec.y() = n; } - auto up(const Float &u) -> void{ vec.z() = u; } + auto east(const Float &e) -> void { vec.x() = e; } + auto north(const Float &n) -> void { vec.y() = n; } + auto up(const Float &u) -> void { vec.z() = u; } template operator Frame() { diff --git a/src/engine.hpp b/src/engine.hpp index e6c3c1b..885f24c 100644 --- a/src/engine.hpp +++ b/src/engine.hpp @@ -82,16 +82,16 @@ namespace trochia { itr = data.cbegin(); } - inline auto progress(const math::Float &time) const -> const math::Float { + inline auto progress(const math::Float &time) const -> math::Float { return time / time_max; } - inline auto weight(const math::Float &time) const -> const math::Float { + inline auto weight(const math::Float &time) const -> math::Float { const auto prop = math::lerp(weight_prop, 0, this->progress(time)); return weight_total - weight_prop + prop; } - auto thrust(const math::Float &time) -> const math::Float { + auto thrust(const math::Float &time) -> math::Float { const auto &next = itr+1; const auto &time_now = itr->first; const auto &thrust_now = itr->second; diff --git a/src/environment/earth/ellipsoid.hpp b/src/environment/earth/ellipsoid.hpp index 2a43399..2e80077 100644 --- a/src/environment/earth/ellipsoid.hpp +++ b/src/environment/earth/ellipsoid.hpp @@ -46,17 +46,17 @@ namespace trochia::environment::earth { e2= f_tmp / (f_inv * f_inv); } - constexpr auto W(const Float &lat) const -> const Float { + constexpr auto W(const Float &lat) const -> Float { const auto sin = math::sin(lat); const auto sin2 = sin*sin; return math::sqrt(1.0 - e2*sin2); } - constexpr auto N(const Float &lat) const -> const Float { + constexpr auto N(const Float &lat) const -> Float { return a / W(lat); } - constexpr auto M(const Float &lat) const -> const Float { + constexpr auto M(const Float &lat) const -> Float { const auto w = W(lat); const auto W2= w*w; return N(lat) * (1.0 - e2) / W2; diff --git a/src/environment/gravity.hpp b/src/environment/gravity.hpp index 9f1f240..b76c4a2 100644 --- a/src/environment/gravity.hpp +++ b/src/environment/gravity.hpp @@ -32,7 +32,7 @@ namespace trochia::environment { // gravitation model // other planet - inline auto gravity(const math::Float &altitude) -> const math::Float { + inline auto gravity(const math::Float &altitude) -> math::Float { const auto tmp = earth::re / (earth::re + altitude); return physics::g0 * tmp * tmp; } diff --git a/src/environment/launcher.hpp b/src/environment/launcher.hpp index fcde7ca..5186eb9 100644 --- a/src/environment/launcher.hpp +++ b/src/environment/launcher.hpp @@ -36,7 +36,7 @@ namespace trochia::environment { math::Quaternion angle; public: - auto get_angle() const -> const math::Quaternion { return this->angle; } + auto get_angle() const -> math::Quaternion { return this->angle; } auto set_angle(const math::Vector3 &euler) -> void { this->set_angle(euler.x(), euler.y(), euler.z()); diff --git a/src/math.hpp b/src/math.hpp index 7e42aeb..78550a1 100644 --- a/src/math.hpp +++ b/src/math.hpp @@ -77,15 +77,15 @@ namespace trochia::math { return series; } - constexpr auto deg2rad(const Float °) -> const Float { + constexpr auto deg2rad(const Float °) -> Float { return deg * (pi / 180.0); } - constexpr auto rad2deg(const Float &rad) -> const Float { + constexpr auto rad2deg(const Float &rad) -> Float { return rad * (180.0 / pi); } [[deprecated("please use AngleAxis")]] - inline auto euler2quat(const Float &roll, const Float &pitch, const Float &yaw) -> const Quaternion { + inline auto euler2quat(const Float &roll, const Float &pitch, const Float &yaw) -> Quaternion { using Eigen::AngleAxisd; Quaternion q; @@ -95,11 +95,11 @@ namespace trochia::math { return q; } - inline auto quat2euler(const Quaternion &q) -> const Vector3 { + inline auto quat2euler(const Quaternion &q) -> Vector3 { return q.toRotationMatrix().eulerAngles(0, 1, 2); } - inline auto lerp(const Float &a, const Float &b, const Float &t) -> const Float { + inline auto lerp(const Float &a, const Float &b, const Float &t) -> Float { return a + t*(b - a); } } diff --git a/src/object.hpp b/src/object.hpp index af7a949..ebbadf6 100644 --- a/src/object.hpp +++ b/src/object.hpp @@ -42,7 +42,7 @@ namespace trochia::object { return ret; } - virtual auto weight() const -> const math::Float { + virtual auto weight() const -> math::Float { return 0.0; } @@ -52,45 +52,45 @@ namespace trochia::object { } // operator - auto operator+=(const Object &o) -> const Object { + auto operator+=(const Object &o) -> Object { this->pos += o.pos; this->vel += o.vel; return *this; } - auto operator-=(const Object &o) -> const Object { + auto operator-=(const Object &o) -> Object { this->pos -= o.pos; this->vel -= o.vel; return *this; } - auto operator*=(const math::Float &a) -> const Object { + auto operator*=(const math::Float &a) -> Object { this->pos *= a; this->vel *= a; return *this; } - auto operator/=(const math::Float &a) -> const Object { + auto operator/=(const math::Float &a) -> Object { this->pos /= a; this->vel /= a; return *this; } - auto operator+(const Object &o) const -> const Object { + auto operator+(const Object &o) const -> Object { Object ret = *this; ret += o; return ret; } - auto operator-(const Object &o) const -> const Object { + auto operator-(const Object &o) const -> Object { Object ret = *this; ret -= o; return ret; } - auto operator*(const math::Float &a) const -> const Object { + auto operator*(const math::Float &a) const -> Object { Object ret = *this; ret *= a; return ret; } - auto operator/(const math::Float &a) const -> const Object { + auto operator/(const math::Float &a) const -> Object { Object ret = *this; ret /= a; return ret; diff --git a/src/rocket.hpp b/src/rocket.hpp index d804c7d..ec7f7dd 100644 --- a/src/rocket.hpp +++ b/src/rocket.hpp @@ -47,11 +47,11 @@ namespace trochia::rocket { return object::Object::dx(t, r); } - auto lcg() const -> const math::Float { + auto lcg() const -> math::Float { return math::lerp(lcg0, lcgf, engine.progress(this->time)); } - auto weight() const -> const math::Float { + auto weight() const -> math::Float { return 10.0 + engine.weight(this->time); } }; From b33899fa8f3b3cb6b8c0ea0c22e1bd7210f158ae Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 03:35:00 +0900 Subject: [PATCH 14/18] [add] calc angle of attack, side-slip --- src/simulation.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/simulation.cpp b/src/simulation.cpp index 9eefb2c..8986193 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -61,6 +61,18 @@ auto trochia::do_simulation(Simulation &sim) -> void { const auto &time = s.t; rocket.time = time; + const coordinate::local::NED vel_ned = rocket.vel; + const auto vab_ned = vel_ned.vec; + + // Body座標系での対気速度ベクトル + const auto vab = coordinate::dcm::ned2body(rocket.quat) * vab_ned; + const auto va = vab.norm(); + + // tan(attack) = z/x + // arctan(z/x) = attack + const auto angle_attack = std::atan(vab.z() / vab.x()); + const auto angle_side_slip = std::atan(vab.y() / va); + // thrust const auto thrust = rocket.engine.thrust(time); // first stage only @@ -95,7 +107,8 @@ auto trochia::do_simulation(Simulation &sim) -> void { << geo_height << " " << (math::Float)environment::temperature::celsius(temperature) << " " << environment::air::pressure(temperature) / 100.0 << " " - << environment::air::density(temperature) + << environment::air::density(temperature) << " " + << angle_attack << std::endl; } From 18e6285ddaf44543a2d7d260d8588534084973c8 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 03:38:53 +0900 Subject: [PATCH 15/18] [update] example configuration --- config-example.toml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/config-example.toml b/config-example.toml index 961febf..2de6aee 100644 --- a/config-example.toml +++ b/config-example.toml @@ -1,11 +1,11 @@ [simulation] dt = 0.01 -output.dt = 0.1 +output.dt = 0.01 [launcher] length = 5 -angle = 86 -# angle.start = 86 +angle = 85 +# angle.start = 85 # angle.end = 89 [rocket] @@ -13,9 +13,11 @@ name = "example rocket" type = "hybrid" [[rocket.stage]] -engine = "larkspur_xp_300.resm" +engine = "K240.eng" length = 1.1540 diameter= 0.112 mass = 5.679 Cd = 0.450 +lcg0 = 0.913 +lcgf = 0.905 parachute= {condition = "top", delay = 2.5} From 5a1431df54127b915ff46e45f2045490208c1c64 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 04:02:27 +0900 Subject: [PATCH 16/18] [add] drag force --- src/io/config.cpp | 4 ++++ src/rocket.hpp | 2 ++ src/simulation.cpp | 13 ++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/io/config.cpp b/src/io/config.cpp index ad5b466..00415a6 100644 --- a/src/io/config.cpp +++ b/src/io/config.cpp @@ -56,8 +56,12 @@ auto load(const std::string &fname, std::vector &sims) -> void { const auto engine = stage[0].at("engine"); sim.rocket.engine.load_eng(engine.as_string()); + sim.rocket.diameter = stage[0].at("diameter").as_floating(); + sim.rocket.lcg0 = stage[0].at("lcg0").as_floating(); sim.rocket.lcgf = stage[0].at("lcgf").as_floating(); + + sim.rocket.Cd = stage[0].at("Cd").as_floating(); } sims.push_back(sim); diff --git a/src/rocket.hpp b/src/rocket.hpp index ec7f7dd..99e27d0 100644 --- a/src/rocket.hpp +++ b/src/rocket.hpp @@ -41,7 +41,9 @@ namespace trochia::rocket { std::string name; Engine engine; + math::Float diameter; // 直径(m) math::Float lcg0, lcgf; // 重心位置 + math::Float Cd; // 抗力係数 static auto dx(const math::Float &t, const Rocket &r) -> const Rocket { return object::Object::dx(t, r); diff --git a/src/simulation.cpp b/src/simulation.cpp index 8986193..4816e06 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -73,11 +73,22 @@ auto trochia::do_simulation(Simulation &sim) -> void { const auto angle_attack = std::atan(vab.z() / vab.x()); const auto angle_side_slip = std::atan(vab.y() / va); + // 代表面積 + const auto S = rocket.diameter * rocket.diameter * math::pi / 4; + + const auto altitude = rocket.pos.altitude(); + const auto geo_height = environment::earth::geodesy::potential_height(altitude); + const auto temperature = environment::air::temperature(geo_height); + const auto rho = environment::air::density(temperature); + + // 空気抵抗 + const auto D = 0.5 * rocket.Cd * rho * va*va*S; + // thrust const auto thrust = rocket.engine.thrust(time); // first stage only const auto force = coordinate::body::Body( - thrust, + thrust - D, 0.0, 0.0 ); From 357d0ca53ed702d708636e1fd4fb372788cf013e Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 04:45:31 +0900 Subject: [PATCH 17/18] [add] side,normal force --- config-example.toml | 3 ++- src/io/config.cpp | 1 + src/rocket.hpp | 1 + src/simulation.cpp | 9 ++++++--- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config-example.toml b/config-example.toml index 2de6aee..9018b40 100644 --- a/config-example.toml +++ b/config-example.toml @@ -17,7 +17,8 @@ engine = "K240.eng" length = 1.1540 diameter= 0.112 mass = 5.679 -Cd = 0.450 +Cd = 0.440 +Cna = 7.840 lcg0 = 0.913 lcgf = 0.905 parachute= {condition = "top", delay = 2.5} diff --git a/src/io/config.cpp b/src/io/config.cpp index 00415a6..076fcd6 100644 --- a/src/io/config.cpp +++ b/src/io/config.cpp @@ -62,6 +62,7 @@ auto load(const std::string &fname, std::vector &sims) -> void { sim.rocket.lcgf = stage[0].at("lcgf").as_floating(); sim.rocket.Cd = stage[0].at("Cd").as_floating(); + sim.rocket.Cna= stage[0].at("Cna").as_floating(); } sims.push_back(sim); diff --git a/src/rocket.hpp b/src/rocket.hpp index 99e27d0..4badab6 100644 --- a/src/rocket.hpp +++ b/src/rocket.hpp @@ -44,6 +44,7 @@ namespace trochia::rocket { math::Float diameter; // 直径(m) math::Float lcg0, lcgf; // 重心位置 math::Float Cd; // 抗力係数 + math::Float Cna; static auto dx(const math::Float &t, const Rocket &r) -> const Rocket { return object::Object::dx(t, r); diff --git a/src/simulation.cpp b/src/simulation.cpp index 4816e06..d6da721 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -82,15 +82,18 @@ auto trochia::do_simulation(Simulation &sim) -> void { const auto rho = environment::air::density(temperature); // 空気抵抗 - const auto D = 0.5 * rocket.Cd * rho * va*va*S; + const auto q = 0.5 * rho * va * va; // 動圧 + const auto D = rocket.Cd * q * S; + const auto Y = rocket.Cna * q * S * std::sin(angle_side_slip); + const auto N = rocket.Cna * q * S * std::sin(angle_attack); // thrust const auto thrust = rocket.engine.thrust(time); // first stage only const auto force = coordinate::body::Body( thrust - D, - 0.0, - 0.0 + -1.0 * Y, + -1.0 * N ); rocket.force(force.to_local(rocket.quat)); From 7ac396ca20bcc86a889d6eb09f11caf6780f5910 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 15 Dec 2019 05:00:49 +0900 Subject: [PATCH 18/18] [fix] dividation by zero --- src/simulation.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/simulation.cpp b/src/simulation.cpp index d6da721..cf85ff0 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -70,8 +70,8 @@ auto trochia::do_simulation(Simulation &sim) -> void { // tan(attack) = z/x // arctan(z/x) = attack - const auto angle_attack = std::atan(vab.z() / vab.x()); - const auto angle_side_slip = std::atan(vab.y() / va); + const auto angle_attack = (vab.x()!=0.0 ? std::atan(vab.z() / vab.x()) : 0.5*math::pi); + const auto angle_side_slip = (va!=0.0 ? std::atan(vab.y() / va) : 0.5*math::pi); // 代表面積 const auto S = rocket.diameter * rocket.diameter * math::pi / 4; @@ -122,7 +122,8 @@ auto trochia::do_simulation(Simulation &sim) -> void { << (math::Float)environment::temperature::celsius(temperature) << " " << environment::air::pressure(temperature) / 100.0 << " " << environment::air::density(temperature) << " " - << angle_attack + << angle_attack << " " + << Y << std::endl; }