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[])
105 const char *mesh_file =
"../data/beam-tri.mesh";
106 int ser_ref_levels = -1;
107 int par_ref_levels = 1;
111 bool amg_elast =
false;
112 bool visualization = 1;
115 args.
AddOption(&mesh_file,
"-m",
"--mesh",
116 "Mesh file to use.");
117 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
118 "Number of times to refine the mesh uniformly before parallel"
119 " partitioning, -1 for auto.");
120 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
121 "Number of times to refine the mesh uniformly after parallel"
124 "Finite element order (polynomial degree).");
126 "One of the two DG penalty parameters, typically +1/-1."
127 " See the documentation of class DGElasticityIntegrator.");
129 "One of the two DG penalty parameters, should be positive."
130 " Negative values are replaced with (order+1)^2.");
131 args.
AddOption(&amg_elast,
"-elast",
"--amg-for-elasticity",
"-sys",
133 "Use the special AMG elasticity solver (GM/LN approaches), "
134 "or standard AMG for systems (unknown approach).");
135 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
136 "--no-visualization",
137 "Enable or disable GLVis visualization.");
146 kappa = (order+1)*(order+1);
151 Mesh mesh(mesh_file, 1, 1);
158 cerr <<
"\nInput mesh should have at least two materials and "
159 <<
"two boundary attributes! (See schematic in ex17p.cpp)\n"
166 if (ser_ref_levels < 0)
168 ser_ref_levels = (int)floor(log(5000./mesh.
GetNE())/log(2.)/
dim);
170 for (
int l = 0; l < ser_ref_levels; l++)
178 ParMesh pmesh(MPI_COMM_WORLD, mesh);
181 for (
int l = 0; l < par_ref_levels; l++)
195 cout <<
"Number of finite element unknowns: " << glob_size
196 <<
"\nAssembling: " << flush;
237 if (mpi.
Root()) { cout <<
"r.h.s. ... " << flush; }
240 init_x, lambda_c, mu_c, alpha, kappa), dir_bdr);
258 if (mpi.
Root()) { cout <<
"matrix ... " << flush; }
264 if (mpi.
Root()) { cout <<
"done." << endl; }
269 const double rtol = 1e-6;
299 if (visualization) { reference_nodes = *pmesh.
GetNodes(); }
308 ostringstream mesh_name, sol_name;
309 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << mpi.
WorldRank();
310 sol_name <<
"sol." << setfill(
'0') << setw(6) << mpi.
WorldRank();
312 ofstream mesh_ofs(mesh_name.str().c_str());
313 mesh_ofs.precision(8);
316 ofstream sol_ofs(sol_name.str().c_str());
317 sol_ofs.precision(8);
324 char vishost[] =
"localhost";
326 VisMan vis(vishost, visport);
327 const char *glvis_keys = (dim < 3) ?
"Rjlc" :
"c";
333 <<
"solution\n" << pmesh << x << flush
334 <<
"keys " << glvis_keys << endl
335 <<
"window_title 'Deformed configuration'" << endl
336 <<
"plot_caption 'Backward displacement'" << endl
340 const char *c =
"xyz";
343 StressCoefficient stress_c(lambda_c, mu_c);
344 *pmesh.
GetNodes() = reference_nodes;
346 stress_c.SetDisplacement(x);
347 for (
int si = 0; si <
dim; si++)
349 for (
int sj = si; sj <
dim; sj++)
351 stress_c.SetComponent(si, sj);
354 MPI_Barrier(MPI_COMM_WORLD);
358 <<
"solution\n" << pmesh << stress << flush
359 <<
"keys " << glvis_keys << endl
360 <<
"window_title |Stress " << c[si] << c[sj] <<
'|' << endl
373 u(u.
Size()-1) = -0.2*x(0);
380 MFEM_ASSERT(u != NULL,
"displacement field is not set");
382 double L = lambda.Eval(T, ip);
383 double M = mu.Eval(T, ip);
384 u->GetVectorGradient(T, grad);
387 double div_u = grad.Trace();
388 return L*div_u + 2*M*grad(si,si);
392 return M*(grad(si,sj) + grad(sj,si));
397 VisMan::VisMan(
const char *vishost,
const int visport)
399 host(vishost), port(visport), sid(0)
405 win_stride_x = win_w;
406 win_stride_y = win_h + 20;
410 void VisMan::NewWindow()
414 iostream::rdbuf(sock[sid]->rdbuf());
417 void VisMan::CloseConnection()
419 if (sid < sock.Size())
427 void VisMan::PositionWindow()
429 *
this <<
"window_geometry "
430 << win_x + win_stride_x*(sid%win_nx) <<
' '
431 << win_y + win_stride_y*(sid/win_nx) <<
' '
432 << win_w <<
' ' << win_h << endl;
437 for (
int i = sock.Size()-1; i >= 0; i--)
444 ostream &
operator<<(ostream &v,
void (*f)(VisMan&))
446 VisMan *vp =
dynamic_cast<VisMan*
>(&v);
447 if (vp) { (*f)(*vp); }
std::ostream & operator<<(std::ostream &out, const Mesh &mesh)
double Eval(ElementTransformation &T, const IntegrationPoint &ip, double t)
Conjugate gradient method.
MPI_Comm GetComm() const
MPI communicator.
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.
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
Abstract parallel finite element space.
virtual void ProjectCoefficient(Coefficient &coeff)
void position_window(VisMan &v)
void SetSystemsOptions(int dim)
The BoomerAMG solver in hypre.
A simple convenience class that calls MPI_Init() at construction and MPI_Finalize() at destruction...
void SetPrintLevel(int print_lvl)
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
void new_window(VisMan &v)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void SetMaxIter(int max_it)
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.
HYPRE_Int GlobalTrueVSize() const
bool Root() const
Return true if WorldRank() == 0.
void SetElasticityOptions(ParFiniteElementSpace *fespace)
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.
int WorldRank() const
Return MPI_COMM_WORLD's rank.
void SetRelTol(double rtol)
Abstract base class for iterative solver.
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
void Clear()
Clear the contents of the Mesh.
void GetNodes(Vector &node_coord) const
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Class for parallel grid function.
Wrapper for hypre's ParCSR matrix class.
Class for parallel meshes.
Array< int > attributes
A list of all unique element attributes used by the Mesh.
Arbitrary order "L2-conforming" discontinuous finite elements.
void Neg()
(*this) = -(*this)