Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

measuredWaterLevelFM.csv

scrollbar

We start by creating a list of coordinates using the cell centers (the initial waterlevel values are defined per cell).

Code Block
languagepy
titleSet intial confitions
coordinates = [[cell.Center.X, cell.Center.Y] for cell in fmModel.Grid.Cells]

 


For the initial conditions of water level, we will use some measurements at the start time of simulation. Since the information is only available at a few locations, we will interpolate those values to the rest of points within the enclosing polygon. Finally, we will assign a default value to the locations which have not been interpolated.

To begin with, we will import the measured data contained in the file measuredWaterLevelFM.csv, and will store that data in the list measuredWaterLevelsThen we get the waterlevel for these coordinates at the start time and set them as the initial waterlevel of our model.

Code Block
languagepy
titleSet intial confitionsImport water level data
# add initial conditions 
import csv

initialWaterLevelsmeasuredWaterLevels = []
initialCsvFilePath = with open(r"D:\\Workshop\data\initialmeasuredWaterLevelFM.csv"



with open(initialCsvFilePath) as csvfile: 

    lines = csv.reader(csvfile, delimiter=',')

    headers = 
lines.next()
    for line in lines:

        initialWaterLevelsmeasuredWaterLevels.append(map(float(line[0]))



fmModel.InitialWaterLevels.SetValues(initialWaterLevels), line))

Once loaded, we add the sample points to the initial water level coverage of the model. Then, we will interpolate the just added set of samples. In order to carry out these spatial operations, we first need to import the corresponding library.

Code Block
languagepy
titleAdd sample points to initital water level
from Libraries.SpatialOperations import * 
samplePoints = AddSamplePoints(fmModel, fmModel.InitialWaterLevel, measuredWaterLevels, subsetName = "subset water level measurements", sampleOperationName = "measurements 1-Jan-2012")
InterpolateSamplePoints(samplePoints[0], samplePoints[1], interpName ="Interpolated water level measurements")

Finally, we set the initial water level to 0.15 m for all the points that haven't been assigned any value after the interpolation. We do this for the entire domain (Envelope of the domain).

Code Block
languagepy
titleSet default water level value to non assigned locations
 AddSpatialOperationByPolygon("SetValue", fmModel, fmModel.InitialWaterLevel, "Envelope", values = [0.15], pointwiseType = "OverwriteWhereMissing")


The initial conditions have now been fully specified. Let's now proceed with the model parameters. 


To limit the calculation time, we change the maximum and initial delta t (time) to 1 hour using the SetModelProperty" function.

Code Block
languagepy
titleSet dtMax and dtInitial
# set model max and initial timestep size
timeStep = timedelta(hours=1)

SetModelProperty(fmModel, KnownProperties.DtMax, str(timeStep.total_seconds()))
SetModelProperty(fmModel, KnownProperties.DtInit, str(timeStep.total_seconds()))
 


scrollbar