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;
320 WaveOperator oper(fespace, ess_bdr, speed);
324 ofstream omesh(
"ex23.mesh");
325 omesh.precision(precision);
327 ofstream osol(
"ex23-init.gf");
328 osol.precision(precision);
348 sout.
open(vishost, visport);
351 cout <<
"Unable to connect to GLVis server at "
352 << vishost <<
':' << visport << endl;
353 visualization =
false;
354 cout <<
"GLVis visualization disabled.\n";
358 sout.precision(precision);
359 sout <<
"solution\n" << *mesh << dudt_gf;
362 cout <<
"GLVis visualization paused."
363 <<
" Press space (in the GLVis window) to resume it.\n";
369 ode_solver->
Init(oper);
372 bool last_step =
false;
373 for (
int ti = 1; !last_step; ti++)
376 if (t + dt >= t_final - dt/2)
381 ode_solver->
Step(u, dudt, t, dt);
383 if (last_step || (ti % vis_steps) == 0)
385 cout <<
"step " << ti <<
", t = " << t << endl;
391 sout <<
"solution\n" << *mesh << u_gf << flush;
401 oper.SetParameters(u);
407 ofstream osol(
"ex23-final.gf");
408 osol.precision(precision);
int Size() const
Return the logical size of the array.
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.
A coefficient that is constant across space and time.
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.
Abstract class for solving systems of ODEs: d2x/dt2 = f(x,dx/dt,t)
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]...
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
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.
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
void PrintUsage(std::ostream &out) const
Print the usage message.
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 Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
virtual void Save() override
Save the collection and a VisIt root file.
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...
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Base abstract class for second order time dependent operators.
double InitialRate(const Vector &x)
virtual void Print(std::ostream &os=mfem::out) const
void PrintOptions(std::ostream &out) const
Print the options.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
A general function coefficient.
Arbitrary order H1-conforming (continuous) finite elements.
double u(const Vector &xvec)
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.
double f(const Vector &p)
virtual void RegisterField(const std::string &field_name, GridFunction *gf) override
Add a grid function to the collection and update the root file.
bool Good() const
Return true if the command line options were parsed successfully.