-
Notifications
You must be signed in to change notification settings - Fork 298
/
ARKode.h
184 lines (135 loc) · 5.62 KB
/
ARKode.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma once
#include "FactoryExport.h"
#include <Core/Solver/SolverDefaultImplementation.h>
#include <nvector/nvector_serial.h> // serial N_Vector types, fcts., macros
// ARKode includieren
//#include <cvode/cvode.h>
/*
*/
/*****************************************************************************/
// Cvode aus dem SUNDIALS-Package
// BDF-Verfahren für steife und nicht-steife ODEs
// Dokumentation siehe offizielle Cvode Doku
/*****************************************************************************
Copyright (c) 2004, Bosch Rexroth AG, All rights reserved
*****************************************************************************/
class Arkode
: public ISolver, public SolverDefaultImplementation
{
public:
Arkode(IMixedSystem* system, ISolverSettings* settings);
virtual ~Arkode();
// geerbt von Object (in SolverDefaultImplementation)
//---------------------------------------
/// Spezielle Solvereinstellungen setzten (default oder user defined)
virtual void initialize();
// geerbt von ISolver
//---------------------------------------
/// Setzen der Startzeit für die numerische Lösung
virtual void setStartTime(const double& time)
{
SolverDefaultImplementation::setStartTime(time);
};
/// Setzen der Endzeit für die numerische Lösung
virtual void setEndTime(const double& time)
{
SolverDefaultImplementation::setEndTime(time);
};
/// Setzen der initialen Schrittweite (z.B. auch nach Nullstelle)
virtual void setInitStepSize(const double& stepSize)
{
SolverDefaultImplementation::setInitStepSize(stepSize);
};
/// Berechung der numerischen Lösung innerhalb eines gegebenen Zeitintervalls
virtual void solve(const SOLVERCALL command = UNDEF_CALL);
/// Liefert den Status des Solvers nach Beendigung der Simulation
virtual ISolver::SOLVERSTATUS getSolverStatus()
{
return (SolverDefaultImplementation::getSolverStatus());
};
//// Ausgabe von statistischen Informationen (wird vom SimManager nach Abschluß der Simulation aufgerufen)
virtual void writeSimulationInfo();
virtual void setTimeOut(unsigned int time_out);
virtual void stop();
virtual int reportErrorMessage(std::ostream& messageStream);
virtual bool stateSelection();
private:
// Solveraufruf
void ArkodeCore();
/// Kapselung der Berechnung der rechten Seite
int calcFunction(const double& time, const double* y, double* yd);
// Callback für die rechte Seite
//static int CV_fCallback(double t, N_Vector y, N_Vector ydot, void *user_data);
static int ARK_fCallback(double t, N_Vector y, N_Vector ydot, void *user_data);
// Checks error flags of SUNDIALS
int check_flag(void *flagvalue, const char *funcname, int opt);
// Nulltellenfunktion
void giveZeroVal(const double &t,const double *y,double *zeroValue);
void writeArkodeOutput(const double &time,const double &h,const int &stp);
bool isInterrupted();
// Callback der Nullstellenfunktion
static int ARK_ZerofCallback(double t, N_Vector y, double *zeroval, void *user_data);
// Functions for Coloured Jacobian
//static int CV_JCallback(long int N, realtype t, N_Vector y, N_Vector fy, DlsMat Jac,void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3);
//int calcJacobian(double t, long int N, N_Vector fHelp, N_Vector errorWeight, N_Vector jthcol, double* y, N_Vector fy, DlsMat Jac);
//void initializeColoredJac();
ISolverSettings
*_arkodesettings; ///< Input - Solver settings
void
*_arkodeMem, ///< Temp - Memory for the solver
*_data; ///< Temp - User data. Contains pointer to Cvode
long int
_dimSys, ///< Input - (total) Dimension of system (=number of ODE)
_idid, ///< Input, Output - Status Flag
_locStps, ///< Output - Number of Steps between two events
_ark_rt; ///< Temp - CVode return flag
int
_outStps, ///< Output - Total number of output-steps
*_zeroSign;
double
*_z, ///< Output - (Current) State vector
*_zInit, ///< Temp - Initial state vector
*_zWrite, ///< Temp - Zustand den das System rausschreibt
*_absTol, /// - Vektor für absolute Toleranzen
*_delta,
*_deltaInv,
*_ysave;
double
_hOut; ///< Temp - Ouput step size for dense output
unsigned int
_event_n;
double
_tLastEvent;
double
_tOut, ///< Output - Time for dense output
_tZero, ///< Temp - Nullstelle
_tLastWrite; ///< Temp - Letzter Ausgabezeitpunkt
bool
_bWritten, ///< Temp - Is output already written
_zeroFound;
N_Vector
_ARK_y0, ///< Temp - Initial values in the Cvode Format
_ARK_y, ///< Temp - State in Cvode Format
_ARK_yWrite, ///< Temp - Vector for dense out
_ARK_absTol;
// Variables for Coloured Jacobians
/*
int* _colorOfColumn;
int _maxColors;
SparseMatrix _jacobianA;
int _jacobianANonzeros;
int const* _jacobianAIndex;
int const* _jacobianALeadindex;
*/
bool _arkode_initialized;
ISystemProperties* _properties;
IContinuous* _continuous_system;
IEvent* _event_system;
IMixedSystem* _mixed_system;
ITime* _time_system;
#ifdef RUNTIME_PROFILING
std::vector<MeasureTimeData> measureTimeFunctionsArray;
MeasureTimeValues *measuredFunctionStartValues, *measuredFunctionEndValues, *solveFunctionStartValues, *solveFunctionEndValues;
MeasureTimeValuesSolver *solverValues;
#endif
};