Skip to content

Commit

Permalink
Merge branch 'precice:develop' into Relax_similarity_condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Fujikawas authored Nov 14, 2023
2 parents e17a662 + 6c08889 commit 8e99cab
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-adaptivity-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test for functions in classes AdaptivityCalculator, LocalAdaptivityCalculator, GlobalAdaptivityCalculator
name: Test adaptivity functionality
on:
push:
branches:
Expand Down
46 changes: 46 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cff-version: "1.2.0"
authors:
- family-names: Desai
given-names: Ishaan
orcid: "https://orcid.org/0000-0002-2552-7509"
- family-names: Scheurer
given-names: Erik
orcid: "https://orcid.org/0009-0000-9396-2994"
- family-names: Bringedal
given-names: Carina
orcid: "https://orcid.org/0000-0003-0495-2634"
- family-names: Uekermann
given-names: Benjamin
orcid: "https://orcid.org/0000-0002-1314-9969"
doi: 10.18419/darus-3764
message: If you use this software, please cite our article in the
Journal of Open Source Software.
preferred-citation:
authors:
- family-names: Desai
given-names: Ishaan
orcid: "https://orcid.org/0000-0002-2552-7509"
- family-names: Scheurer
given-names: Erik
orcid: "https://orcid.org/0009-0000-9396-2994"
- family-names: Bringedal
given-names: Carina
orcid: "https://orcid.org/0000-0003-0495-2634"
- family-names: Uekermann
given-names: Benjamin
orcid: "https://orcid.org/0000-0002-1314-9969"
date-published: 2023-11-07
doi: 10.21105/joss.05842
issn: 2475-9066
issue: 91
journal: Journal of Open Source Software
publisher:
name: Open Journals
start: 5842
title: "Micro Manager: a Python package for adaptive and flexible
two-scale coupling"
type: article
url: "https://joss.theoj.org/papers/10.21105/joss.05842"
volume: 8
title: "Micro Manager: a Python package for adaptive and flexible
two-scale coupling"
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Contributing to the Micro Manager

