65 Vector &d2udt2)
const override;
75 void SetParameters(
const Vector &
u);
77 ~WaveOperator()
override;
84 fespace(
f), M(NULL), K(NULL), T(NULL), current_dt(0.0), z(height)
98 fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list);
99 K->FormSystemMatrix(ess_tdof_list, Kmat);
100 M->FormSystemMatrix(ess_tdof_list, Mmat);
103 const real_t rel_tol = 1e-8;
104 M_solver.iterative_mode =
false;
105 M_solver.SetRelTol(rel_tol);
106 M_solver.SetAbsTol(0.0);
107 M_solver.SetMaxIter(30);
108 M_solver.SetPrintLevel(0);
109 M_solver.SetPreconditioner(M_prec);
110 M_solver.SetOperator(Mmat);
113 T_solver.iterative_mode =
false;
114 T_solver.SetRelTol(rel_tol);
115 T_solver.SetAbsTol(0.0);
116 T_solver.SetMaxIter(100);
117 T_solver.SetPrintLevel(0);
118 T_solver.SetPreconditioner(T_prec);
130 M_solver.
Mult(z, d2udt2);
134void WaveOperator::ImplicitSolve(
const real_t fac0,
const real_t fac1,
142 T =
Add(1.0, Mmat, fac0, Kmat);
148 T_solver.
Mult(z, d2udt2);
152void WaveOperator::SetParameters(
const Vector &
u)
158WaveOperator::~WaveOperator()
177int main(
int argc,
char *argv[])
180 const char *mesh_file =
"../data/star.mesh";
181 const char *ref_dir =
"";
184 int ode_solver_type = 10;
188 bool visualization =
true;
190 bool dirichlet =
true;
194 cout.precision(precision);
197 args.
AddOption(&mesh_file,
"-m",
"--mesh",
198 "Mesh file to use.");
199 args.
AddOption(&ref_levels,
"-r",
"--refine",
200 "Number of times to refine the mesh uniformly.");
202 "Order (degree) of the finite elements.");
203 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
205 args.
AddOption(&t_final,
"-tf",
"--t-final",
206 "Final time; start time is 0.");
207 args.
AddOption(&dt,
"-dt",
"--time-step",
211 args.
AddOption(&dirichlet,
"-dir",
"--dirichlet",
"-neu",
215 "Reference directory for checking final solution.");
216 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
217 "--no-visualization",
218 "Enable or disable GLVis visualization.");
219 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
220 "--no-visit-datafiles",
221 "Save data files for VisIt (visit.llnl.gov) visualization.");
222 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
223 "Visualize every n-th timestep.");
234 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
244 for (
int lev = 0; lev < ref_levels; lev++)
255 cout <<
"Number of temperature unknowns: " << fe_size << endl;
287 WaveOperator oper(fespace, ess_bdr, speed);
291 ofstream omesh(
"ex23.mesh");
292 omesh.precision(precision);
294 ofstream osol(
"ex23-init.gf");
295 osol.precision(precision);
318 cout <<
"Unable to connect to GLVis server at "
319 <<
vishost <<
':' << visport << endl;
320 visualization =
false;
321 cout <<
"GLVis visualization disabled.\n";
325 sout.precision(precision);
326 sout <<
"solution\n" << *mesh << u_gf;
329 cout <<
"GLVis visualization paused."
330 <<
" Press space (in the GLVis window) to resume it.\n";
336 ode_solver->
Init(oper);
339 bool last_step =
false;
340 for (
int ti = 1; !last_step; ti++)
343 if (t + dt >= t_final - dt/2)
348 ode_solver->
Step(
u, dudt, t, dt);
350 if (last_step || (ti % vis_steps) == 0)
352 cout <<
"step " << ti <<
", t = " << t << endl;
358 sout <<
"solution\n" << *mesh << u_gf << flush;
368 oper.SetParameters(
u);
374 ofstream osol(
"ex23-final.gf");
375 osol.precision(precision);
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
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.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
A coefficient that is constant across space and time.
Data type for scaled Jacobi-type smoother of 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.
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)
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.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
int Dimension() const
Dimension of the reference space used within the elements.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
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 class for solving systems of ODEs: d2x/dt2 = f(x,dx/dt,t)
static MFEM_EXPORT std::string Types
Help info for SecondOrderODESolver options.
static MFEM_EXPORT SecondOrderODESolver * Select(const int ode_solver_type)
Function selecting the desired SecondOrderODESolver.
virtual void Init(SecondOrderTimeDependentOperator &f)
Associate a TimeDependentOperator with the ODE solver.
virtual void Step(Vector &x, Vector &dxdt, 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].
Base abstract class for second order time dependent operators.
virtual void Mult(const Vector &x, const Vector &dxdt, Vector &y) const
Perform the action of the operator: y = k = f(x,@ dxdt, t), where k solves the algebraic equation F(x...
virtual void ImplicitSolve(const real_t fac0, const real_t fac1, const Vector &x, const Vector &dxdt, Vector &k)
Solve the equation: k = f(x + fac0 k, dxdt + fac1 k, t), for the unknown k at the current time t.
void Neg()
(*this) = -(*this)
void SetSubVector(const Array< int > &dofs, const real_t value)
Set the entries listed in dofs to the given value.
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'.
real_t InitialRate(const Vector &x)
real_t InitialSolution(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.