1 #ifndef HELPER_FUNCTIONS 2 #define HELPER_FUNCTIONS 13 #include <deal.II/base/exceptions.h> 14 #include <deal.II/lac/vector.h> 16 #include <gsl/gsl_integration.h> 17 #include <gsl/gsl_sf_gamma.h> 37 for(
unsigned int i=0; i<dim; ++i)
38 for(
unsigned int j=0; j<dim; ++j)
39 for(
unsigned int k=0; k<dim; ++k)
40 for(
unsigned int l=k; l<dim; ++l)
42 double tmp_scalar = Ma[i][k] * Mb[j][l] + Ma[i][l] * Mb[j][k];
43 tmp[i][j][k][l] = tmp_scalar;
44 tmp[i][j][l][k] = tmp_scalar;
54 const SymmetricTensor<2,dim> &Mb,
55 const SymmetricTensor<2,dim> &Mc,
56 const SymmetricTensor<2,dim> &T )
60 Tensor<2,dim> temp_tensor = contract<1,0>((Tensor<2,dim>)T, (Tensor<2,dim>)Mc);
61 Tensor<2,dim> MbTMc = contract<1,0>((Tensor<2,dim>)Mb,temp_tensor);
63 for(
unsigned int i=0; i<dim; ++i)
64 for(
unsigned int j=0; j<dim; ++j)
65 for(
unsigned int k=0; k<dim; ++k)
66 for(
unsigned int l=k; l<dim; ++l)
68 double tmp_scalar = Ma[i][k] * MbTMc[j][l] + Ma[i][l] * MbTMc[j][k];
69 tmp[i][j][k][l] = tmp_scalar;
70 tmp[i][j][l][k] = tmp_scalar;
80 const SymmetricTensor<2,dim> &Mb,
81 const SymmetricTensor<2,dim> &Mc,
82 const SymmetricTensor<2,dim> &T){
85 Tensor<2,dim> temp_tensor = contract<1,0>((Tensor<2,dim>)T, (Tensor<2,dim>)Mb);
86 Tensor<2,dim> MaTMb = contract<1,0>((Tensor<2,dim>)Ma,temp_tensor);
88 for(
unsigned int i=0; i<dim; ++i)
89 for(
unsigned int j=0; j<dim; ++j)
90 for(
unsigned int k=0; k<dim; ++k)
91 for(
unsigned int l=k; l<dim; ++l)
93 double tmp_scalar = MaTMb[i][k] * Mc[j][l] + MaTMb[i][l] * Mc[j][k];
94 tmp[i][j][k][l] = tmp_scalar;
95 tmp[i][j][l][k] = tmp_scalar;
106 #ifndef outer_product_sym_H 107 #define outer_product_sym_H 110 SymmetricTensor<4,dim>
outer_product_sym(
const SymmetricTensor<2,dim> &A,
const SymmetricTensor<2,dim> &B )
112 SymmetricTensor<4,dim> D;
115 for (
unsigned int i=0; i<dim; ++i )
116 for (
unsigned int j=i; j<dim; ++j )
117 for (
unsigned int k=i; k<dim; ++k )
118 for (
unsigned int l=k; l<dim; ++l )
120 double tmp = A[i][j] * B[k][l] + B[i][j] * A[k][l];
129 SymmetricTensor<4,dim> D;
132 for (
unsigned int i=0; i<dim; ++i )
133 for (
unsigned int j=i; j<dim; ++j )
134 for (
unsigned int k=i; k<dim; ++k )
135 for (
unsigned int l=k; l<dim; ++l )
137 double tmp = A[i][j] * A[k][l];
146 SymmetricTensor<2,dim> D;
149 for (
unsigned int i=0; i<dim; ++i )
150 for (
unsigned int j=i; j<dim; ++j )
151 D[i][j] = A[i] * A[j];
156 #endif //outer_product_sym_H 165 for (
unsigned int i=0; i<dim; i++ )
166 for (
unsigned int j=0; j<dim; j++ )
167 if ( i!=j && ( std::abs(tensor[i][j] - tensor[j][i])>1e-12 ) )
174 for(
unsigned int i=0; i<dim; ++i){
175 for(
unsigned int j=0; j<dim; ++j){
176 for(
unsigned int k=0; k<dim; ++k){
177 for(
unsigned int l=0; l<dim; ++l){
179 if( ( fabs(temp[i][j][k][l] - temp[j][i][k][l]) > 1e-6 )
181 ( fabs(temp[i][j][k][l] - temp[i][j][l][k]) > 1e-6 ) )
184 if( (fabs(fabs(temp[i][j][k][l] - temp[j][i][k][l])/temp[j][i][k][l])> 1e-8)
186 (fabs(fabs(temp[i][j][k][l] - temp[i][j][l][k])/temp[i][j][l][k]) >1e-8) )
189 deallog<<
"Abs not matching: "<<fabs(temp[i][j][k][l] - temp[j][i][k][l])
190 <<
" | Rel not matching: "<<fabs(temp[i][j][k][l] - temp[j][i][k][l])/temp[j][i][k][l]
191 <<
" | Abs not matching: "<<fabs(temp[i][j][k][l] - temp[i][j][l][k])
192 <<
" | Rel not matching: "<<fabs(temp[i][j][k][l] - temp[i][j][l][k])/temp[i][j][l][k]
193 <<
" | value ijkl: "<< std::scientific << temp[i][j][k][l]
194 <<
" | value jikl: "<< std::scientific << temp[j][i][k][l]
195 <<
" | value ijlk: "<< std::scientific << temp[i][j][l][k]
209 SymmetricTensor<4,dim>
symmetrize(
const Tensor<4,dim> &tensor){
210 SymmetricTensor<4,dim> sym_tensor;
211 Assert(
symmetry_check(tensor), ExcMessage(
"Tensor to symmetrize is not symmetric!"));
213 Tensor<4,dim> temp_tensor;
214 for(
unsigned int i=0; i<dim; ++i)
215 for(
unsigned int j=0; j<dim; ++j)
216 for(
unsigned int k=0; k<dim; ++k)
217 for(
unsigned int l=0; l<dim; ++l)
218 temp_tensor[i][j][k][l] = (tensor[i][j][k][l]+tensor[j][i][k][l]+tensor[i][j][l][k]) / 3.0;
220 for(
unsigned int i=0; i<dim; ++i)
221 for(
unsigned int j=i; j<dim; ++j)
222 for(
unsigned int k=0; k<dim; ++k)
223 for(
unsigned int l=k; l<dim; ++l)
224 sym_tensor[i][j][k][l] = temp_tensor[i][j][k][l];
bool symmetry_check(Tensor< 2, dim > &tensor)
Definition: functions.h:163
Tensor< 4, dim > get_tensor_operator_F_right(const SymmetricTensor< 2, dim > &Ma, const SymmetricTensor< 2, dim > &Mb, const SymmetricTensor< 2, dim > &Mc, const SymmetricTensor< 2, dim > &T)
Definition: functions.h:53
SymmetricTensor< 4, dim > outer_product_sym(const SymmetricTensor< 2, dim > &A, const SymmetricTensor< 2, dim > &B)
Definition: functions.h:110
Tensor< 4, dim > get_tensor_operator_G(const SymmetricTensor< 2, dim > &Ma, const SymmetricTensor< 2, dim > &Mb)
Definition: functions.h:33
Tensor< 4, dim > get_tensor_operator_F_left(const SymmetricTensor< 2, dim > &Ma, const SymmetricTensor< 2, dim > &Mb, const SymmetricTensor< 2, dim > &Mc, const SymmetricTensor< 2, dim > &T)
Definition: functions.h:79
SymmetricTensor< 4, dim > symmetrize(const Tensor< 4, dim > &tensor)
Definition: functions.h:209