81 virtual void ImplicitSolve(
const double dt,
const Vector &
u,
Vector &k);
84 void SetParameters(
const Vector &
u);
86 virtual ~ConductionOperator();
91 int main(
int argc,
char *argv[])
95 MPI_Init(&argc, &argv);
96 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
97 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
100 const char *mesh_file =
"../data/star.mesh";
101 int ser_ref_levels = 2;
102 int par_ref_levels = 1;
104 int ode_solver_type = 3;
105 double t_final = 0.5;
107 double alpha = 1.0e-2;
109 bool visualization =
true;
115 cout.precision(precision);
118 args.
AddOption(&mesh_file,
"-m",
"--mesh",
119 "Mesh file to use.");
120 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
121 "Number of times to refine the mesh uniformly in serial.");
122 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
123 "Number of times to refine the mesh uniformly in parallel.");
125 "Order (degree) of the finite elements.");
126 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
127 "ODE solver: 1 - Backward Euler, 2 - SDIRK2, 3 - SDIRK3,\n\t"
128 "\t 11 - Forward Euler, 12 - RK2, 13 - RK3 SSP, 14 - RK4.");
129 args.
AddOption(&t_final,
"-tf",
"--t-final",
130 "Final time; start time is 0.");
131 args.
AddOption(&dt,
"-dt",
"--time-step",
134 "Alpha coefficient.");
136 "Kappa coefficient offset.");
137 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
138 "--no-visualization",
139 "Enable or disable GLVis visualization.");
140 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
141 "--no-visit-datafiles",
142 "Save data files for VisIt (visit.llnl.gov) visualization.");
143 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
144 "Visualize every n-th timestep.");
145 args.
AddOption(&adios2,
"-adios2",
"--adios2-streams",
"-no-adios2",
146 "--no-adios2-streams",
147 "Save data using adios2 streams.");
164 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
171 switch (ode_solver_type)
179 case 12: ode_solver =
new RK2Solver(0.5);
break;
181 case 14: ode_solver =
new RK4Solver;
break;
188 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
196 for (
int lev = 0; lev < ser_ref_levels; lev++)
206 for (
int lev = 0; lev < par_ref_levels; lev++)
219 cout <<
"Number of temperature unknowns: " << fe_size << endl;
232 ConductionOperator oper(fespace, alpha, kappa, u);
236 ostringstream mesh_name, sol_name;
237 mesh_name <<
"ex16-mesh." << setfill(
'0') << setw(6) << myid;
238 sol_name <<
"ex16-init." << setfill(
'0') << setw(6) << myid;
239 ofstream omesh(mesh_name.str().c_str());
240 omesh.precision(precision);
242 ofstream osol(sol_name.str().c_str());
243 osol.precision(precision);
258 #ifdef MFEM_USE_ADIOS2
262 std::string postfix(mesh_file);
263 postfix.erase(0, std::string(
"../data/").size() );
264 postfix +=
"_o" + std::to_string(order);
265 postfix +=
"_solver" + std::to_string(ode_solver_type);
266 const std::string collection_name =
"ex16-p-" + postfix +
".bp";
269 adios2_dc->
SetParameter(
"SubStreams", std::to_string(num_procs/2) );
282 sout.
open(vishost, visport);
283 sout <<
"parallel " << num_procs <<
" " << myid << endl;
284 int good = sout.good(), all_good;
285 MPI_Allreduce(&good, &all_good, 1, MPI_INT, MPI_MIN, pmesh->
GetComm());
289 visualization =
false;
292 cout <<
"Unable to connect to GLVis server at "
293 << vishost <<
':' << visport << endl;
294 cout <<
"GLVis visualization disabled.\n";
299 sout.precision(precision);
300 sout <<
"solution\n" << *pmesh << u_gf;
305 cout <<
"GLVis visualization paused."
306 <<
" Press space (in the GLVis window) to resume it.\n";
313 ode_solver->
Init(oper);
316 bool last_step =
false;
317 for (
int ti = 1; !last_step; ti++)
319 if (t + dt >= t_final - dt/2)
324 ode_solver->
Step(u, t, dt);
326 if (last_step || (ti % vis_steps) == 0)
330 cout <<
"step " << ti <<
", t = " << t << endl;
336 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
337 sout <<
"solution\n" << *pmesh << u_gf << flush;
347 #ifdef MFEM_USE_ADIOS2
356 oper.SetParameters(u);
359 #ifdef MFEM_USE_ADIOS2
369 ostringstream sol_name;
370 sol_name <<
"ex16-final." << setfill(
'0') << setw(6) << myid;
371 ofstream osol(sol_name.str().c_str());
388 T(NULL), current_dt(0.0),
389 M_solver(f.GetComm()), T_solver(f.GetComm()), z(height)
391 const double rel_tol = 1e-8;
396 M->FormSystemMatrix(ess_tdof_list, Mmat);
398 M_solver.iterative_mode =
false;
399 M_solver.SetRelTol(rel_tol);
400 M_solver.SetAbsTol(0.0);
401 M_solver.SetMaxIter(100);
402 M_solver.SetPrintLevel(0);
403 M_prec.SetType(HypreSmoother::Jacobi);
404 M_solver.SetPreconditioner(M_prec);
405 M_solver.SetOperator(Mmat);
410 T_solver.iterative_mode =
false;
411 T_solver.SetRelTol(rel_tol);
412 T_solver.SetAbsTol(0.0);
413 T_solver.SetMaxIter(100);
414 T_solver.SetPrintLevel(0);
415 T_solver.SetPreconditioner(T_prec);
427 M_solver.Mult(z, du_dt);
430 void ConductionOperator::ImplicitSolve(
const double dt,
438 T =
Add(1.0, Mmat, dt, Kmat);
440 T_solver.SetOperator(*T);
442 MFEM_VERIFY(dt == current_dt,
"");
445 T_solver.Mult(z, du_dt);
448 void ConductionOperator::SetParameters(
const Vector &u)
451 u_alpha_gf.SetFromTrueDofs(u);
452 for (
int i = 0; i < u_alpha_gf.Size(); i++)
464 K->FormSystemMatrix(ess_tdof_list, Kmat);
469 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]...
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()
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)
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 Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
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 ...
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
virtual void Print(std::ostream &out=mfem::out) const
void SetParameter(const std::string key, const std::string value) noexcept
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)
The classical explicit forth-order Runge-Kutta method, RK4.
int precision
Precision (number of digits) used for the text output of doubles.
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.
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
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.
double u(const Vector &xvec)
Class for parallel grid function.
The classical forward Euler method.
Wrapper for hypre's ParCSR matrix class.
Class for parallel meshes.
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
double f(const Vector &p)
bool Good() const
Return true if the command line options were parsed successfully.