FourthOrderTensor.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "FourthOrderTensor.hpp"
00030
00032
00034
00035
00036 template<unsigned DIM>
00037 FourthOrderTensor<DIM>::FourthOrderTensor()
00038 {
00039
00040 assert(DIM>0);
00041 assert(DIM<4);
00042
00043 mDimSqd = DIM*DIM;
00044 mDimCubed = DIM*DIM*DIM;
00045 mDimToFour = DIM*DIM*DIM*DIM;
00046
00047
00048 mData.resize(mDimToFour, 0.0);
00049 }
00050
00051 template<unsigned DIM>
00052 void FourthOrderTensor<DIM>::SetAsProduct(FourthOrderTensor<DIM>& rTensor, const c_matrix<double,DIM,DIM>& rMatrix, unsigned component)
00053 {
00054 Zero();
00055
00056
00057 switch (component)
00058 {
00059 case 0:
00060 {
00061 for (unsigned M=0; M<DIM; M++)
00062 {
00063 for (unsigned N=0; N<DIM; N++)
00064 {
00065 for (unsigned P=0; P<DIM; P++)
00066 {
00067 for (unsigned Q=0; Q<DIM; Q++)
00068 {
00069 unsigned index = M*mDimCubed + N*mDimSqd + P*DIM + Q;
00070 for (unsigned s=0; s<DIM; s++)
00071 {
00072 mData[index] += rMatrix(M,s) * rTensor(s,N,P,Q);
00073 }
00074 }
00075 }
00076 }
00077 }
00078 break;
00079 }
00080 case 1:
00081 {
00082 for (unsigned M=0; M<DIM; M++)
00083 {
00084 for (unsigned N=0; N<DIM; N++)
00085 {
00086 for (unsigned P=0; P<DIM; P++)
00087 {
00088 for (unsigned Q=0; Q<DIM; Q++)
00089 {
00090 unsigned index = M*mDimCubed + N*mDimSqd + P*DIM + Q;
00091 for (unsigned s=0; s<DIM; s++)
00092 {
00093 mData[index] += rMatrix(N,s) * rTensor(M,s,P,Q);
00094 }
00095 }
00096 }
00097 }
00098 }
00099 break;
00100 }
00101 case 2:
00102 {
00103 for (unsigned M=0; M<DIM; M++)
00104 {
00105 for (unsigned N=0; N<DIM; N++)
00106 {
00107 for (unsigned P=0; P<DIM; P++)
00108 {
00109 for (unsigned Q=0; Q<DIM; Q++)
00110 {
00111 unsigned index = M*mDimCubed + N*mDimSqd + P*DIM + Q;
00112 for (unsigned s=0; s<DIM; s++)
00113 {
00114 mData[index] += rMatrix(P,s) * rTensor(M,N,s,Q);
00115 }
00116 }
00117 }
00118 }
00119 }
00120 break;
00121 }
00122 case 3:
00123 {
00124 for (unsigned M=0; M<DIM; M++)
00125 {
00126 for (unsigned N=0; N<DIM; N++)
00127 {
00128 for (unsigned P=0; P<DIM; P++)
00129 {
00130 for (unsigned Q=0; Q<DIM; Q++)
00131 {
00132 unsigned index = M*mDimCubed + N*mDimSqd + P*DIM + Q;
00133 for (unsigned s=0; s<DIM; s++)
00134 {
00135 mData[index] += rMatrix(Q,s) * rTensor(M,N,P,s);
00136 }
00137 }
00138 }
00139 }
00140 }
00141 break;
00142 }
00143 default:
00144 {
00145 EXCEPTION("Component not 0, 1, 2, or 3");
00146 }
00147 }
00148 }
00149
00150 template<unsigned DIM>
00151 double& FourthOrderTensor<DIM>::operator()(unsigned M, unsigned N, unsigned P, unsigned Q)
00152 {
00153 assert(M<DIM);
00154 assert(N<DIM);
00155 assert(P<DIM);
00156 assert(Q<DIM);
00157
00158 unsigned index = M*mDimCubed + N*mDimSqd + P*DIM + Q;
00159 return mData[index];
00160 }
00161
00162 template<unsigned DIM>
00163 void FourthOrderTensor<DIM>::Zero()
00164 {
00165 for (unsigned i=0; i<mDimToFour; i++)
00166 {
00167 mData[i] = 0.0;
00168 }
00169 }
00170
00172
00174
00175 template class FourthOrderTensor<1>;
00176 template class FourthOrderTensor<2>;
00177 template class FourthOrderTensor<3>;