88 void SetParameters(
const Vector &
u);
90 ~ConductionOperator()
override;
95int main(
int argc,
char *argv[])
104 const char *mesh_file =
"../data/star.mesh";
105 int ser_ref_levels = 2;
106 int par_ref_levels = 1;
109 int ode_solver_type = 23;
115 bool visualization =
true;
119 bool solve_implicit_state =
false;
122 cout.precision(precision);
125 args.
AddOption(&mesh_file,
"-m",
"--mesh",
126 "Mesh file to use.");
127 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
128 "Number of times to refine the mesh uniformly in serial.");
129 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
130 "Number of times to refine the mesh uniformly in parallel.");
132 "Order (degree) of the finite elements.");
133 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
135 args.
AddOption(&t_final,
"-tf",
"--t-final",
136 "Final time; start time is 0.");
137 args.
AddOption(&dt,
"-dt",
"--time-step",
140 "Alpha coefficient.");
142 "Kappa coefficient offset.");
143 args.
AddOption(&solve_implicit_state,
"-imp-state",
"--implicit-state",
144 "-imp-slope",
"--implicit-slope",
145 "Implicitly solve for stage state or slope.");
146 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
147 "--no-visualization",
148 "Enable or disable GLVis visualization.");
149 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
150 "--no-visit-datafiles",
151 "Save data files for VisIt (visit.llnl.gov) visualization.");
152 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
153 "Visualize every n-th timestep.");
154 args.
AddOption(&adios2,
"-adios2",
"--adios2-streams",
"-no-adios2",
155 "--no-adios2-streams",
156 "Save data using adios2 streams.");
172 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
183 for (
int lev = 0; lev < ser_ref_levels; lev++)
193 for (
int lev = 0; lev < par_ref_levels; lev++)
206 cout <<
"Number of temperature unknowns: " << fe_size << endl;
224 ostringstream mesh_name, sol_name;
225 mesh_name <<
"ex16-mesh." << setfill(
'0') << setw(6) << myid;
226 sol_name <<
"ex16-init." << setfill(
'0') << setw(6) << myid;
227 ofstream omesh(mesh_name.str().c_str());
228 omesh.precision(precision);
230 ofstream osol(sol_name.str().c_str());
231 osol.precision(precision);
246#ifdef MFEM_USE_ADIOS2
250 std::string postfix(mesh_file);
251 postfix.erase(0, std::string(
"../data/").size() );
252 postfix +=
"_o" + std::to_string(order);
253 postfix +=
"_solver" + std::to_string(ode_solver_type);
254 const std::string collection_name =
"ex16-p-" + postfix +
".bp";
257 adios2_dc->
SetParameter(
"SubStreams", std::to_string(num_procs/2) );
271 sout <<
"parallel " << num_procs <<
" " << myid << endl;
272 int good = sout.good(), all_good;
273 MPI_Allreduce(&good, &all_good, 1, MPI_INT, MPI_MIN, pmesh->
GetComm());
277 visualization =
false;
280 cout <<
"Unable to connect to GLVis server at "
281 <<
vishost <<
':' << visport << endl;
282 cout <<
"GLVis visualization disabled.\n";
287 sout.precision(precision);
288 sout <<
"solution\n" << *pmesh << u_gf;
293 cout <<
"GLVis visualization paused."
294 <<
" Press space (in the GLVis window) to resume it.\n";
299 ImplicitVariableType imp_var = solve_implicit_state ?
300 ImplicitVariableType::STATE
301 : ImplicitVariableType::SLOPE;
305 ode_solver->Init(oper);
306 ode_solver->SetImplicitVariableType(imp_var);
309 bool last_step =
false;
310 for (
int ti = 1; !last_step; ti++)
312 if (t + dt >= t_final - dt/2)
317 ode_solver->Step(
u, t, dt);
319 if (last_step || (ti % vis_steps) == 0)
323 cout <<
"step " << ti <<
", t = " << t << endl;
329 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
330 sout <<
"solution\n" << *pmesh << u_gf << flush;
340#ifdef MFEM_USE_ADIOS2
349 oper.SetParameters(
u);
352#ifdef MFEM_USE_ADIOS2
362 ostringstream sol_name;
363 sol_name <<
"ex16-final." << setfill(
'0') << setw(6) << myid;
364 ofstream osol(sol_name.str().c_str());
365 osol.precision(precision);
378 M(NULL), K(NULL), T(NULL), current_dt(0.0),
379 M_solver(
f.GetComm()), T_solver(
f.GetComm()), z(height)
381 const real_t rel_tol = 1e-8;
388 M_solver.iterative_mode =
false;
389 M_solver.SetRelTol(rel_tol);
390 M_solver.SetAbsTol(0.0);
391 M_solver.SetMaxIter(100);
392 M_solver.SetPrintLevel(0);
394 M_solver.SetPreconditioner(M_prec);
395 M_solver.SetOperator(Mmat);
400 T_solver.iterative_mode =
false;
401 T_solver.SetRelTol(rel_tol);
402 T_solver.SetAbsTol(0.0);
403 T_solver.SetMaxIter(100);
404 T_solver.SetPrintLevel(0);
405 T_solver.SetPreconditioner(T_prec);
410void ConductionOperator::Mult(
const Vector &
u,
Vector &du_dt)
const
417 M_solver.
Mult(z, du_dt);
420void ConductionOperator::ImplicitSolve(
const real_t dt,
431 T =
Add(1.0, Mmat, dt, Kmat);
435 MFEM_VERIFY(dt == current_dt,
"");
452void ConductionOperator::SetParameters(
const Vector &
u)
455 u_alpha_gf.SetFromTrueDofs(
u);
456 for (
int i = 0; i < u_alpha_gf.Size(); i++)
458 u_alpha_gf(i) = kappa + alpha*u_alpha_gf(i);
473ConductionOperator::~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
void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
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.
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.
virtual bool ImplicitVarTypeIsState() const
Returns true if implicit variable is STATE and false otherwise. Used by ODESolver to identify the sta...
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.
const int * ess_tdof_list
real_t InitialTemperature(const Vector &x)
int GetTrueVSize(const FieldDescriptor &f)
Get the true dof size of a field descriptor.
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.