OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
245 stars 120 forks source link

How to prevent simulation stopping with no active elements #871

Closed Kiwichar closed 2 years ago

Kiwichar commented 2 years ago

I am trying to release elements at different times, but all the elements from the first release are stranded before the second release takes place so the simulation stops. Is there a way to prevent this (other than creating a whole new simulation)?

Thank you

knutfrode commented 2 years ago

Hi. The simulation should not stop if there are unseeded elements. Can you share your script?

Kiwichar commented 2 years ago

Hi, thanks for reply. I assume the issue is because I am trying to use 2 different readers for separate months and which landmask I use as when I dont include o.set_config('general:use_auto_landmask', False it works fine.

from opendrift.readers import reader_netCDF_CF_generic
from opendrift.readers import reader_ROMS_native
from opendrift.readers import reader_ROMS_native_MOANA
from datetime import datetime,timedelta
from opendrift.models.oceandrift import OceanDrift
import numpy as np
import sys

o = OceanDrift(loglevel=0)  # Set loglevel to 0 for debug information

###############################
# READERS
###############################
thredds_path_1 = 'http://thredds.moanaproject.org:8080/thredds/dodsC/moana/ocean/NZB/v1.9/monthly_avg/nz5km_avg_201711.nc'
reader_moana_v1 = reader_ROMS_native_MOANA.Reader(thredds_path_1) 
reader_moana_v1.multiprocessing_fail = True # bypass the use of multi core for coordinates conversion and seems to make the model run much faster.
thredds_path_2 = 'http://thredds.moanaproject.org:8080/thredds/dodsC/moana/ocean/NZB/v1.9/monthly_avg/nz5km_avg_201712.nc'
reader_moana_v2 = reader_ROMS_native_MOANA.Reader(thredds_path_2) 
reader_moana_v2.multiprocessing_fail = True
print(reader_moana_v1)
print(reader_moana_v2)
# use native landmask of ROMS files
o.add_reader([reader_moana_v1, reader_moana_v2])
o.set_config('general:use_auto_landmask', False) # prevent opendrift from making a new dynamical landmask

###############################
# PHYSICS & CONFIG
###############################

o.seed_elements( lon = 174.949513895-.1, lat = -40.029317969-.1, 
                 number=100, z = - np.linspace(2,50,100) ,
                 radius = 1000,
                 terminal_velocity = -1.0, # setting a large settling velocity on purpose to make seafloor contacts
                 time = [reader_moana_v1.start_time, reader_moana_v1.start_time+timedelta(days=15)],
                 origin_marker=0)
o.seed_elements( lon = 174.949513895-.1, lat = -40.029317969-.1, 
                 number=100, z = - np.linspace(2,50,100) ,
                 radius = 1000,
                 terminal_velocity = -1.0, # setting a large settling velocity on purpose to make seafloor contacts
                 time = [reader_moana_v2.start_time, reader_moana_v2.start_time+timedelta(days=15)],
                 origin_marker=1)
o.set_config('drift:max_age_seconds', 3888000)
# Running model (until end of driver data)
print(o)
o.run(
      time_step=timedelta(seconds = 900),
      end_time = reader_moana_v2.end_time,
      time_step_output=timedelta(seconds = 3600 * 3))
Kiwichar commented 2 years ago

Ah! I should clarify that this code uses different dates so all elements dont become stranded anyway, but I still have the issue which the simulation ends at the end of first reader date not second.

knutfrode commented 2 years ago

Ok, it seems here that the problem is that you don't have landmask (which is required variable) for the interim period. I guess this can be solved by adding this line: o.set_config('environment:fallback:land_binary_mask', 0)

Kiwichar commented 2 years ago

Thanks for your help, this solution worked!