First steps¶
Let's import and create a first model.
from hydrolib.core.io.structure.models import FlowDirection, StructureModel, Weir
from hydrolib.core.io.mdu.models import FMModel
fm = FMModel(filepath="test.mdu")
We can now add and/or manipulate features within the model.
# Start adding geometry
fm.geometry.netfile.network.mesh1d_add_branch() # TODO fix example
Add some structures, note this is invalid because it doesn't have a branch or coordinates yet, but it will work for demo purposes
struc = Weir(allowedflowdir=FlowDirection.none, crestlevel=0.0)
struc.comments.crestlevel = "This is a comment"
fm.geometry.structurefile = [StructureModel(structure=[struc])]
Weir
and other models always require
the use of keyword arguments. A ValidationError
will be raised
when the model isn't correct or complete, for instance, in the case
that StructureModel
was assigned directly to structurefile
instead
of as a list.
Now let's add this model to a DIMR config and save it.
from hydrolib.core.io.dimr.models import DIMR, FMComponent
dimr = DIMR()
dimr.component.append(
FMComponent(name="test", workingDir=".", inputfile=fm.filepath, model=fm)
)
dimr.save(folder=".")
dimrconfig.xml
, network.nc
, structures.ini
,test.mdu
)
in the working directory.