[Greater-commits] r3858 - trunk/GREAT-ERModel/GreaterModel/Worker

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Dec 2 17:01:55 CET 2011


Author: aheinecke
Date: 2011-12-02 17:01:53 +0100 (Fri, 02 Dec 2011)
New Revision: 3858

Modified:
   trunk/GREAT-ERModel/GreaterModel/Worker/rivermodels.py
Log:
Add Support for lakes


Modified: trunk/GREAT-ERModel/GreaterModel/Worker/rivermodels.py
===================================================================
--- trunk/GREAT-ERModel/GreaterModel/Worker/rivermodels.py	2011-12-02 16:01:11 UTC (rev 3857)
+++ trunk/GREAT-ERModel/GreaterModel/Worker/rivermodels.py	2011-12-02 16:01:53 UTC (rev 3858)
@@ -1,4 +1,4 @@
-# Copyright (C) 2002 by Intevation GmbH
+# Copyright (C) 2002, 2011 by Intevation GmbH
 # Authors:
 # Frank Koormann <frank.koormann at intevation.de>
 #
@@ -8,8 +8,6 @@
 """GREAT-ER Model Worker: River Model implementations."""
 
 __version__ = "$Revision: 1.32 $"
-# $Source: /home/bricks/source/greater/cvs/greaterrepository/GREAT-ERModel/GreaterModel/Worker/rivermodels.py,v $
-# $Id: rivermodels.py,v 1.32 2006-04-25 15:39:26 frank Exp $
 
 from types import ListType, TupleType
 from string import upper, lower, atof, atoi, split
