Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/migration.h
[mareframe] / trunk / gadget / migration.h Repository:
ViewVC logotype

Annotation of /trunk/gadget/migration.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #ifndef migration_h
2 :     #define migration_h
3 :    
4 :     #include "livesonareas.h"
5 :     #include "actionattimes.h"
6 :     #include "keeper.h"
7 :     #include "intmatrix.h"
8 :     #include "modelvariable.h"
9 :     #include "rectangle.h"
10 :     #include "doublematrixptrvector.h"
11 :     #include "formulamatrixptrvector.h"
12 :     #include "migrationareaptrvector.h"
13 :    
14 :     /**
15 :     * \class Migration
16 :     * \brief This is the base class used to calculate the migration of a stock within the model
17 :     *
18 :     * This class moves fish from one area to another within the model. The proportion of the fish that move is calculated according to a migration matrix. The migration matrix is either specified in the input files (either directly or by specifying the ratio that move), or is calculated from a migration function, based on drift and diffusion parameters. Care is taken to ensure that the columns of the migration matrix will sum to 1, so that no fish are created or lost during the migration process. Once the migration matrix has been calculated, the fish are moved between the areas using a simple matrix multiplication function.
19 :     *
20 :     * \note This will always be overridden by the derived classes that actually calculate the migration
21 :     */
22 :     class Migration : public HasName, protected LivesOnAreas {
23 :     public:
24 :     /**
25 :     * \brief This is the default Migration constructor
26 :     * \param areas is the IntVector of areas that the migration will be calculated on
27 :     * \param givenname is the name of the stock for this Migration class
28 :     */
29 :     Migration(const IntVector& areas, const char* givenname);
30 :     /**
31 :     * \brief This is the default Migration destructor
32 :     */
33 :     virtual ~Migration() {};
34 :     /**
35 :     * \brief This function will reset the migration data
36 :     */
37 :     virtual void Reset() = 0;
38 :     /**
39 :     * \brief This function will print the migration data
40 :     * \param outfile is the ofstream that all the model information gets sent to
41 :     */
42 :     virtual void Print(ofstream& outfile) = 0;
43 :     /**
44 :     * \brief This will return the migration matrix that has been calculated
45 :     * \param TimeInfo is the TimeClass for the current model
46 :     * \return 0 (will be overridden in derived classes)
47 :     */
48 :     virtual const DoubleMatrix& getMigrationMatrix(const TimeClass* const TimeInfo) = 0;
49 :     /**
50 :     * \brief This will return the penalty that has been calculated due to invalid migration
51 :     * \return penalty, a DoubleVector of the calculated migration penalty
52 :     */
53 :     const DoubleVector& getPenalty() const { return penalty; };
54 :     /**
55 :     * \brief This will check if the migration process will take place on the current timestep
56 :     * \param TimeInfo is the TimeClass for the current model
57 :     * \return 0 (will be overridden in derived classes)
58 :     */
59 :     virtual int isMigrationStep(const TimeClass* const TimeInfo) = 0;
60 :     protected:
61 :     /**
62 :     * \brief This is the DoubleVector used to store the migration penalty information
63 :     */
64 :     DoubleVector penalty;
65 :     };
66 :    
67 :     /**
68 :     * \class MigrationNumbers
69 :     * \brief This is the class used to calculate the migration of a stock within the model based on migration ratios specified in the input file
70 :     */
71 :     class MigrationNumbers : public Migration {
72 :     public:
73 :     /**
74 :     * \brief This is the MigrationNumbers constructor
75 :     * \param areas is the IntVector of areas that the migration will be calculated on
76 :     * \param infile is the CommentStream to read the migration data from
77 :     * \param Area is the AreaClass for the current model
78 :     * \param TimeInfo is the TimeClass for the current model
79 :     * \param givenname is the name of the stock for this Migration class
80 :     * \param keeper is the Keeper for the current model
81 :     */
82 :     MigrationNumbers(CommentStream& infile, const IntVector& areas,
83 :     const AreaClass* const Area, const TimeClass* const TimeInfo,
84 :     const char* givenname, Keeper* const keeper);
85 :     /**
86 :     * \brief This is the default MigrationNumbers destructor
87 :     */
88 :     ~MigrationNumbers();
89 :     /**
90 :     * \brief This function will reset the migration data
91 :     */
92 :     void Reset();
93 :     /**
94 :     * \brief This function will print the migration data
95 :     * \param outfile is the ofstream that all the model information gets sent to
96 :     */
97 :     void Print(ofstream& outfile);
98 :     /**
99 :     * \brief This will return the migration matrix that has been calculated
100 :     * \param TimeInfo is the TimeClass for the current model
101 :     * \return migration, a DoubleMatrix of the calculated migration
102 :     */
103 :     const DoubleMatrix& getMigrationMatrix(const TimeClass* const TimeInfo);
104 :     /**
105 :     * \brief This will check if the migration process will take place on the current timestep
106 :     * \param TimeInfo is the TimeClass for the current model
107 :     * \return 1 if the migration process will take place, 0 otherwise
108 :     */
109 :     virtual int isMigrationStep(const TimeClass* const TimeInfo);
110 :     private:
111 :     /**
112 :     * \brief This function will read the migration timestep data from the input file
113 :     * \param infile is the CommentStream to read the migration timestep data from
114 :     * \param TimeInfo is the TimeClass for the current model
115 :     */
116 :     void readTimeStepData(CommentStream& infile, const TimeClass* const TimeInfo);
117 :     /**
118 :     * \brief This function will read the migration ratio data from the input file
119 :     * \param infile is the CommentStream to read the migration timestep data from
120 :     * \param keeper is the Keeper for the current model
121 :     * \param Area is the AreaClass for the current model
122 :     */
123 :     void readGivenRatios(CommentStream& infile, Keeper* const keeper, const AreaClass* const Area);
124 :     /**
125 :     * \brief This function will read the migration matrix data from the input file
126 :     * \param infile is the CommentStream to read the migration timestep data from
127 :     * \param keeper is the Keeper for the current model
128 :     */
129 :     void readGivenMatrices(CommentStream& infile, Keeper* const keeper);
130 :     /**
131 :     * \brief This will set the name of the migration matrix to be used in the simulation
132 :     * \param name is the name of the migration matrix
133 :     */
134 :     void setMatrixName(char* name);
135 :     /**
136 :     * \brief This will check if the migration matrix is used in the simulation
137 :     * \param name is the name of the migration matrix
138 :     * \return 1 if the migration matrix is used, 0 otherwise
139 :     */
140 :     int useMatrix(char* name);
141 :     /**
142 :     * \brief This will check to ensure that all the required migration information has been specified in the input file
143 :     */
144 :     void checkMatrixIndex();
145 :     /**
146 :     * \brief This is the CharPtrVector used to store the names of the migration matrices that have been read from file
147 :     */
148 :     CharPtrVector allmatrixnames;
149 :     /**
150 :     * \brief This is the CharPtrVector used to store the names of the migration matrices that are used in the simulation
151 :     */
152 :     CharPtrVector usedmatrixnames;
153 :     /**
154 :     * \brief This is the IntVector used to store information about when the migration matrices are to be used in the simulation
155 :     */
156 :     IntVector timeindex;
157 :     /**
158 :     * \brief This is the IntMatrix used to check that sufficient information has been specified to calculate the migration matrices based on the migration ratios given in the input file
159 :     */
160 :     IntMatrix checkvalues;
161 :     /**
162 :     * \brief This is the DoubleMatrixPtrVector used to store the calculated migration parameters
163 :     */
164 :     DoubleMatrixPtrVector calcMigration;
165 :     /**
166 :     * \brief This is the FormulaMatrixPtrVector used to store the migration variables
167 :     */
168 :     FormulaMatrixPtrVector readMigration;
169 :     };
170 :    
171 :     /**
172 :     * \class MigrationFunction
173 :     * \brief This is the class used to calculate the migration of a stock within the model based on a migration function
174 :     */
175 :     class MigrationFunction : public Migration {
176 :     public:
177 :     /**
178 :     * \brief This is the MigrationFunction constructor
179 :     * \param areas is the IntVector of areas that the migration will be calculated on
180 :     * \param infile is the CommentStream to read the migration data from
181 :     * \param Area is the AreaClass for the current model
182 :     * \param TimeInfo is the TimeClass for the current model
183 :     * \param givenname is the name of the stock for this Migration class
184 :     * \param keeper is the Keeper for the current model
185 :     */
186 :     MigrationFunction(CommentStream& infile, const IntVector& areas,
187 :     const AreaClass* const Area, const TimeClass* const TimeInfo,
188 :     const char* givenname, Keeper* const keeper);
189 :     /**
190 :     * \brief This is the default MigrationFunction destructor
191 :     */
192 :     ~MigrationFunction();
193 :     /**
194 :     * \brief This function will reset the migration data
195 :     */
196 :     void Reset();
197 :     /**
198 :     * \brief This function will print the migration data
199 :     * \param outfile is the ofstream that all the model information gets sent to
200 :     */
201 :     void Print(ofstream& outfile);
202 :     /**
203 :     * \brief This will return the migration matrix that has been calculated
204 :     * \param TimeInfo is the TimeClass for the current model
205 :     * \return migration, a DoubleMatrix of the calculated migration
206 :     */
207 :     const DoubleMatrix& getMigrationMatrix(const TimeClass* const TimeInfo);
208 :     /**
209 :     * \brief This will check if the migration process will take place on the current timestep
210 :     * \param TimeInfo is the TimeClass for the current model
211 :     * \return 1 if the migration process will take place, 0 otherwise
212 :     */
213 :     virtual int isMigrationStep(const TimeClass* const TimeInfo);
214 :     private:
215 :     /**
216 :     * \brief This function will read the migration data from the input file
217 :     * \param infile is the CommentStream to read the migration timestep data from
218 :     * \param Area is the AreaClass for the current model
219 :     * \param TimeInfo is the TimeClass for the current model
220 :     * \param keeper is the Keeper for the current model
221 :     */
222 :     void readAreaData(CommentStream& infile, const AreaClass* const Area,
223 :     const TimeClass* const TimeInfo, Keeper* const keeper);
224 :     int updateVariables(const TimeClass* const TimeInfo);
225 :     void recalcMatrix();
226 :     double getMigrationFunction(Rectangle* fromRec, Rectangle* toRec);
227 :     double f1x(double w, double u, double D, double beta);
228 :     double f2x(double w, double u, double D, double beta);
229 :     DoubleMatrix calcMigration;
230 :     /**
231 :     * \brief This is the ModelVariable used to store the diffusion parameter
232 :     */
233 :     ModelVariable diffusion;
234 :     /**
235 :     * \brief This is the ModelVariable used to store the longitude drift parameter
236 :     */
237 :     ModelVariable driftx;
238 :     /**
239 :     * \brief This is the ModelVariable used to store the latitude drift parameter
240 :     */
241 :     ModelVariable drifty;
242 :     double lambda;
243 :     double delta;
244 :     /**
245 :     * \brief This is the MigrationAreaPtrVector used to store the migration area information
246 :     */
247 :     MigrationAreaPtrVector oceanareas;
248 :     };
249 :    
250 :     #endif

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge