Table.C
Go to the documentation of this file.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 #include "Table.H"
00028
00029
00030
00031 template<class Type>
00032 Foam::Table<Type>::Table(const word& entryName, Istream& is)
00033 :
00034 DataEntry<Type>(entryName),
00035 table_(is)
00036 {
00037 if (!table_.size())
00038 {
00039 FatalErrorIn("Foam::Table<Type>::Table(const Istream&)")
00040 << "Table for entry " << this->name_ << " is invalid (empty)"
00041 << nl << exit(FatalError);
00042 }
00043 }
00044
00045
00046 template<class Type>
00047 Foam::Table<Type>::Table(const Table<Type>& tbl)
00048 :
00049 DataEntry<Type>(tbl),
00050 table_(tbl.table_)
00051 {}
00052
00053
00054
00055
00056 template<class Type>
00057 Foam::Table<Type>::~Table()
00058 {}
00059
00060
00061
00062
00063 template<class Type>
00064 Type Foam::Table<Type>::value(const scalar x) const
00065 {
00066
00067 if ((x > table_[table_.size()-1].first()) || (x < table_[0].first()))
00068 {
00069 return pTraits<Type>::zero;
00070 }
00071
00072
00073 label i = 0;
00074 while ((table_[i+1].first() < x) && (i+1 < table_.size()))
00075 {
00076 i++;
00077 }
00078
00079
00080
00081 return Type
00082 (
00083 (x - table_[i].first())/(table_[i+1].first() - table_[i].first())
00084 * (table_[i+1].second() - table_[i].second())
00085 + table_[i].second()
00086 );
00087 }
00088
00089
00090 template<class Type>
00091 Type Foam::Table<Type>::integrate(const scalar x1, const scalar x2) const
00092 {
00093
00094 Type sum = pTraits<Type>::zero;
00095
00096
00097 if ((x1 > table_[table_.size()-1].first()) || (x2 < table_[0].first()))
00098 {
00099 return sum;
00100 }
00101
00102
00103 label id1 = 0;
00104 while ((table_[id1].first() < x1) && (id1 < table_.size()))
00105 {
00106 id1++;
00107 }
00108
00109
00110 label id2 = table_.size() - 1;
00111 while ((table_[id2].first() > x2) && (id2 >= 1))
00112 {
00113 id2--;
00114 }
00115
00116
00117 for (label i=id1; i<id2; i++)
00118 {
00119 sum +=
00120 (table_[i].second() + table_[i+1].second())
00121 * (table_[i+1].first() - table_[i].first());
00122 }
00123 sum *= 0.5;
00124
00125
00126 if (id1 > 0)
00127 {
00128 sum += 0.5
00129 * (value(x1) + table_[id1].second())
00130 * (table_[id1].first() - x1);
00131 }
00132 if (id2 < table_.size() - 1)
00133 {
00134 sum += 0.5
00135 * (table_[id2].second() + value(x2))
00136 * (x2 - table_[id2].first());
00137 }
00138
00139 return sum;
00140 }
00141
00142
00143
00144
00145 #include "TableIO.C"
00146
00147
00148
Copyright © 2000-2009 OpenCFD Ltd