80 virtual void ImplicitSolve(
const double dt,
const Vector &u,
Vector &k);
83 void SetParameters(
const Vector &u);
85 virtual ~ConductionOperator();
90 int main(
int argc,
char *argv[])
94 MPI_Init(&argc, &argv);
95 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
96 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
99 const char *mesh_file =
"../data/star.mesh";
100 int ser_ref_levels = 2;
101 int par_ref_levels = 1;
103 int ode_solver_type = 3;
104 double t_final = 0.5;
106 double alpha = 1.0e-2;
108 bool visualization =
true;
113 cout.precision(precision);
116 args.
AddOption(&mesh_file,
"-m",
"--mesh",
117 "Mesh file to use.");
118 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
119 "Number of times to refine the mesh uniformly in serial.");
120 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
121 "Number of times to refine the mesh uniformly in parallel.");
123 "Order (degree) of the finite elements.");
124 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
125 "ODE solver: 1 - Backward Euler, 2 - SDIRK2, 3 - SDIRK3,\n\t"
126 "\t 11 - Forward Euler, 12 - RK2, 13 - RK3 SSP, 14 - RK4.");
127 args.
AddOption(&t_final,
"-tf",
"--t-final",
128 "Final time; start time is 0.");
129 args.
AddOption(&dt,
"-dt",
"--time-step",
132 "Alpha coefficient.");
134 "Kappa coefficient offset.");
135 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
136 "--no-visualization",
137 "Enable or disable GLVis visualization.");
138 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
139 "--no-visit-datafiles",
140 "Save data files for VisIt (visit.llnl.gov) visualization.");
141 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
142 "Visualize every n-th timestep.");
159 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
166 switch (ode_solver_type)
174 case 12: ode_solver =
new RK2Solver(0.5);
break;
176 case 14: ode_solver =
new RK4Solver;
break;
183 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
191 for (
int lev = 0; lev < ser_ref_levels; lev++)
201 for (
int lev = 0; lev < par_ref_levels; lev++)
214 cout <<
"Number of temperature unknowns: " << fe_size << endl;
227 ConductionOperator oper(fespace, alpha, kappa, u);
231 ostringstream mesh_name, sol_name;
232 mesh_name <<
"ex16-mesh." << setfill(
'0') << setw(6) << myid;
233 sol_name <<
"ex16-init." << setfill(
'0') << setw(6) << myid;
234 ofstream omesh(mesh_name.str().c_str());
235 omesh.precision(precision);
237 ofstream osol(sol_name.str().c_str());
238 osol.precision(precision);
254 char vishost[] =
"localhost";
256 sout.
open(vishost, visport);
257 sout <<
"parallel " << num_procs <<
" " << myid << endl;
258 int good = sout.good(), all_good;
259 MPI_Allreduce(&good, &all_good, 1, MPI_INT, MPI_MIN, pmesh->
GetComm());
263 visualization =
false;
266 cout <<
"Unable to connect to GLVis server at "
267 << vishost <<
':' << visport << endl;
268 cout <<
"GLVis visualization disabled.\n";
273 sout.precision(precision);
274 sout <<
"solution\n" << *pmesh << u_gf;
279 cout <<
"GLVis visualization paused."
280 <<
" Press space (in the GLVis window) to resume it.\n";
287 ode_solver->
Init(oper);
290 bool last_step =
false;
291 for (
int ti = 1; !last_step; ti++)
293 if (t + dt >= t_final - dt/2)
298 ode_solver->
Step(u, t, dt);
300 if (last_step || (ti % vis_steps) == 0)
304 cout <<
"step " << ti <<
", t = " << t << endl;
310 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
311 sout <<
"solution\n" << *pmesh << u_gf << flush;
321 oper.SetParameters(u);
327 ostringstream sol_name;
328 sol_name <<
"ex16-final." << setfill(
'0') << setw(6) << myid;
329 ofstream osol(sol_name.str().c_str());
330 osol.precision(precision);
344 double kap,
const Vector &u)
346 T(NULL), current_dt(0.0),
347 M_solver(f.GetComm()), T_solver(f.GetComm()), z(height)
349 const double rel_tol = 1e-8;
354 M->FormSystemMatrix(ess_tdof_list, Mmat);
356 M_solver.iterative_mode =
false;
357 M_solver.SetRelTol(rel_tol);
358 M_solver.SetAbsTol(0.0);
359 M_solver.SetMaxIter(100);
360 M_solver.SetPrintLevel(0);
361 M_prec.SetType(HypreSmoother::Jacobi);
362 M_solver.SetPreconditioner(M_prec);
363 M_solver.SetOperator(Mmat);
368 T_solver.iterative_mode =
false;
369 T_solver.SetRelTol(rel_tol);
370 T_solver.SetAbsTol(0.0);
371 T_solver.SetMaxIter(100);
372 T_solver.SetPrintLevel(0);
373 T_solver.SetPreconditioner(T_prec);
385 M_solver.Mult(z, du_dt);
388 void ConductionOperator::ImplicitSolve(
const double dt,
396 T =
Add(1.0, Mmat, dt, Kmat);
398 T_solver.SetOperator(*T);
400 MFEM_VERIFY(dt == current_dt,
"");
403 T_solver.Mult(z, du_dt);
406 void ConductionOperator::SetParameters(
const Vector &u)
409 u_alpha_gf.SetFromTrueDofs(u);
410 for (
int i = 0; i < u_alpha_gf.Size(); i++)
422 K->FormSystemMatrix(ess_tdof_list, Kmat);
427 ConductionOperator::~ConductionOperator()
Conjugate gradient method.
double InitialTemperature(const Vector &x)
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
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]...
virtual void Init(TimeDependentOperator &f)
Associate a TimeDependentOperator with the ODE solver.
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()
Save the collection and a VisIt root file.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
virtual void ProjectCoefficient(Coefficient &coeff)
int main(int argc, char *argv[])
Backward Euler ODE solver. L-stable.
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 UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
HYPRE_Int GlobalTrueVSize() const
virtual void Print(std::ostream &out=mfem::out) const
Parallel smoothers in hypre.
void PrintUsage(std::ostream &out) const
void SetTime(double t)
Set physical time (for time-dependent simulations)
The classical explicit forth-order Runge-Kutta method, RK4.
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.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
Implicit midpoint method. A-stable, not L-stable.
void PrintOptions(std::ostream &out) const
HypreParVector * GetTrueDofs() const
Returns the true dofs in a new HypreParVector.
int open(const char hostname[], int port)
class for C-function coefficient
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.