|
| 1 | +# Application overview |
| 2 | + |
| 3 | +The application is setup using a layered architecture (see [link](architecture.md)). |
| 4 | + |
| 5 | +To create the application you will need to create these three components: logger, data-access layer and model builder (see [main.py](https://github.com/Deltares/D-EcoImpact/blob/main/main.py)). |
| 6 | + |
| 7 | +```python |
| 8 | + # configure logger and data-access layer |
| 9 | + logger: ILogger = LoggerFactory.create_logger() |
| 10 | + da_layer: IDataAccessLayer = DataAccessLayer(logger) |
| 11 | + model_builder = ModelBuilder(da_layer, logger) |
| 12 | + |
| 13 | + # create and run application |
| 14 | + application = Application(logger, da_layer, model_builder) |
| 15 | + application.run(path) |
| 16 | +``` |
| 17 | + |
| 18 | +The logger provides logging functionality to the application, like reporting errors, warnings, user information and debug messages and is created using a factory pattern. |
| 19 | +The DataAccessLayer gives the application access to the file system and allows for parsing of input and output. |
| 20 | +The modelbuilder uses the builder pattern to create a model from a IModelData data object (created by the data-access layer). |
| 21 | + |
| 22 | +## Running the application |
| 23 | + |
| 24 | +After constructing the application, the application should be ready to run. |
| 25 | +During the running of the application the following steps are executed. |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +The application starts by reading the `ModelData` object from the input files via the `IDataAccessLayer`. |
| 30 | +This gets passed to the `IModelBuilder`to convert the `ModelData` into a `IModel` that can be run. |
| 31 | +The static `ModelRunner` will then be called to run the created `IModel` and do the real computation. |
| 32 | + |
| 33 | +## Model run |
| 34 | + |
| 35 | +When the `ModelRunner` `run_model` command is executed, the following steps are performed (using `RuleBasedModel` and `ICellBasedRule` as an example). |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +The `ModelRunner` starts by validating the model (`RuleBasedModel` in this example). |
| 40 | +The `RuleBasedModel` delegates the validation of the set of rules that it is composed with, calling the validate on every rule (`ICellBasedRule` in this example). |
| 41 | +After the model is successfully validated, the initialize of the model is called. In case of the `RuleBasedModel`, this creates an instance of the `RuleProcessor` and initializes it. |
| 42 | + |
| 43 | +The `ModelRunner` continues by calling the `execute` method on the `RuleBasedModel` that in turn calls `process_rules` on the `RuleBasedProcessor`. |
| 44 | +This method loops over all the specified rules and executes the rules based on their type. So for example, with the `ICellBasedRule` the `RuleBasedProcessor` will loop over all the cells and call the `ICellBasedRule` execute method for every cell. |
| 45 | + |
| 46 | +When the model execute has successfully finished with the execute step, the `finalize` method will be called on the model to clean up all resources. |
| 47 | + |
| 48 | +## Class diagram |
| 49 | + |
| 50 | + |
0 commit comments