55 class JacobianPreconditioner :
public Solver
82 virtual void SetOperator(
const Operator &op);
84 virtual ~JacobianPreconditioner();
91 class RubberOperator :
public Operator
120 Array<int> &block_trueOffsets,
double rel_tol,
double abs_tol,
128 void Solve(
Vector &xp)
const;
130 virtual ~RubberOperator();
136 bool init_vis =
false);
143 int main(
int argc,
char *argv[])
146 const char *mesh_file =
"../data/beam-hex.mesh";
149 bool visualization =
true;
150 double newton_rel_tol = 1e-4;
151 double newton_abs_tol = 1e-6;
152 int newton_iter = 500;
156 args.
AddOption(&mesh_file,
"-m",
"--mesh",
157 "Mesh file to use.");
158 args.
AddOption(&ref_levels,
"-r",
"--refine",
159 "Number of times to refine the mesh uniformly.");
161 "Order (degree) of the finite elements.");
162 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
163 "--no-visualization",
164 "Enable or disable GLVis visualization.");
165 args.
AddOption(&newton_rel_tol,
"-rel",
"--relative-tolerance",
166 "Relative tolerance for the Newton solve.");
167 args.
AddOption(&newton_abs_tol,
"-abs",
"--absolute-tolerance",
168 "Absolute tolerance for the Newton solve.");
169 args.
AddOption(&newton_iter,
"-it",
"--newton-iterations",
170 "Maximum iterations for the Newton solve.");
171 args.
AddOption(&mu,
"-mu",
"--shear-modulus",
172 "Shear modulus for the neo-Hookean material.");
183 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
189 for (
int lev = 0; lev < ref_levels; lev++)
207 spaces[0] = &R_space;
208 spaces[1] = &W_space;
224 ess_bdr[0] = &ess_bdr_u;
225 ess_bdr[1] = &ess_bdr_p;
228 std::cout <<
"***********************************************************\n";
229 std::cout <<
"dim(u) = " << R_size <<
"\n";
230 std::cout <<
"dim(p) = " << W_size <<
"\n";
231 std::cout <<
"dim(u+p) = " << R_size + W_size <<
"\n";
232 std::cout <<
"***********************************************************\n";
236 block_offsets[0] = 0;
237 block_offsets[1] = R_space.
GetVSize();
238 block_offsets[2] = W_space.
GetVSize();
261 RubberOperator oper(spaces, ess_bdr, block_offsets,
262 newton_rel_tol, newton_abs_tol, newton_iter, c_mu);
274 char vishost[] =
"localhost";
276 vis_u.
open(vishost, visport);
278 visualize(vis_u, mesh, &x_gf, &x_def,
"Deformation",
true);
279 vis_p.
open(vishost, visport);
281 visualize(vis_p, mesh, &x_gf, &p_gf,
"Pressure",
true);
290 ofstream mesh_ofs(
"deformed.mesh");
291 mesh_ofs.precision(8);
292 mesh->
Print(mesh_ofs);
294 ofstream pressure_ofs(
"pressure.sol");
295 pressure_ofs.precision(8);
296 p_gf.
Save(pressure_ofs);
298 ofstream deformation_ofs(
"deformation.sol");
299 deformation_ofs.precision(8);
300 x_def.
Save(deformation_ofs);
313 :
Solver(offsets[2]), block_offsets(offsets), pressure_mass(&mass)
323 mass_prec = mass_prec_gs;
334 mass_pcg = mass_pcg_iter;
346 block_offsets[1]-block_offsets[0]);
348 block_offsets[2]-block_offsets[1]);
351 block_offsets[1]-block_offsets[0]);
353 block_offsets[2]-block_offsets[1]);
355 Vector temp(block_offsets[1]-block_offsets[0]);
356 Vector temp2(block_offsets[1]-block_offsets[0]);
359 mass_pcg->Mult(pres_in, pres_out);
362 jacobian->GetBlock(0,1).Mult(pres_out, temp);
365 stiff_pcg->Mult(temp2, disp_out);
368 void JacobianPreconditioner::SetOperator(
const Operator &op)
373 if (stiff_prec == NULL)
377 stiff_prec = stiff_prec_gs;
387 stiff_pcg = stiff_pcg_iter;
395 JacobianPreconditioner::~JacobianPreconditioner()
411 :
Operator(fes[0]->GetVSize() + fes[1]->GetVSize()),
412 newton_solver(), mu(c_mu), block_offsets(offsets)
426 Hform->SetEssentialBC(ess_bdr, rhs);
438 JacobianPreconditioner *jac_prec =
439 new JacobianPreconditioner(fes, *pressure_mass, block_offsets);
454 newton_solver.SetSolver(*j_solver);
455 newton_solver.SetOperator(*
this);
456 newton_solver.SetPrintLevel(1);
457 newton_solver.SetRelTol(rel_tol);
458 newton_solver.SetAbsTol(abs_tol);
459 newton_solver.SetMaxIter(iter);
463 void RubberOperator::Solve(
Vector &xp)
const
466 newton_solver.Mult(zero, xp);
467 MFEM_VERIFY(newton_solver.GetConverged(),
468 "Newton Solver did not converge.");
483 RubberOperator::~RubberOperator()
486 delete pressure_mass;
494 GridFunction *field,
const char *field_name,
bool init_vis)
506 out <<
"solution\n" << *mesh << *field;
512 out <<
"window_size 800 800\n";
513 out <<
"window_title '" << field_name <<
"'\n";
520 out <<
"autoscale value\n";
536 y[1] = x[1] + 0.25*x[0];
void visualize(ostream &out, Mesh *mesh, GridFunction *deformed_nodes, GridFunction *field, const char *field_name=NULL, bool init_vis=false)
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
void InitialDeformation(const Vector &x, Vector &y)
virtual void Print(std::ostream &out=mfem::out) const
Conjugate gradient method.
void ReferenceConfiguration(const Vector &x, Vector &y)
Class for grid function - Vector with associated FE space.
Subclass constant coefficient.
virtual Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate ...
void SwapNodes(GridFunction *&nodes, int &own_nodes_)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
void Copy(Array ©) const
Create a copy of the current array.
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
int main(int argc, char *argv[])
double * GetData() const
Return a pointer to the beginning of the Vector data.
Data type for Gauss-Seidel smoother of sparse matrix.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void SetPrintLevel(int print_lvl)
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
Mesh * GetMesh() const
Returns the mesh.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void SetMaxIter(int max_it)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
Newton's method for solving F(x)=b for a given operator F.
virtual void MakeRef(FiniteElementSpace *f, double *v)
Make the GridFunction reference external data on a new FiniteElementSpace.
void PrintUsage(std::ostream &out) const
int SpaceDimension() const
void SetAbsTol(double atol)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void SetRelTol(double rtol)
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 subtract(const Vector &x, const Vector &y, Vector &z)
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 PartialSum()
Partial Sum.
void PrintOptions(std::ostream &out) const
virtual void ProjectCoefficient(Coefficient &coeff)
int open(const char hostname[], int port)
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Arbitrary order H1-conforming (continuous) finite elements.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
A class to handle Block systems in a matrix-free implementation.
Vector & GetBlock(int i)
Get the i-th vector in the block.