[GeoMechanicsApplication] Reuse Python script to run multiple stages#13550
[GeoMechanicsApplication] Reuse Python script to run multiple stages#13550
Conversation
- Added a context manager that sets the current working directory in the present context. - Only read the `ProjectParameters.json` file when we are about to run that stage. - Don't let the Python script that runs multiple stages modify the system's path. - The 1D consolidation test now reuses the general run multiple stages function.
All tests that used to call `run_stages` from `test_helper.py` now call `run_stages` from `run_multiple_stages.py`. In this way, we have removed some duplicated code.
After running the geomechanics analysis stages, return a list of run stages.
Prefer to use the Python script that runs multiple analysis stages.
Rather use `"input_type": "use_input_model_part"`, since the model did not change over the stages.
That required reading the analysis results from the output files.
This function was no longer used.
mcgicjn2
left a comment
There was a problem hiding this comment.
This appears to do as expected and I like some of the improvements.
WPK4FEM
left a comment
There was a problem hiding this comment.
Thank you for the clean up. Using context_managers.py makes the behaviour of the test suite more predictable as it solves the directory switching issues. I commented most on the changes in the functional part, the changes in the tests themselves as clear to me and a direct and predictable consequence of the changes in functionality.
applications/GeoMechanicsApplication/python_scripts/run_multiple_stages.py
Show resolved
Hide resolved
applications/GeoMechanicsApplication/python_scripts/run_multiple_stages.py
Show resolved
Hide resolved
applications/GeoMechanicsApplication/python_scripts/run_multiple_stages.py
Outdated
Show resolved
Hide resolved
| import KratosMultiphysics.GeoMechanicsApplication.context_managers as context_managers | ||
|
|
||
|
|
||
| def run_stages(project_path, n_stages): |
There was a problem hiding this comment.
It would be nice that at some point n_stages becomes an optional argument, such that on omission all stages present are executed. The n_stages argument could then be used to execute the first n stages.
There was a problem hiding this comment.
Agreed. Also, I can imagine that at some point we'd like to have the option to explicitly specify a set of filenames or a different filename pattern. But, indeed, such extensions need a bit more thought before attempting to implement them.
Moved a few files and removed two subdirectories. Also improved the assertions: make sure that the stress vector results have the correct sizes.
📝 Description
The integration tests that called
run_stagesfrom thetest_helper.pyscript now use the cleaned up Python scriptrun_multiple_stages.py.🆕 Changelog
Changes include:
run_stages,get_stages,get_separated_directory_names, andget_separated_stagesfromtest_helper.py. Their usages have been replaced byrun_stagesfromrun_multiple_stages.py.setUpandtearDownmethods of the modified integration tests, since doing nothing is the default behavior. Thus no overrides are needed.run_stagesfunction fromrun_multiple_stages.pynow returns a list ofGeoMechanicsAnalysisinstances, just like the replacedrun_stagesfunction fromtest_helper.pydid..mdpafiles and used"input_type": "use_input_model_part"to indicate that no model files need to be read for those stages.