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 #ifndef dimensionedType_H
00036 #define dimensionedType_H
00037
00038 #include <OpenFOAM/word.H>
00039 #include <OpenFOAM/direction.H>
00040 #include <OpenFOAM/dimensionSet.H>
00041 #include <OpenFOAM/VectorSpace.H>
00042
00043
00044
00045 namespace Foam
00046 {
00047
00048
00049
00050 template<class Type> class dimensioned;
00051
00052 template<class Type>
00053 Istream& operator>>(Istream&, dimensioned<Type>&);
00054
00055 template<class Type>
00056 Ostream& operator<<(Ostream&, const dimensioned<Type>&);
00057
00058 class dictionary;
00059
00060
00061
00062
00063
00064 template <class Type>
00065 class dimensioned
00066 {
00067
00068
00069
00070 word name_;
00071
00072
00073 dimensionSet dimensions_;
00074
00075
00076 Type value_;
00077
00078
00079 public:
00080
00081
00082 typedef typename pTraits<Type>::cmptType cmptType;
00083
00084
00085
00086
00087
00088 dimensioned(const word&, const dimensionSet&, const Type);
00089
00090
00091 dimensioned(const word&, const dimensioned<Type>&);
00092
00093
00094 dimensioned(const Type& t)
00095 :
00096 name_(::Foam::name(t)),
00097 dimensions_(dimless),
00098 value_(t)
00099 {}
00100
00101
00102 dimensioned(Istream&);
00103
00104
00105 dimensioned(const word&, Istream&);
00106
00107
00108 dimensioned(const word&, const dimensionSet&, Istream&);
00109
00110
00111 static dimensioned<Type> lookupOrDefault
00112 (
00113 const word&,
00114 const dictionary&,
00115 const Type& defaultValue = pTraits<Type>::zero,
00116 const dimensionSet& dims = dimless
00117 );
00118
00119
00120
00121 static dimensioned<Type> lookupOrAddToDict
00122 (
00123 const word&,
00124 dictionary&,
00125 const Type& defaultValue = pTraits<Type>::zero,
00126 const dimensionSet& dims = dimless
00127 );
00128
00129
00130
00131
00132
00133 const word& name() const;
00134
00135
00136 word& name();
00137
00138
00139 const dimensionSet& dimensions() const;
00140
00141
00142 dimensionSet& dimensions();
00143
00144
00145 const Type& value() const;
00146
00147
00148 Type& value();
00149
00150
00151 dimensioned<cmptType> component(const direction) const;
00152
00153
00154 void replace(const direction, const dimensioned<cmptType>&);
00155
00156
00157 dimensioned<Type> T() const;
00158
00159
00160 bool readIfPresent(const dictionary&);
00161
00162
00163
00164
00165
00166 dimensioned<cmptType> operator[](const direction) const;
00167
00168 void operator+=(const dimensioned<Type>&);
00169 void operator-=(const dimensioned<Type>&);
00170 void operator*=(const scalar);
00171 void operator/=(const scalar);
00172
00173
00174
00175
00176 friend Istream& operator>> <Type>
00177 (Istream&, dimensioned<Type>&);
00178
00179 friend Ostream& operator<< <Type>
00180 (Ostream&, const dimensioned<Type>&);
00181 };
00182
00183
00184
00185
00186 template<class Type, int r>
00187 dimensioned<typename powProduct<Type, r>::type>
00188 pow
00189 (
00190 const dimensioned<Type>&,
00191 typename powProduct<Type, r>::type
00192 = pTraits<typename powProduct<Type, r>::type>::zero
00193 );
00194
00195 template<class Type>
00196 dimensioned<typename outerProduct<Type, Type>::type>
00197 sqr(const dimensioned<Type>&);
00198
00199 template<class Type>
00200 dimensioned<scalar> magSqr(const dimensioned<Type>&);
00201
00202 template<class Type>
00203 dimensioned<scalar> mag(const dimensioned<Type>&);
00204
00205 template<class Type>
00206 dimensioned<Type> cmptMultiply
00207 (
00208 const dimensioned<Type>&,
00209 const dimensioned<Type>&
00210 );
00211
00212 template<class Type>
00213 dimensioned<Type> cmptDivide
00214 (
00215 const dimensioned<Type>&,
00216 const dimensioned<Type>&
00217 );
00218
00219 template<class Type>
00220 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
00221
00222 template<class Type>
00223 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
00224
00225 template<class Type>
00226 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
00227
00228 template<class Type>
00229 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
00230
00231 template<class Type>
00232 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
00233
00234 template<class Type>
00235 dimensioned<Type> operator-(const dimensioned<Type>&);
00236
00237 template<class Type>
00238 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
00239
00240 template<class Type>
00241 dimensioned<Type> operator*
00242 (
00243 const dimensioned<scalar>&,
00244 const dimensioned<Type>&
00245 );
00246
00247 template<class Type>
00248 dimensioned<Type> operator/
00249 (
00250 const dimensioned<Type>&,
00251 const dimensioned<scalar>&
00252 );
00253
00254
00255
00256
00257
00258 #define PRODUCT_OPERATOR(product, op, opFunc) \
00259 \
00260 template<class Type1, class Type2> \
00261 dimensioned<typename product<Type1, Type2>::type> \
00262 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
00263 \
00264 template<class Type, class Form, class Cmpt, int nCmpt> \
00265 dimensioned<typename product<Type, Form>::type> \
00266 operator op \
00267 ( \
00268 const dimensioned<Type>&, \
00269 const VectorSpace<Form,Cmpt,nCmpt>& \
00270 ); \
00271 \
00272 template<class Type, class Form, class Cmpt, int nCmpt> \
00273 dimensioned<typename product<Form, Type>::type> \
00274 operator op \
00275 ( \
00276 const VectorSpace<Form,Cmpt,nCmpt>&, \
00277 const dimensioned<Type>& \
00278 );
00279
00280 PRODUCT_OPERATOR(outerProduct, *, outer)
00281 PRODUCT_OPERATOR(crossProduct, ^, cross)
00282 PRODUCT_OPERATOR(innerProduct, &, dot)
00283 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
00284
00285 #undef PRODUCT_OPERATOR
00286
00287
00288
00289
00290 }
00291
00292
00293
00294 #ifdef NoRepository
00295 # include <OpenFOAM/dimensionedType.C>
00296 #endif
00297
00298
00299
00300 #endif
00301
00302