CArl
Code Arlequin / C++ implementation
anisotropic_elasticity_cubic_sym.cpp
Go to the documentation of this file.
1 /*
2  * anisotropic_elasticity_cubic_sym.cpp
3  *
4  * Created on: Sep 4, 2016
5  * Author: Thiago Milanetto Schlittler
6  */
7 
8 /*
9  * assemble_functions_elasticity_anisotropy.cpp
10  *
11  * Created on: Sep 3, 2016
12  * Author: Thiago Milanetto Schlittler
13  */
14 
16 
17 void carl::anisotropic_elasticity_tensor_cubic_sym::set_parameters(libMesh::EquationSystems& es, std::string& physicalParamsFile)
18 {
19  const libMesh::Parallel::Communicator& SysComm = es.comm();
20  int rank = SysComm.rank();
21  int nodes = SysComm.size();
22  std::vector<int> temp_idx;
23 
24  // Read the random data info
25  if(rank == 0)
26  {
27  std::ifstream physicalParamsIFS(physicalParamsFile);
28  physicalParamsIFS >> m_nb_grains >> m_c11 >> m_c12 >> m_c44;
29  m_angles_x.resize(m_nb_grains);
30  m_angles_y.resize(m_nb_grains);
31  m_angles_z.resize(m_nb_grains);
32  temp_idx.resize(m_nb_grains);
33  m_domain_to_vec_map.reserve(m_nb_grains);
34 
35  for(int iii = 0; iii < m_nb_grains; ++iii)
36  {
37  physicalParamsIFS >> m_angles_x[iii];
38  physicalParamsIFS >> m_angles_y[iii];
39  physicalParamsIFS >> m_angles_z[iii];
40  physicalParamsIFS >> temp_idx[iii];
41  }
42 
43  physicalParamsIFS.close();
44  }
45 
46  if(nodes > 1)
47  {
48  SysComm.broadcast(m_c11);
49  SysComm.broadcast(m_c12);
50  SysComm.broadcast(m_c44);
51  SysComm.broadcast(m_nb_grains);
52 
53  if(rank != 0)
54  {
55  m_angles_x.resize(m_nb_grains);
56  m_angles_y.resize(m_nb_grains);
57  m_angles_z.resize(m_nb_grains);
58  temp_idx.resize(m_nb_grains);
59  m_domain_to_vec_map.reserve(m_nb_grains);
60  }
61  SysComm.broadcast(m_angles_x);
62  SysComm.broadcast(m_angles_y);
63  SysComm.broadcast(m_angles_z);
64  SysComm.broadcast(temp_idx);
65  }
66 
67  for(int iii = 0; iii < m_nb_grains; ++iii)
68  {
69  m_domain_to_vec_map[temp_idx[iii]] = iii;
70  }
71 
72  m_Rotation_matrices.resize(m_nb_grains,libMesh::DenseMatrix<libMesh::Real>(3,3));
73  m_Elasticity_tensors.resize(m_nb_grains);
74  for(int iii = 0; iii < m_nb_grains; ++iii)
75  {
76  m_Elasticity_tensors[iii].set_dimension(3);
77  }
78 
79  // Mesh pointer
80  const libMesh::MeshBase& mesh = es.get_mesh();
81 
82  // Indexes
83  libMesh::ExplicitSystem& physical_param_system = es.get_system<libMesh::ExplicitSystem>("PhysicalConstants");
84  const libMesh::DofMap& physical_dof_map = physical_param_system.get_dof_map();
85 
86  unsigned int physical_consts[7];
87  physical_consts[0] = physical_param_system.variable_number ("Index");
88  physical_consts[1] = physical_param_system.variable_number ("Angle_x");
89  physical_consts[2] = physical_param_system.variable_number ("Angle_y");
90  physical_consts[3] = physical_param_system.variable_number ("Angle_z");
91  physical_consts[4] = physical_param_system.variable_number ("color_r");
92  physical_consts[5] = physical_param_system.variable_number ("color_g");
93  physical_consts[6] = physical_param_system.variable_number ("color_b");
94 
95  // Calculate the rotation matrices
96  this->generate_rotation_matrices();
97 
98  // And generate the elasticity tensors
99  this->generate_elasticity_tensors();
100 
101  std::vector<libMesh::dof_id_type> physical_dof_indices_var;
102  libMesh::MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
103  const libMesh::MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
104 
105  for ( ; el != end_el; ++el)
106  {
107  const libMesh::Elem* elem = *el;
108 
109  // Grain index
110  physical_dof_map.dof_indices(elem, physical_dof_indices_var, physical_consts[0]);
111  libMesh::dof_id_type dof_index = physical_dof_indices_var[0];
112 
113  if( (physical_param_system.solution->first_local_index() <= dof_index) &&
114  (dof_index < physical_param_system.solution->last_local_index()) )
115  {
116  physical_param_system.solution->set(dof_index, elem->subdomain_id());
117  }
118  }
119 
120  physical_param_system.solution->close();
121  physical_param_system.update();
122 }
123 
124 void carl::anisotropic_elasticity_tensor_cubic_sym::generate_rotation_matrices()
125 {
126  double phi, theta, psi;
127  double c_phi, c_theta, c_psi;
128  double s_phi, s_theta, s_psi;
129  for(int iii = 0; iii < m_nb_grains; ++iii)
130  {
131  phi = m_angles_x[iii];
132  theta = m_angles_y[iii];
133  psi = m_angles_z[iii];
134 
135  s_phi = sin(phi); c_phi = cos(phi);
136  s_theta = sin(theta); c_theta = cos(theta);
137  s_psi = sin(psi); c_psi = cos(psi);
138 
139  m_Rotation_matrices[iii](0,0) = c_theta;
140  m_Rotation_matrices[iii](0,1) = - s_theta * c_psi;
141  m_Rotation_matrices[iii](0,2) = s_theta * s_psi;
142 
143  m_Rotation_matrices[iii](1,0) = c_phi * s_theta;
144  m_Rotation_matrices[iii](1,1) = c_phi * c_theta * c_psi
145  - s_phi * s_psi;
146  m_Rotation_matrices[iii](1,2) = - s_phi * c_psi
147  - c_phi * c_theta * s_psi;
148 
149  m_Rotation_matrices[iii](2,0) = s_phi * s_theta;
150  m_Rotation_matrices[iii](2,1) = c_phi * s_psi
151  + s_phi * c_theta * c_psi;
152  m_Rotation_matrices[iii](2,2) = c_phi * c_psi
153  - s_phi * c_theta * s_psi;
154  }
155 }
156 
157 void carl::anisotropic_elasticity_tensor_cubic_sym::generate_elasticity_tensors()
158 {
159  for(int nnn = 0; nnn < m_nb_grains; ++nnn)
160  {
161  libMesh::DenseMatrix<libMesh::Real>& R = m_Rotation_matrices[nnn];
162  Order4Tensor& C = m_Elasticity_tensors[nnn];
163 
164  for(unsigned int iii = 0; iii < 3; ++iii)
165  for(unsigned int jjj = 0; jjj < 3; ++jjj)
166  for(unsigned int kkk = 0; kkk < 3; ++kkk)
167  for(unsigned int lll = 0; lll < 3; ++lll)
168  {
169  // Contraction indexes
170  for(unsigned int ppp = 0; ppp < 3; ++ppp)
171  for(unsigned int qqq = 0; qqq < 3; ++qqq)
172  for(unsigned int rrr = 0; rrr < 3; ++rrr)
173  for(unsigned int sss = 0; sss < 3; ++sss)
174  {
175  C(iii,jjj,kkk,lll)+= R(iii,ppp) * R(jjj,qqq) * R(kkk,rrr) * R(lll,sss) *
176  this->eval_internal_elasticity_tensor(ppp,qqq,rrr,sss);
177  }
178  }
179  }
180 }
181 
182 libMesh::Real carl::anisotropic_elasticity_tensor_cubic_sym::eval_internal_elasticity_tensor(unsigned int i,
183  unsigned int j,
184  unsigned int k,
185  unsigned int l)
186 {
187  double output = 0;
188 
189  if(i == j && k == l)
190  {
191  if(i == k && j == l)
192  {
193  output = m_c11;
194  }
195  else
196  {
197  output = m_c12;
198  }
199  }
200  else if( (i == k && j == l) || (i == l && j == k) )
201  {
202  output = m_c44;
203  }
204 
205  return output;
206 }
207 
208 libMesh::DenseMatrix<libMesh::Real>& carl::anisotropic_elasticity_tensor_cubic_sym::get_rotation(int idx_grain)
209 {
210  return m_Rotation_matrices[m_domain_to_vec_map[idx_grain]];
211 }
212 
213 carl::Order4Tensor& carl::anisotropic_elasticity_tensor_cubic_sym::get_elasticity(int idx_grain)
214 {
215  return m_Elasticity_tensors[m_domain_to_vec_map[idx_grain]];
216 }
217 
219  unsigned int j,
220  unsigned int k,
221  unsigned int l,
222  int idx_grain)
223 {
224  Order4Tensor& C = get_elasticity(idx_grain);
225 
226  return C(i,j,k,l);
227 }
228 
229 
230 
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.