SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
examples/lorenz.cc
Lorenz equation
////////////////////////////////////////////////////////////////////////////
// Model lorenz SIMLIB/C++
//
// Lorenz equation:
//
// dx1/dt = sigma * (x2 - x1)
// dx2/dt = (1 + lambda - x3) * x1 - x2
// dx3/dt = x1 * x2 - b * x3
//
// Parameters: sigma = 10
// lambda = 24
// b = 2
// Initial conditions: xi(0) = 1.0
//
// SOURCE: SimPack
//
// Creates output for GNU-Plot
//
// Results strongly depend on required accuracy
//
#include "
simlib.h
"
#include <cstdlib>
// atof()
const
double
DEFAULT_T1 = 30.0;
// Model
struct
Lorenz {
Integrator x1, x2, x3;
Lorenz(
double
sigma,
double
lambda,
double
b) :
// blocks:
x1(sigma*(x2 - x1), 1),
// dx1/dt = sigma * (x2 - x1)
x2((1 + lambda - x3)*x1 - x2, 1),
// dx2/dt = (1 + lambda - x3) * x1 - x2
x3(x1*x2 - b*x3, 1) {}
// dx3/dt = x1 * x2 - b * x3
};
Lorenz L(10, 24, 2);
// Create instance of model
// Output sampling
void
Sample
() {
Print(
"%6.2f %.5g %.5g %.5g\n"
, T.
Value
(), L.x1.Value(), L.x2.Value(), L.x3.Value());
}
Sampler
S
(
Sample
, 0.01);
// Output step
// Experiment control
int
main
(
int
argc,
char
*argv[]) {
double
maxtime = DEFAULT_T1;
if
(argc > 1)
maxtime = std::atof(argv[1]);
// Parameter of simulation
if
(maxtime < 1.0) {
_Print
(
"\nUsage: %s [maxtime>=1,default=%g] \n\n"
, argv[0], DEFAULT_T1);
return
1;
}
SetOutput
(
"lorenz.dat"
);
// Redirect output to file
Print
(
"# Lorenz equation output (maxtime=%g) \n"
, maxtime);
Print
(
"# Time x1 x2 \n"
);
Init
(0, maxtime);
// Initialize simulator
SetAccuracy
(1e-8);
// Required accuracy
Run
();
// Simulate
SIMLIB_statistics
.
Output
();
// Print simulation run statistics
}
//
S
Sampler S(Sample, 1)
Sample
void Sample()
Definition
_test_.cc:38
main
int main()
Definition
_test_.cc:44
simlib3::aContiBlock::Value
virtual double Value()=0
simlib3::SetOutput
void SetOutput(const char *name)
Definition
print.cc:50
simlib3::_Print
int _Print(const char *fmt,...)
Definition
print.cc:68
simlib3::Run
void Run()
run simulation experiment
Definition
run.cc:228
simlib3::Print
int Print(const char *fmt,...)
for Output methods, can be redirected
Definition
print.cc:92
simlib3::Init
void Init(double t0, double t1=SIMLIB_MAXTIME)
Definition
simlib.h:186
simlib3::SetAccuracy
void SetAccuracy(double _abserr, double _relerr)
Definition
intg.cc:106
simlib3::SIMLIB_statistics
const SIMLIB_statistics_t & SIMLIB_statistics
interface to internal run-time statistics structure
Definition
run.cc:78
simlib.h
Main SIMLIB/C++ interface.
simlib3::SIMLIB_statistics_t::Output
void Output() const
print run-time statistics to output
Definition
output1.cc:63
Generated on
for SIMLIB/C++ by
1.18.0