68 static double m_ = 1.0;
69 static double k_ = 1.0;
88 int main(
int argc,
char *argv[])
94 bool visualization =
true;
99 "Time integration order.");
100 args.
AddOption(&prob_,
"-p",
"--problem-type",
102 "\t 0 - Simple Harmonic Oscillator\n"
104 "\t 2 - Gaussian Potential Well\n"
105 "\t 3 - Quartic Potential\n"
106 "\t 4 - Negative Quartic Potential");
107 args.
AddOption(&nsteps,
"-n",
"--number-of-steps",
108 "Number of time steps.");
109 args.
AddOption(&dt,
"-dt",
"--time-step",
113 args.
AddOption(&k_,
"-k",
"--spring-const",
115 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
116 "--no-visualization",
117 "Enable or disable GLVis visualization.");
118 args.
AddOption(&gnuplot,
"-gp",
"--gnuplot",
"-no-gp",
"--no-gnuplot",
119 "Enable or disable GnuPlot visualization.");
145 ofs.open(
"ex20.dat");
146 ofs << t <<
"\t" << q(0) <<
"\t" << p(0) << endl;
150 int nverts = (visualization) ? 2*(nsteps+1) : 0;
151 int nelems = (visualization) ? nsteps : 0;
152 Mesh mesh(2, nverts, nelems, 0, 3);
161 for (
int i = 0; i < nsteps; i++)
180 siaSolver.
Step(q,p,t,dt);
187 ofs << t <<
"\t" << q(0) <<
"\t" << p(0) <<
"\t" << e[i+1] << endl;
208 e_mean /= (nsteps + 1);
210 for (
int i=0; i<=nsteps; i++)
212 e_var += pow(e[i] - e_mean, 2);
214 e_var /= (nsteps + 1);
215 double e_sd = sqrt(e_var);
216 cout << endl <<
"Mean and standard deviation of the energy" << endl;
217 cout << e_mean <<
"\t" << e_sd << endl;
224 ofs.open(
"gnuplot_ex20.inp");
225 ofs <<
"plot 'ex20.dat' using 1:2 w l t 'q', "
226 <<
"'ex20.dat' using 1:3 w l t 'p', "
227 <<
"'ex20.dat' using 1:4 w l t 'H'" << endl;
238 for (
int i = 0; i <= nsteps; i++)
240 energy[2*i+0] = e[i];
241 energy[2*i+1] = e[i];
244 char vishost[] =
"localhost";
248 sock <<
"solution\n" << mesh << energy
249 <<
"window_title 'Energy in Phase Space'\n"
250 <<
"keys\n maac\n" <<
"axis_labels 'q' 'p' 't'\n"<< flush;
256 double h = 1.0 - 0.5 / m_ + 0.5 * p * p / m_;
260 h += k_ * (1.0 - cos(q));
263 h += k_ * (1.0 - exp(-0.5 * q * q));
266 h += 0.5 * k_ * (1.0 + q * q) * q * q;
269 h += 0.5 * k_ * (1.0 - 0.125 * q * q) * q * q;
272 h += 0.5 * k_ * q * q;
283 y(0) = - k_* sin(x(0));
286 y(0) = - k_ * x(0) * exp(-0.5 * x(0) * x(0));
289 y(0) = - k_ * (1.0 + 2.0 * x(0) * x(0)) * x(0);
292 y(0) = - k_ * (1.0 - 0.25 * x(0) * x(0)) * x(0);
double hamiltonian(double q, double p, double t)
virtual void Init(Operator &P, TimeDependentOperator &F)
Class for grid function - Vector with associated FE space.
Base abstract class for first order time dependent operators.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
int main(int argc, char *argv[])
void AddVertex(const double *)
void PrintUsage(std::ostream &out) const
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
void AddQuad(const int *vi, int attr=1)
Vector & Set(const double a, const Vector &x)
(*this) = a * x
void Step(Vector &q, Vector &p, double &t, double &dt)
void PrintOptions(std::ostream &out) const
Arbitrary order H1-conforming (continuous) finite elements.