73 static double m_ = 1.0;
74 static double k_ = 1.0;
93 int main(
int argc,
char *argv[])
97 MPI_Comm comm = MPI_COMM_WORLD;
98 MPI_Init(&argc, &argv);
99 MPI_Comm_size(comm, &num_procs);
100 MPI_Comm_rank(comm, &myid);
106 bool visualization =
true;
107 bool gnuplot =
false;
111 "Time integration order.");
112 args.
AddOption(&prob_,
"-p",
"--problem-type",
114 "\t 0 - Simple Harmonic Oscillator\n"
116 "\t 2 - Gaussian Potential Well\n"
117 "\t 3 - Quartic Potential\n"
118 "\t 4 - Negative Quartic Potential");
119 args.
AddOption(&nsteps,
"-n",
"--number-of-steps",
120 "Number of time steps.");
121 args.
AddOption(&dt,
"-dt",
"--time-step",
125 args.
AddOption(&k_,
"-k",
"--spring-const",
127 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
128 "--no-visualization",
129 "Enable or disable GLVis visualization.");
130 args.
AddOption(&gnuplot,
"-gp",
"--gnuplot",
"-no-gp",
"--no-gnuplot",
131 "Enable or disable GnuPlot visualization.");
157 q(0) = sin(2.0*M_PI*(
double)myid/num_procs);
158 p(0) = cos(2.0*M_PI*(
double)myid/num_procs);
165 oss <<
"ex20p_" << setfill(
'0') << setw(5) << myid <<
".dat";
166 ofs.open(oss.str().c_str());
167 ofs << t <<
"\t" << q(0) <<
"\t" << p(0) << endl;
171 int nverts = (visualization) ? (num_procs+1)*(nsteps+1) : 0;
172 int nelems = (visualization) ? (nsteps * num_procs) : 0;
173 Mesh mesh(2, nverts, nelems, 0, 3);
175 int *part = (visualization) ? (
new int[nelems]) : NULL;
183 for (
int i = 0; i < nsteps; i++)
194 for (
int j = 0; j < num_procs; j++)
205 siaSolver.
Step(q,p,t,dt);
212 ofs << t <<
"\t" << q(0) <<
"\t" << p(0) <<
"\t" << e[i+1] << endl;
220 for (
int j = 0; j < num_procs; j++)
226 v[0] = (num_procs + 1) * i;
227 v[1] = (num_procs + 1) * (i + 1);
228 v[2] = (num_procs + 1) * (i + 1) + j + 1;
229 v[3] = (num_procs + 1) * i + j + 1;
231 part[num_procs * i + j] = j;
237 e_mean /= (nsteps + 1);
239 for (
int i = 0; i <= nsteps; i++)
241 e_var += pow(e[i] - e_mean, 2);
243 e_var /= (nsteps + 1);
244 double e_sd = sqrt(e_var);
248 cout << endl <<
"Mean and standard deviation of the energy" << endl;
250 for (
int i = 0; i < num_procs; i++)
254 cout << myid <<
": " << e_mean <<
"\t" << e_sd << endl;
265 ofs.open(
"gnuplot_ex20p.inp");
266 for (
int i = 0; i < num_procs; i++)
269 ossi <<
"ex20p_" << setfill(
'0') << setw(5) << i <<
".dat";
274 ofs <<
" '" << ossi.str() <<
"' using 1:2 w l t 'q" << i <<
"',"
275 <<
" '" << ossi.str() <<
"' using 1:3 w l t 'p" << i <<
"',"
276 <<
" '" << ossi.str() <<
"' using 1:4 w l t 'H" << i <<
"'";
294 ParMesh pmesh(comm, mesh, part);
301 for (
int i = 0; i <= nsteps; i++)
303 energy[2*i+0] = e[i];
304 energy[2*i+1] = e[i];
307 char vishost[] =
"localhost";
311 sock <<
"parallel " << num_procs <<
" " << myid <<
"\n"
312 <<
"solution\n" << pmesh << energy
313 <<
"window_title 'Energy in Phase Space'\n"
314 <<
"keys\n maac\n" <<
"axis_labels 'q' 'p' 't'\n"<< flush;
322 double h = 1.0 - 0.5 / m_ + 0.5 * p * p / m_;
326 h += k_ * (1.0 - cos(q));
329 h += k_ * (1.0 - exp(-0.5 * q * q));
332 h += 0.5 * k_ * (1.0 + q * q) * q * q;
335 h += 0.5 * k_ * (1.0 - 0.125 * q * q) * q * q;
338 h += 0.5 * k_ * q * q;
349 y(0) = - k_* sin(x(0));
352 y(0) = - k_ * x(0) * exp(-0.5 * x(0) * x(0));
355 y(0) = - k_ * (1.0 + 2.0 * x(0) * x(0)) * x(0);
358 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)
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)
Abstract parallel finite element space.
int main(int argc, char *argv[])
void AddVertex(const double *)
void PrintUsage(std::ostream &out) const
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 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
Arbitrary order H1-conforming (continuous) finite elements.
Class for parallel grid function.
Class for parallel meshes.