AxisymmetricConductivityTensors.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
00030
00031
00032
00033
00034
00035
00036 #include <vector>
00037 #include "UblasIncludes.hpp"
00038 #include "AxisymmetricConductivityTensors.hpp"
00039 #include "Exception.hpp"
00040
00041
00042 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00043 AxisymmetricConductivityTensors<ELEMENT_DIM, SPACE_DIM>::AxisymmetricConductivityTensors()
00044 {
00045 if (SPACE_DIM != 3)
00046 {
00047 EXCEPTION("Axisymmetric anisotropic conductivity only makes sense in 3D");
00048 }
00049 }
00050
00051 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00052 void AxisymmetricConductivityTensors<ELEMENT_DIM, SPACE_DIM>::SetConstantConductivities(c_vector<double, 3> constantConductivities)
00053 {
00054
00055 if (constantConductivities[1] != constantConductivities[2])
00056 {
00057 EXCEPTION("Axisymmetric media defined: transversal and normal conductivities should have the same value");
00058 }
00059
00060 this->mUseNonConstantConductivities = false;
00061 this->mConstantConductivities = constantConductivities;
00062 }
00063
00064 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00065 void AxisymmetricConductivityTensors<ELEMENT_DIM, SPACE_DIM>::Init(AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> *pMesh) throw (Exception)
00066 {
00067 this->mpMesh = pMesh;
00068
00069 if (!this->mUseNonConstantConductivities && !this->mUseFibreOrientation)
00070 {
00071
00072 c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
00073
00074 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00075 {
00076 assert(this->mConstantConductivities(dim) != DBL_MAX);
00077 conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
00078 }
00079 this->mTensors.push_back(conductivity_matrix);
00080 }
00081 else
00082 {
00083 c_vector<double,SPACE_DIM> fibre_vector((zero_vector<double>(SPACE_DIM)));
00084 fibre_vector[0]=1.0;
00085
00086 if (this->mUseFibreOrientation)
00087 {
00088
00089 this->mFileReader.reset(new FibreReader<SPACE_DIM>(this->mFibreOrientationFile, AXISYM));
00090 if(this->mFileReader->GetNumLinesOfData() != this->mpMesh->GetNumElements())
00091 {
00092 EXCEPTION("The size of the fibre file does not match the number of elements in the mesh");
00093 }
00094 }
00095
00096 if (this->mUseNonConstantConductivities)
00097 {
00098 if(this->mpNonConstantConductivities->size() != this->mpMesh->GetNumLocalElements())
00099 {
00100 EXCEPTION("The size of the conductivities vector does not match the number of elements in the mesh");
00101 }
00102 }
00103
00104
00105
00106 this->mTensors.reserve(this->mpMesh->GetNumLocalElements());
00107
00108 c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
00109
00110 unsigned local_element_index = 0;
00111
00112 for (typename AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>::ElementIterator it = this->mpMesh->GetElementIteratorBegin();
00113 it != this->mpMesh->GetElementIteratorEnd();
00114 ++it)
00115 {
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 if (this->mUseNonConstantConductivities)
00142 {
00143 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00144 {
00145 conductivity_matrix(dim,dim) = (*this->mpNonConstantConductivities)[local_element_index][dim];
00146 }
00147 }
00148 else
00149 {
00150 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00151 {
00152 assert(this->mConstantConductivities(dim) != DBL_MAX);
00153 conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
00154 }
00155 }
00156
00157 if (this->mUseFibreOrientation)
00158 {
00159 unsigned current_fibre_global_index = it->GetIndex();
00160 this->mFileReader->GetFibreVector(current_fibre_global_index, fibre_vector);
00161 }
00162
00163 this->mTensors.push_back( conductivity_matrix(1,1) * identity_matrix<double>(SPACE_DIM) +
00164 (conductivity_matrix(0,0) - conductivity_matrix(1,1)) * outer_prod(fibre_vector,fibre_vector));
00165
00166 local_element_index++;
00167 }
00168
00169 assert(this->mTensors.size() == this->mpMesh->GetNumLocalElements());
00170 assert(this->mTensors.size() == local_element_index);
00171
00172 if (this->mUseFibreOrientation)
00173 {
00174
00175 this->mFileReader.reset();
00176 }
00177 }
00178
00179 this->mInitialised = true;
00180 }
00181
00182
00183
00185
00187
00188
00189
00190 template class AxisymmetricConductivityTensors<1,1>;
00191 template class AxisymmetricConductivityTensors<1,2>;
00192 template class AxisymmetricConductivityTensors<1,3>;
00193 template class AxisymmetricConductivityTensors<2,2>;
00194 template class AxisymmetricConductivityTensors<2,3>;
00195 template class AxisymmetricConductivityTensors<3,3>;