20#include "../../kernel.hpp"
87 for (
int i = 0; i < nResults; i++)
89 dydx[i] = v[i].real();
104 const gsl_odeiv_step_type* odeStepType_ly = 0;
105 gsl_odeiv_step* odeStep_ly = 0;
106 gsl_odeiv_control* odeControl_ly = 0;
107 gsl_odeiv_evolve* odeEvolve_ly = 0;
108 gsl_odeiv_system odeSystem_ly;
118 double dRelTolerance = 0.0;
119 double dAbsTolerance = 0.0;
121 int nLyapuSamples = 100;
123 vector<double> vInterval;
124 vector<double> vStartValues;
128 string sTarget =
"ode()";
129 string sVarDecl =
"y1";
131 bool bAllowCacheClearance =
false;
132 bool bCalcLyapunov =
false;
134 time_t tTimeControl = time(0);
138 double lyapu[2] = {0.0, 0.0};
139 double dist[2] = {1.0e-6,0.0};
148 if (sCmd.find(
"-set") != string::npos || sCmd.find(
"--") != string::npos)
150 if (sCmd.find(
"-set") != string::npos)
152 sFunc = sCmd.substr(0,sCmd.find(
"-set"));
153 sParams = sCmd.substr(sCmd.find(
"-set"));
157 sFunc = sCmd.substr(0,sCmd.find(
"--"));
158 sParams = sCmd.substr(sCmd.find(
"--"));
177 sParams.erase(sParams.find(sTarget,
findParameter(sParams,
"target",
'=')+6), sTarget.length());
179 if (sTarget.find(
'(') == string::npos)
182 bAllowCacheClearance =
true;
186 bAllowCacheClearance =
true;
197 sTarget.erase(sTarget.find(
'('));
233 bCalcLyapunov =
true;
238 if (sToleranceParams.front() ==
'[' && sToleranceParams.back() ==
']')
240 sToleranceParams.pop_back();
241 sToleranceParams.erase(0,1);
247 dRelTolerance = v[0].real();
248 dAbsTolerance = v[1].real();
252 dRelTolerance = v[0].real();
253 dAbsTolerance = v[0].real();
258 dRelTolerance = 1e-6;
259 dAbsTolerance = 1e-6;
265 if (sStartValues.front() ==
'[' && sStartValues.back() ==
']')
267 sStartValues.pop_back();
268 sStartValues.erase(0,1);
272 for (
int i = 0; i < nRes; i++)
274 vStartValues.push_back(v[i].
real());
288 nLyapuSamples = nSamples / 10;
289 else if (nSamples <= 1000)
290 nLyapuSamples = nSamples / 20;
292 nLyapuSamples = nSamples / 100;
297 if (!vInterval.size() ||
isnan(vInterval[0]) ||
isinf(vInterval[0]) ||
isnan(vInterval[1]) ||
isinf(vInterval[1]))
299 dt = (vInterval[1]-vInterval[0])/(
double)nSamples;
321 if (bAllowCacheClearance)
333 if (i < (
int)vStartValues.size())
334 y[i] = vStartValues[i];
339 if (i < (
int)vStartValues.size())
340 y2[i] = vStartValues[i];
358 odeControl = gsl_odeiv_control_y_new(dAbsTolerance, dRelTolerance);
366 odeStep_ly = gsl_odeiv_step_alloc(odeStepType_ly,
nDimensions);
367 odeControl_ly = gsl_odeiv_control_y_new(dAbsTolerance, dRelTolerance);
368 odeEvolve_ly = gsl_odeiv_evolve_alloc(
nDimensions);
373 odeSystem_ly.params = 0;
378 if (bAllowCacheClearance || !_idx.
row.
front())
388 if (bAllowCacheClearance || !_idx.
row.
front())
401 for (
size_t i = 0; i < (size_t)nSamples; i++)
416 gsl_odeiv_evolve_free(odeEvolve_ly);
417 gsl_odeiv_control_free(odeControl_ly);
418 gsl_odeiv_step_free(odeStep_ly);
446 while (t2 < t1 && bCalcLyapunov)
448 if (GSL_SUCCESS != gsl_odeiv_evolve_apply(odeEvolve_ly, odeControl_ly, odeStep_ly, &odeSystem_ly, &t2, t1, &h2, y2))
457 dist[1] += (y[n]-y2[n])*(y[n]-y2[n]);
459 dist[1] = sqrt(dist[1]);
460 lyapu[1] = log(dist[1]/dist[0])/dt;
461 lyapu[0] = (i*lyapu[0] + lyapu[1])/(
double)(i+1);
471 y2[n] = y[n] + (y2[n]-y[n])*dist[0]/dist[1];
474 gsl_odeiv_evolve_reset(odeEvolve_ly);
475 gsl_odeiv_step_reset(odeStep_ly);
495 gsl_odeiv_evolve_free(odeEvolve_ly);
496 gsl_odeiv_control_free(odeControl_ly);
497 gsl_odeiv_step_free(odeStep_ly);
This class implements the function definition managing instance.
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
This class represents the central memory managing instance. It will handle all tables and clusters,...
void deleteBulk(const std::string &_sCache, int i1, int i2, int j1=0, int j2=0)
int getLines(StringView sTable, bool _bFull=false) const
bool isTable(const std::string &sTable) const
This member function returns, whether the passed table name corresponds to a known table.
bool addTable(const std::string &sCache, const Settings &_option)
This member function creates a new table. It is checked, whether its name is valid and not already us...
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
void writeToTable(int _nLine, int _nCol, const std::string &_sCache, const mu::value_type &_dData)
bool setHeadLineElement(int _i, const std::string &_sTable, std::string _sHead)
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
static bool GetAsyncCancelState()
This function is used by the kernel to get informed, when the user pressed ESC or used other means of...
static mu::Parser * _odeParser
static int odeFunction(double x, const double y[], double dydx[], void *params)
bool solve(const std::string &sCmd)
FunctionDefinitionManager * _odeFunctions
const gsl_odeiv_step_type * odeStepType
gsl_odeiv_control * odeControl
static mu::varmap_type mVars
gsl_odeiv_evolve * odeEvolve
static int jacobian(double x, const double y[], double dydx[], double dfdt[], void *params)
This class manages the setting values of the internal (kernel) settings of this application.
bool systemPrints() const
Returns, whether system messages shall be printed to the terminal.
Common exception class for all exceptions thrown in NumeRe.
@ STRINGS_MAY_NOT_BE_EVALUATED_WITH_CMD
@ PROCESS_ABORTED_BY_USER
static size_t invalid_position
size_t size() const
This member function returns the size of the indices stored in this class.
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
void setRange(int nMin, int nMax)
This member function can be used to force the indices stored internally to be in a defined interval....
int & front()
This member function returns a reference to the first index value stored internally.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
const varmap_type & GetVar() const
Return a map containing the used variables only.
Mathematical expressions parser.
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
Indices getIndices(StringView sCmd, mu::Parser &_parser, MemoryManager &_data, const Settings &_option)
Wrapper for the new getIndices function interface.
bool isValidIndexSet(const Indices &_idx)
std::string toSystemCodePage(std::string)
Converts an internal to an external string. Does nothing currently.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
bool isnan(const value_type &v)
std::vector< double > real(const std::vector< value_type > &vVec)
bool isinf(const value_type &v)
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
DefaultVariables _defVars
vector< double > readAndParseIntervals(string &sExpr, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option, bool bEraseInterval)
This function will read the interval syntax in commands and return their values in a single vector.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
Structure for the four standard variables.
mu::value_type vValue[4][4]
This structure is central for managing the indices of a table or cluster read or write data access....
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
std::string toString(int)
Converts an integer to a string without the Settings bloat.