37 using std::endl;
using std::cout;
using std::cerr;
38 using std::ends;
using std::cin;
46 using bgeot::scalar_type;
48 using bgeot::base_matrix;
53 typedef getfem::modeling_standard_sparse_matrix sparse_matrix;
54 typedef getfem::modeling_standard_plain_vector plain_vector;
56 template<
typename VEC>
57 static void vecsave(std::string fname,
const VEC& V);
60 template<
typename VEC>
61 static void vecsave( std::string fname,
const VEC& V) {
63 std::ofstream f(fname.c_str()); f.precision(16);
74 struct elastoplasticity_problem {
76 enum { DIRICHLET_BOUNDARY_NUM = 0,
77 NEUMANN_BOUNDARY_NUM = 1};
87 scalar_type lambda, mu;
92 std::string datafilename;
93 bgeot::md_param PARAM;
96 bool solve(plain_vector &U);
99 elastoplasticity_problem(
void) : mim(mesh), mim_data(mim), mf_u(mesh),
100 mf_xi(mesh), mf_rhs(mesh) {}
111 void elastoplasticity_problem::init(
void) {
113 std::string MESH_TYPE =
114 PARAM.string_value(
"MESH_TYPE",
"Mesh type ");
115 std::string FEM_TYPE =
116 PARAM.string_value(
"FEM_TYPE",
"FEM name");
117 std::string FEM_TYPE_XI =
118 PARAM.string_value(
"FEM_TYPE_XI",
"FEM name");
119 std::string INTEGRATION =
120 PARAM.string_value(
"INTEGRATION",
121 "Name of integration method");
122 do_export = (PARAM.int_value(
"EXPORT",
"Perform or not the vtk export") != 0);
124 cout <<
"MESH_TYPE=" << MESH_TYPE <<
"\n";
125 cout <<
"FEM_TYPE=" << FEM_TYPE <<
"\n";
126 cout <<
"INTEGRATION=" << INTEGRATION <<
"\n";
128 residual = PARAM.real_value(
"RESIDUAL",
"residual");
131 datafilename = PARAM.string_value(
"ROOTFILENAME",
132 "Filename for saving");
138 if (MESH_TYPE !=
"load") {
139 std::cout <<
"created getfem mesh" <<
"\n";
142 std::vector<size_type> nsubdiv(N);
143 nsubdiv[0]=PARAM.int_value
144 (
"NX",
"Number of space steps in x direction ");
145 nsubdiv[1]=PARAM.int_value
146 (
"NY",
"Number of space steps in y direction ");
149 nsubdiv[2]=PARAM.int_value
150 (
"NZ",
"Number of space steps in z direction ");
152 PARAM.int_value(
"MESH_NOISED")!= 0);
154 bgeot::base_matrix M(N,N);
157 static const char *t[] = {
"LX",
"LY",
"LZ"};
158 M(i,i) = (i<3) ? PARAM.real_value(t[i],t[i]) : 1.0;
162 M(0,1) = PARAM.real_value(
"INCLINE") *
163 PARAM.real_value(
"LY");
167 mesh.transformation(M);
170 std ::cout <<
"mesh from pdetool" <<
"\n";
171 std::string MESH_FILE
172 = PARAM.string_value(
"MESH_FILE",
"Mesh file name");
174 mesh.read_from_file(MESH_FILE);
177 pgt = mesh.trans_of_convex
178 (mesh.convex_index().first_true());
181 mu = PARAM.real_value(
"MU",
"Lamé coefficient mu");
186 lambda = PARAM.real_value(
"LAMBDA",
187 "Lamé coefficient lambda");
188 mf_u.set_qdim(bgeot::dim_type(N));
194 getfem::pintegration_method ppi =
197 mim.set_integration_method(mesh.convex_index(), ppi);
198 mim_data.set_tensor_size(bgeot::multi_index(N,N));
199 mf_u.set_finite_element(mesh.convex_index(), pf_u);
204 mf_xi.set_finite_element(mesh.convex_index(), pf_xi);
209 std::string data_fem_name
210 = PARAM.string_value(
"DATA_FEM_TYPE");
212 if (data_fem_name.size() == 0) {
213 GMM_ASSERT1(pf_u->is_lagrange(),
214 "You are using a non-lagrange FEM. "
215 <<
"In that case you need to set "
216 <<
"DATA_FEM_TYPE in the .param file");
217 mf_rhs.set_finite_element(mesh.convex_index(), pf_u);
220 mf_rhs.set_finite_element(mesh.convex_index(),
227 cout <<
"Selecting Neumann and Dirichlet boundaries\n";
232 !it.finished(); ++it) {
233 assert(it.is_face());
235 = mesh.normal_of_face_of_convex(it.cv(), it.f());
238 if (gmm::abs(un[0] - 1.0) < 1.0E-7)
239 mesh.region(NEUMANN_BOUNDARY_NUM).add(it.cv(), it.f());
240 else if (gmm::abs(un[0] + 1.0) < 1.0E-7)
241 mesh.region(DIRICHLET_BOUNDARY_NUM).add(it.cv(),it.f());
246 sigma_y = PARAM.real_value(
"SIGMA_Y",
"plasticity yield stress");
247 flag_hyp=PARAM.int_value(
"FLAG_HYP");
256 bool elastoplasticity_problem::solve(plain_vector &U) {
262 gmm::set_traces_level(1);
277 getfem::pconstraints_projection
278 proj = std::make_shared<getfem::VM_projection>(0);
280 std::vector<std::string> plastic_variables = {
"u",
"xi",
"Previous_Ep"};
281 std::vector<std::string> plastic_data = {
"lambda",
"mu",
"sigma_y"};
285 (model, mim,
"Prandtl Reuss", getfem::DISPLACEMENT_ONLY,
286 plastic_variables, plastic_data);
288 plain_vector F(nb_dof_rhs * N);
291 (model, mim,
"u",
"NeumannData", NEUMANN_BOUNDARY_NUM);
295 (model, mim,
"u", mf_u, DIRICHLET_BOUNDARY_NUM,
299 std::vector<scalar_type> T(19);
300 T[0] = 0; T[1] = 0.9032; T[2] = 1; T[3] = 1.1; T[4] = 1.3;
301 T[5] = 1.5; T[6] = 1.7; T[7] = 1.74; T[8] = 1.7; T[9] = 1.5;
302 T[10] = 1.3; T[11] = 1.1; T[12] = 1; T[13] = 0.9032; T[14] = 0.7;
303 T[15] = 0.5; T[16] = 0.3; T[17] = 0.1; T[18] = 0;
307 mf_vm.set_classical_discontinuous_finite_element(1);
308 getfem::base_vector VM(mf_vm.nb_dof());
309 getfem::base_vector plast(mf_vm.nb_dof());
311 for (
size_type nb = 0; nb < Nb_t; ++nb) {
312 cout <<
"=============iteration number : " << nb <<
"==========" << endl;
314 scalar_type t = T[nb];
317 base_small_vector v(N);
318 v[N-1] = -PARAM.real_value(
"FORCE");
321 for (
size_type i = 0; i < nb_dof_rhs; ++i)
322 gmm::copy(v, gmm::sub_vector
323 (F, gmm::sub_interval(i*N, N)));
328 cout <<
"Number of variables : "
329 << model.
nb_dof() << endl;
331 getfem::newton_search_with_step_control ls;
335 getfem::rselect_linear_solver(model,
"superlu"), ls);
338 (model, mim,
"Prandtl Reuss", getfem::DISPLACEMENT_ONLY,
339 plastic_variables, plastic_data);
346 (model, mim,
"Prandtl Reuss", getfem::DISPLACEMENT_ONLY,
347 plastic_variables, plastic_data, mf_vm, VM);
349 std::stringstream fname; fname << datafilename <<
"_" << nb <<
".vtk";
353 exp.exporting(mf_vm);
354 exp.write_point_data(mf_vm,VM,
"Von Mises stress");
355 exp.write_point_data(mf_u, U,
"displacement");
361 cout <<
"export done, you can view the data file with "
363 "mayavi2 -d " << datafilename <<
"_1.vtk -f "
364 "WarpVector -m Surface -m Outline\n";
375 int main(
int argc,
char *argv[]) {
377 GETFEM_MPI_INIT(argc, argv);
378 GMM_SET_EXCEPTION_DEBUG;
384 elastoplasticity_problem p;
385 p.PARAM.read_command_line(argc, argv);
387 p.mesh.write_to_file(p.datafilename +
".mesh");
388 plain_vector U(p.mf_u.nb_dof());
389 if (!p.solve(U)) GMM_ASSERT1(
false,
"Solve has failed");
390 vecsave(p.datafilename +
".U", U);
391 cout <<
"Resultats dans fichier : "
392 <<p.datafilename<<
".U \n";
393 p.mf_u.write_to_file(p.datafilename +
".meshfem",
true);
394 scalar_type t[2]={p.mu,p.lambda};
395 vecsave(p.datafilename+
".coef",
396 std::vector<scalar_type>(t, t+2));