-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsimpleSimulation.cpp
More file actions
71 lines (54 loc) · 2.02 KB
/
Copy pathsimpleSimulation.cpp
File metadata and controls
71 lines (54 loc) · 2.02 KB
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
/*
* vdp_multiple_shooting.cpp
*
* Created on: Nov 5, 2015
* Author: laetus
*/
#include "simpleSimulation.hpp"
//#include <stdio.h>
using namespace casadi;
Integrator createIntegrator(SXFunction dae, double steplength) {
Dict opts;
Integrator integrator;
opts = make_dict("tf", steplength, "abstol", 1e-8, "reltol", 1e-8,
"steps_per_checkpoint", 1000, "max_num_steps", 1000);
integrator = Integrator("integrator", "idas", dae, opts);
integrator.setOption("linear_solver", "csparse");
// integrator.setOption("regularity_check", false);
std::cout << "Integrator created" << std::endl;
return integrator;
}
int main(int argc, const char ** argv) {
std::cout << "Programm started" << std::endl;
// Define global variables/settings
omp_set_num_threads(7);
int nTimesteps = 384; // 384;
int horizon = nTimesteps * 15 * 60; //86400/4;
//Zeit, die pro Realtimeschritt vergeht: horizon / nTimesteps
int n_f = 384 / 4;
// For Global Solver:
n_f = 1;
// For Realtime Solver:
LakesAndFlows* model = new LakesAndFlows(nTimesteps, horizon, n_f);
SXFunction dae = model->buildDAE();
Integrator integrator = createIntegrator(dae, (double) horizon
/ (double) nTimesteps);
////////////////////////////////////////////////////////////////
// Optimization problem //
////////////////////////////////////////////////////////////////
// RealtimeSolver* solver = new RealtimeSolver(model, &integrator,n_f);
GlobalSolver* solver = new GlobalSolver(model, &integrator, n_f);
solver->solve();
////////////////////////////////////////////////////////////////
// Visualisation //
////////////////////////////////////////////////////////////////
model->calcProducedPower();
model->writeModelToConsole(true);
model->writeResultToFile();
////////////////////////////////////////////////////////////////
// Verification //
////////////////////////////////////////////////////////////////
Matrix<double> waterMass = model->waterMass();
std::cout << waterMass.dimString();
waterMass.print(std::cout << "Water Mass: \n");
}