00001 /*************************************************************************** 00002 reservoirfunction.h 00003 ----------- 00004 00005 begin : Wed Apr 25 00:47:40 CEST 2001 00006 author : (C) 2001 by Michael Peeters 00007 email : Michael.Peeters@vub.ac.be 00008 ***************************************************************************/ 00009 00010 /*************************************************************************** 00011 * * 00012 * This program is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU General Public License as published by * 00014 * the Free Software Foundation; either version 2 of the License, or * 00015 * (at your option) any later version. * 00016 * * 00017 ***************************************************************************/ 00018 00019 #ifndef RESERVOIR_H 00020 #define RESERVOIR_H 00021 #include "numerictypes.h" 00022 #include "numvector.h" 00023 #include "vectorfunction.h" 00024 #include "scalarfunction.h" 00025 00026 namespace MODEL 00027 { 00028 00058 template<integer dims, typename nelem=number, class NT = NumericTraits<nelem,dims> > 00059 class ReservoirFunction : public VectorFunction<dims,nelem,NT> 00060 { 00061 public: 00062 typedef typename NT::number numT; 00063 typedef typename NT::vect vect; 00064 typedef typename NT::vf vf; 00065 typedef typename NT::matrix matrix; 00066 00067 // typedef ScalarFunction<dims>* exchange_rate; 00068 typedef number exchange_rate_f(ReservoirFunction*,const vect& u); 00069 typedef exchange_rate_f* exchange_rate; 00070 00071 // typedef number (ReservoirFunction::*exchange_rate)(const vect&); 00072 typedef exchange_rate* exchange_rate_list; 00073 00074 ReservoirFunction() 00075 { 00076 for (integer i=0;i<dims+1;i++) 00077 { 00078 R[i]=new exchange_rate[dims+1]; 00079 for(integer j=0;j<dims+1;j++) 00080 R[i][j]=0; // make sure all pointer are zero to start with 00081 } 00082 } 00083 00096 ReservoirFunction(const 00097 ReservoirFunction& rf) 00098 { 00099 const map<string,number*>& subparlist=rf.get_parlist(); 00100 map<string,number*>::const_iterator run=subparlist.begin(); 00101 map<string,number*>::const_iterator endrun=subparlist.end(); 00102 00103 while(run!=endrun){ 00104 define_parameter(run->first,*(run->second)); 00105 ++run; 00106 } 00107 00108 // copy R functions... 00109 for (integer i=0;i<dims+1;i++) 00110 { 00111 R[i]=new exchange_rate[dims+1]; 00112 for(integer j=0;j<dims+1;j++) 00113 R[i][j]=rf.R[i][j]; // make sure all pointer are zero to start with 00114 } 00115 00116 } 00117 00118 virtual void add_exchange_rate(int from, int to, 00119 exchange_rate er) 00120 { 00121 R[from][to]=er; 00122 } 00123 00125 virtual const vect& input(vect& fu,const vect& u) = 0; 00126 00132 virtual const vect& function(vect& fu,const vect& u) 00133 { 00134 // set input (sources) 00135 input (fu,u); 00136 00137 for (integer i=0;i<dims;i++) 00138 { 00139 // non-universe terms 00140 // problem: you have to be exact/const when specifying the 00141 // template parameters... 00142 for (integer j=0;j<dims;j++) 00143 { 00144 if(i!=j){ 00145 00146 if(R[i+1][j+1] && R[j+1][i+1]) // if this one is not specified 00147 fu[i]+=-(R[i+1][j+1])(this,u)+(R[j+1][i+1])(this,u); 00148 else 00149 cerr << "EXCHANGE RATE UNDEFINED: (" << i+1 << "," << 00150 j+1 << ")" << endl; 00151 } 00152 } 00153 00154 //universe contributions 00155 if(R[i+1][0]) // if this one is specified 00156 fu[i]-=(R[i+1][0])(this,u); 00157 else 00158 cerr << "UNIVERSE EXCHANGE RATE UNDEFINED: (" << i+1 << ",0)" << endl; 00159 } 00160 00161 return fu; 00162 } 00163 00164 number get_rate(integer from,integer to,const vect& 00165 u) 00166 { 00167 if(R[from][to]) 00168 return R[from][to](this,u); 00169 else 00170 cerr << "EXCHANGE RATE UNDEFINED: (" << from << "," << 00171 to << ")" << endl; 00172 return 0; 00173 00174 } 00175 00176 00177 private: 00178 exchange_rate_list R[dims+1]; 00179 }; 00180 00181 } 00182 00184 #define EXCHANGE_RATE(a,b) static::MODEL::number R_a_b 00185 00186 #endif 00187 00188 /********************************************************************* 00189 $Id: reservoirfunction.h,v 1.2 2001/07/26 12:01:22 mpeeters Exp $ 00190 ********************************************************************** 00191 00192 $Log: reservoirfunction.h,v $ 00193 Revision 1.2 2001/07/26 12:01:22 mpeeters 00194 Make start point selection easier (add_start). Removed some bugs. 00195 00196 Revision 1.1 2001/05/22 10:54:55 mpeeters 00197 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter". 00198 00199 Revision 1.1 2001/05/21 12:00:23 mpeeters 00200 Reservoirfunction is a special kind of vectorfunction (at the moment, implemented like a heap of dung), vfamputation if a way to remove dependencies from certain vectorfuncions (to remove their dimensionality). 00201 00202 *********************************************************************/
More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be
Last update: June 2002.