Skip to content

Commit

Permalink
Merge pull request #22 from sk2sat/develop
Browse files Browse the repository at this point in the history
Release version 0.2
  • Loading branch information
sksat authored Dec 14, 2019
2 parents a36e76c + 7ac396c commit 263f31d
Show file tree
Hide file tree
Showing 18 changed files with 418 additions and 134 deletions.
13 changes: 8 additions & 5 deletions config-example.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
[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]
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
Cd = 0.440
Cna = 7.840
lcg0 = 0.913
lcgf = 0.905
parachute= {condition = "top", delay = 2.5}
2 changes: 1 addition & 1 deletion src/coordinate/earth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 31 additions & 31 deletions src/coordinate/local.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<typename Frame>
operator Frame() {
Expand All @@ -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<typename Frame>
operator Frame() {
Expand Down
6 changes: 3 additions & 3 deletions src/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions src/environment.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* ----------------------------------------------------------------------- *
*
* Copyright (C) 2019 sksat <sksat@sksat.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
* ----------------------------------------------------------------------- */

#ifndef ENVIRONMENT_HPP_
#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"
#include "environment/launcher.hpp"

#endif
20 changes: 19 additions & 1 deletion src/environment/air.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,26 @@
#define ENVIRONMENT_AIR_HPP_

#include "../math.hpp"
#include "temperature.hpp"

namespace environment::air {
namespace trochia::environment::air {
// from FROGS (return kelvin)
auto temperature(const math::Float &height) -> temperature::kelvin {
const auto height_km = height * 0.001;
return temperature::celsius(15.0 - 6.5*height_km);
}

// from FROGS (return Pa)
auto pressure(const temperature::kelvin &t) -> math::Float {
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_;
}
}

#endif
60 changes: 5 additions & 55 deletions src/environment/earth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,11 @@
#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),
f(0.0), b(0.0), e(0.0), e2(0.0)
{
calc_parameters();
}

constexpr auto calc_parameters() -> void {
// https://psgsv2.gsi.go.jp/koukyou/jyunsoku/pdf/h28/h28_junsoku_furoku6.pdf
f = 1.0 / f_inv;
b = a * (f_inv - 1.0) / f_inv;

const auto f_tmp = 2.0 * f_inv - 1.0;
e = math::sqrt(f_tmp) / f_inv;
e2= f_tmp / (f_inv * f_inv);
}

constexpr auto W(const Float &lat) const -> 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 {
return a / W(lat);
}

constexpr auto M(const Float &lat) const -> const Float {
const auto w = W(lat);
const auto W2= w*w;
return N(lat) * (1.0 - e2) / W2;
}

Float a, f_inv;
Float f, b, e, e2;
};

// https://www.jmu.edu/cisr/research/sic/standards/ellipsoid.htm
constexpr auto Airy_1830 = Ellipsoid(6'377'563, 299.33);
constexpr auto Everest_1830 = Ellipsoid(6'377'276.3, 300.80);
constexpr auto Bessel_1841 = Ellipsoid(6'377'397.2, 299.15);
constexpr auto Clarke_1866 = Ellipsoid(6'378'206.4, 294.98);
constexpr auto Clarke_1880 = Ellipsoid(6'378'249.2, 293.47);
constexpr auto International_1924 = Ellipsoid(6'378'388, 297);
constexpr auto Krasovsky_1924 = Ellipsoid(6'378'245, 298.3);
constexpr auto International_Astronomical_Union_1968
= Ellipsoid(6'378'160, 298.25);
constexpr auto WGS72 = Ellipsoid(6'378'135, 298.26);
constexpr auto GRS80 = Ellipsoid(6'378'137, 298.26);
constexpr auto WGS84 = Ellipsoid(GRS80.a, 298.25722);
}
// Chronological Scientific Tables 2014
constexpr math::Float re = 6.3781366e6;
}

#include "earth/ellipsoid.hpp"
#include "earth/geodesy.hpp"

#endif
85 changes: 85 additions & 0 deletions src/environment/earth/ellipsoid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* ----------------------------------------------------------------------- *
*
* Copyright (C) 2019 sksat <sksat@sksat.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
* ----------------------------------------------------------------------- */

#ifndef ENVIRONMENT_EARTH_ELLIPSOID_HPP_
#define ENVIRONMENT_EARTH_ELLIPSOID_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),
f(0.0), b(0.0), e(0.0), e2(0.0)
{
calc_parameters();
}

constexpr auto calc_parameters() -> void {
// https://psgsv2.gsi.go.jp/koukyou/jyunsoku/pdf/h28/h28_junsoku_furoku6.pdf
f = 1.0 / f_inv;
b = a * (f_inv - 1.0) / f_inv;

const auto f_tmp = 2.0 * f_inv - 1.0;
e = math::sqrt(f_tmp) / f_inv;
e2= f_tmp / (f_inv * f_inv);
}

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 -> Float {
return a / W(lat);
}

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;
}

Float a, f_inv;
Float f, b, e, e2;
};

// https://www.jmu.edu/cisr/research/sic/standards/ellipsoid.htm
constexpr auto Airy_1830 = Ellipsoid(6'377'563, 299.33);
constexpr auto Everest_1830 = Ellipsoid(6'377'276.3, 300.80);
constexpr auto Bessel_1841 = Ellipsoid(6'377'397.2, 299.15);
constexpr auto Clarke_1866 = Ellipsoid(6'378'206.4, 294.98);
constexpr auto Clarke_1880 = Ellipsoid(6'378'249.2, 293.47);
constexpr auto International_1924 = Ellipsoid(6'378'388, 297);
constexpr auto Krasovsky_1924 = Ellipsoid(6'378'245, 298.3);
constexpr auto International_Astronomical_Union_1968
= Ellipsoid(6'378'160, 298.25);
constexpr auto WGS72 = Ellipsoid(6'378'135, 298.26);
constexpr auto GRS80 = Ellipsoid(6'378'137, 298.26);
constexpr auto WGS84 = Ellipsoid(GRS80.a, 298.25722);
}
}

#endif
Loading

0 comments on commit 263f31d

Please sign in to comment.