diff --git a/docs/configuration.md b/docs/configuration.md index 50282950..d2243f29 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -107,7 +107,7 @@ The Micro Manager can adaptively control micro simulations. The adaptivity strat All the adaptivity parameters are chosen from the second publication. -To turn on adaptivity, the following options need to be set in `simulation_params` under the sub-heading `adaptivity`: +To turn on adaptivity, set `"adaptivity": True` in `simulation_params`. Then under `adaptivity_settings` set the following variables: Parameter | Description --- | --- @@ -119,12 +119,13 @@ Parameter | Description `every_implicit_iteration` | If True, adaptivity is calculated in every implicit iteration.
If False, adaptivity is calculated once at the start of the time window and then reused in every implicit time iteration. `similarity_measure`| Similarity measure to be used for adaptivity. Can be either `L1`, `L2`, `L1rel` or `L2rel`. By default, `L1` is used. The `rel` variants calculate the respective relative norms. This parameter is *optional*. -Example of adaptivity configuration +Example of adaptivity configuration is ```json "simulation_params": { "macro_domain_bounds": [0, 1, 0, 1, 0, 1], - "adaptivity" { + "adaptivity": "True", + "adaptivity_settings" { "type": "local", "data": ["temperature", "porosity"], "history_param": 0.5, diff --git a/examples/micro-manager-adaptivity-config.json b/examples/micro-manager-adaptivity-config.json index 76a7fd78..920f5c35 100644 --- a/examples/micro-manager-adaptivity-config.json +++ b/examples/micro-manager-adaptivity-config.json @@ -8,7 +8,8 @@ }, "simulation_params": { "macro_domain_bounds": [0.0, 25.0, 0.0, 25.0, 0.0, 25.0], - "adaptivity": { + "adaptivity": "True", + "adaptivity_settings": { "type": "local", "data": ["macro-scalar-data", "macro-vector-data"], "history_param": 0.5, diff --git a/micro_manager/config.py b/micro_manager/config.py index 700f70ac..4024b059 100644 --- a/micro_manager/config.py +++ b/micro_manager/config.py @@ -124,25 +124,33 @@ def read_json(self, config_filename): ) try: - if data["simulation_params"]["adaptivity"]: + if data["simulation_params"]["adaptivity"] == "True": self._adaptivity = True + if not data["simulation_params"]["adaptivity_settings"]: + raise Exception( + "Adaptivity is turned on but no adaptivity settings are provided." + ) else: self._adaptivity = False + if data["simulation_params"]["adaptivity_settings"]: + raise Exception( + "Adaptivity settings are provided but adaptivity is turned off." + ) except BaseException: self._logger.info( - "Micro Manager will not adaptively run micro simulations, but instead will run all micro simulations in all time steps." + "Micro Manager will not adaptively run micro simulations, but instead will run all micro simulations." ) if self._adaptivity: - if data["simulation_params"]["adaptivity"]["type"] == "local": + if data["simulation_params"]["adaptivity_settings"]["type"] == "local": self._adaptivity_type = "local" - elif data["simulation_params"]["adaptivity"]["type"] == "global": + elif data["simulation_params"]["adaptivity_settings"]["type"] == "global": self._adaptivity_type = "global" else: raise Exception("Adaptivity type can be either local or global.") exchange_data = {**self._read_data_names, **self._write_data_names} - for dname in data["simulation_params"]["adaptivity"]["data"]: + for dname in data["simulation_params"]["adaptivity_settings"]["data"]: self._data_for_adaptivity[dname] = exchange_data[dname] if self._data_for_adaptivity.keys() == self._write_data_names.keys(): @@ -152,19 +160,19 @@ def read_json(self, config_filename): " please include macro simulation data as well." ) - self._adaptivity_history_param = data["simulation_params"]["adaptivity"][ - "history_param" - ] + self._adaptivity_history_param = data["simulation_params"][ + "adaptivity_settings" + ]["history_param"] self._adaptivity_coarsening_constant = data["simulation_params"][ - "adaptivity" + "adaptivity_settings" ]["coarsening_constant"] self._adaptivity_refining_constant = data["simulation_params"][ - "adaptivity" + "adaptivity_settings" ]["refining_constant"] - if "similarity_measure" in data["simulation_params"]["adaptivity"]: + if "similarity_measure" in data["simulation_params"]["adaptivity_settings"]: self._adaptivity_similarity_measure = data["simulation_params"][ - "adaptivity" + "adaptivity_settings" ]["similarity_measure"] else: self._logger.info( @@ -173,7 +181,7 @@ def read_json(self, config_filename): self._adaptivity_similarity_measure = "L1" adaptivity_every_implicit_iteration = data["simulation_params"][ - "adaptivity" + "adaptivity_settings" ]["every_implicit_iteration"] if adaptivity_every_implicit_iteration == "True": diff --git a/tests/integration/test_unit_cube/micro-manager-config-global-adaptivity-parallel.json b/tests/integration/test_unit_cube/micro-manager-config-global-adaptivity-parallel.json index 4edbd391..62f2006d 100644 --- a/tests/integration/test_unit_cube/micro-manager-config-global-adaptivity-parallel.json +++ b/tests/integration/test_unit_cube/micro-manager-config-global-adaptivity-parallel.json @@ -9,7 +9,8 @@ "simulation_params": { "macro_domain_bounds": [0, 1, 0, 1, 0, 1], "decomposition": [2, 1, 1], - "adaptivity": { + "adaptivity": "True", + "adaptivity_settings": { "type": "global", "data": ["macro-scalar-data", "micro-vector-data"], "history_param": 0.5, diff --git a/tests/integration/test_unit_cube/micro-manager-config-global-adaptivity.json b/tests/integration/test_unit_cube/micro-manager-config-global-adaptivity.json index 808bcae4..43e63601 100644 --- a/tests/integration/test_unit_cube/micro-manager-config-global-adaptivity.json +++ b/tests/integration/test_unit_cube/micro-manager-config-global-adaptivity.json @@ -8,7 +8,8 @@ }, "simulation_params": { "macro_domain_bounds": [0, 1, 0, 1, 0, 1], - "adaptivity": { + "adaptivity": "True", + "adaptivity_settings": { "type": "global", "data": ["macro-scalar-data", "macro-vector-data"], "history_param": 0.5, diff --git a/tests/integration/test_unit_cube/micro-manager-config-local-adaptivity.json b/tests/integration/test_unit_cube/micro-manager-config-local-adaptivity.json index f6884e83..acd0563c 100644 --- a/tests/integration/test_unit_cube/micro-manager-config-local-adaptivity.json +++ b/tests/integration/test_unit_cube/micro-manager-config-local-adaptivity.json @@ -8,7 +8,8 @@ }, "simulation_params": { "macro_domain_bounds": [0, 1, 0, 1, 0, 1], - "adaptivity": { + "adaptivity": "True", + "adaptivity_settings": { "type": "local", "data": ["macro-scalar-data", "macro-vector-data"], "history_param": 0.5, diff --git a/tests/unit/micro-manager-config.json b/tests/unit/micro-manager-config.json index 42a4181f..d1a4bbaf 100644 --- a/tests/unit/micro-manager-config.json +++ b/tests/unit/micro-manager-config.json @@ -8,7 +8,8 @@ }, "simulation_params": { "macro_domain_bounds": [0.0, 25.0, 0.0, 25.0, 0.0, 25.0], - "adaptivity": { + "adaptivity": "True", + "adaptivity_settings": { "type": "local", "data": ["macro-scalar-data", "macro-vector-data"], "history_param": 0.5,