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.");
136 ifstream imesh(mesh_file);
140 cerr <<
"\nCan not open mesh file: " << mesh_file <<
'\n' << endl;
144 mesh =
new Mesh(imesh, 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;
160 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
169 for (
int lev = 0; lev < ser_ref_levels; lev++)
174 int mesh_order = std::max(order, 1);
186 for (
int lev = 0; lev < par_ref_levels; lev++)
196 cout <<
"Number of unknowns: " << global_vSize << endl;
237 ostringstream mesh_name, sol_name;
238 mesh_name <<
"ex9-mesh." << setfill(
'0') << setw(6) << myid;
239 sol_name <<
"ex9-init." << setfill(
'0') << setw(6) << myid;
240 ofstream omesh(mesh_name.str().c_str());
241 omesh.precision(precision);
243 ofstream osol(sol_name.str().c_str());
244 osol.precision(precision);
260 char vishost[] =
"localhost";
262 sout.
open(vishost, visport);
266 cout <<
"Unable to connect to GLVis server at "
267 << vishost <<
':' << visport << endl;
268 visualization =
false;
270 cout <<
"GLVis visualization disabled.\n";
274 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
275 sout.precision(precision);
276 sout <<
"solution\n" << *pmesh << *u;
280 cout <<
"GLVis visualization paused."
281 <<
" Press space (in the GLVis window) to resume it.\n";
288 FE_Evolution adv(*M, *K, *B);
289 ode_solver->
Init(adv);
292 for (
int ti = 0;
true; )
294 if (t >= t_final - dt/2)
297 ode_solver->
Step(*U, t, dt);
300 if (ti % vis_steps == 0)
303 cout <<
"time step: " << ti <<
", time: " << t << endl;
311 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
312 sout <<
"solution\n" << *pmesh << *u << flush;
328 ostringstream sol_name;
329 sol_name <<
"ex9-final." << setfill(
'0') << setw(6) << myid;
330 ofstream osol(sol_name.str().c_str());
331 osol.precision(precision);
356 M(_M), K(_K), b(_b), M_solver(M.GetComm()), z(_M.Height())
358 M_prec.SetType(HypreSmoother::Jacobi);
359 M_solver.SetPreconditioner(M_prec);
360 M_solver.SetOperator(M);
362 M_solver.iterative_mode =
false;
363 M_solver.SetRelTol(1e-9);
364 M_solver.SetAbsTol(0.0);
365 M_solver.SetMaxIter(100);
366 M_solver.SetPrintLevel(0);
390 case 1: v(0) = 1.0;
break;
391 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
392 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
break;
400 const double w = M_PI/2;
403 case 1: v(0) = 1.0;
break;
404 case 2: v(0) = w*x(1); v(1) = -w*x(0);
break;
405 case 3: v(0) = w*x(1); v(1) = -w*x(0); v(2) = 0.0;
break;
412 const double w = M_PI/2;
413 double d = max((x(0)+1.)*(1.-x(0)),0.) * max((x(1)+1.)*(1.-x(1)),0.);
417 case 1: v(0) = 1.0;
break;
418 case 2: v(0) = d*w*x(1); v(1) = -d*w*x(0);
break;
419 case 3: v(0) = d*w*x(1); v(1) = -d*w*x(0); v(2) = 0.0;
break;
439 return exp(-40.*pow(x(0)-0.5,2));
443 double rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
446 const double s = (1. + 0.25*cos(2*M_PI*x(2)));
450 return ( erfc(w*(x(0)-cx-rx))*erfc(-w*(x(0)-cx+rx)) *
451 erfc(w*(x(1)-cy-ry))*erfc(-w*(x(1)-cy+ry)) )/16;
457 const double r = sqrt(8.);
458 double x_ = x(0), y_ = x(1), rho, phi;
459 rho = hypot(x_, y_) / r;
461 return pow(sin(M_PI*rho),2)*sin(3*phi);
465 const double f = M_PI;
466 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
int Size() const
Returns the size of the vector.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
double inflow_function(Vector &x)
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 HypreParVector.
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.
double u0_function(Vector &x)
NURBSExtension * NURBSext
void PrintOptions(std::ostream &out) const
int open(const char hostname[], int port)
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.
Arbitrary order "L2-conforming" discontinuous finite elements.
virtual void Print(std::ostream &out=std::cout) const