67 : lambda(lambda_),
mu(mu_),
u(NULL), si(0), sj(0) { }
70 void SetComponent(
int i,
int j) { si = i; sj = j; }
76class VisMan :
public iostream
84 int win_x, win_y, win_w, win_h;
85 int win_stride_x, win_stride_y, win_nx;
90 void CloseConnection();
91 void PositionWindow();
101int main(
int argc,
char *argv[])
107 const char *mesh_file =
"../data/beam-tri.mesh";
108 int ser_ref_levels = -1;
109 int par_ref_levels = 1;
113 bool amg_elast =
false;
114 bool visualization = 1;
117 args.
AddOption(&mesh_file,
"-m",
"--mesh",
118 "Mesh file to use.");
119 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
120 "Number of times to refine the mesh uniformly before parallel"
121 " partitioning, -1 for auto.");
122 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
123 "Number of times to refine the mesh uniformly after parallel"
126 "Finite element order (polynomial degree).");
128 "One of the two DG penalty parameters, typically +1/-1."
129 " See the documentation of class DGElasticityIntegrator.");
131 "One of the two DG penalty parameters, should be positive."
132 " Negative values are replaced with (order+1)^2.");
133 args.
AddOption(&amg_elast,
"-elast",
"--amg-for-elasticity",
"-sys",
135 "Use the special AMG elasticity solver (GM/LN approaches), "
136 "or standard AMG for systems (unknown approach).");
137 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
138 "--no-visualization",
139 "Enable or disable GLVis visualization.");
148 kappa = (order+1)*(order+1);
153 Mesh mesh(mesh_file, 1, 1);
160 cerr <<
"\nInput mesh should have at least two materials and "
161 <<
"two boundary attributes! (See schematic in ex17p.cpp)\n"
168 if (ser_ref_levels < 0)
170 ser_ref_levels = (int)floor(log(5000./mesh.
GetNE())/log(2.)/
dim);
172 for (
int l = 0; l < ser_ref_levels; l++)
180 ParMesh pmesh(MPI_COMM_WORLD, mesh);
183 for (
int l = 0; l < par_ref_levels; l++)
197 cout <<
"Number of finite element unknowns: " << glob_size
198 <<
"\nAssembling: " << flush;
239 if (
Mpi::Root()) { cout <<
"r.h.s. ... " << flush; }
240 b.AddBdrFaceIntegrator(
242 init_x, lambda_c, mu_c,
alpha,
kappa), dir_bdr);
254 a.AddInteriorFaceIntegrator(
256 a.AddBdrFaceIntegrator(
260 if (
Mpi::Root()) { cout <<
"matrix ... " << flush; }
265 a.FormLinearSystem(ess_tdof_list, x,
b, A, X, B);
266 if (
Mpi::Root()) { cout <<
"done." << endl; }
294 a.RecoverFEMSolution(X,
b, x);
301 if (visualization) { reference_nodes = *pmesh.
GetNodes(); }
310 ostringstream mesh_name, sol_name;
311 mesh_name <<
"mesh." << setfill(
'0') << setw(6) <<
Mpi::WorldRank();
312 sol_name <<
"sol." << setfill(
'0') << setw(6) <<
Mpi::WorldRank();
314 ofstream mesh_ofs(mesh_name.str().c_str());
315 mesh_ofs.precision(8);
318 ofstream sol_ofs(sol_name.str().c_str());
319 sol_ofs.precision(8);
329 const char *glvis_keys = (
dim < 3) ?
"Rjlc" :
"c";
335 <<
"solution\n" << pmesh << x << flush
336 <<
"keys " << glvis_keys << endl
337 <<
"window_title 'Deformed configuration'" << endl
338 <<
"plot_caption 'Backward displacement'" << endl
342 const char *c =
"xyz";
345 StressCoefficient stress_c(lambda_c, mu_c);
346 *pmesh.
GetNodes() = reference_nodes;
348 stress_c.SetDisplacement(x);
349 for (
int si = 0; si <
dim; si++)
351 for (
int sj = si; sj <
dim; sj++)
353 stress_c.SetComponent(si, sj);
356 MPI_Barrier(MPI_COMM_WORLD);
360 <<
"solution\n" << pmesh << stress << flush
361 <<
"keys " << glvis_keys << endl
362 <<
"window_title |Stress " << c[si] << c[sj] <<
'|' << endl
375 u(
u.Size()-1) = -0.2*x(0);
382 MFEM_ASSERT(u != NULL,
"displacement field is not set");
390 return L*div_u + 2*M*grad(si,si);
394 return M*(grad(si,sj) + grad(sj,si));
407 win_stride_x = win_w;
408 win_stride_y = win_h + 20;
412void VisMan::NewWindow()
416 iostream::rdbuf(sock[sid]->rdbuf());
419void VisMan::CloseConnection()
421 if (sid < sock.Size())
429void VisMan::PositionWindow()
431 *
this <<
"window_geometry "
432 << win_x + win_stride_x*(sid%win_nx) <<
' '
433 << win_y + win_stride_y*(sid/win_nx) <<
' '
434 << win_w <<
' ' << win_h << endl;
439 for (
int i = sock.Size()-1; i >= 0; i--)
447 VisMan *vp =
dynamic_cast<VisMan*
>(&v);
448 if (vp) { (*f)(*vp); }
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
@ GaussLobatto
Closed type.
Conjugate gradient method.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
virtual real_t Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
Data type dense matrix using column-major storage.
real_t Trace() const
Trace of a square matrix.
void SetKDim(int dim)
Set the number of iteration to perform between restarts, default is 50.
Class for grid function - Vector with associated FE space.
void GetVectorGradient(ElementTransformation &tr, DenseMatrix &grad) const
Compute the vector gradient with respect to the physical element variable.
The BoomerAMG solver in hypre.
void SetSystemsOptions(int dim, bool order_bynodes=false)
void SetElasticityOptions(ParFiniteElementSpace *fespace, bool interp_refine=true)
Wrapper for hypre's ParCSR matrix class.
MPI_Comm GetComm() const
MPI communicator.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Class for integration point with weight.
Abstract base class for iterative solver.
virtual void SetOperator(const Operator &op) override
Also calls SetOperator for the preconditioner if there is one.
void SetRelTol(real_t rtol)
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
void SetMaxIter(int max_it)
Arbitrary order "L2-conforming" discontinuous finite elements.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
void Clear()
Clear the contents of the Mesh.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
void GetNodes(Vector &node_coord) const
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Set the curvature of the mesh nodes using the given polynomial degree.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Array< int > attributes
A list of all unique element attributes used by the Mesh.
static bool Root()
Return true if the rank in MPI_COMM_WORLD is zero.
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
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.
A piecewise constant coefficient with the constants keyed off the element attribute numbers.
Abstract parallel finite element space.
HYPRE_BigInt GlobalTrueVSize() const
Class for parallel grid function.
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Class for parallel meshes.
void SetNodalFESpace(FiniteElementSpace *nfes) override
A general vector function coefficient.
void Neg()
(*this) = -(*this)
void close_connection(VisMan &v)
void InitDisplacement(const Vector &x, Vector &u)
void position_window(VisMan &v)
void new_window(VisMan &v)
std::ostream & operator<<(std::ostream &os, SparseMatrix const &mat)
real_t u(const Vector &xvec)
std::function< real_t(const Vector &)> f(real_t mass_coeff)