92int 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++)
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 real_t 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 real_t 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);
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Class for grid function - Vector with associated FE space.
Arbitrary order H1-conforming (continuous) finite elements.
int AddQuad(int v1, int v2, int v3, int v4, int attr=1)
Adds a quadrilateral to the mesh given by 4 vertices v1 through v4.
int AddVertex(real_t x, real_t y=0.0, real_t z=0.0)
void FinalizeQuadMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a quadrilateral Mesh.
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.
void PrintOptions(std::ostream &out) const
Print the options.
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...
bool Good() const
Return true if the command line options were parsed successfully.
virtual void Init(Operator &P, TimeDependentOperator &F)
Variable order Symplectic Integration Algorithm (orders 1-4)
void Step(Vector &q, Vector &p, real_t &t, real_t &dt) override
Base abstract class for first order time dependent operators.
Vector & Set(const real_t a, const Vector &x)
(*this) = a * x
real_t hamiltonian(real_t q, real_t p, real_t t)
real_t p(const Vector &x, real_t t)