Contributions to the Micro Manager are most welcome! Please have a look at the page [contributing to preCICE](https://precice.org/community-contribute-to-precice.html) and also this page for more details.

## Automatic checks

We check every contribution with a few GitHub Actions workflows that report at the bottom of each pull request. For example, we have an Action to check if the contributed code is formatting correctly according to [autopep8](https://pypi.org/project/autopep8/).

## Changelog

We maintain a `CHANGELOG.md` where all major changes and contributions are entered.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<img src="https://github.com/precice/micro-manager/actions/workflows/pythonpublish.yml/badge.svg" alt="Upload Python Package">
</a>

[![DOI](https://joss.theoj.org/papers/10.21105/joss.05842/status.svg)](https://doi.org/10.21105/joss.05842)

A tool to facilitate solving two-scale (macro-micro) coupled problems using the coupling library [preCICE](https://www.precice.org/).

The main documentation is rendered on the [preCICE website](https://precice.org/tooling-micro-manager-overview.html).

Please report any [issues](https://github.com/precice/micro-manager/issues) and give us feedback through [one of our community channels](https://precice.org/community-channels.html).

The concept and initial design of the Micro Manager is described in *Desai, Ishaan, & Bringedal, Carina & Uekermann, Benjamin. A flexible software approach to simulate two-scale coupled problems. ECCOMAS Congress 2022. [10.23967/eccomas.2022.037](https://doi.org/10.23967/eccomas.2022.037)*.
22 changes: 18 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# Solverdummies

The `solverdummies` are minimal working examples for using the preCICE Micro Manager with different languages. At the moment, there are examples for Python, and C++. They can be coupled with any other solver, for example the `macro-dummy.py` in this directory.
The `solverdummies` are minimal working examples for using the preCICE Micro Manager with different languages. At the moment, there are examples for Python, and C++. They can be coupled with any other solver, for example the `macro_dummy.py` in this directory.

## Python

To run the Python solverdummies, run the following commands in the `examples/` directory in **two different terminals**:

```bash
python macro-dummy.py
python python-dummy/run_micro_manager.py
python macro_dummy.py
python python-dummy/run_micro_manager.py --config micro-manager-config.json
```

Note that running `micro_manager micro-manager-config.json` from the terminal will not work, as the path in the configuration file is relative to the current working directory. See [#36](https://github.com/precice/micro-manager/issues/36) for more information.

To run the Python solverdummies with adaptivity run the following commands in the `examples/` directory in **two different terminals**:

```bash
python macro_dummy.py
python python-dummy/run_micro_manager.py --config micro-manager-adaptivity-config.json
```

## C++

The C++ solverdummies have to be compiled first using [`pybind11`](https://pybind11.readthedocs.io/en/stable/index.html). To do so, install `pybind11` using `pip`:
Expand Down Expand Up @@ -42,7 +49,14 @@ Then, run the following commands in the `examples/` directory, in **two differen

```bash
python macro_dummy.py
python cpp-dummy/run_micro_manager.py
python cpp-dummy/run_micro_manager.py --config micro-manager-config.json
```

To run the C++ solverdummies with adaptivity run the following commands in the `examples/` directory in **two different terminals**:

```bash
python macro_dummy.py
python cpp-dummy/run_micro_manager.py --config micro-manager-adaptivity-config.json
```

When changing the C++ solverdummy to your own solver, make sure to change the `PYBIND11_MODULE` in `micro_cpp_dummy.cpp` to the name that you want to compile to.
Expand Down
10 changes: 6 additions & 4 deletions micro_manager/micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(self, config_file: str) -> None:
if name in self._write_data_names:
self._adaptivity_micro_data_names[name] = is_data_vector

self._is_adaptivity_required_in_every_implicit_iteration = self._config.is_adaptivity_required_in_every_implicit_iteration()
self._adaptivity_in_every_implicit_step = self._config.is_adaptivity_required_in_every_implicit_iteration()
self._micro_sims_active_steps = None

# **************
Expand Down Expand Up @@ -149,6 +149,8 @@ def initialize(self) -> None:

self._mesh_vertex_ids, mesh_vertex_coords = self._participant.get_mesh_vertex_ids_and_coordinates(
self._macro_mesh_name)
assert (mesh_vertex_coords.size != 0), "Macro mesh has no vertices."

self._local_number_of_sims, _ = mesh_vertex_coords.shape
self._logger.info("Number of local micro simulations = {}".format(self._local_number_of_sims))

Expand Down Expand Up @@ -282,7 +284,7 @@ def solve(self) -> None:
n_checkpoint = n

if self._is_adaptivity_on:
if not self._is_adaptivity_required_in_every_implicit_iteration:
if not self._adaptivity_in_every_implicit_step:
similarity_dists, is_sim_active, sim_is_associated_to = self._adaptivity_controller.compute_adaptivity(
self._dt, self._micro_sims, similarity_dists, is_sim_active, sim_is_associated_to, self._data_for_adaptivity)

Expand All @@ -304,7 +306,7 @@ def solve(self) -> None:
micro_sims_input = self._read_data_from_precice()

if self._is_adaptivity_on:
if self._is_adaptivity_required_in_every_implicit_iteration:
if self._adaptivity_in_every_implicit_step:
similarity_dists, is_sim_active, sim_is_associated_to = self._adaptivity_controller.compute_adaptivity(
self._dt, self._micro_sims, similarity_dists, is_sim_active, sim_is_associated_to, self._data_for_adaptivity)

Expand Down Expand Up @@ -339,7 +341,7 @@ def solve(self) -> None:

# If adaptivity is computed only once per time window, the states of sims need to be reset too
if self._is_adaptivity_on:
if not self._is_adaptivity_required_in_every_implicit_iteration:
if not self._adaptivity_in_every_implicit_step:
similarity_dists = np.copy(similarity_dists_cp)
is_sim_active = np.copy(is_sim_active_cp)
sim_is_associated_to = np.copy(sim_is_associated_to_cp)
Expand Down
18 changes: 0 additions & 18 deletions tests/unit/test_adaptivity_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ def test_update_active_sims(self):

is_sim_active = np.array([True, True, True, True, True]) # Activate all micro sims before calling functionality

class MicroSimulation():
pass

dummy_micro_sims = []
for _ in range(self._number_of_sims):
dummy_micro_sims.append(MicroSimulation())

is_sim_active = adaptivity_controller._update_active_sims(
self._similarity_dists, is_sim_active)

Expand Down Expand Up @@ -153,17 +146,6 @@ def test_associate_active_to_inactive(self):
is_sim_active = np.array([True, False, False, True, False])
expected_sim_is_associated_to = np.array([-2, 0, 0, -2, 3])

class MicroSimulation():
def __init__(self, global_id):
self._global_id = global_id

def get_global_id(self):
return self._global_id

dummy_micro_sims = []
for i in range(self._number_of_sims):
dummy_micro_sims.append(MicroSimulation(i))

sim_is_associated_to = np.array([-2, -2, -2, -2, -2])

sim_is_associated_to = adaptivity_controller._associate_inactive_to_active(
Expand Down

0 comments on commit 8e99cab

Please sign in to comment.