68 virtual ~FE_Evolution() { }
72 int main(
int argc,
char *argv[])
76 MPI_Init(&argc, &argv);
77 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
78 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
82 const char *mesh_file =
"../data/periodic-hexagon.mesh";
83 int ser_ref_levels = 2;
84 int par_ref_levels = 0;
86 int ode_solver_type = 4;
87 double t_final = 10.0;
89 bool visualization =
true;
94 cout.precision(precision);
97 args.
AddOption(&mesh_file,
"-m",
"--mesh",
100 "Problem setup to use. See options in velocity_function().");
101 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
102 "Number of times to refine the mesh uniformly in serial.");
103 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
104 "Number of times to refine the mesh uniformly in parallel.");
106 "Order (degree) of the finite elements.");
107 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
108 "ODE solver: 1 - Forward Euler, 2 - RK2 SSP, 3 - RK3 SSP,"
109 " 4 - RK4, 6 - RK6.");
110 args.
AddOption(&t_final,
"-tf",
"--t-final",
111 "Final time; start time is 0.");
112 args.
AddOption(&dt,
"-dt",
"--time-step",
114 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
115 "--no-visualization",
116 "Enable or disable GLVis visualization.");
117 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
118 "--no-visit-datafiles",
119 "Save data files for VisIt (visit.llnl.gov) visualization.");
120 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
121 "Visualize every n-th timestep.");
140 ifstream imesh(mesh_file);
145 cerr <<
"\nCan not open mesh file: " << mesh_file <<
'\n' << endl;
150 mesh =
new Mesh(imesh, 1, 1);
157 switch (ode_solver_type)
160 case 2: ode_solver =
new RK2Solver(1.0);
break;
162 case 4: ode_solver =
new RK4Solver;
break;
163 case 6: ode_solver =
new RK6Solver;
break;
167 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
177 for (
int lev = 0; lev < ser_ref_levels; lev++)
184 int mesh_order = std::max(order, 1);
196 for (
int lev = 0; lev < par_ref_levels; lev++)
209 cout <<
"Number of unknowns: " << global_vSize << endl;
251 ostringstream mesh_name, sol_name;
252 mesh_name <<
"ex9-mesh." << setfill(
'0') << setw(6) << myid;
253 sol_name <<
"ex9-init." << setfill(
'0') << setw(6) << myid;
254 ofstream omesh(mesh_name.str().c_str());
255 omesh.precision(precision);
257 ofstream osol(sol_name.str().c_str());
258 osol.precision(precision);
274 char vishost[] =
"localhost";
276 sout.
open(vishost, visport);
280 cout <<
"Unable to connect to GLVis server at "
281 << vishost <<
':' << visport << endl;
282 visualization =
false;
285 cout <<
"GLVis visualization disabled.\n";
290 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
291 sout.precision(precision);
292 sout <<
"solution\n" << *pmesh << *u;
296 cout <<
"GLVis visualization paused."
297 <<
" Press space (in the GLVis window) to resume it.\n";
304 FE_Evolution adv(*M, *K, *B);
305 ode_solver->
Init(adv);
308 for (
int ti = 0;
true; )
310 if (t >= t_final - dt/2)
315 ode_solver->
Step(*U, t, dt);
318 if (ti % vis_steps == 0)
322 cout <<
"time step: " << ti <<
", time: " << t << endl;
331 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
332 sout <<
"solution\n" << *pmesh << *u << flush;
348 ostringstream sol_name;
349 sol_name <<
"ex9-final." << setfill(
'0') << setw(6) << myid;
350 ofstream osol(sol_name.str().c_str());
351 osol.precision(precision);
377 M(_M), K(_K), b(_b), M_solver(M.GetComm()), z(_M.Height())
379 M_prec.SetType(HypreSmoother::Jacobi);
380 M_solver.SetPreconditioner(M_prec);
381 M_solver.SetOperator(M);
383 M_solver.iterative_mode =
false;
384 M_solver.SetRelTol(1e-9);
385 M_solver.SetAbsTol(0.0);
386 M_solver.SetMaxIter(100);
387 M_solver.SetPrintLevel(0);
411 case 1: v(0) = 1.0;
break;
412 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
413 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
422 const double w = M_PI/2;
425 case 1: v(0) = 1.0;
break;
426 case 2: v(0) = w*x(1); v(1) = -w*x(0);
break;
427 case 3: v(0) = w*x(1); v(1) = -w*x(0); v(2) = 0.0;
break;
434 const double w = M_PI/2;
435 double d = max((x(0)+1.)*(1.-x(0)),0.) * max((x(1)+1.)*(1.-x(1)),0.);
439 case 1: v(0) = 1.0;
break;
440 case 2: v(0) = d*w*x(1); v(1) = -d*w*x(0);
break;
441 case 3: v(0) = d*w*x(1); v(1) = -d*w*x(0); v(2) = 0.0;
break;
461 return exp(-40.*pow(x(0)-0.5,2));
465 double rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
468 const double s = (1. + 0.25*cos(2*M_PI*x(2)));
472 return ( erfc(w*(x(0)-cx-rx))*erfc(-w*(x(0)-cx+rx)) *
473 erfc(w*(x(1)-cy-ry))*erfc(-w*(x(1)-cy+ry)) )/16;
479 const double r = sqrt(8.);
480 double x_ = x(0), y_ = x(1), rho, phi;
481 rho = hypot(x_, y_) / r;
483 return pow(sin(M_PI*rho),2)*sin(3*phi);
487 const double f = M_PI;
488 return sin(f*x(0))*sin(f*x(1));
Conjugate gradient method.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
virtual void RegisterField(const char *field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
Base abstract class for time dependent operators: (x,t) -> f(x,t)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
virtual void Step(Vector &x, double &t, double &dt)=0
HYPRE_Int GlobalTrueVSize()
int Size() const
Returns the size of the vector.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
virtual void Save()
Save the collection and a VisIt root file.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
void ProjectCoefficient(Coefficient &coeff)
virtual void Init(TimeDependentOperator &_f)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
Parallel smoothers in hypre.
void SetNodalFESpace(FiniteElementSpace *nfes)
void PrintUsage(std::ostream &out) const
void SetTime(double t)
Set physical time (for time-dependent simulations)
void GetTrueDofs(Vector &tv) const
Returns the true dofs in a Vector.
Wrapper for hypre's parallel vector class.
The classical explicit forth-order Runge-Kutta method, RK4.
int main(int argc, char *argv[])
void velocity_function(const Vector &x, Vector &v)
Abstract finite element space.
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)
Third-order, strong stability preserving (SSP) Runge-Kutta method.
NURBSExtension * NURBSext
void PrintOptions(std::ostream &out) const
int open(const char hostname[], int port)
double u0_function(const Vector &x)
class for C-function coefficient
void GetNodes(Vector &node_coord) const
Arbitrary order H1-conforming (continuous) finite elements.
Class for parallel grid function.
The classical forward Euler method.
Wrapper for hypre's ParCSR matrix class.
Class for parallel meshes.
double inflow_function(const Vector &x)
Arbitrary order "L2-conforming" discontinuous finite elements.
virtual void Print(std::ostream &out=std::cout) const