71 using SecondOrderTimeDependentOperator::ImplicitSolve;
72 virtual void ImplicitSolve(
const double fac0,
const double fac1,
76 void SetParameters(
const Vector &u);
78 virtual ~WaveOperator();
86 T(NULL), current_dt(0.0), z(height)
88 const double rel_tol = 1e-8;
90 fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list);
99 K->FormSystemMatrix(dummy, Kmat0);
100 K->FormSystemMatrix(ess_tdof_list, Kmat);
105 M->FormSystemMatrix(ess_tdof_list, Mmat);
107 M_solver.iterative_mode =
false;
108 M_solver.SetRelTol(rel_tol);
109 M_solver.SetAbsTol(0.0);
110 M_solver.SetMaxIter(30);
111 M_solver.SetPrintLevel(0);
112 M_solver.SetPreconditioner(M_prec);
113 M_solver.SetOperator(Mmat);
115 T_solver.iterative_mode =
false;
116 T_solver.SetRelTol(rel_tol);
117 T_solver.SetAbsTol(0.0);
118 T_solver.SetMaxIter(100);
119 T_solver.SetPrintLevel(0);
120 T_solver.SetPreconditioner(T_prec);
133 M_solver.Mult(z, d2udt2);
144 T =
Add(1.0, Mmat, fac0, Kmat);
145 T_solver.SetOperator(*T);
150 for (
int i = 0; i < ess_tdof_list.Size(); i++)
152 z[ess_tdof_list[i]] = 0.0;
154 T_solver.Mult(z, d2udt2);
157 void WaveOperator::SetParameters(
const Vector &u)
163 WaveOperator::~WaveOperator()
182 int main(
int argc,
char *argv[])
185 const char *mesh_file =
"../data/star.mesh";
186 const char *ref_dir =
"";
189 int ode_solver_type = 10;
190 double t_final = 0.5;
193 bool visualization =
true;
195 bool dirichlet =
true;
199 cout.precision(precision);
202 args.
AddOption(&mesh_file,
"-m",
"--mesh",
203 "Mesh file to use.");
204 args.
AddOption(&ref_levels,
"-r",
"--refine",
205 "Number of times to refine the mesh uniformly.");
207 "Order (degree) of the finite elements.");
208 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
209 "ODE solver: [0--10] - GeneralizedAlpha(0.1 * s),\n\t"
210 "\t 11 - Average Acceleration, 12 - Linear Acceleration\n"
211 "\t 13 - CentralDifference, 14 - FoxGoodwin");
212 args.
AddOption(&t_final,
"-tf",
"--t-final",
213 "Final time; start time is 0.");
214 args.
AddOption(&dt,
"-dt",
"--time-step",
218 args.
AddOption(&dirichlet,
"-dir",
"--dirichlet",
"-neu",
222 "Reference directory for checking final solution.");
223 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
224 "--no-visualization",
225 "Enable or disable GLVis visualization.");
226 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
227 "--no-visit-datafiles",
228 "Save data files for VisIt (visit.llnl.gov) visualization.");
229 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
230 "Visualize every n-th timestep.");
241 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
247 switch (ode_solver_type)
268 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
276 for (
int lev = 0; lev < ref_levels; lev++)
287 cout <<
"Number of temperature unknowns: " << fe_size << endl;
319 WaveOperator oper(fespace, ess_bdr, speed);
323 ofstream omesh(
"ex23.mesh");
324 omesh.precision(precision);
326 ofstream osol(
"ex23-init.gf");
327 osol.precision(precision);
345 char vishost[] =
"localhost";
347 sout.
open(vishost, visport);
350 cout <<
"Unable to connect to GLVis server at "
351 << vishost <<
':' << visport << endl;
352 visualization =
false;
353 cout <<
"GLVis visualization disabled.\n";
357 sout.precision(precision);
358 sout <<
"solution\n" << *mesh << dudt_gf;
361 cout <<
"GLVis visualization paused."
362 <<
" Press space (in the GLVis window) to resume it.\n";
368 ode_solver->
Init(oper);
371 bool last_step =
false;
372 for (
int ti = 1; !last_step; ti++)
375 if (t + dt >= t_final - dt/2)
380 ode_solver->
Step(u, dudt, t, dt);
382 if (last_step || (ti % vis_steps) == 0)
384 cout <<
"step " << ti <<
", t = " << t << endl;
390 sout <<
"solution\n" << *mesh << u_gf << flush;
400 oper.SetParameters(u);
406 ofstream osol(
"ex23-final.gf");
407 osol.precision(precision);
int Size() const
Logical size of the array.
virtual void Print(std::ostream &out=mfem::out) const
Conjugate gradient method.
Class for grid function - Vector with associated FE space.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
Data type for scaled Jacobi-type smoother of sparse matrix.
Subclass constant coefficient.
virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k)
Solve the equation: k = f(x + dt k, t), for the unknown k at the current time t.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
double Norml2() const
Returns the l2 norm of the vector.
virtual void Save()
Save the collection and a VisIt root file.
Abstract class for solving systems of ODEs: d2x/dt2 = f(x,dx/dt,t)
int main(int argc, char *argv[])
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
virtual void Step(Vector &x, Vector &dxdt, double &t, double &dt)=0
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
The classical midpoint method.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
virtual void Init(SecondOrderTimeDependentOperator &f)
Associate a TimeDependentOperator with the ODE solver.
void GetTrueDofs(Vector &tv) const
Extract the true-dofs from the GridFunction. If all dofs are true, then tv will be set to point to th...
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
void PrintUsage(std::ostream &out) const
void SetTime(double t)
Set physical time (for time-dependent simulations)
double InitialSolution(const Vector &x)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Base class Coefficient that may optionally depend on time.
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)
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
Base abstract class for second order time dependent operators.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
double InitialRate(const Vector &x)
void PrintOptions(std::ostream &out) const
virtual void ProjectCoefficient(Coefficient &coeff)
int open(const char hostname[], int port)
class for C-function coefficient
Arbitrary order H1-conforming (continuous) finite elements.
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.