72 static double m_ = 1.0;
73 static double k_ = 1.0;
92 int main(
int argc,
char *argv[])
98 bool visualization =
true;
103 "Time integration order.");
104 args.
AddOption(&prob_,
"-p",
"--problem-type",
106 "\t 0 - Simple Harmonic Oscillator\n"
108 "\t 2 - Gaussian Potential Well\n"
109 "\t 3 - Quartic Potential\n"
110 "\t 4 - Negative Quartic Potential");
111 args.
AddOption(&nsteps,
"-n",
"--number-of-steps",
112 "Number of time steps.");
113 args.
AddOption(&dt,
"-dt",
"--time-step",
117 args.
AddOption(&k_,
"-k",
"--spring-const",
119 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
120 "--no-visualization",
121 "Enable or disable GLVis visualization.");
122 args.
AddOption(&gnuplot,
"-gp",
"--gnuplot",
"-no-gp",
"--no-gnuplot",
123 "Enable or disable GnuPlot visualization.");
149 ofs.open(
"ex20.dat");
150 ofs << t <<
"\t" << q(0) <<
"\t" <<
p(0) << endl;
154 int nverts = (visualization) ? 2*(nsteps+1) : 0;
155 int nelems = (visualization) ? nsteps : 0;
156 Mesh mesh(2, nverts, nelems, 0, 3);
165 for (
int i = 0; i < nsteps; i++)
184 siaSolver.
Step(q,p,t,dt);
191 ofs << t <<
"\t" << q(0) <<
"\t" <<
p(0) <<
"\t" << e[i+1] << endl;
212 e_mean /= (nsteps + 1);
214 for (
int i=0; i<=nsteps; i++)
216 e_var += pow(e[i] - e_mean, 2);
218 e_var /= (nsteps + 1);
219 double e_sd = sqrt(e_var);
220 cout << endl <<
"Mean and standard deviation of the energy" << endl;
221 cout << e_mean <<
"\t" << e_sd << endl;
228 ofs.open(
"gnuplot_ex20.inp");
229 ofs <<
"plot 'ex20.dat' using 1:2 w l t 'q', "
230 <<
"'ex20.dat' using 1:3 w l t 'p', "
231 <<
"'ex20.dat' using 1:4 w l t 'H'" << endl;
243 for (
int i = 0; i <= nsteps; i++)
245 energy[2*i+0] = e[i];
246 energy[2*i+1] = e[i];
253 sock <<
"solution\n" << mesh << energy
254 <<
"window_title 'Energy in Phase Space'\n"
255 <<
"keys\n maac\n" <<
"axis_labels 'q' 'p' 't'\n"<< flush;
261 double h = 1.0 - 0.5 / m_ + 0.5 * p * p / m_;
265 h += k_ * (1.0 - cos(q));
268 h += k_ * (1.0 - exp(-0.5 * q * q));
271 h += 0.5 * k_ * (1.0 + q * q) * q * q;
274 h += 0.5 * k_ * (1.0 - 0.125 * q * q) * q * q;
277 h += 0.5 * k_ * q * q;
288 y(0) = - k_* sin(x(0));
291 y(0) = - k_ * x(0) * exp(-0.5 * x(0) * x(0));
294 y(0) = - k_ * (1.0 + 2.0 * x(0) * x(0)) * x(0);
297 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.
int AddQuad(int v1, int v2, int v3, int v4, int attr=1)
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)
void Step(Vector &q, Vector &p, double &t, double &dt) override
int AddVertex(double x, double y=0.0, double z=0.0)
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
double p(const Vector &x, double t)
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)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
Vector & Set(const double a, const Vector &x)
(*this) = a * x
void FinalizeQuadMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a quadrilateral Mesh.
void PrintOptions(std::ostream &out) const
Print the options.
Arbitrary order H1-conforming (continuous) finite elements.
Variable order Symplectic Integration Algorithm (orders 1-4)
bool Good() const
Return true if the command line options were parsed successfully.