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 "AbstractConductivityTensors.hpp"
00030 #include "Exception.hpp"
00031 #include <sstream>
00032
00033 template<unsigned SPACE_DIM>
00034 void AbstractConductivityTensors<SPACE_DIM>::OpenFibreOrientationFile()
00035 {
00036 mDataFile.open(mFibreOrientationFilename.c_str());
00037 if (!mDataFile.is_open())
00038 {
00039 EXCEPTION("Wrong fibre orientation file name.");
00040 }
00041 }
00042
00043 template<unsigned SPACE_DIM>
00044 void AbstractConductivityTensors<SPACE_DIM>::CloseFibreOrientationFile()
00045 {
00046 mDataFile.close();
00047 }
00048
00049 template<unsigned SPACE_DIM>
00050 unsigned AbstractConductivityTensors<SPACE_DIM>::GetTokensAtNextLine(std::vector<double>& tokens)
00051 {
00052 std::string line;
00053
00054 bool comment_line;
00055 bool blank_line;
00056
00057 do
00058 {
00059 getline(mDataFile, line);
00060
00061 if (mDataFile.eof())
00062 {
00063 CloseFibreOrientationFile();
00064 EXCEPTION("Fibre orientation file contains less fibre definitions than the number of elements in the mesh");
00065 }
00066
00067 comment_line = (line.find('#',0) != std::string::npos);
00068 blank_line = (line.find_first_not_of(" \t",0) == std::string::npos);
00069 }
00070 while(comment_line || blank_line);
00071
00072
00073 std::stringstream line_stream(line);
00074
00075
00076 while (!line_stream.eof())
00077 {
00078 double item;
00079 line_stream >> item;
00080 tokens.push_back(item);
00081 }
00082
00083 return tokens.size();
00084 }
00085
00086 template<unsigned SPACE_DIM>
00087 unsigned AbstractConductivityTensors<SPACE_DIM>::GetNumElementsFromFile()
00088 {
00089 std::vector<double> tokens;
00090
00091 if (GetTokensAtNextLine(tokens) != 1)
00092 {
00093 CloseFibreOrientationFile();
00094 EXCEPTION("First (non comment) line of the fibre orientation file should contain the number of elements of the mesh (and nothing else)");
00095 }
00096
00097 return (unsigned) tokens[0];
00098 }
00099
00100
00101 template<unsigned SPACE_DIM>
00102 AbstractConductivityTensors<SPACE_DIM>::AbstractConductivityTensors()
00103 : mNumElements(1),
00104 mUseNonConstantConductivities(false),
00105 mUseFibreOrientation(false),
00106 mInitialised(false)
00107 {
00108 double init_data[]={DBL_MAX, DBL_MAX, DBL_MAX};
00109
00110 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00111 {
00112 mConstantConductivities[dim] = init_data[dim];
00113 }
00114 }
00115
00116 template<unsigned SPACE_DIM>
00117 AbstractConductivityTensors<SPACE_DIM>::~AbstractConductivityTensors()
00118 {
00119 }
00120
00121 template<unsigned SPACE_DIM>
00122 void AbstractConductivityTensors<SPACE_DIM>::SetFibreOrientationFile(const std::string &rFibreOrientationFilename)
00123 {
00124 mUseFibreOrientation = true;
00125 mFibreOrientationFilename = rFibreOrientationFilename;
00126 }
00127
00128 template<unsigned SPACE_DIM>
00129 void AbstractConductivityTensors<SPACE_DIM>::SetConstantConductivities(c_vector<double, 1> constantConductivities)
00130 {
00131 if (SPACE_DIM != 1)
00132 {
00133 EXCEPTION("Wrong number of conductivities provided");
00134 }
00135
00136 mUseNonConstantConductivities = false;
00137 mConstantConductivities = constantConductivities;
00138 }
00139
00140 template<unsigned SPACE_DIM>
00141 void AbstractConductivityTensors<SPACE_DIM>::SetConstantConductivities(c_vector<double, 2> constantConductivities)
00142 {
00143 if (SPACE_DIM != 2)
00144 {
00145 EXCEPTION("Wrong number of conductivities provided");
00146 }
00147
00148 mUseNonConstantConductivities = false;
00149 mConstantConductivities = constantConductivities;
00150 }
00151
00152 template<unsigned SPACE_DIM>
00153 void AbstractConductivityTensors<SPACE_DIM>::SetConstantConductivities(c_vector<double, 3> constantConductivities)
00154 {
00155 if (SPACE_DIM != 3)
00156 {
00157 EXCEPTION("Wrong number of conductivities provided");
00158 }
00159
00160 mUseNonConstantConductivities = false;
00161 mConstantConductivities = constantConductivities;
00162 }
00163
00164 template<unsigned SPACE_DIM>
00165 void AbstractConductivityTensors<SPACE_DIM>::SetNonConstantConductivities(std::vector<c_vector<double, SPACE_DIM> >* pNonConstantConductivities)
00166 {
00167 mUseNonConstantConductivities = true;
00168 mpNonConstantConductivities = pNonConstantConductivities;
00169 }
00170
00171 template<unsigned SPACE_DIM>
00172 c_matrix<double,SPACE_DIM,SPACE_DIM>& AbstractConductivityTensors<SPACE_DIM>::operator[](const unsigned index)
00173 {
00174 assert(mInitialised);
00175
00176 if (!mUseNonConstantConductivities && !mUseFibreOrientation)
00177 {
00178 return mTensors[0];
00179 }
00180 else
00181 {
00182 assert(index < mNumElements);
00183 return mTensors[index];
00184 }
00185 }
00186
00188
00190
00191 template class AbstractConductivityTensors<1>;
00192 template class AbstractConductivityTensors<2>;
00193 template class AbstractConductivityTensors<3>;