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