87 void SetParameters(
const Vector &
u);
89 ~ConductionOperator()
override;
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;
108 int ode_solver_type = 23;
114 bool visualization =
true;
120 cout.precision(precision);
123 args.
AddOption(&mesh_file,
"-m",
"--mesh",
124 "Mesh file to use.");
125 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
126 "Number of times to refine the mesh uniformly in serial.");
127 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
128 "Number of times to refine the mesh uniformly in parallel.");
130 "Order (degree) of the finite elements.");
131 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
133 args.
AddOption(&t_final,
"-tf",
"--t-final",
134 "Final time; start time is 0.");
135 args.
AddOption(&dt,
"-dt",
"--time-step",
138 "Alpha coefficient.");
140 "Kappa coefficient offset.");
141 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
142 "--no-visualization",
143 "Enable or disable GLVis visualization.");
144 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
145 "--no-visit-datafiles",
146 "Save data files for VisIt (visit.llnl.gov) visualization.");
147 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
148 "Visualize every n-th timestep.");
149 args.
AddOption(&adios2,
"-adios2",
"--adios2-streams",
"-no-adios2",
150 "--no-adios2-streams",
151 "Save data using adios2 streams.");
167 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
178 for (
int lev = 0; lev < ser_ref_levels; lev++)
188 for (
int lev = 0; lev < par_ref_levels; lev++)
201 cout <<
"Number of temperature unknowns: " << fe_size << endl;
218 ostringstream mesh_name, sol_name;
219 mesh_name <<
"ex16-mesh." << setfill(
'0') << setw(6) << myid;
220 sol_name <<
"ex16-init." << setfill(
'0') << setw(6) << myid;
221 ofstream omesh(mesh_name.str().c_str());
222 omesh.precision(precision);
224 ofstream osol(sol_name.str().c_str());
225 osol.precision(precision);
240#ifdef MFEM_USE_ADIOS2
244 std::string postfix(mesh_file);
245 postfix.erase(0, std::string(
"../data/").size() );
246 postfix +=
"_o" + std::to_string(order);
247 postfix +=
"_solver" + std::to_string(ode_solver_type);
248 const std::string collection_name =
"ex16-p-" + postfix +
".bp";
251 adios2_dc->
SetParameter(
"SubStreams", std::to_string(num_procs/2) );
265 sout <<
"parallel " << num_procs <<
" " << myid << endl;
266 int good = sout.good(), all_good;
267 MPI_Allreduce(&good, &all_good, 1, MPI_INT, MPI_MIN, pmesh->
GetComm());
271 visualization =
false;
274 cout <<
"Unable to connect to GLVis server at "
275 <<
vishost <<
':' << visport << endl;
276 cout <<
"GLVis visualization disabled.\n";
281 sout.precision(precision);
282 sout <<
"solution\n" << *pmesh << u_gf;
287 cout <<
"GLVis visualization paused."
288 <<
" Press space (in the GLVis window) to resume it.\n";
295 ode_solver->Init(oper);
298 bool last_step =
false;
299 for (
int ti = 1; !last_step; ti++)
301 if (t + dt >= t_final - dt/2)
306 ode_solver->Step(
u, t, dt);
308 if (last_step || (ti % vis_steps) == 0)
312 cout <<
"step " << ti <<
", t = " << t << endl;
318 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
319 sout <<
"solution\n" << *pmesh << u_gf << flush;
329#ifdef MFEM_USE_ADIOS2
338 oper.SetParameters(
u);
341#ifdef MFEM_USE_ADIOS2
351 ostringstream sol_name;
352 sol_name <<
"ex16-final." << setfill(
'0') << setw(6) << myid;
353 ofstream osol(sol_name.str().c_str());
354 osol.precision(precision);
367 M(NULL), K(NULL), T(NULL), current_dt(0.0),
368 M_solver(
f.GetComm()), T_solver(
f.GetComm()), z(height)
370 const real_t rel_tol = 1e-8;
375 M->FormSystemMatrix(ess_tdof_list, Mmat);
377 M_solver.iterative_mode =
false;
378 M_solver.SetRelTol(rel_tol);
379 M_solver.SetAbsTol(0.0);
380 M_solver.SetMaxIter(100);
381 M_solver.SetPrintLevel(0);
383 M_solver.SetPreconditioner(M_prec);
384 M_solver.SetOperator(Mmat);
389 T_solver.iterative_mode =
false;
390 T_solver.SetRelTol(rel_tol);
391 T_solver.SetAbsTol(0.0);
392 T_solver.SetMaxIter(100);
393 T_solver.SetPrintLevel(0);
394 T_solver.SetPreconditioner(T_prec);
399void ConductionOperator::Mult(
const Vector &
u,
Vector &du_dt)
const
406 M_solver.
Mult(z, du_dt);
409void ConductionOperator::ImplicitSolve(
const real_t dt,
417 T =
Add(1.0, Mmat, dt, Kmat);
421 MFEM_VERIFY(dt == current_dt,
"");
424 T_solver.
Mult(z, du_dt);
427void ConductionOperator::SetParameters(
const Vector &
u)
430 u_alpha_gf.SetFromTrueDofs(
u);
431 for (
int i = 0; i < u_alpha_gf.Size(); i++)
433 u_alpha_gf(i) = kappa + alpha*u_alpha_gf(i);
448ConductionOperator::~ConductionOperator()
void SetParameter(const std::string key, const std::string value) noexcept
Conjugate gradient method.
void Mult(const Vector &b, Vector &x) const override
Iterative solution of the linear system using the Conjugate Gradient method.
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
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)
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).
static MFEM_EXPORT std::string Types
static MFEM_EXPORT std::unique_ptr< ODESolver > Select(const int ode_solver_type)
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
void Mult(const Vector &x, Vector &y) const override
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.
void Save() override
Save the collection and a VisIt root file.
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.