36 using std::endl;
using std::cout;
using std::cerr;
37 using std::ends;
using std::cin;
45 using bgeot::scalar_type;
47 using bgeot::base_matrix;
52 typedef getfem::modeling_standard_sparse_matrix sparse_matrix;
53 typedef getfem::modeling_standard_plain_vector plain_vector;
55 template<
typename VEC>
56 static void vecsave(std::string fname,
const VEC& V);
59 template<
typename VEC>
60 static void vecsave( std::string fname,
const VEC& V) {
62 std::ofstream f(fname.c_str()); f.precision(16);
73 struct elastoplasticity_problem {
75 enum { DIRICHLET_BOUNDARY_NUM = 0,
76 NEUMANN_BOUNDARY_NUM = 1};
86 scalar_type lambda, mu;
91 std::string datafilename;
92 bgeot::md_param PARAM;
95 bool solve(plain_vector &U);
98 elastoplasticity_problem(
void) : mim(mesh), mim_data(mim), mf_u(mesh),
99 mf_xi(mesh), mf_rhs(mesh) {}
110 void elastoplasticity_problem::init(
void) {
112 std::string MESH_TYPE =
113 PARAM.string_value(
"MESH_TYPE",
"Mesh type ");
114 std::string FEM_TYPE =
115 PARAM.string_value(
"FEM_TYPE",
"FEM name");
116 std::string FEM_TYPE_XI =
117 PARAM.string_value(
"FEM_TYPE_XI",
"FEM name");
118 std::string INTEGRATION =
119 PARAM.string_value(
"INTEGRATION",
120 "Name of integration method");
121 do_export = (PARAM.int_value(
"EXPORT",
"Perform or not the vtk export") != 0);
123 cout <<
"MESH_TYPE=" << MESH_TYPE <<
"\n";
124 cout <<
"FEM_TYPE=" << FEM_TYPE <<
"\n";
125 cout <<
"INTEGRATION=" << INTEGRATION <<
"\n";
127 residual = PARAM.real_value(
"RESIDUAL",
"residual");
130 datafilename = PARAM.string_value(
"ROOTFILENAME",
131 "Filename for saving");
137 if (MESH_TYPE !=
"load") {
138 std::cout <<
"created getfem mesh" <<
"\n";
141 std::vector<size_type> nsubdiv(N);
142 nsubdiv[0]=PARAM.int_value
143 (
"NX",
"Number of space steps in x direction ");
144 nsubdiv[1]=PARAM.int_value
145 (
"NY",
"Number of space steps in y direction ");
148 nsubdiv[2]=PARAM.int_value
149 (
"NZ",
"Number of space steps in z direction ");
151 PARAM.int_value(
"MESH_NOISED")!= 0);
153 bgeot::base_matrix M(N,N);
156 static const char *t[] = {
"LX",
"LY",
"LZ"};
157 M(i,i) = (i<3) ? PARAM.real_value(t[i],t[i]) : 1.0;
161 M(0,1) = PARAM.real_value(
"INCLINE") *
162 PARAM.real_value(
"LY");
166 mesh.transformation(M);
169 std ::cout <<
"mesh from pdetool" <<
"\n";
170 std::string MESH_FILE
171 = PARAM.string_value(
"MESH_FILE",
"Mesh file name");
173 mesh.read_from_file(MESH_FILE);
176 pgt = mesh.trans_of_convex
177 (mesh.convex_index().first_true());
180 mu = PARAM.real_value(
"MU",
"Lamé coefficient mu");
185 lambda = PARAM.real_value(
"LAMBDA",
186 "Lamé coefficient lambda");
187 mf_u.set_qdim(bgeot::dim_type(N));
193 getfem::pintegration_method ppi =
196 mim.set_integration_method(mesh.convex_index(), ppi);
197 mim_data.set_tensor_size(bgeot::multi_index(N,N));
198 mf_u.set_finite_element(mesh.convex_index(), pf_u);
203 mf_xi.set_finite_element(mesh.convex_index(), pf_xi);
208 std::string data_fem_name
209 = PARAM.string_value(
"DATA_FEM_TYPE");
211 if (data_fem_name.size() == 0) {
212 GMM_ASSERT1(pf_u->is_lagrange(),
213 "You are using a non-lagrange FEM. "
214 <<
"In that case you need to set "
215 <<
"DATA_FEM_TYPE in the .param file");
216 mf_rhs.set_finite_element(mesh.convex_index(), pf_u);
219 mf_rhs.set_finite_element(mesh.convex_index(),
226 cout <<
"Selecting Neumann and Dirichlet boundaries\n";
231 !it.finished(); ++it) {
232 assert(it.is_face());
234 = mesh.normal_of_face_of_convex(it.cv(), it.f());
237 if (gmm::abs(un[0] - 1.0) < 1.0E-7)
238 mesh.region(NEUMANN_BOUNDARY_NUM).add(it.cv(), it.f());
239 else if (gmm::abs(un[0] + 1.0) < 1.0E-7)
240 mesh.region(DIRICHLET_BOUNDARY_NUM).add(it.cv(),it.f());
245 sigma_y = PARAM.real_value(
"SIGMA_Y",
"plasticity yield stress");
246 flag_hyp=PARAM.int_value(
"FLAG_HYP");
255 bool elastoplasticity_problem::solve(plain_vector &U) {
261 gmm::set_traces_level(1);
276 getfem::pconstraints_projection
277 proj = std::make_shared<getfem::VM_projection>(0);
279 std::vector<std::string> plastic_variables = {
"u",
"xi",
"Previous_Ep"};
280 std::vector<std::string> plastic_data = {
"lambda",
"mu",
"sigma_y"};
284 (model, mim,
"Prandtl Reuss", getfem::DISPLACEMENT_ONLY,
285 plastic_variables, plastic_data);
287 plain_vector F(nb_dof_rhs * N);
290 (model, mim,
"u",
"NeumannData", NEUMANN_BOUNDARY_NUM);
294 (model, mim,
"u", mf_u, DIRICHLET_BOUNDARY_NUM,
298 std::vector<scalar_type> T(19);
299 T[0] = 0; T[1] = 0.9032; T[2] = 1; T[3] = 1.1; T[4] = 1.3;
300 T[5] = 1.5; T[6] = 1.7; T[7] = 1.74; T[8] = 1.7; T[9] = 1.5;
301 T[10] = 1.3; T[11] = 1.1; T[12] = 1; T[13] = 0.9032; T[14] = 0.7;
302 T[15] = 0.5; T[16] = 0.3; T[17] = 0.1; T[18] = 0;
306 mf_vm.set_classical_discontinuous_finite_element(1);
307 getfem::base_vector VM(mf_vm.nb_dof());
308 getfem::base_vector plast(mf_vm.nb_dof());
310 for (
size_type nb = 0; nb < Nb_t; ++nb) {
311 cout <<
"=============iteration number : " << nb <<
"==========" << endl;
313 scalar_type t = T[nb];
316 base_small_vector v(N);
317 v[N-1] = -PARAM.real_value(
"FORCE");
320 for (
size_type i = 0; i < nb_dof_rhs; ++i)
321 gmm::copy(v, gmm::sub_vector
322 (F, gmm::sub_interval(i*N, N)));
327 cout <<
"Number of variables : "
328 << model.
nb_dof() << endl;
330 getfem::newton_search_with_step_control ls;
334 #
if defined(GMM_USES_MUMPS)
335 getfem::rselect_linear_solver(model,
"mumps"), ls);
337 getfem::rselect_linear_solver(model,
"superlu"), ls);
341 (model, mim,
"Prandtl Reuss", getfem::DISPLACEMENT_ONLY,
342 plastic_variables, plastic_data);
349 (model, mim,
"Prandtl Reuss", getfem::DISPLACEMENT_ONLY,
350 plastic_variables, plastic_data, mf_vm, VM);
352 std::stringstream fname; fname << datafilename <<
"_" << nb <<
".vtk";
356 exp.exporting(mf_vm);
357 exp.write_point_data(mf_vm,VM,
"Von Mises stress");
358 exp.write_point_data(mf_u, U,
"displacement");
364 cout <<
"export done, you can view the data file with "
366 "mayavi2 -d " << datafilename <<
"_1.vtk -f "
367 "WarpVector -m Surface -m Outline\n";
378 int main(
int argc,
char *argv[]) {
380 GETFEM_MPI_INIT(argc, argv);
381 GMM_SET_EXCEPTION_DEBUG;
387 elastoplasticity_problem p;
388 p.PARAM.read_command_line(argc, argv);
390 p.mesh.write_to_file(p.datafilename +
".mesh");
391 plain_vector U(p.mf_u.nb_dof());
392 if (!p.solve(U)) GMM_ASSERT1(
false,
"Solve has failed");
393 vecsave(p.datafilename +
".U", U);
394 cout <<
"Resultats dans fichier : "
395 <<p.datafilename<<
".U \n";
396 p.mf_u.write_to_file(p.datafilename +
".meshfem",
true);
397 scalar_type t[2]={p.mu,p.lambda};
398 vecsave(p.datafilename+
".coef",
399 std::vector<scalar_type>(t, t+2));
im_data provides indexing to the integration points of a mesh im object.
Describe a finite element method linked to a mesh.
Describe an integration method linked to a mesh.
"iterator" class for regions.
structure used to hold a set of convexes and/or convex faces.
Describe a mesh (collection of convexes (elements) and points).
`‘Model’' variables store the variables, the data and the description of a model.
size_type nb_dof(bool with_internal=false) const
Total number of degrees of freedom in the model.
void add_initialized_scalar_data(const std::string &name, T e)
Add a scalar data (i.e.
void add_fem_variable(const std::string &name, const mesh_fem &mf, size_type niter=1)
Add a variable being the dofs of a finite element method to the model.
void add_im_data(const std::string &name, const im_data &imd, size_type niter=1)
Add data defined at integration points.
void add_initialized_fem_data(const std::string &name, const mesh_fem &mf, const VECT &v)
Add an initialized fixed size data to the model, assumed to be a vector field if the size of the vect...
model_real_plain_vector & set_real_variable(const std::string &name, size_type niter) const
Gives the write access to the vector value of a variable.
const model_real_plain_vector & real_variable(const std::string &name, size_type niter) const
Gives the access to the vector value of a variable.
void add_fem_data(const std::string &name, const mesh_fem &mf, dim_type qdim=1, size_type niter=1)
Add a data being the dofs of a finite element method to the model.
The Iteration object calculates whether the solution has reached the desired accuracy,...
sparse vector built upon std::vector.
Miscelleanous assembly routines for common terms. Use the low-level generic assembly....
Export solutions to various formats.
Standard solvers for model bricks.
void copy(const L1 &l1, L2 &l2)
*/
number_traits< typename linalg_traits< V >::value_type >::magnitude_type vect_norm2(const V &v)
Euclidean norm of a vector.
void APIDECL outer_faces_of_mesh(const mesh &m, const dal::bit_vector &cvlst, convex_face_ct &flist)
returns a list of "exterior" faces of a mesh (i.e.
std::shared_ptr< const getfem::virtual_fem > pfem
type of pointer on a fem description
pfem fem_descriptor(const std::string &name)
get a fem descriptor from its string name.
pgeometric_trans geometric_trans_descriptor(std::string name)
Get the geometric transformation from its string name.
size_t size_type
used as the common size type in the library
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation
size_type APIDECL add_Dirichlet_condition_with_multipliers(model &md, const mesh_im &mim, const std::string &varname, const std::string &multname, size_type region, const std::string &dataname=std::string())
Add a Dirichlet condition on the variable varname and the mesh region region.
void compute_small_strain_elastoplasticity_Von_Mises(model &md, const mesh_im &mim, std::string lawname, plasticity_unknowns_type unknowns_type, const std::vector< std::string > &varnames, const std::vector< std::string > ¶ms, const mesh_fem &mf_vm, model_real_plain_vector &VM, size_type region=size_type(-1))
This function computes the Von Mises stress field with respect to a small strain elastoplasticity ter...
void regular_unit_mesh(mesh &m, std::vector< size_type > nsubdiv, bgeot::pgeometric_trans pgt, bool noised=false)
Build a regular mesh of the unit square/cube/, etc.
size_type add_small_strain_elastoplasticity_brick(model &md, const mesh_im &mim, std::string lawname, plasticity_unknowns_type unknowns_type, const std::vector< std::string > &varnames, const std::vector< std::string > ¶ms, size_type region=size_type(-1))
Adds a small strain plasticity term to the model md.
pintegration_method int_method_descriptor(std::string name, bool throw_if_not_found=true)
Get an integration method from its name .
void small_strain_elastoplasticity_next_iter(model &md, const mesh_im &mim, std::string lawname, plasticity_unknowns_type unknowns_type, const std::vector< std::string > &varnames, const std::vector< std::string > ¶ms, size_type region=size_type(-1))
Function that allows to pass from a time step to another for the small strain plastic brick.
size_type APIDECL add_source_term_brick(model &md, const mesh_im &mim, const std::string &varname, const std::string &dataexpr, size_type region=size_type(-1), const std::string &directdataname=std::string())
Add a source term on the variable varname.
void standard_solve(model &md, gmm::iteration &iter, rmodel_plsolver_type lsolver, abstract_newton_line_search &ls)
A default solver for the model brick system.