Deltares / GEOLib

GEOLib: Python wrappers around the input and output files of the Deltares D-Serie models
https://deltares.github.io/GEOLib/
MIT License
21 stars 17 forks source link

Changing existing model using Geolib #84

Closed kniazmajowiec closed 2 weeks ago

kniazmajowiec commented 1 year ago

I'm trying to use Geolib to modify existing DSheetPilling model: model = DSheetPilingModel() model.parse(Path('tutorial.shi'))

tutorial.shi is based on the tutorial https://deltares.github.io/GEOLib/latest/community/tutorial_dsheetpiling.html

However, when I want to add new construction stage, the existing one in the model is overwritten. new_stage_id = model.add_stage( name="Newer Stage", passive_side=PassiveSide.DSHEETPILING_DETERMINED, method_left=LateralEarthPressureMethodStage.KA_KO_KP, method_right=LateralEarthPressureMethodStage.KA_KO_KP, pile_top_displacement=0.02, )

I found out that construction stages (model.datastructure.input_data.construction_stages) are of the type str Is there a better way of working with existing models?

VirginieTrompille commented 1 year ago

We can't reproduce the problem you describe. We created the following test where 2 construction stages are added. It works as expected.

Best regards, Virginie Trompille

==================================== @pytest.mark.unittest def test_add_second_stage_with_different_name(self): model = DSheetPilingModel() name_1st_stage = "Initial stage" name_2nd_stage = "Second stage"

    assert model.current_stage is None

    model.add_stage(
        name=name_1st_stage,
        passive_side=PassiveSide.DSHEETPILING_DETERMINED,
        method_left=LateralEarthPressureMethodStage.KA_KO_KP,
        method_right=LateralEarthPressureMethodStage.KA_KO_KP,
    )
    assert model.current_stage == 0
    assert len(model.datastructure.input_data.construction_stages.stages) == 1
    assert (model.datastructure.input_data.construction_stages.stages[0].passive_side
            == PassiveSide.DSHEETPILING_DETERMINED)

    model.add_stage(
        name=name_2nd_stage,
        passive_side=PassiveSide.LEFT,
        method_left=LateralEarthPressureMethodStage.KA_KO_KP,
        method_right=LateralEarthPressureMethodStage.KA_KO_KP,
    )
    assert model.current_stage == 1
    assert len(model.datastructure.input_data.construction_stages.stages) == 2
    assert (model.datastructure.input_data.construction_stages.stages[0].passive_side
            == PassiveSide.DSHEETPILING_DETERMINED)
    assert (model.datastructure.input_data.construction_stages.stages[1].passive_side
            == PassiveSide.LEFT)
kniazmajowiec commented 1 year ago

Dear Virginie,

Correct me if I am wrong, but in the provided test I do not see that you are parsing any existing model. In the parsed model with existing stages I would expect model.current_stage not to be None.

I checked and indeed, in my case, the model.current_stage in None when I parse my file with existing construction stage.

Maybe I did not make myself clear but how can I add the construction stage to existing model, which I generated by parsing existing .shi file without loosing the previous stages

Thank you in advance for your help

VirginieTrompille commented 1 year ago

When parsing a SHI file into a model (DSheetPilingModel), model.current_stage is indeed always set to None. And not all the components of the object model.datastructure.input_data (DSheetPilingInputStructure) are converted, many are left as string (see the list below), which is the case for construction_stages as you already noticed. When adding a new stage as object, the string is replaced by the new created object. In the future, we aim to convert more components of the DSheetPilingInputStructure. For the time being, it is unfortunately not possible to work with the string objects.

List of not converted objects:

Best regards, Virginie Trompille