86 void SetParameters(
const Vector &
u);
88 ~ConductionOperator()
override;
93int main(
int argc,
char *argv[])
96 const char *mesh_file =
"../data/star.mesh";
100 int ode_solver_type = 23;
106 bool visualization =
true;
109 bool solve_implicit_state =
false;
112 cout.precision(precision);
115 args.
AddOption(&mesh_file,
"-m",
"--mesh",
116 "Mesh file to use.");
117 args.
AddOption(&ref_levels,
"-r",
"--refine",
118 "Number of times to refine the mesh uniformly.");
120 "Order (degree) of the finite elements.");
121 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
123 args.
AddOption(&t_final,
"-tf",
"--t-final",
124 "Final time; start time is 0.");
125 args.
AddOption(&dt,
"-dt",
"--time-step",
128 "Alpha coefficient.");
130 "Kappa coefficient offset.");
131 args.
AddOption(&solve_implicit_state,
"-imp-state",
"--implicit-state",
132 "-imp-slope",
"--implicit-slope",
133 "Implicitly solve for stage state or slope.");
134 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
135 "--no-visualization",
136 "Enable or disable GLVis visualization.");
137 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
138 "--no-visit-datafiles",
139 "Save data files for VisIt (visit.llnl.gov) visualization.");
140 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
141 "Visualize every n-th timestep.");
152 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
163 for (
int lev = 0; lev < ref_levels; lev++)
174 cout <<
"Number of temperature unknowns: " << fe_size << endl;
190 ofstream omesh(
"ex16.mesh");
191 omesh.precision(precision);
193 ofstream osol(
"ex16-init.gf");
194 osol.precision(precision);
215 cout <<
"Unable to connect to GLVis server at "
216 <<
vishost <<
':' << visport << endl;
217 visualization =
false;
218 cout <<
"GLVis visualization disabled.\n";
222 sout.precision(precision);
223 sout <<
"solution\n" << *mesh << u_gf;
226 cout <<
"GLVis visualization paused."
227 <<
" Press space (in the GLVis window) to resume it.\n";
232 ImplicitVariableType imp_var = solve_implicit_state ?
233 ImplicitVariableType::STATE
234 : ImplicitVariableType::SLOPE;
238 ode_solver->Init(oper);
239 ode_solver->SetImplicitVariableType(imp_var);
242 bool last_step =
false;
243 for (
int ti = 1; !last_step; ti++)
245 if (t + dt >= t_final - dt/2)
250 ode_solver->Step(
u, t, dt);
252 if (last_step || (ti % vis_steps) == 0)
254 cout <<
"step " << ti <<
", t = " << t << endl;
259 sout <<
"solution\n" << *mesh << u_gf << flush;
269 oper.SetParameters(
u);
275 ofstream osol(
"ex16-final.gf");
276 osol.precision(precision);
289 M(NULL), K(NULL), T(NULL), current_dt(0.0), z(height)
291 const real_t rel_tol = 1e-8;
298 M_solver.iterative_mode =
false;
299 M_solver.SetRelTol(rel_tol);
300 M_solver.SetAbsTol(0.0);
301 M_solver.SetMaxIter(30);
302 M_solver.SetPrintLevel(0);
303 M_solver.SetPreconditioner(M_prec);
304 M_solver.SetOperator(Mmat);
309 T_solver.iterative_mode =
false;
310 T_solver.SetRelTol(rel_tol);
311 T_solver.SetAbsTol(0.0);
312 T_solver.SetMaxIter(100);
313 T_solver.SetPrintLevel(0);
314 T_solver.SetPreconditioner(T_prec);
319void ConductionOperator::Mult(
const Vector &
u,
Vector &du_dt)
const
326 M_solver.
Mult(z, du_dt);
329void ConductionOperator::ImplicitSolve(
const real_t dt,
340 T =
Add(1.0, Mmat, dt, Kmat);
344 MFEM_VERIFY(dt == current_dt,
"");
361void ConductionOperator::SetParameters(
const Vector &
u)
364 u_alpha_gf.SetFromTrueDofs(
u);
365 for (
int i = 0; i < u_alpha_gf.Size(); i++)
367 u_alpha_gf(i) = kappa + alpha*u_alpha_gf(i);
382ConductionOperator::~ConductionOperator()
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.
Jacobi-type diagonal smoother of a sparse matrix.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetTime(real_t t)
Set physical time (for time-dependent simulations)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
A general function coefficient.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Class for grid function - Vector with associated FE space.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.
virtual void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
void GetTrueDofs(Vector &tv) const
Extract the true-dofs from the GridFunction.
Arbitrary order H1-conforming (continuous) finite elements.
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
Print the mesh to the given stream using the default MFEM mesh format.
int Dimension() const
Dimension of the reference space used within the elements.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
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.
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'.
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.