My Project
simulation.hpp
Go to the documentation of this file.
1 #include<readParameters.hpp>
2 #include<armadillo>
3 
4 using namespace std;
5 
6 class Simulation{
7  public:
9  string parameters_path);
10  Simulation(
11  string parameters_path,
12  bool friction_parallelized);
13  void main();
14  protected:
15  void setupModelVectorsMatrices();
16  void setupBlockMatrix();
17  void setupBlockMatrixDerivative();
18  void setupPadVector();
19  void setupPadVectorDerivative();
20  void setupSaveVectorsMatrices();
21 
22  void setupSliderSpeedMode();
23 
24  void setupConstants();
25 
26  double phi(double y);
27 
28  void setSpeedAfterThreshold();
29  void updateSliderSpeed(
30  int time_step
31  );
32 
33  void function_u(
34  const arma::mat& current_block_matrix,
35  const arma::rowvec& current_pad_vector,
36  arma::mat& current_block_matrix_derivative
37  );
38 
39  void function_x(
40  const arma::mat& current_block_matrix,
41  const arma::rowvec& current_pad_vector,
42  arma::rowvec& current_pad_vector_derivative
43  );
44  void function_x_odof(
45  const arma::rowvec& current_pad_vector,
46  arma::rowvec& current_pad_vector_derivative
47  );
48  double calculatePadSupportDamper(
49  arma::rowvec current_pad_vector
50  );
51  double calculatePadFriction(
52  arma::mat current_block_matrix,
53  arma::rowvec current_pad_vector
54  );
55 
56  void midpointMethod(
57  int time_step
58  );
59 
60  void oneDegreeOfFreedomMidpointMethod(
61  int time_step
62  );
63 
64  void writeValuesToLoggers(
65  const int& time_step
66  );
67 
68  void printMidPointMethod(
69  arma::mat block_matrix,
70  arma::rowvec pad_vector,
71  string explanation_text = "");
72  void runMidpointMethod();
73 
74  void saveToCsv(
75  string filename,
76  string result_path);
77 
78  void midpointMethodParallel(
79  int timestep,
80  arma::mat& block_matrix_parallel,
81  arma::rowvec& pad_vector_parallel,
82  arma::mat block_matrix_derivative_parallel,
83  arma::rowvec pad_vector_derivative_parallel);
84  void setupAndRunFrictionInParallel(
85  int time_step,
86  double slider_speed);
87  void calculateFrictionInParallel();
88  void saveToCsvParallel(
89  const arma::colvec& armadillo_vector,
90  const string& result_path,
91  const double& slider_speed
92  );
93 
95 
97 
98  arma::mat block_matrix;
100 
101  arma::rowvec pad_vector;
102  arma::rowvec pad_vector_derivative;
103 
107 
108  double m_u; // mass of block
109  double k_p; // Stationary spring between pad and blocks
110  double m_c_crit; // Critical damping coefficient
111  double c_p; // Damper between pad and surface
112  double k_c; // Neighboring spring
113 
114  int updateSliderSpeedDtInterval; //translate the interval for updating slider speed based on dt
115 
116  bool loggingSpecificBlocks = false;
117  arma::uvec block_position_column_index = {0};
118  arma::uvec block_velocity_column_index = {1};
119 
122  arma::colvec pad_position_to_file;
123  arma::colvec pad_velocity_to_file;
124  arma::colvec pad_friction_to_file;
125 
126  int index_pad_friction_to_file = 0;
127  int index_to_file = 0;
128 
129  int friction_zero_counter = 0;
130 };
131 
133  public:
134  DebugSimulation(string debug_parameters_path) : Simulation(debug_parameters_path){};
135  void main();
136 
137  protected:
138  void printMatrix(arma::mat matrix, bool arra_format);
139  void printRowVector(arma::rowvec vector);
140 
141 };
arma::mat block_matrix_derivative
Definition: simulation.hpp:99
double k_p
Definition: simulation.hpp:109
DebugSimulation(string debug_parameters_path)
Definition: simulation.hpp:134
arma::colvec pad_friction_to_file
Definition: simulation.hpp:124
arma::mat block_velocity_to_file
Definition: simulation.hpp:121
arma::mat block_position_to_file
Definition: simulation.hpp:120
arma::rowvec pad_vector_derivative
Definition: simulation.hpp:102
string input_parameters_path
Definition: simulation.hpp:94
int main(int argc, char *agrv[])
Definition: main.cpp:6
double m_u
Definition: simulation.hpp:108
Parameters input_parameters
Definition: simulation.hpp:96
arma::colvec pad_position_to_file
Definition: simulation.hpp:122
int updateSliderSpeedDtInterval
Definition: simulation.hpp:114
int number_of_time_steps
Definition: simulation.hpp:104
int number_of_save_steps
Definition: simulation.hpp:105
arma::rowvec pad_vector
Definition: simulation.hpp:101
double k_c
Definition: simulation.hpp:112
arma::colvec pad_velocity_to_file
Definition: simulation.hpp:123
int number_of_interval_save_step
Definition: simulation.hpp:106
double m_c_crit
Definition: simulation.hpp:110
double c_p
Definition: simulation.hpp:111
arma::mat block_matrix
Definition: simulation.hpp:98