83 virtual void ImplicitSolve(
const double dt,
const Vector &
u,
Vector &k);
87 virtual int SUNImplicitSetup(
const Vector &x,
const Vector &fx,
88 int jok,
int *jcur,
double gamma);
92 virtual int SUNImplicitSolve(
const Vector &
b,
Vector &x,
double tol);
95 void SetParameters(
const Vector &
u);
97 virtual ~ConductionOperator();
102 int main(
int argc,
char *argv[])
105 Mpi::Init(argc, argv);
106 int num_procs = Mpi::WorldSize();
107 int myid = Mpi::WorldRank();
112 const char *mesh_file =
"../../data/star.mesh";
113 int ser_ref_levels = 2;
114 int par_ref_levels = 1;
116 int ode_solver_type = 9;
117 double t_final = 0.5;
119 double alpha = 1.0e-2;
121 bool visualization =
true;
126 const double reltol = 1e-4, abstol = 1e-4;
129 cout.precision(precision);
132 args.
AddOption(&mesh_file,
"-m",
"--mesh",
133 "Mesh file to use.");
134 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
135 "Number of times to refine the mesh uniformly in serial.");
136 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
137 "Number of times to refine the mesh uniformly in parallel.");
139 "Order (degree) of the finite elements.");
140 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
142 "1 - Forward Euler,\n\t"
146 "5 - Backward Euler,\n\t"
149 "8 - CVODE (implicit Adams),\n\t"
150 "9 - CVODE (implicit BDF),\n\t"
151 "10 - ARKODE (default explicit),\n\t"
152 "11 - ARKODE (explicit Fehlberg-6-4-5),\n\t"
153 "12 - ARKODE (default impicit).");
154 args.
AddOption(&t_final,
"-tf",
"--t-final",
155 "Final time; start time is 0.");
156 args.
AddOption(&dt,
"-dt",
"--time-step",
159 "Alpha coefficient.");
161 "Kappa coefficient offset.");
162 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
163 "--no-visualization",
164 "Enable or disable GLVis visualization.");
165 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
166 "--no-visit-datafiles",
167 "Save data files for VisIt (visit.llnl.gov) visualization.");
168 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
169 "Visualize every n-th timestep.");
183 if (ode_solver_type < 1 || ode_solver_type > 12)
187 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
195 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
201 for (
int lev = 0; lev < ser_ref_levels; lev++)
211 for (
int lev = 0; lev < par_ref_levels; lev++)
224 cout <<
"Number of temperature unknowns: " << fe_size << endl;
237 ConductionOperator oper(fespace, alpha, kappa, u);
241 ostringstream mesh_name, sol_name;
242 mesh_name <<
"ex16-mesh." << setfill(
'0') << setw(6) << myid;
243 sol_name <<
"ex16-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);
266 sout.
open(vishost, visport);
267 sout <<
"parallel " << num_procs <<
" " << myid << endl;
268 int good = sout.good(), all_good;
269 MPI_Allreduce(&good, &all_good, 1, MPI_INT, MPI_MIN, pmesh->
GetComm());
273 visualization =
false;
276 cout <<
"Unable to connect to GLVis server at "
277 << vishost <<
':' << visport << endl;
278 cout <<
"GLVis visualization disabled.\n";
283 sout.precision(precision);
284 sout <<
"solution\n" << *pmesh << u_gf;
289 cout <<
"GLVis visualization paused."
290 <<
" Press space (in the GLVis window) to resume it.\n";
300 switch (ode_solver_type)
304 case 2: ode_solver =
new RK2Solver(0.5);
break;
306 case 4: ode_solver =
new RK4Solver;
break;
317 ode_solver = cvode;
break;
323 ode_solver = cvode;
break;
327 arkode =
new ARKStepSolver(MPI_COMM_WORLD, ARKStepSolver::EXPLICIT);
331 if (ode_solver_type == 11)
335 ode_solver = arkode;
break;
337 arkode =
new ARKStepSolver(MPI_COMM_WORLD, ARKStepSolver::IMPLICIT);
341 ode_solver = arkode;
break;
345 if (ode_solver_type < 8) { ode_solver->
Init(oper); }
356 cout <<
"Integrating the ODE ..." << endl;
361 bool last_step =
false;
362 for (
int ti = 1; !last_step; ti++)
364 double dt_real = min(dt, t_final - t);
371 ode_solver->
Step(u, t, dt_real);
373 last_step = (t >= t_final - 1e-8*dt);
375 if (last_step || (ti % vis_steps) == 0)
379 cout <<
"step " << ti <<
", t = " << t << endl;
387 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
388 sout <<
"solution\n" << *pmesh << u_gf << flush;
398 oper.SetParameters(u);
409 ostringstream sol_name;
410 sol_name <<
"ex16-final." << setfill(
'0') << setw(6) << myid;
411 ofstream osol(sol_name.str().c_str());
412 osol.precision(precision);
427 M_solver(f.GetComm()), T_solver(f.GetComm()), z(height)
429 const double rel_tol = 1e-8;
434 M->FormSystemMatrix(ess_tdof_list, Mmat);
436 M_solver.iterative_mode =
false;
437 M_solver.SetRelTol(rel_tol);
438 M_solver.SetAbsTol(0.0);
439 M_solver.SetMaxIter(100);
440 M_solver.SetPrintLevel(0);
441 M_prec.SetType(HypreSmoother::Jacobi);
442 M_solver.SetPreconditioner(M_prec);
443 M_solver.SetOperator(Mmat);
448 T_solver.iterative_mode =
false;
449 T_solver.SetRelTol(rel_tol);
450 T_solver.SetAbsTol(0.0);
451 T_solver.SetMaxIter(100);
452 T_solver.SetPrintLevel(0);
453 T_solver.SetPreconditioner(T_prec);
465 M_solver.Mult(z, du_dt);
468 void ConductionOperator::ImplicitSolve(
const double dt,
475 T =
Add(1.0, Mmat, dt, Kmat);
476 T_solver.SetOperator(*T);
479 T_solver.Mult(z, du_dt);
482 int ConductionOperator::SUNImplicitSetup(
const Vector &x,
483 const Vector &fx,
int jok,
int *jcur,
488 T =
Add(1.0, Mmat, gamma, Kmat);
489 T_solver.SetOperator(*T);
494 int ConductionOperator::SUNImplicitSolve(
const Vector &
b,
Vector &x,
double tol)
502 void ConductionOperator::SetParameters(
const Vector &u)
505 u_alpha_gf.SetFromTrueDofs(u);
506 for (
int i = 0; i < u_alpha_gf.Size(); i++)
518 K->FormSystemMatrix(ess_tdof_list, Kmat);
521 ConductionOperator::~ConductionOperator()
void Init(TimeDependentOperator &f_)
Initialize CVODE: calls CVodeCreate() to create the CVODE memory and set some defaults.
Conjugate gradient method.
double InitialTemperature(const Vector &x)
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
void SetStepMode(int itask)
Select the ARKode step mode: ARK_NORMAL (default) or ARK_ONE_STEP.
void SetERKTableNum(ARKODE_ERKTableID table_id)
Choose a specific Butcher table for an explicit RK method.
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)
double Norml2() const
Returns the l2 norm of the vector.
virtual void Step(Vector &x, double &t, double &dt)=0
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
HYPRE_BigInt GlobalTrueVSize() const
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
virtual void Save(std::ostream &out) const
void SetMaxStep(double dt_max)
Set the maximum time step.
Abstract parallel finite element space.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Backward Euler ODE solver. L-stable.
int close()
Close the socketstream.
void Stop()
Stop the stopwatch.
Interface to ARKode's ARKStep module – additive Runge-Kutta methods.
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
Interface to the CVODE library – linear multi-step methods.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
void SetMaxStep(double dt_max)
Set the maximum time step.
Parallel smoothers in hypre.
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetTime(double t)
Set physical time (for time-dependent simulations)
void Start()
Start the stopwatch. The elapsed time is not cleared.
The classical explicit forth-order Runge-Kutta method, RK4.
virtual void Save() override
Save the collection and a VisIt root file.
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...
Third-order, strong stability preserving (SSP) Runge-Kutta method.
constexpr ARKODE_ERKTableID ARKODE_FEHLBERG_13_7_8
void PrintInfo() const
Print various ARKStep statistics.
void PrintOptions(std::ostream &out) const
Print the options.
HypreParVector * GetTrueDofs() const
Returns the true dofs in a new HypreParVector.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
A general function coefficient.
Arbitrary order H1-conforming (continuous) finite elements.
void PrintInfo() const
Print various CVODE statistics.
void Print(std::ostream &out=mfem::out) const override
double u(const Vector &xvec)
Class for parallel grid function.
The classical forward Euler method.
Wrapper for hypre's ParCSR matrix class.
void Init(TimeDependentOperator &f_)
Initialize ARKode: calls ARKStepCreate() to create the ARKStep memory and set some defaults...
Class for parallel meshes.
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
void Clear()
Clear the elapsed time on the stopwatch and restart it if it's running.
double f(const Vector &p)
virtual void RegisterField(const std::string &field_name, GridFunction *gf) override
Add a grid function to the collection and update the root file.
void SetStepMode(int itask)
Select the CVODE step mode: CV_NORMAL (default) or CV_ONE_STEP.
bool Good() const
Return true if the command line options were parsed successfully.