71 virtual void ImplicitSolve(
const real_t fac0,
const real_t fac1,
75 void SetParameters(
const Vector &
u);
77 virtual ~WaveOperator();
84 fespace(
f), M(NULL), K(NULL), T(NULL), current_dt(0.0), z(height)
86 const real_t rel_tol = 1e-8;
88 fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list);
97 K->FormSystemMatrix(dummy, Kmat0);
98 K->FormSystemMatrix(ess_tdof_list, Kmat);
103 M->FormSystemMatrix(ess_tdof_list, Mmat);
105 M_solver.iterative_mode =
false;
106 M_solver.SetRelTol(rel_tol);
107 M_solver.SetAbsTol(0.0);
108 M_solver.SetMaxIter(30);
109 M_solver.SetPrintLevel(0);
110 M_solver.SetPreconditioner(M_prec);
111 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);
131 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 for (
int i = 0; i < ess_tdof_list.
Size(); i++)
150 z[ess_tdof_list[i]] = 0.0;
152 T_solver.
Mult(z, d2udt2);
155void WaveOperator::SetParameters(
const Vector &
u)
161WaveOperator::~WaveOperator()
180int main(
int argc,
char *argv[])
183 const char *mesh_file =
"../data/star.mesh";
184 const char *ref_dir =
"";
187 int ode_solver_type = 10;
191 bool visualization =
true;
193 bool dirichlet =
true;
197 cout.precision(precision);
200 args.
AddOption(&mesh_file,
"-m",
"--mesh",
201 "Mesh file to use.");
202 args.
AddOption(&ref_levels,
"-r",
"--refine",
203 "Number of times to refine the mesh uniformly.");
205 "Order (degree) of the finite elements.");
206 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
207 "ODE solver: [0--10] - GeneralizedAlpha(0.1 * s),\n\t"
208 "\t 11 - Average Acceleration, 12 - Linear Acceleration\n"
209 "\t 13 - CentralDifference, 14 - FoxGoodwin");
210 args.
AddOption(&t_final,
"-tf",
"--t-final",
211 "Final time; start time is 0.");
212 args.
AddOption(&dt,
"-dt",
"--time-step",
216 args.
AddOption(&dirichlet,
"-dir",
"--dirichlet",
"-neu",
220 "Reference directory for checking final solution.");
221 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
222 "--no-visualization",
223 "Enable or disable GLVis visualization.");
224 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
225 "--no-visit-datafiles",
226 "Save data files for VisIt (visit.llnl.gov) visualization.");
227 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
228 "Visualize every n-th timestep.");
239 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
245 switch (ode_solver_type)
266 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
274 for (
int lev = 0; lev < ref_levels; lev++)
285 cout <<
"Number of temperature unknowns: " << fe_size << endl;
318 WaveOperator oper(fespace, ess_bdr, speed);
322 ofstream omesh(
"ex23.mesh");
323 omesh.precision(precision);
325 ofstream osol(
"ex23-init.gf");
326 osol.precision(precision);
349 cout <<
"Unable to connect to GLVis server at "
351 visualization =
false;
352 cout <<
"GLVis visualization disabled.\n";
356 sout.precision(precision);
357 sout <<
"solution\n" << *mesh << u_gf;
360 cout <<
"GLVis visualization paused."
361 <<
" Press space (in the GLVis window) to resume it.\n";
367 ode_solver->
Init(oper);
370 bool last_step =
false;
371 for (
int ti = 1; !last_step; ti++)
374 if (
t + dt >= t_final - dt/2)
379 ode_solver->
Step(
u, dudt,
t, dt);
381 if (last_step || (ti % vis_steps) == 0)
383 cout <<
"step " << ti <<
", t = " <<
t << endl;
389 sout <<
"solution\n" << *mesh << u_gf << flush;
399 oper.SetParameters(
u);
405 ofstream osol(
"ex23-final.gf");
406 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.
The classical midpoint method.
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.
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)
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.
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication.
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'.
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.