74 virtual ~FE_Evolution() { }
78 int main(
int argc,
char *argv[])
82 MPI_Init(&argc, &argv);
83 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
84 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
88 const char *mesh_file =
"../data/periodic-hexagon.mesh";
89 int ser_ref_levels = 2;
90 int par_ref_levels = 0;
92 int ode_solver_type = 4;
93 double t_final = 10.0;
95 bool visualization =
true;
100 cout.precision(precision);
103 args.
AddOption(&mesh_file,
"-m",
"--mesh",
104 "Mesh file to use.");
106 "Problem setup to use. See options in velocity_function().");
107 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
108 "Number of times to refine the mesh uniformly in serial.");
109 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
110 "Number of times to refine the mesh uniformly in parallel.");
112 "Order (degree) of the finite elements.");
113 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
114 "ODE solver: 1 - Forward Euler, 2 - RK2 SSP, 3 - RK3 SSP,"
115 " 4 - RK4, 6 - RK6.");
116 args.
AddOption(&t_final,
"-tf",
"--t-final",
117 "Final time; start time is 0.");
118 args.
AddOption(&dt,
"-dt",
"--time-step",
120 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
121 "--no-visualization",
122 "Enable or disable GLVis visualization.");
123 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
124 "--no-visit-datafiles",
125 "Save data files for VisIt (visit.llnl.gov) visualization.");
126 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
127 "Visualize every n-th timestep.");
145 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
151 switch (ode_solver_type)
154 case 2: ode_solver =
new RK2Solver(1.0);
break;
156 case 4: ode_solver =
new RK4Solver;
break;
157 case 6: ode_solver =
new RK6Solver;
break;
161 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
171 for (
int lev = 0; lev < ser_ref_levels; lev++)
186 for (
int lev = 0; lev < par_ref_levels; lev++)
199 cout <<
"Number of unknowns: " << global_vSize << endl;
241 ostringstream mesh_name, sol_name;
242 mesh_name <<
"ex9-mesh." << setfill(
'0') << setw(6) << myid;
243 sol_name <<
"ex9-init." << setfill(
'0') << setw(6) << myid;
244 ofstream omesh(mesh_name.str().c_str());
245 omesh.precision(precision);
247 ofstream osol(sol_name.str().c_str());
248 osol.precision(precision);
264 char vishost[] =
"localhost";
266 sout.
open(vishost, visport);
270 cout <<
"Unable to connect to GLVis server at "
271 << vishost <<
':' << visport << endl;
272 visualization =
false;
275 cout <<
"GLVis visualization disabled.\n";
280 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
281 sout.precision(precision);
282 sout <<
"solution\n" << *pmesh << *u;
286 cout <<
"GLVis visualization paused."
287 <<
" Press space (in the GLVis window) to resume it.\n";
294 FE_Evolution adv(*M, *K, *B);
295 ode_solver->
Init(adv);
298 for (
int ti = 0;
true; )
300 if (t >= t_final - dt/2)
305 ode_solver->
Step(*U, t, dt);
308 if (ti % vis_steps == 0)
312 cout <<
"time step: " << ti <<
", time: " << t << endl;
321 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
322 sout <<
"solution\n" << *pmesh << *u << flush;
338 ostringstream sol_name;
339 sol_name <<
"ex9-final." << setfill(
'0') << setw(6) << myid;
340 ofstream osol(sol_name.str().c_str());
341 osol.precision(precision);
367 M(_M), K(_K), b(_b), M_solver(M.GetComm()), z(_M.Height())
369 M_prec.SetType(HypreSmoother::Jacobi);
370 M_solver.SetPreconditioner(M_prec);
371 M_solver.SetOperator(M);
373 M_solver.iterative_mode =
false;
374 M_solver.SetRelTol(1e-9);
375 M_solver.SetAbsTol(0.0);
376 M_solver.SetMaxIter(100);
377 M_solver.SetPrintLevel(0);
396 for (
int i = 0; i <
dim; i++)
409 case 1: v(0) = 1.0;
break;
410 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
411 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
420 const double w = M_PI/2;
423 case 1: v(0) = 1.0;
break;
424 case 2: v(0) = w*X(1); v(1) = -w*X(0);
break;
425 case 3: v(0) = w*X(1); v(1) = -w*X(0); v(2) = 0.0;
break;
432 const double w = M_PI/2;
433 double d = max((X(0)+1.)*(1.-X(0)),0.) * max((X(1)+1.)*(1.-X(1)),0.);
437 case 1: v(0) = 1.0;
break;
438 case 2: v(0) = d*w*X(1); v(1) = -d*w*X(0);
break;
439 case 3: v(0) = d*w*X(1); v(1) = -d*w*X(0); v(2) = 0.0;
break;
453 for (
int i = 0; i <
dim; i++)
467 return exp(-40.*pow(X(0)-0.5,2));
471 double rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
474 const double s = (1. + 0.25*cos(2*M_PI*X(2)));
478 return ( erfc(w*(X(0)-cx-rx))*erfc(-w*(X(0)-cx+rx)) *
479 erfc(w*(X(1)-cy-ry))*erfc(-w*(X(1)-cy+ry)) )/16;
485 double x_ = X(0), y_ = X(1), rho, phi;
488 return pow(sin(M_PI*rho),2)*sin(3*phi);
492 const double f = M_PI;
493 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)
void GetBoundingBox(Vector &min, Vector &max, int ref=2)
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)
int main(int argc, char *argv[])
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Parallel smoothers in hypre.
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.
void velocity_function(const Vector &x, Vector &v)
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
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