@@ -2103,29 +2103,22 @@ def run(self,
2103
2103
logger .debug ('%s elements scheduled.' %
2104
2104
self .num_elements_scheduled ())
2105
2105
logger .debug ('===================================' * 2 )
2106
- if len ( self . elements . lon ) > 0 :
2107
- lonmin = self . elements . lon . min ()
2108
- lonmax = self . elements . lon . max ()
2109
- latmin = self .elements . lat . min ( )
2110
- latmax = self . elements . lat . max ()
2111
- zmin = self . elements . z . min ()
2112
- zmax = self . elements . z . max ( )
2113
- if latmin == latmax :
2114
- logger .debug ('\t \t latitude = %s' % ( latmin ) )
2106
+
2107
+ # Display element locations to terminal
2108
+ for n in [ 'lat' , ' lon' , 'z' ]:
2109
+ d = getattr ( self .elements , n )
2110
+ dmin = d . min ();
2111
+ dmax = d . max ()
2112
+ n = n . replace ( 'lat' , 'latitude' ). replace ( 'lon' , 'longitude' )
2113
+ if dmin == dmax :
2114
+ logger .debug (f '\t \t { n } = { dmin } ' )
2115
2115
else :
2116
- logger .debug ('\t \t %s <- latitude -> %s' %
2117
- (latmin , latmax ))
2118
- if lonmin == lonmax :
2119
- logger .debug ('\t \t longitude = %s' % (lonmin ))
2120
- else :
2121
- logger .debug ('\t \t %s <- longitude -> %s' %
2122
- (lonmin , lonmax ))
2123
- if zmin == zmax :
2124
- logger .debug ('\t \t z = %s' % (zmin ))
2125
- else :
2126
- logger .debug ('\t \t %s <- z -> %s' % (zmin , zmax ))
2127
- logger .debug ('---------------------------------' )
2116
+ logger .debug (f'\t \t { dmin } <- { n } -> { dmax } ' )
2117
+ logger .debug ('---------------------------------' )
2128
2118
2119
+ ###############################################
2120
+ # Get environment data for all active elements
2121
+ ###############################################
2129
2122
self .environment , self .environment_profiles , missing = \
2130
2123
self .env .get_environment (list (self .required_variables ),
2131
2124
self .time ,
@@ -2137,57 +2130,40 @@ def run(self,
2137
2130
2138
2131
self .calculate_missing_environment_variables ()
2139
2132
2140
- if any (missing ):
2141
- self .report_missing_variables ()
2142
-
2143
- self .store_previous_variables ()
2133
+ self .report_missing_variables (missing )
2144
2134
2145
2135
self .interact_with_coastline ()
2146
2136
2147
2137
self .interact_with_seafloor ()
2148
2138
2149
- self .deactivate_elements (missing , reason = 'missing_data' )
2150
-
2151
2139
self .state_to_buffer () # Append status to history array
2152
-
2140
+
2153
2141
self .increase_age_and_retire ()
2154
2142
2155
2143
self .remove_deactivated_elements ()
2156
2144
2157
- # Propagate one timestep forwards
2158
- self .steps_calculation += 1
2159
-
2160
- if self .num_elements_active (
2161
- ) == 0 and self .num_elements_scheduled () == 0 :
2162
- raise ValueError (
2163
- 'No more active or scheduled elements, quitting.' )
2164
-
2165
2145
# Store location, in case elements shall be moved back
2166
2146
self .store_present_positions ()
2167
-
2168
- #####################################################
2147
+
2169
2148
if self .num_elements_active () > 0 :
2149
+ ########################################
2150
+ # Calling module specific update method
2151
+ ########################################
2170
2152
logger .debug ('Calling %s.update()' % type (self ).__name__ )
2171
2153
self .timer_start ('main loop:updating elements' )
2172
2154
self .update ()
2173
2155
self .timer_end ('main loop:updating elements' )
2174
2156
else :
2175
- logger .info ('No active elements, skipping update() method' )
2176
- #####################################################
2157
+ if self .num_elements_scheduled () == 0 :
2158
+ raise ValueError ('No more active or scheduled elements, quitting.' )
2159
+ else :
2160
+ logger .info ('No active elements, skipping update() method' )
2177
2161
2178
2162
self .horizontal_diffusion ()
2179
2163
2180
- if self .num_elements_active (
2181
- ) == 0 and self .num_elements_scheduled () == 0 :
2182
- raise ValueError (
2183
- 'No active or scheduled elements, quitting simulation' )
2184
-
2185
- logger .debug ('%s active elements (%s deactivated)' %
2186
- (self .num_elements_active (),
2187
- self .num_elements_deactivated ()))
2188
2164
# Updating time
2189
- if self .time is not None :
2190
- self .time = self . time + self . time_step
2165
+ self .time = self . time + self . time_step
2166
+ self .steps_calculation += 1
2191
2167
2192
2168
except Exception as e :
2193
2169
message = ('The simulation stopped before requested '
@@ -2218,7 +2194,7 @@ def run(self,
2218
2194
self .timer_end ('total time' )
2219
2195
self .state_to_buffer (final = True ) # Append final status to buffer
2220
2196
2221
- ## Add any other data to the result here .
2197
+ # Module specific post processing .
2222
2198
self .post_run ()
2223
2199
2224
2200
if outfile is not None :
@@ -2390,18 +2366,22 @@ def state_to_buffer(self, final=False):
2390
2366
self .result .coords ['time' ] = newtime
2391
2367
logger .debug (f'Reset self.result, size { self .result .sizes } ' )
2392
2368
2393
- def report_missing_variables (self ):
2394
- """Issue warning if some environment variables missing."""
2369
+ def report_missing_variables (self , missing ):
2370
+ """Deactivate elements whose environment variables are missing."""
2371
+
2372
+ if not any (missing ):
2373
+ return
2395
2374
2396
- missing_variables = []
2397
- for var in self .required_variables :
2398
- if np .isnan (getattr (self .environment , var ).min ()):
2399
- missing_variables .append (var )
2375
+ missing_variables = [v for v in self .required_variables
2376
+ if np .any (np .isnan (getattr (self .environment , v )))]
2400
2377
2401
2378
if len (missing_variables ) > 0 :
2402
2379
logger .warning ('Missing variables: ' + str (missing_variables ))
2403
2380
self .store_message ('Missing variables: ' + str (missing_variables ))
2404
2381
2382
+ # TODO: missing should probably be updated after calculating derived variables
2383
+ self .deactivate_elements (missing , reason = 'missing_data' )
2384
+
2405
2385
def index_of_first_and_last (self ):
2406
2386
"""Return the indices when elements were seeded and deactivated."""
2407
2387
0 commit comments