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();
102int main(
int argc,
char *argv[])
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;
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);
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 "
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;
331 if (ode_solver_type == 11)
335 ode_solver = arkode;
break;
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);
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);
458void ConductionOperator::Mult(
const Vector &
u,
Vector &du_dt)
const
465 M_solver.
Mult(z, du_dt);
468void ConductionOperator::ImplicitSolve(
const double dt,
475 T =
Add(1.0, Mmat, dt, Kmat);
479 T_solver.
Mult(z, du_dt);
482int ConductionOperator::SUNImplicitSetup(
const Vector &x,
483 const Vector &fx,
int jok,
int *jcur,
488 T =
Add(1.0, Mmat, gamma, Kmat);
494int ConductionOperator::SUNImplicitSolve(
const Vector &
b,
Vector &x,
double tol)
502void ConductionOperator::SetParameters(
const Vector &
u)
505 u_alpha_gf.SetFromTrueDofs(
u);
506 for (
int i = 0; i < u_alpha_gf.Size(); i++)
508 u_alpha_gf(i) = kappa + alpha*u_alpha_gf(i);
521ConductionOperator::~ConductionOperator()
Interface to ARKode's ARKStep module – additive Runge-Kutta methods.
void SetMaxStep(double dt_max)
Set the maximum time step.
void PrintInfo() const
Print various ARKStep statistics.
void Init(TimeDependentOperator &f_)
Initialize ARKode: calls ARKStepCreate() to create the ARKStep memory and set some defaults.
void SetStepMode(int itask)
Select the ARKode step mode: ARK_NORMAL (default) or ARK_ONE_STEP.
@ IMPLICIT
Implicit RK method.
@ EXPLICIT
Explicit RK method.
void SetERKTableNum(ARKODE_ERKTableID table_id)
Choose a specific Butcher table for an explicit RK method.
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
Backward Euler ODE solver. L-stable.
Conjugate gradient method.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
virtual void Mult(const Vector &b, Vector &x) const
Iterative solution of the linear system using the Conjugate Gradient method.
Interface to the CVODE library – linear multi-step methods.
void SetStepMode(int itask)
Select the CVODE step mode: CV_NORMAL (default) or CV_ONE_STEP.
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
void SetMaxStep(double dt_max)
Set the maximum time step.
void Init(TimeDependentOperator &f_)
Initialize CVODE: calls CVodeCreate() to create the CVODE memory and set some defaults.
void PrintInfo() const
Print various CVODE statistics.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetTime(real_t t)
Set physical time (for time-dependent simulations)
The classical forward Euler method.
A general function coefficient.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Arbitrary order H1-conforming (continuous) finite elements.
Wrapper for hypre's ParCSR matrix class.
Parallel smoothers in hypre.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
int Dimension() const
Dimension of the reference space used within the elements.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
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).
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
virtual void Step(Vector &x, real_t &t, real_t &dt)=0
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in].
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.
HYPRE_BigInt GlobalTrueVSize() const
Class for parallel grid function.
void Save(std::ostream &out) const override
HypreParVector * GetTrueDofs() const
Returns the true dofs in a new HypreParVector.
void SetFromTrueDofs(const Vector &tv) override
Set the GridFunction from the given true-dof vector.
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Class for parallel meshes.
void Print(std::ostream &out=mfem::out, const std::string &comments="") const override
Third-order, strong stability preserving (SSP) Runge-Kutta method.
The classical explicit forth-order Runge-Kutta method, RK4.
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication.
double RealTime()
Return the number of real seconds elapsed since the stopwatch was started.
void Start()
Start the stopwatch. The elapsed time is not cleared.
void Stop()
Stop the stopwatch.
void Clear()
Clear the elapsed time on the stopwatch and restart it if it's running.
Base abstract class for first order time dependent operators.
void Neg()
(*this) = -(*this)
real_t Norml2() const
Returns the l2 norm of the vector.
Data collection with VisIt I/O routines.
virtual void Save() override
Save the collection and a VisIt root file.
virtual void RegisterField(const std::string &field_name, GridFunction *gf) override
Add a grid function to the collection and update the root file.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
int close()
Close the socketstream.
real_t u(const Vector &xvec)
std::function< real_t(const Vector &)> f(real_t mass_coeff)
void Add(const DenseMatrix &A, const DenseMatrix &B, real_t alpha, DenseMatrix &C)
C = A + alpha*B.
double InitialTemperature(const Vector &x)
constexpr ARKODE_ERKTableID ARKODE_FEHLBERG_13_7_8