97int main(
int argc,
char *argv[])
104 MPI_Comm comm = MPI_COMM_WORLD;
110 bool visualization =
true;
111 bool gnuplot =
false;
115 "Time integration order.");
116 args.
AddOption(&prob_,
"-p",
"--problem-type",
118 "\t 0 - Simple Harmonic Oscillator\n"
120 "\t 2 - Gaussian Potential Well\n"
121 "\t 3 - Quartic Potential\n"
122 "\t 4 - Negative Quartic Potential");
123 args.
AddOption(&nsteps,
"-n",
"--number-of-steps",
124 "Number of time steps.");
125 args.
AddOption(&dt,
"-dt",
"--time-step",
129 args.
AddOption(&k_,
"-k",
"--spring-const",
131 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
132 "--no-visualization",
133 "Enable or disable GLVis visualization.");
134 args.
AddOption(&gnuplot,
"-gp",
"--gnuplot",
"-no-gp",
"--no-gnuplot",
135 "Enable or disable GnuPlot visualization.");
160 q(0) = sin(2.0*M_PI*(
real_t)myid/num_procs);
161 p(0) = cos(2.0*M_PI*(
real_t)myid/num_procs);
168 oss <<
"ex20p_" << setfill(
'0') << setw(5) << myid <<
".dat";
169 ofs.open(oss.str().c_str());
170 ofs <<
t <<
"\t" << q(0) <<
"\t" <<
p(0) << endl;
174 int nverts = (visualization) ? 2*num_procs*(nsteps+1) : 0;
175 int nelems = (visualization) ? (nsteps * num_procs) : 0;
176 Mesh mesh(2, nverts, nelems, 0, 3);
178 int *part = (visualization) ? (
new int[nelems]) : NULL;
186 for (
int i = 0; i < nsteps; i++)
196 for (
int j = 0; j < num_procs; j++)
215 ofs <<
t <<
"\t" << q(0) <<
"\t" <<
p(0) <<
"\t" << e[i+1] << endl;
222 for (
int j = 0; j < num_procs; j++)
229 v[0] = 2 * num_procs * i + 2 * j;
230 v[1] = 2 * num_procs * (i + 1) + 2 * j;
231 v[2] = 2 * num_procs * (i + 1) + 2 * j + 1;
232 v[3] = 2 * num_procs * i + 2 * j + 1;
234 part[num_procs * i + j] = j;
240 e_mean /= (nsteps + 1);
242 for (
int i = 0; i <= nsteps; i++)
244 e_var += pow(e[i] - e_mean, 2);
246 e_var /= (nsteps + 1);
247 real_t e_sd = sqrt(e_var);
252 e_loc_stats[0] = e_mean;
253 e_loc_stats[1] = e_sd;
259 cout << endl <<
"Mean and standard deviation of the energy "
260 <<
"for different initial conditions" << endl;
261 for (
int i = 0; i < num_procs; i++)
263 cout << i <<
": " << e_stats[2 * i + 0]
264 <<
"\t" << e_stats[2 * i + 1] << endl;
275 ofs.open(
"gnuplot_ex20p.inp");
276 for (
int i = 0; i < num_procs; i++)
279 ossi <<
"ex20p_" << setfill(
'0') << setw(5) << i <<
".dat";
284 ofs <<
" '" << ossi.str() <<
"' using 1:2 w l t 'q" << i <<
"',"
285 <<
" '" << ossi.str() <<
"' using 1:3 w l t 'p" << i <<
"',"
286 <<
" '" << ossi.str() <<
"' using 1:4 w l t 'H" << i <<
"'";
304 ParMesh pmesh(comm, mesh, part);
311 for (
int i = 0; i <= nsteps; i++)
313 energy[2*i+0] = e[i];
314 energy[2*i+1] = e[i];
321 sock <<
"parallel " << num_procs <<
" " << myid <<
"\n"
322 <<
"solution\n" << pmesh << energy
323 <<
"window_title 'Energy in Phase Space'\n"
324 <<
"keys\n maac\n" <<
"axis_labels 'q' 'p' 't'\n"<< flush;
330 real_t h = 1.0 - 0.5 / m_ + 0.5 *
p *
p / m_;
334 h += k_ * (1.0 - cos(q));
337 h += k_ * (1.0 - exp(-0.5 * q * q));
340 h += 0.5 * k_ * (1.0 + q * q) * q * q;
343 h += 0.5 * k_ * (1.0 - 0.125 * q * q) * q * q;
346 h += 0.5 * k_ * q * q;
357 y(0) = - k_* sin(x(0));
360 y(0) = - k_ * x(0) * exp(-0.5 * x(0) * x(0));
363 y(0) = - k_ * (1.0 + 2.0 * x(0) * x(0)) * x(0);
366 y(0) = - k_ * (1.0 - 0.25 * x(0) * x(0)) * x(0);
Arbitrary order H1-conforming (continuous) finite elements.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
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.
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static int WorldSize()
Return the size of MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
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.
Abstract parallel finite element space.
Class for parallel grid function.
Class for parallel meshes.
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)
Helper struct to convert a C++ type to an MPI type.