5 const libMesh::Parallel::Communicator& SysComm = es.comm();
6 int rank = SysComm.rank();
7 int nodes = SysComm.size();
15 std::ifstream physicalParamsIFS(physicalParamsFile);
16 physicalParamsIFS >> inputE >> inputMu;
21 SysComm.broadcast(inputE);
22 SysComm.broadcast(inputMu);
26 const libMesh::MeshBase& mesh = es.get_mesh();
29 libMesh::ExplicitSystem& physical_param_system = es.get_system<libMesh::ExplicitSystem>(
"PhysicalConstants");
30 const libMesh::DofMap& physical_dof_map = physical_param_system.get_dof_map();
32 unsigned int physical_consts[2];
33 physical_consts[0] = physical_param_system.variable_number (
"E");
34 physical_consts[1] = physical_param_system.variable_number (
"mu");
36 std::vector<libMesh::dof_id_type> physical_dof_indices_var;
37 libMesh::MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
38 const libMesh::MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
40 for ( ; el != end_el; ++el)
42 const libMesh::Elem* elem = *el;
45 physical_dof_map.dof_indices(elem, physical_dof_indices_var, physical_consts[0]);
46 libMesh::dof_id_type dof_index = physical_dof_indices_var[0];
48 if( (physical_param_system.solution->first_local_index() <= dof_index) &&
49 (dof_index < physical_param_system.solution->last_local_index()) )
51 physical_param_system.solution->set(dof_index, inputE);
55 physical_dof_map.dof_indices (elem, physical_dof_indices_var, physical_consts[1]);
57 dof_index = physical_dof_indices_var[0];
59 if( (physical_param_system.solution->first_local_index() <= dof_index) &&
60 (dof_index < physical_param_system.solution->last_local_index()) )
62 physical_param_system.solution->set(dof_index, inputMu);
67 physical_param_system.solution->close();
68 physical_param_system.update();
73 const libMesh::Parallel::Communicator& SysComm = es.comm();
74 int rank = SysComm.rank();
75 int nodes = SysComm.size();
78 std::vector<double> inputE;
79 std::vector<double> inputMu;
80 std::vector<int> inputIdx;
82 int NbOfSubdomains = -1;
89 std::ifstream physicalParamsIFS(physicalParamsFile);
90 physicalParamsIFS >> NbOfSubdomains;
91 inputE.resize(NbOfSubdomains);
92 inputMu.resize(NbOfSubdomains);
93 inputIdx.resize(NbOfSubdomains);
95 for(
int iii = 0; iii < NbOfSubdomains; ++iii)
97 physicalParamsIFS >> inputE[iii];
98 physicalParamsIFS >> inputMu[iii];
99 physicalParamsIFS >> inputIdx[iii];
101 meanE += inputE[iii];
102 meanMu += inputMu[iii];
104 meanE /= NbOfSubdomains;
105 meanMu /= NbOfSubdomains;
106 physicalParamsIFS.close();
111 SysComm.broadcast(NbOfSubdomains);
112 SysComm.broadcast(meanE);
113 SysComm.broadcast(meanMu);
117 inputE.resize(NbOfSubdomains);
118 inputMu.resize(NbOfSubdomains);
119 inputIdx.resize(NbOfSubdomains);
121 SysComm.broadcast(inputE);
122 SysComm.broadcast(inputMu);
123 SysComm.broadcast(inputIdx);
127 const libMesh::MeshBase& mesh = es.get_mesh();
130 libMesh::ExplicitSystem& physical_param_system = es.get_system<libMesh::ExplicitSystem>(
"PhysicalConstants");
131 const libMesh::DofMap& physical_dof_map = physical_param_system.get_dof_map();
133 unsigned int physical_consts[2];
134 physical_consts[0] = physical_param_system.variable_number (
"E");
135 physical_consts[1] = physical_param_system.variable_number (
"mu");
137 std::vector<libMesh::dof_id_type> physical_dof_indices_var;
138 libMesh::MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
139 const libMesh::MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
141 int currentSubdomain = -1;
143 for ( ; el != end_el; ++el)
145 const libMesh::Elem* elem = *el;
147 currentSubdomain = elem->subdomain_id()-1;
150 physical_dof_map.dof_indices(elem, physical_dof_indices_var, physical_consts[0]);
151 libMesh::dof_id_type dof_index = physical_dof_indices_var[0];
153 if( (physical_param_system.solution->first_local_index() <= dof_index) &&
154 (dof_index < physical_param_system.solution->last_local_index()) )
156 physical_param_system.solution->set(dof_index, inputE[currentSubdomain]);
160 physical_dof_map.dof_indices (elem, physical_dof_indices_var, physical_consts[1]);
162 dof_index = physical_dof_indices_var[0];
164 if( (physical_param_system.solution->first_local_index() <= dof_index) &&
165 (dof_index < physical_param_system.solution->last_local_index()) )
167 physical_param_system.solution->set(dof_index, inputMu[currentSubdomain]);
171 physical_param_system.solution->close();
172 physical_param_system.update();
177 return mu*(E - 2*mu)/(3*mu-E);
188 const libMesh::Real lambda_2 = mu;
199 const std::vector<std::vector<libMesh::RealGradient> >& dphi,
200 const unsigned int n_components,
201 const unsigned int n_u_dofs,
202 const std::vector<libMesh::Real>& JxW,
208 for (
unsigned int iii=0; iii<n_u_dofs; iii++)
210 for (
unsigned int jjj=0; jjj<n_u_dofs; jjj++)
212 for(
unsigned int C_j=0; C_j<n_components; C_j++)
214 for(
unsigned int C_l=0; C_l<n_components; C_l++)
216 SubK(iii,jjj) += cte * JxW[qp]*(
eval_elasticity_tensor(C_i,C_j,C_k,C_l,E,mu) * dphi[iii][qp](C_j)*dphi[jjj][qp](C_l));
224 const std::string& system_name,
228 libmesh_assert_equal_to(system_name,
"Elasticity");
232 perf_log.push(
"Preamble");
234 const libMesh::MeshBase& mesh = es.get_mesh();
236 const unsigned int dim = mesh.mesh_dimension();
239 libMesh::ExplicitSystem& physical_param_system = es.get_system<libMesh::ExplicitSystem>(
"PhysicalConstants");
240 const unsigned int young_var = physical_param_system.variable_number (
"E");
241 const unsigned int mu_var = physical_param_system.variable_number (
"mu");
243 const libMesh::DofMap& physical_dof_map = physical_param_system.get_dof_map();
244 std::vector<libMesh::dof_id_type> physical_dof_indices_var;
247 const libMesh::Elem* phys_elem = *(mesh.active_local_elements_begin());
248 physical_dof_map.dof_indices(phys_elem, physical_dof_indices_var, young_var);
249 libMesh::Number localE = physical_param_system.current_solution(physical_dof_indices_var[0]);
251 physical_dof_map.dof_indices(phys_elem, physical_dof_indices_var, mu_var);
252 libMesh::Number localMu = physical_param_system.current_solution(physical_dof_indices_var[0]);
255 libMesh::LinearImplicitSystem& system = es.get_system<libMesh::LinearImplicitSystem>(
"Elasticity");
257 const unsigned int n_components = 3;
258 const unsigned int u_var = system.variable_number (
"u");
259 const unsigned int v_var = system.variable_number (
"v");
260 const unsigned int w_var = system.variable_number (
"w");
262 const libMesh::DofMap& dof_map = system.get_dof_map();
263 libMesh::FEType fe_type = dof_map.variable_type(u_var);
267 libMesh::UniquePtr<libMesh::FEBase> fe (libMesh::FEBase::build(dim, fe_type));
268 libMesh::QGauss qrule (dim, fe_type.default_quadrature_order());
269 fe->attach_quadrature_rule (&qrule);
272 libMesh::UniquePtr<libMesh::FEBase> fe_face (libMesh::FEBase::build(dim, fe_type));
273 libMesh::QGauss qface(dim-1, fe_type.default_quadrature_order());
274 fe_face->attach_quadrature_rule (&qface);
277 const std::vector<libMesh::Real>& JxW = fe->get_JxW();
280 const std::vector<std::vector<libMesh::RealGradient> >& dphi = fe->get_dphi();
283 const std::vector<libMesh::Point>& qp_points = fe->get_xyz();
286 double weight_alpha = 1;
288 libMesh::DenseMatrix<libMesh::Number> Ke;
289 libMesh::DenseVector<libMesh::Number> Fe;
291 libMesh::DenseSubMatrix<libMesh::Number>
292 Kuu(Ke), Kuv(Ke), Kuw(Ke),
293 Kvu(Ke), Kvv(Ke), Kvw(Ke),
294 Kwu(Ke), Kwv(Ke), Kww(Ke);
296 libMesh::DenseSubVector<libMesh::Number>
301 std::vector<libMesh::dof_id_type> dof_indices;
302 std::vector<libMesh::dof_id_type> dof_indices_u;
303 std::vector<libMesh::dof_id_type> dof_indices_v;
304 std::vector<libMesh::dof_id_type> dof_indices_w;
306 libMesh::MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
307 const libMesh::MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
309 perf_log.pop(
"Preamble");
312 for ( ; el != end_el; ++el)
315 const libMesh::Elem* elem = *el;
317 perf_log.push(
"Define DoF");
319 dof_map.dof_indices (elem, dof_indices);
320 dof_map.dof_indices (elem, dof_indices_u, u_var);
321 dof_map.dof_indices (elem, dof_indices_v, v_var);
322 dof_map.dof_indices (elem, dof_indices_w, w_var);
324 const unsigned int n_dofs = dof_indices.size();
325 const unsigned int n_u_dofs = dof_indices_u.size();
326 const unsigned int n_v_dofs = dof_indices_v.size();
327 const unsigned int n_w_dofs = dof_indices_w.size();
329 perf_log.pop(
"Define DoF");
337 perf_log.push(
"Matrix manipulations");
338 Ke.resize (n_dofs, n_dofs);
342 Kuu.reposition (u_var*n_u_dofs, u_var*n_u_dofs, n_u_dofs, n_u_dofs);
343 Kuv.reposition (u_var*n_u_dofs, v_var*n_u_dofs, n_u_dofs, n_v_dofs);
344 Kuw.reposition (u_var*n_u_dofs, w_var*n_u_dofs, n_u_dofs, n_w_dofs);
346 Kvu.reposition (v_var*n_u_dofs, u_var*n_u_dofs, n_v_dofs, n_u_dofs);
347 Kvv.reposition (v_var*n_u_dofs, v_var*n_u_dofs, n_v_dofs, n_v_dofs);
348 Kvw.reposition (v_var*n_u_dofs, w_var*n_u_dofs, n_v_dofs, n_w_dofs);
350 Kwu.reposition (w_var*n_u_dofs, u_var*n_u_dofs, n_w_dofs, n_u_dofs);
351 Kwv.reposition (w_var*n_u_dofs, v_var*n_u_dofs, n_w_dofs, n_v_dofs);
352 Kww.reposition (w_var*n_u_dofs, w_var*n_u_dofs, n_w_dofs, n_w_dofs);
354 Fu.reposition (u_var*n_u_dofs, n_u_dofs);
355 Fv.reposition (v_var*n_u_dofs, n_v_dofs);
356 Fw.reposition (w_var*n_u_dofs, n_w_dofs);
357 perf_log.push(
"Matrix manipulations");
360 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
363 perf_log.push(
"Rigidity",
"Matrix element calculations");
364 weight_alpha = weight_mask.
get_alpha(qp_points[qp],system_type);
367 Update_SubK_isotropic(Kuu, qp, 0, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
368 Update_SubK_isotropic(Kuv, qp, 0, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
369 Update_SubK_isotropic(Kuw, qp, 0, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
371 Update_SubK_isotropic(Kvu, qp, 1, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
372 Update_SubK_isotropic(Kvv, qp, 1, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
373 Update_SubK_isotropic(Kvw, qp, 1, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
375 Update_SubK_isotropic(Kwu, qp, 2, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
376 Update_SubK_isotropic(Kwv, qp, 2, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
377 Update_SubK_isotropic(Kww, qp, 2, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
379 perf_log.pop(
"Rigidity",
"Matrix element calculations");
383 perf_log.push(
"Constraints",
"Matrix element calculations");
384 dof_map.heterogenously_constrain_element_matrix_and_vector(Ke, Fe, dof_indices);
385 perf_log.pop(
"Constraints",
"Matrix element calculations");
387 perf_log.push(
"Adding elements");
388 system.matrix->add_matrix (Ke, dof_indices);
389 system.rhs->add_vector (Fe, dof_indices);
390 perf_log.pop(
"Adding elements");
393 system.matrix->close();
398 const std::string& system_name,
401 int traction_boundary_id,
402 std::vector<double> traction_density)
405 libmesh_assert_equal_to(system_name,
"Elasticity");
409 perf_log.push(
"Preamble");
411 const libMesh::MeshBase& mesh = es.get_mesh();
413 const unsigned int dim = mesh.mesh_dimension();
416 libMesh::ExplicitSystem& physical_param_system = es.get_system<libMesh::ExplicitSystem>(
"PhysicalConstants");
417 const unsigned int young_var = physical_param_system.variable_number (
"E");
418 const unsigned int mu_var = physical_param_system.variable_number (
"mu");
420 const libMesh::DofMap& physical_dof_map = physical_param_system.get_dof_map();
421 std::vector<libMesh::dof_id_type> physical_dof_indices_var;
424 const libMesh::Elem* phys_elem = *(mesh.active_local_elements_begin());
425 physical_dof_map.dof_indices(phys_elem, physical_dof_indices_var, young_var);
426 libMesh::Number localE = physical_param_system.current_solution(physical_dof_indices_var[0]);
428 physical_dof_map.dof_indices(phys_elem, physical_dof_indices_var, mu_var);
429 libMesh::Number localMu = physical_param_system.current_solution(physical_dof_indices_var[0]);
432 libMesh::LinearImplicitSystem& system = es.get_system<libMesh::LinearImplicitSystem>(
"Elasticity");
434 const unsigned int n_components = 3;
435 const unsigned int u_var = system.variable_number (
"u");
436 const unsigned int v_var = system.variable_number (
"v");
437 const unsigned int w_var = system.variable_number (
"w");
439 const libMesh::DofMap& dof_map = system.get_dof_map();
440 libMesh::FEType fe_type = dof_map.variable_type(u_var);
444 libMesh::UniquePtr<libMesh::FEBase> fe (libMesh::FEBase::build(dim, fe_type));
445 libMesh::QGauss qrule (dim, fe_type.default_quadrature_order());
446 fe->attach_quadrature_rule (&qrule);
449 libMesh::UniquePtr<libMesh::FEBase> fe_face (libMesh::FEBase::build(dim, fe_type));
450 libMesh::QGauss qface(dim-1, fe_type.default_quadrature_order());
451 fe_face->attach_quadrature_rule (&qface);
454 libMesh::DenseVector<libMesh::Number> g_vec(3);
455 g_vec(0) = traction_density[0];
456 g_vec(1) = traction_density[1];
457 g_vec(2) = traction_density[2];
460 const std::vector<libMesh::Real>& JxW = fe->get_JxW();
463 const std::vector<std::vector<libMesh::RealGradient> >& dphi = fe->get_dphi();
466 const std::vector<libMesh::Point>& qp_points = fe->get_xyz();
469 const std::vector<libMesh::Real> & JxW_face = fe_face->get_JxW();
472 const std::vector<std::vector<libMesh::Real> > & phi_face = fe_face->get_phi();
475 const std::vector<libMesh::Point>& qp_face_points = fe_face->get_xyz();
479 double weight_alpha = 1;
481 libMesh::DenseMatrix<libMesh::Number> Ke;
482 libMesh::DenseVector<libMesh::Number> Fe;
484 libMesh::DenseSubMatrix<libMesh::Number>
485 Kuu(Ke), Kuv(Ke), Kuw(Ke),
486 Kvu(Ke), Kvv(Ke), Kvw(Ke),
487 Kwu(Ke), Kwv(Ke), Kww(Ke);
489 libMesh::DenseSubVector<libMesh::Number>
494 std::vector<libMesh::dof_id_type> dof_indices;
495 std::vector<libMesh::dof_id_type> dof_indices_u;
496 std::vector<libMesh::dof_id_type> dof_indices_v;
497 std::vector<libMesh::dof_id_type> dof_indices_w;
499 libMesh::MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
500 const libMesh::MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
502 perf_log.pop(
"Preamble");
505 for ( ; el != end_el; ++el)
508 const libMesh::Elem* elem = *el;
510 perf_log.push(
"Define DoF");
512 dof_map.dof_indices (elem, dof_indices);
513 dof_map.dof_indices (elem, dof_indices_u, u_var);
514 dof_map.dof_indices (elem, dof_indices_v, v_var);
515 dof_map.dof_indices (elem, dof_indices_w, w_var);
517 const unsigned int n_dofs = dof_indices.size();
518 const unsigned int n_u_dofs = dof_indices_u.size();
519 const unsigned int n_v_dofs = dof_indices_v.size();
520 const unsigned int n_w_dofs = dof_indices_w.size();
522 perf_log.pop(
"Define DoF");
530 perf_log.push(
"Matrix manipulations");
531 Ke.resize (n_dofs, n_dofs);
535 Kuu.reposition (u_var*n_u_dofs, u_var*n_u_dofs, n_u_dofs, n_u_dofs);
536 Kuv.reposition (u_var*n_u_dofs, v_var*n_u_dofs, n_u_dofs, n_v_dofs);
537 Kuw.reposition (u_var*n_u_dofs, w_var*n_u_dofs, n_u_dofs, n_w_dofs);
539 Kvu.reposition (v_var*n_u_dofs, u_var*n_u_dofs, n_v_dofs, n_u_dofs);
540 Kvv.reposition (v_var*n_u_dofs, v_var*n_u_dofs, n_v_dofs, n_v_dofs);
541 Kvw.reposition (v_var*n_u_dofs, w_var*n_u_dofs, n_v_dofs, n_w_dofs);
543 Kwu.reposition (w_var*n_u_dofs, u_var*n_u_dofs, n_w_dofs, n_u_dofs);
544 Kwv.reposition (w_var*n_u_dofs, v_var*n_u_dofs, n_w_dofs, n_v_dofs);
545 Kww.reposition (w_var*n_u_dofs, w_var*n_u_dofs, n_w_dofs, n_w_dofs);
547 Fu.reposition (u_var*n_u_dofs, n_u_dofs);
548 Fv.reposition (v_var*n_u_dofs, n_v_dofs);
549 Fw.reposition (w_var*n_u_dofs, n_w_dofs);
550 perf_log.push(
"Matrix manipulations");
553 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
556 perf_log.push(
"Rigidity",
"Matrix element calculations");
557 weight_alpha = weight_mask.
get_alpha(qp_points[qp],system_type);
560 Update_SubK_isotropic(Kuu, qp, 0, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
561 Update_SubK_isotropic(Kuv, qp, 0, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
562 Update_SubK_isotropic(Kuw, qp, 0, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
564 Update_SubK_isotropic(Kvu, qp, 1, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
565 Update_SubK_isotropic(Kvv, qp, 1, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
566 Update_SubK_isotropic(Kvw, qp, 1, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
568 Update_SubK_isotropic(Kwu, qp, 2, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
569 Update_SubK_isotropic(Kwv, qp, 2, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
570 Update_SubK_isotropic(Kww, qp, 2, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
572 perf_log.pop(
"Rigidity",
"Matrix element calculations");
576 for (
unsigned int side=0; side<elem->n_sides(); side++)
578 if (elem->neighbor_ptr(side) == libmesh_nullptr)
580 fe_face->reinit(elem, side);
583 for (
unsigned int qp=0; qp<qface.n_points(); qp++)
585 weight_alpha = weight_mask.
get_alpha(qp_face_points[qp],system_type);
587 if (mesh.get_boundary_info().has_boundary_id(elem, side, traction_boundary_id))
589 for (
unsigned int dof_iii=0; dof_iii<n_u_dofs; dof_iii++)
591 Fu(dof_iii) += weight_alpha * JxW_face[qp] * (g_vec(0) * phi_face[dof_iii][qp]);
592 Fv(dof_iii) += weight_alpha * JxW_face[qp] * (g_vec(1) * phi_face[dof_iii][qp]);
593 Fw(dof_iii) += weight_alpha * JxW_face[qp] * (g_vec(2) * phi_face[dof_iii][qp]);
601 perf_log.push(
"Constraints",
"Matrix element calculations");
602 dof_map.heterogenously_constrain_element_matrix_and_vector(Ke, Fe, dof_indices);
603 perf_log.pop(
"Constraints",
"Matrix element calculations");
605 perf_log.push(
"Adding elements");
606 system.matrix->add_matrix (Ke, dof_indices);
607 system.rhs->add_vector (Fe, dof_indices);
608 perf_log.pop(
"Adding elements");
611 system.matrix->close();
616 const std::string& system_name,
620 libmesh_assert_equal_to (system_name,
"Elasticity");
624 perf_log.push(
"Preamble");
626 const libMesh::MeshBase& mesh = es.get_mesh();
628 const unsigned int dim = mesh.mesh_dimension();
631 libMesh::Number localE = -1;
632 libMesh::Number localMu = -1;
634 libMesh::ExplicitSystem& physical_param_system = es.get_system<libMesh::ExplicitSystem>(
"PhysicalConstants");
635 const unsigned int young_var = physical_param_system.variable_number (
"E");
636 const unsigned int mu_var = physical_param_system.variable_number (
"mu");
638 const libMesh::DofMap& physical_dof_map = physical_param_system.get_dof_map();
639 std::vector<libMesh::dof_id_type> physical_dof_indices_var;
642 libMesh::LinearImplicitSystem& system = es.get_system<libMesh::LinearImplicitSystem>(
"Elasticity");
644 const unsigned int n_components = 3;
645 const unsigned int u_var = system.variable_number (
"u");
646 const unsigned int v_var = system.variable_number (
"v");
647 const unsigned int w_var = system.variable_number (
"w");
649 const libMesh::DofMap& dof_map = system.get_dof_map();
650 libMesh::FEType fe_type = dof_map.variable_type(u_var);
654 libMesh::UniquePtr<libMesh::FEBase> fe (libMesh::FEBase::build(dim, fe_type));
655 libMesh::QGauss qrule (dim, fe_type.default_quadrature_order());
656 fe->attach_quadrature_rule (&qrule);
659 libMesh::UniquePtr<libMesh::FEBase> fe_face (libMesh::FEBase::build(dim, fe_type));
660 libMesh::QGauss qface(dim-1, fe_type.default_quadrature_order());
661 fe_face->attach_quadrature_rule (&qface);
664 const std::vector<libMesh::Real>& JxW = fe->get_JxW();
667 const std::vector<std::vector<libMesh::RealGradient> >& dphi = fe->get_dphi();
670 const std::vector<libMesh::Point>& qp_points = fe->get_xyz();
673 double weight_alpha = 1;
675 libMesh::DenseMatrix<libMesh::Number> Ke;
676 libMesh::DenseVector<libMesh::Number> Fe;
678 libMesh::DenseSubMatrix<libMesh::Number>
679 Kuu(Ke), Kuv(Ke), Kuw(Ke),
680 Kvu(Ke), Kvv(Ke), Kvw(Ke),
681 Kwu(Ke), Kwv(Ke), Kww(Ke);
683 libMesh::DenseSubVector<libMesh::Number>
688 std::vector<libMesh::dof_id_type> dof_indices;
689 std::vector<libMesh::dof_id_type> dof_indices_u;
690 std::vector<libMesh::dof_id_type> dof_indices_v;
691 std::vector<libMesh::dof_id_type> dof_indices_w;
693 libMesh::MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
694 const libMesh::MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
696 perf_log.pop(
"Preamble");
699 for ( ; el != end_el; ++el)
702 const libMesh::Elem* elem = *el;
704 perf_log.push(
"Define DoF");
706 dof_map.dof_indices (elem, dof_indices);
707 dof_map.dof_indices (elem, dof_indices_u, u_var);
708 dof_map.dof_indices (elem, dof_indices_v, v_var);
709 dof_map.dof_indices (elem, dof_indices_w, w_var);
711 const unsigned int n_dofs = dof_indices.size();
712 const unsigned int n_u_dofs = dof_indices_u.size();
713 const unsigned int n_v_dofs = dof_indices_v.size();
714 const unsigned int n_w_dofs = dof_indices_w.size();
716 perf_log.pop(
"Define DoF");
718 perf_log.push(
"Define physical params");
720 physical_dof_map.dof_indices(elem, physical_dof_indices_var, young_var);
721 localE = physical_param_system.current_solution(physical_dof_indices_var[0]);
723 physical_dof_map.dof_indices(elem, physical_dof_indices_var, mu_var);
724 localMu = physical_param_system.current_solution(physical_dof_indices_var[0]);
725 perf_log.pop(
"Define physical params");
733 perf_log.push(
"Matrix manipulations");
734 Ke.resize (n_dofs, n_dofs);
738 Kuu.reposition (u_var*n_u_dofs, u_var*n_u_dofs, n_u_dofs, n_u_dofs);
739 Kuv.reposition (u_var*n_u_dofs, v_var*n_u_dofs, n_u_dofs, n_v_dofs);
740 Kuw.reposition (u_var*n_u_dofs, w_var*n_u_dofs, n_u_dofs, n_w_dofs);
742 Kvu.reposition (v_var*n_u_dofs, u_var*n_u_dofs, n_v_dofs, n_u_dofs);
743 Kvv.reposition (v_var*n_u_dofs, v_var*n_u_dofs, n_v_dofs, n_v_dofs);
744 Kvw.reposition (v_var*n_u_dofs, w_var*n_u_dofs, n_v_dofs, n_w_dofs);
746 Kwu.reposition (w_var*n_u_dofs, u_var*n_u_dofs, n_w_dofs, n_u_dofs);
747 Kwv.reposition (w_var*n_u_dofs, v_var*n_u_dofs, n_w_dofs, n_v_dofs);
748 Kww.reposition (w_var*n_u_dofs, w_var*n_u_dofs, n_w_dofs, n_w_dofs);
750 Fu.reposition (u_var*n_u_dofs, n_u_dofs);
751 Fv.reposition (v_var*n_u_dofs, n_v_dofs);
752 Fw.reposition (w_var*n_u_dofs, n_w_dofs);
753 perf_log.push(
"Matrix manipulations");
755 perf_log.push(
"Matrix element calculations");
757 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
760 perf_log.push(
"Rigidity",
"Matrix element calculations");
761 weight_alpha = weight_mask.
get_alpha(qp_points[qp],system_type);
764 Update_SubK_isotropic(Kuu, qp, 0, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
765 Update_SubK_isotropic(Kuv, qp, 0, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
766 Update_SubK_isotropic(Kuw, qp, 0, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
768 Update_SubK_isotropic(Kvu, qp, 1, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
769 Update_SubK_isotropic(Kvv, qp, 1, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
770 Update_SubK_isotropic(Kvw, qp, 1, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
772 Update_SubK_isotropic(Kwu, qp, 2, 0, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
773 Update_SubK_isotropic(Kwv, qp, 2, 1, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
774 Update_SubK_isotropic(Kww, qp, 2, 2, dphi, n_components, n_u_dofs, JxW, localE, localMu, weight_alpha);
776 perf_log.pop(
"Rigidity",
"Matrix element calculations");
780 perf_log.push(
"Constraints",
"Matrix element calculations");
781 dof_map.heterogenously_constrain_element_matrix_and_vector(Ke, Fe, dof_indices);
782 perf_log.pop(
"Constraints",
"Matrix element calculations");
784 perf_log.push(
"Adding elements");
785 system.matrix->add_matrix (Ke, dof_indices);
786 system.rhs->add_vector (Fe, dof_indices);
787 perf_log.pop(
"Adding elements");
790 system.matrix->close();
797 const libMesh::MeshBase& mesh = es.get_mesh();
799 const unsigned int dim = mesh.mesh_dimension();
802 libMesh::LinearImplicitSystem& elasticity_system = es.get_system<libMesh::LinearImplicitSystem>(
"Elasticity");
805 unsigned int displacement_vars[3];
806 displacement_vars[0] = elasticity_system.variable_number (
"u");
807 displacement_vars[1] = elasticity_system.variable_number (
"v");
808 displacement_vars[2] = elasticity_system.variable_number (
"w");
809 const unsigned int u_var = elasticity_system.variable_number (
"u");
812 libMesh::ExplicitSystem& physical_param_system = es.get_system<libMesh::ExplicitSystem>(
"PhysicalConstants");
813 const unsigned int young_var = physical_param_system.variable_number (
"E");
814 const unsigned int mu_var = physical_param_system.variable_number (
"mu");
816 const libMesh::DofMap& physical_dof_map = physical_param_system.get_dof_map();
817 std::vector<libMesh::dof_id_type> physical_dof_indices_var;
820 const libMesh::Elem* phys_elem = *(mesh.active_local_elements_begin());
821 physical_dof_map.dof_indices(phys_elem, physical_dof_indices_var, young_var);
822 libMesh::Number localE = physical_param_system.current_solution(physical_dof_indices_var[0]);
824 physical_dof_map.dof_indices(phys_elem, physical_dof_indices_var, mu_var);
825 libMesh::Number localMu = physical_param_system.current_solution(physical_dof_indices_var[0]);
829 const libMesh::DofMap& elasticity_dof_map = elasticity_system.get_dof_map();
832 libMesh::FEType fe_type = elasticity_dof_map.variable_type(u_var);
835 libMesh::UniquePtr<libMesh::FEBase> fe (libMesh::FEBase::build(dim, fe_type));
836 libMesh::QGauss qrule (dim, fe_type.default_quadrature_order());
837 fe->attach_quadrature_rule (&qrule);
842 const std::vector<libMesh::Real>& JxW = fe->get_JxW();
843 const std::vector<std::vector<libMesh::RealGradient> >& dphi = fe->get_dphi();
846 libMesh::ExplicitSystem& stress_system = es.get_system<libMesh::ExplicitSystem>(
"StressSystem");
847 const libMesh::DofMap& stress_dof_map = stress_system.get_dof_map();
850 unsigned int sigma_vars[3][3];
851 sigma_vars[0][0] = stress_system.variable_number (
"sigma_00");
852 sigma_vars[0][1] = stress_system.variable_number (
"sigma_01");
853 sigma_vars[0][2] = stress_system.variable_number (
"sigma_02");
854 sigma_vars[1][0] = stress_system.variable_number (
"sigma_10");
855 sigma_vars[1][1] = stress_system.variable_number (
"sigma_11");
856 sigma_vars[1][2] = stress_system.variable_number (
"sigma_12");
857 sigma_vars[2][0] = stress_system.variable_number (
"sigma_20");
858 sigma_vars[2][1] = stress_system.variable_number (
"sigma_21");
859 sigma_vars[2][2] = stress_system.variable_number (
"sigma_22");
860 unsigned int vonMises_var = stress_system.variable_number (
"vonMises");
863 std::vector< std::vector<libMesh::dof_id_type> > elasticity_dof_indices_var(elasticity_system.n_vars());
866 std::vector<libMesh::dof_id_type> stress_dof_indices_var;
869 libMesh::DenseMatrix<libMesh::Number> elem_sigma;
872 libMesh::MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
873 const libMesh::MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
875 for ( ; el != end_el; ++el)
877 const libMesh::Elem* elem = *el;
883 for(
unsigned int var=0; var<3; var++)
885 elasticity_dof_map.dof_indices (elem, elasticity_dof_indices_var[var], displacement_vars[var]);
888 physical_dof_map.dof_indices(elem, physical_dof_indices_var, young_var);
889 localE = physical_param_system.current_solution(physical_dof_indices_var[0]);
891 physical_dof_map.dof_indices(elem, physical_dof_indices_var, mu_var);
892 localMu = physical_param_system.current_solution(physical_dof_indices_var[0]);
896 elem_sigma.resize(3,3);
899 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
901 for(
unsigned int C_i=0; C_i<3; C_i++)
903 for(
unsigned int C_j=0; C_j<3; C_j++)
905 for(
unsigned int C_k=0; C_k<3; C_k++)
908 const unsigned int n_var_dofs = elasticity_dof_indices_var[C_k].size();
910 libMesh::Gradient displacement_gradient_k;
911 for(
unsigned int l=0; l<n_var_dofs; l++)
921 displacement_gradient_k.add_scaled(dphi[l][qp], elasticity_system.current_solution(elasticity_dof_indices_var[C_k][l]));
924 for(
unsigned int C_l=0; C_l<3; C_l++)
927 elem_sigma(C_i,C_j) += JxW[qp]*(
eval_elasticity_tensor(C_i,C_j,C_k,C_l,localE,localMu) * displacement_gradient_k(C_l) );
935 elem_sigma.scale(1./elem->volume());
937 for(
unsigned int i=0; i<3; i++)
939 for(
unsigned int j=0; j<3; j++)
942 stress_dof_map.dof_indices(elem, stress_dof_indices_var, sigma_vars[i][j]);
946 libMesh::dof_id_type dof_index = stress_dof_indices_var[0];
949 if( (stress_system.solution->first_local_index() <= dof_index) &&
950 (dof_index < stress_system.solution->last_local_index()) )
952 stress_system.solution->set(dof_index, elem_sigma(i,j));
958 libMesh::Number vonMises_value = std::sqrt( 0.5*( pow(elem_sigma(0,0) - elem_sigma(1,1),2.) +
959 pow(elem_sigma(1,1) - elem_sigma(2,2),2.) +
960 pow(elem_sigma(2,2) - elem_sigma(0,0),2.) +
961 6.*(pow(elem_sigma(0,1),2.) + pow(elem_sigma(1,2),2.) + pow(elem_sigma(2,0),2.))
965 stress_dof_map.dof_indices (elem, stress_dof_indices_var, vonMises_var);
969 libMesh::dof_id_type dof_index = stress_dof_indices_var[0];
972 if( (stress_system.solution->first_local_index() <= dof_index) &&
973 (dof_index < stress_system.solution->last_local_index()) )
975 stress_system.solution->set(dof_index, vonMises_value);
980 stress_system.solution->close();
981 stress_system.update();
void set_homogeneous_physical_properties(libMesh::EquationSystems &es, std::string &physicalParamsFile)
Set the homogeneous physical properties from a file.
void assemble_elasticity_with_weight_and_traction(libMesh::EquationSystems &es, const std::string &system_name, weight_parameter_function &weight_mask, WeightFunctionSystemType system_type, int traction_boundary_id, std::vector< double > traction_density)
Assemble homogeneous elasticity with domain weights and traction.
libMesh::Real eval_elasticity_tensor(unsigned int i, unsigned int j, unsigned int k, unsigned int l, libMesh::Number E, libMesh::Number mu)
Calculate the elasticity tensor.
void set_heterogeneous_physical_properties(libMesh::EquationSystems &es, std::string &physicalParamsFile)
Set the heterogeneous, isotropic physical properties from a file.
int kronecker_delta(unsigned int i, unsigned int j)
void compute_stresses(libMesh::EquationSystems &es)
Compute the stress (based on one of libMesh's examples)
WeightFunctionSystemType
Enumerate used to define which weight function must be used to assemble the system.
void assemble_elasticity_with_weight(libMesh::EquationSystems &es, const std::string &system_name, weight_parameter_function &weight_mask, WeightFunctionSystemType system_type)
Assemble homogeneous elasticity with domain weights.
void assemble_elasticity_heterogeneous_with_weight(libMesh::EquationSystems &es, const std::string &system_name, weight_parameter_function &weight_mask, WeightFunctionSystemType system_type)
Assemble heterogeneous elasticity with domain weights.
double get_alpha(const libMesh::Point &qpoint, WeightFunctionSystemType system_type)
libMesh::Real eval_lambda_1(libMesh::Real E, libMesh::Real mu)
Calculate lambda_1 from E and Mu.
const bool MASTER_bPerfLog_assemble_fem
void Update_SubK_isotropic(libMesh::DenseSubMatrix< libMesh::Number > &SubK, unsigned int qp, unsigned int C_i, unsigned int C_k, const std::vector< std::vector< libMesh::RealGradient > > &dphi, const unsigned int n_components, const unsigned int n_u_dofs, const std::vector< libMesh::Real > &JxW, libMesh::Number E, libMesh::Number mu, double cte)
Calculate the rigidity sub-matrix contribution.