-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simulator.h
145 lines (113 loc) · 4.38 KB
/
Simulator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Copyright © 2021 TokiNoBug
This file is part of UniSimulator.
UniSimulator 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.
UniSimulator 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 UniSimulator. If not, see <https://www.gnu.org/licenses/>.
Contact with me:
github:https://github.com/ToKiNoBug
bilibili:https://space.bilibili.com/351429231
*/
#ifndef SIMULATOR_H
#define SIMULATOR_H
#include <iostream>
#include <cmath>
#include <list>
#include <vector>
#include <tuple>
#include <fstream>
#include <string>
#include "defines.h"
extern const double G; //gravity constant
extern const double Ms; //standard mass (solar mass)
extern const double omega_s; //standard angle speed
extern const double rho; //solar density
extern const double year; //seconds of a year
extern const double rs; //standard distance (1AU)
extern const double vs; //standard speed
extern const double as; //standard accelerate
class Simulator
{
public:
Simulator();
enum Algorithm {
Euler,
RK4Fixed,
RK4Var1,
//ODE45
};
static const std::string paraSuffix;
static const std::string dataSuffix;
public:
void simulateEuler(const double,
TimeSpan,
Statue,
bool * noCollide=nullptr);
void simulateRK4Fixed(const double,
TimeSpan,
Statue,
bool * noCollide=nullptr);
void simulateRK4Var1(double,
TimeSpan,
Statue,
bool * noCollide=nullptr);
void clear();
void setMass(const BodyVector &);
const BodyVector & getMass() const;
const std::list<Point> & getResult() const;
double calculateKinetic(const Statue & it) const;
double calculatePotential(const Statue & it) const;
double calculateEnergy(const Statue & it) const;
void calculateTotalMotion(const Statue & it,
DimVector &) const;
void savePath(const char * fileName);
public:
static void calculateSafeDistance(const BodyVector &,
DistanceMat & dest);
static void calculateGM(const BodyVector &,
Interaction &);
static bool calculateDiff(const Position & y,
const Interaction &,
const DistanceMat &,
Acceleration & dy);
//To avoid useless deep copying, dy.first will not be used.
static bool RK4(const Time h,
const Statue & y,
const Interaction &,
const DistanceMat& ,
Statue & y_n1);
static bool isErrorTolerantable(const Statue & y_h,
const Statue & y_h_2,
double errorRatio=1e-8);
static void deval(const Simulator * source,
Simulator * dest,
const Eigen::ArrayXd & timeQueried);
static void motionAlign(const BodyVector & mass, Velocity & velocity);
static void positonAlign(Position &);
static void saveParameters(const char * fileName,
const BodyVector & mass,
const Statue & y0,
const TimeSpan ts,
const double step);
static bool loadParameters(const char * fileName,
BodyVector & mass,
Statue & y0,
TimeSpan & ts,
double & step);
void saveAsData(const char * fileName) const;
bool loadFromData(const char * fileName);
#ifdef BODY3_DIM3
static void positionShrink(Position &);
#endif
private:
std::list<Point> sol;
BodyVector mass;
};
#endif // SIMULATOR_H