@@ -27,7 +25,7 @@
     _required_parameters = [('MOD','MODE_RIVER','1'), 
         ('STRETCH','Q_VAL'), ('STRETCH','Q_DIST'),
         ('STRETCH','V_VAL'), ('STRETCH','V_DIST'),
-        ('STRETCH','L'), 
+        ('STRETCH','L'), ('STRETCH','VOL_VAL'), ('STRETCH','VOL_DIST'),
         ('SUBST','K_INSTREAM'),
         [('MOD','USE_DIFFUSE_INPUT','Y'),
             ('ENV','TERRACE_FILENAME') ]
@@ -107,7 +105,8 @@
         self.k = Parameter(('SUBST','K_INSTREAM'), 
                         data['SUBST']['K_INSTREAM'].value,
                         st_params, data['STOCHASTICS']) 
-
+        self.V = Parameter(('STRETCH','VOL_VAL'), data['STRETCH'][ID].vol_val,
+                        st_params, data['STOCHASTICS'])
         # Diffuse Input: 
         use_diffuse_input = eval_parameter(data, 
                                  ('MOD','USE_DIFFUSE_INPUT','value'))
@@ -126,7 +125,10 @@
         data = self.session.data
         # Get the flux input
         PHI = segment.PHIin()
-        
+
+        PHIout = PHI
+        c_start, c_end, c_internal = ( 0.0, 0.0, 0.0 )
+
         # Opt: Only compute if the stretch is expected to be loaded.
         if PHI > 0.0 or self.use_diffuse:
             # Get the parameters from the data
@@ -139,29 +141,25 @@
                                                         # [kg/a] -> [kg/s]
             else:
                 I = 0.0
-            
+
             # Avoid division by zero
-            if v > 0.0 and Q > 0.0 and L > 0.0:
-                # Hydralic Residence time in stretch [h]
+            if Q > 0.0 and L > 0.0:
                 if segment.type in model.LakeTypes:
-                    V = L           # In case of a lake the length stores the 
-                    HRT=L/Q         # volume by definition.
-                else:    
+                    V = self.V.get(shot_num)
+
+                    # lake elimination process
+                    PHIout, c_start, c_end, c_internal = \
+                            self.lake_concentration(PHI, Q, V, k)
+                elif v > 0.0:
                     V = Q * L / v
                     HRT = L/v
 
-                # 1st order river elimination process
-                exp_term = exp( - k * HRT )
-                PHIout, c_start, c_end, c_internal = self.first_order_elimination(
+                    # 1st order river elimination process
+                    exp_term = exp( - k * HRT )
+                    PHIout, c_start, c_end, c_internal = \
+                            self.first_order_elimination(
                                         PHI, I, Q, v, HRT, L, V, k, exp_term)
-            else:
-                # flux output
-                PHIout = PHI
-                c_start, c_end, c_internal = ( 0.0, 0.0, 0.0 )
-        else:
-            PHIout = PHI
-            c_start, c_end, c_internal = ( 0.0, 0.0, 0.0 )
-            
+
         # Collect different concentrations [kg/m^3]
         self.Results['CSIMSTART'].add( c_start )
         self.Results['CSIMEND'].add( c_end )
@@ -169,6 +167,15 @@
 
         return PHIout
 
+    def lake_concentration(self, PHI, Q, V, k):
+        """Elimination in lakes, diffuse input specified by homogeneous tanks."""
+
+        if k != 0.0:
+            PHIout = PHI *Q / (Q + k * V)
+        else:
+            PHIout = PHI
+        return (  PHIout, PHIout / Q, PHIout / Q, PHIout / Q )
+ 
     def first_order_elimination(self, PHI, I, Q, v, HRT, L, V, k, exp_term):
         """Generic first order elimination for rivers with diffuse input.""" 
 
@@ -200,7 +207,7 @@
     _required_parameters = [('MOD','MODE_RIVER','2'), 
         ('STRETCH','Q_VAL'), ('STRETCH','Q_DIST'),
         ('STRETCH','V_VAL'), ('STRETCH','V_DIST'),
-        ('STRETCH','L'), 
+        ('STRETCH','L'), ('STRETCH','VOL_VAL'), ('STRETCH','VOL_DIST'),
         ('SUBST','K_DEG'), ('SUBST','K_SED'), ('SUBST','K_VOL'),
         ('SUBST','KD_RIVER'), ('SUBST','K_OC'),
         ('ENV', 'SS_CORR'),
@@ -422,7 +429,8 @@
                         st_params, data['STOCHASTICS']) 
         self.v = Parameter(('STRETCH','V_VAL'), data['STRETCH'][ID].v_val,
                         st_params, data['STOCHASTICS']) 
-
+        self.V = Parameter(('STRETCH','VOL_VAL'), data['STRETCH'][ID].vol_val,
+                        st_params, data['STOCHASTICS']) 
         # Sediment Extension related Parameters
         if self.mode_sed:
             self.eps_sed = atof(eval_class_parameter(data, 
@@ -467,7 +475,8 @@
             self.SS = Parameter(('ENV','SS_RIVER'), 
                             data['ENV']['SS_RIVER'].value,
                             st_params, data['STOCHASTICS'])
-
+        self.V = Parameter(('STRETCH','VOL_VAL'), data['STRETCH'][ID].vol_val,
+                        st_params, data['STOCHASTICS'])
         # Diffuse Input: 
         use_diffuse_input = eval_parameter(data, 
                                  ('MOD','USE_DIFFUSE_INPUT','value'))
@@ -531,24 +540,29 @@
             f_s = 1.0 - f_d
 
             # Avoid division by zero
-            if v > 0.0 and Q > 0.0 and L > 0.0:
+            if Q > 0.0 and L > 0.0:
+                # 1st order river elimination process
+                k = k_deg + f_s * k_sed + f_d * k_vol
+
                 # Hydralic Residence time in stretch [h]
                 if segment.type in model.LakeTypes:
-                    V = L           # In case of a lake the length stores the 
-                    HRT=L/Q  # volume by definition.
-                else:    
+                    V = self.V.get(shot_num)
+                    # lake elimination process
+                    PHIout, c_start, c_end, c_internal = self.lake_concentration(
+                                                        PHI, Q, V, k)
+                elif v > 0.0:
                     V = Q * L / v
                     HRT = L/v
-
-                # 1st order river elimination process
-                k = k_deg + f_s * k_sed + f_d * k_vol
-                exp_term = exp( - k * HRT )
-                PHIout, c_start, c_end, c_internal = self.first_order_elimination(
+                    exp_term = exp( - k * HRT )
+                    PHIout, c_start, c_end, c_internal = \
+                            self.first_order_elimination(
                                        PHI, I, Q, v, HRT, L, V, k, exp_term)
+                else:
+                    PHIout = PHI
+                    c_start, c_end, c_internal = ( 0.0, 0.0, 0.0 )
             else:       # flux output
                 PHIout = PHI
                 c_start, c_end, c_internal = ( 0.0, 0.0, 0.0 )
-
         else:       # Opt: No loads in this stretch
             PHIout = PHI
             c_start, c_end, c_internal = ( 0.0, 0.0, 0.0 )
@@ -588,6 +602,7 @@
         ('STRETCH','Q_VAL'), ('STRETCH','Q_DIST'),
         ('STRETCH','V_VAL'), ('STRETCH','V_DIST'),
         ('STRETCH','L'), ('STRETCH','STRETCH_CLASS_ID'),
+        ('STRETCH','VOL_VAL'), ('STRETCH','VOL_DIST'),
         ('ENV', 'SS_CORR'),
         ('SUBST','KD_RIVER'), ('SUBST','K_OC'),
         ('SUBST','MM'),('SUBST','WS'),
@@ -1039,26 +1054,27 @@
     
                 # Hydralic Residence time in stretch [h]
                 if segment.type in model.LakeTypes:
-                    V = L           # In case of a lake the length stores the 
-                    HRT=L/Q         # volume by definition.
-                else:    
+                    V = self.V.get(shot_num)
+                    PHIout, c_start, c_end, c_internal = self.lake_concentration(
+                                                          PHI, Q, V, k)
+                else:
                     V = Q * L / v
                     HRT = L/v
     
-                # Solubility correction
-                if (PHI / Q) < (self.MM * self.WS):
-                    Cinitial = PHI / Q
-                else:
-                    Cinitial = self.MM * self.WS
-                Cx = Cinitial * exp( - k * HRT )
+                    # Solubility correction
+                    if (PHI / Q) < (self.MM * self.WS):
+                        Cinitial = PHI / Q
+                    else:
+                        Cinitial = self.MM * self.WS
+                    Cx = Cinitial * exp( - k * HRT )
+        
+                    if (PHI / Q) == 0:
+                        exp_term = 0
+                    else:
+                        exp_term = ( Cx / (PHI / Q) )
+                    PHIout, c_start, c_end, c_internal = self.first_order_elimination(
+                                            PHI, I, Q, v, HRT, L, V, k, exp_term)
     
-                if (PHI / Q) == 0:
-                    exp_term = 0
-                else:
-                    exp_term = ( Cx / (PHI / Q) )
-                PHIout, c_start, c_end, c_internal = self.first_order_elimination(
-                                        PHI, I, Q, v, HRT, L, V, k, exp_term)
-    
             else:   # flux output
                 PHIout = PHI
                 c_start, c_end, c_internal = ( 0.0, 0.0, 0.0 )



More information about the Greater-commits mailing list