66 : lambda(lambda_), mu(mu_), u(NULL), si(0), sj(0) { }
69 void SetComponent(
int i,
int j) { si = i; sj = j; }
75 class VisMan :
public iostream
83 int win_x, win_y, win_w, win_h;
84 int win_stride_x, win_stride_y, win_nx;
87 VisMan(
const char *vishost,
const int visport);
89 void CloseConnection();
90 void PositionWindow();
98 ostream &
operator<<(ostream &v,
void (*f)(VisMan&));
100 int main(
int argc,
char *argv[])
103 const char *mesh_file =
"../data/beam-tri.mesh";
108 bool visualization = 1;
111 args.
AddOption(&mesh_file,
"-m",
"--mesh",
112 "Mesh file to use.");
113 args.
AddOption(&ref_levels,
"-r",
"--refine",
114 "Number of times to refine the mesh uniformly, -1 for auto.");
116 "Finite element order (polynomial degree).");
118 "One of the two DG penalty parameters, typically +1/-1."
119 " See the documentation of class DGElasticityIntegrator.");
121 "One of the two DG penalty parameters, should be positive."
122 " Negative values are replaced with (order+1)^2.");
123 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
124 "--no-visualization",
125 "Enable or disable GLVis visualization.");
134 kappa = (order+1)*(order+1);
139 Mesh mesh(mesh_file, 1, 1);
144 cerr <<
"\nInput mesh should have at least two materials and "
145 <<
"two boundary attributes! (See schematic in ex17.cpp)\n"
153 ref_levels = (int)floor(log(5000./mesh.
GetNE())/log(2.)/
dim);
155 for (
int l = 0; l < ref_levels; l++)
169 cout <<
"Number of finite element unknowns: " << fespace.
GetTrueVSize()
170 <<
"\nAssembling: " << flush;
210 cout <<
"r.h.s. ... " << flush;
213 init_x, lambda_c, mu_c, alpha, kappa), dir_bdr);
231 cout <<
"matrix ... " << flush;
237 cout <<
"done." << endl;
242 #ifndef MFEM_USE_SUITESPARSE
247 const double rtol = 1e-6;
250 PCG(A, M, B, X, 3, 5000, rtol*rtol, 0.0);
254 GMRES(A, M, B, X, 3, 5000, 50, rtol*rtol, 0.0);
259 umf_solver.
Control[UMFPACK_ORDERING] = UMFPACK_ORDERING_METIS;
261 umf_solver.
Mult(B, X);
272 if (visualization) { reference_nodes = *mesh.
GetNodes(); }
280 ofstream mesh_ofs(
"displaced.mesh");
281 mesh_ofs.precision(8);
282 mesh.
Print(mesh_ofs);
283 ofstream sol_ofs(
"sol.gf");
284 sol_ofs.precision(8);
291 char vishost[] =
"localhost";
293 VisMan vis(vishost, visport);
294 const char *glvis_keys = (dim < 3) ?
"Rjlc" :
"c";
298 <<
"solution\n" << mesh << x << flush
299 <<
"keys " << glvis_keys << endl
300 <<
"window_title 'Deformed configuration'" << endl
301 <<
"plot_caption 'Backward displacement'" << endl
305 const char *c =
"xyz";
308 StressCoefficient stress_c(lambda_c, mu_c);
311 stress_c.SetDisplacement(x);
312 for (
int si = 0; si <
dim; si++)
314 for (
int sj = si; sj <
dim; sj++)
316 stress_c.SetComponent(si, sj);
320 <<
"solution\n" << mesh << stress << flush
321 <<
"keys " << glvis_keys << endl
322 <<
"window_title |Stress " << c[si] << c[sj] <<
'|' << endl
335 u(u.
Size()-1) = -0.2*x(0);
342 MFEM_ASSERT(u != NULL,
"displacement field is not set");
344 double L = lambda.Eval(T, ip);
345 double M = mu.Eval(T, ip);
346 u->GetVectorGradient(T, grad);
349 double div_u = grad.Trace();
350 return L*div_u + 2*M*grad(si,si);
354 return M*(grad(si,sj) + grad(sj,si));
359 VisMan::VisMan(
const char *vishost,
const int visport)
361 host(vishost), port(visport), sid(0)
367 win_stride_x = win_w;
368 win_stride_y = win_h + 20;
372 void VisMan::NewWindow()
376 iostream::rdbuf(sock[sid]->rdbuf());
379 void VisMan::CloseConnection()
381 if (sid < sock.Size())
389 void VisMan::PositionWindow()
391 *
this <<
"window_geometry "
392 << win_x + win_stride_x*(sid%win_nx) <<
' '
393 << win_y + win_stride_y*(sid/win_nx) <<
' '
394 << win_w <<
' ' << win_h << endl;
399 for (
int i = sock.Size()-1; i >= 0; i--)
408 VisMan *vp =
dynamic_cast<VisMan*
>(&v);
409 if (vp) { (*f)(*vp); }
std::ostream & operator<<(std::ostream &out, const Mesh &mesh)
double Eval(ElementTransformation &T, const IntegrationPoint &ip, double t)
virtual void Print(std::ostream &out=mfem::out) const
Class for grid function - Vector with associated FE space.
Data type dense matrix using column-major storage.
int Size() const
Returns the size of the vector.
int GetNE() const
Returns number of elements.
void PrintInfo(std::ostream &out) const
Print various sparse matrix staticstics.
Data type for Gauss-Seidel smoother of sparse matrix.
void position_window(VisMan &v)
Direct sparse solver using UMFPACK.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void new_window(VisMan &v)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void PCG(const Operator &A, Solver &B, const Vector &b, Vector &x, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
Preconditioned conjugate gradient method. (tolerances are squared)
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
void SetNodalFESpace(FiniteElementSpace *nfes)
void PrintUsage(std::ostream &out) const
void close_connection(VisMan &v)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
double Control[UMFPACK_CONTROL]
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)
NURBSExtension * NURBSext
Optional NURBS mesh extension.
class for piecewise constant coefficient
Class for integration point with weight.
void InitDisplacement(const Vector &x, Vector &u)
void PrintOptions(std::ostream &out) const
virtual void ProjectCoefficient(Coefficient &coeff)
void GetNodes(Vector &node_coord) const
Array< int > attributes
A list of all unique element attributes used by the Mesh.
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
int GMRES(const Operator &A, Vector &x, const Vector &b, Solver &M, int &max_iter, int m, double &tol, double atol, int printit)
GMRES method. (tolerances are squared)
Arbitrary order "L2-conforming" discontinuous finite elements.
void Neg()
(*this) = -(*this)
virtual void SetOperator(const Operator &op)
Factorize the given Operator op which must be a SparseMatrix.