87 void SetParameters(
const Vector &
u);
89 virtual ~ConductionOperator();
94int main(
int argc,
char *argv[])
103 const char *mesh_file =
"../data/star.mesh";
104 int ser_ref_levels = 2;
105 int par_ref_levels = 1;
107 int ode_solver_type = 3;
112 bool visualization =
true;
118 cout.precision(precision);
121 args.
AddOption(&mesh_file,
"-m",
"--mesh",
122 "Mesh file to use.");
123 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
124 "Number of times to refine the mesh uniformly in serial.");
125 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
126 "Number of times to refine the mesh uniformly in parallel.");
128 "Order (degree) of the finite elements.");
129 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
130 "ODE solver: 1 - Backward Euler, 2 - SDIRK2, 3 - SDIRK3,\n\t"
131 "\t 11 - Forward Euler, 12 - RK2, 13 - RK3 SSP, 14 - RK4.");
132 args.
AddOption(&t_final,
"-tf",
"--t-final",
133 "Final time; start time is 0.");
134 args.
AddOption(&dt,
"-dt",
"--time-step",
137 "Alpha coefficient.");
139 "Kappa coefficient offset.");
140 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
141 "--no-visualization",
142 "Enable or disable GLVis visualization.");
143 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
144 "--no-visit-datafiles",
145 "Save data files for VisIt (visit.llnl.gov) visualization.");
146 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
147 "Visualize every n-th timestep.");
148 args.
AddOption(&adios2,
"-adios2",
"--adios2-streams",
"-no-adios2",
149 "--no-adios2-streams",
150 "Save data using adios2 streams.");
166 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
173 switch (ode_solver_type)
181 case 12: ode_solver =
new RK2Solver(0.5);
break;
183 case 14: ode_solver =
new RK4Solver;
break;
190 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
198 for (
int lev = 0; lev < ser_ref_levels; lev++)
208 for (
int lev = 0; lev < par_ref_levels; lev++)
221 cout <<
"Number of temperature unknowns: " << fe_size << endl;
238 ostringstream mesh_name, sol_name;
239 mesh_name <<
"ex16-mesh." << setfill(
'0') << setw(6) << myid;
240 sol_name <<
"ex16-init." << setfill(
'0') << setw(6) << myid;
241 ofstream omesh(mesh_name.str().c_str());
242 omesh.precision(precision);
244 ofstream osol(sol_name.str().c_str());
245 osol.precision(precision);
260#ifdef MFEM_USE_ADIOS2
264 std::string postfix(mesh_file);
265 postfix.erase(0, std::string(
"../data/").size() );
266 postfix +=
"_o" + std::to_string(order);
267 postfix +=
"_solver" + std::to_string(ode_solver_type);
268 const std::string collection_name =
"ex16-p-" + postfix +
".bp";
271 adios2_dc->
SetParameter(
"SubStreams", std::to_string(num_procs/2) );
285 sout <<
"parallel " << num_procs <<
" " << myid << endl;
286 int good = sout.good(), all_good;
287 MPI_Allreduce(&good, &all_good, 1, MPI_INT, MPI_MIN, pmesh->
GetComm());
291 visualization =
false;
294 cout <<
"Unable to connect to GLVis server at "
296 cout <<
"GLVis visualization disabled.\n";
301 sout.precision(precision);
302 sout <<
"solution\n" << *pmesh << u_gf;
307 cout <<
"GLVis visualization paused."
308 <<
" Press space (in the GLVis window) to resume it.\n";
315 ode_solver->
Init(oper);
318 bool last_step =
false;
319 for (
int ti = 1; !last_step; ti++)
321 if (
t + dt >= t_final - dt/2)
326 ode_solver->
Step(
u,
t, dt);
328 if (last_step || (ti % vis_steps) == 0)
332 cout <<
"step " << ti <<
", t = " <<
t << endl;
338 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
339 sout <<
"solution\n" << *pmesh << u_gf << flush;
349#ifdef MFEM_USE_ADIOS2
358 oper.SetParameters(
u);
361#ifdef MFEM_USE_ADIOS2
371 ostringstream sol_name;
372 sol_name <<
"ex16-final." << setfill(
'0') << setw(6) << myid;
373 ofstream osol(sol_name.str().c_str());
374 osol.precision(precision);
388 M(NULL), K(NULL), T(NULL), current_dt(0.0),
389 M_solver(
f.GetComm()), T_solver(
f.GetComm()), z(height)
391 const real_t 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);
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);
420void ConductionOperator::Mult(
const Vector &
u,
Vector &du_dt)
const
427 M_solver.
Mult(z, du_dt);
430void ConductionOperator::ImplicitSolve(
const real_t dt,
438 T =
Add(1.0, Mmat, dt, Kmat);
442 MFEM_VERIFY(dt == current_dt,
"");
445 T_solver.
Mult(z, du_dt);
448void ConductionOperator::SetParameters(
const Vector &
u)
451 u_alpha_gf.SetFromTrueDofs(
u);
452 for (
int i = 0; i < u_alpha_gf.Size(); i++)
454 u_alpha_gf(i) = kappa + alpha*u_alpha_gf(i);
469ConductionOperator::~ConductionOperator()
void SetParameter(const std::string key, const std::string value) noexcept
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.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
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(),...
Implicit midpoint method. A-stable, not L-stable.
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.
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 InitialTemperature(const Vector &x)
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.