Skip to content

Commit ccf86ef

Browse files
committed
Merge branch 'develop' into feature/GBDiffusion
2 parents 465c2ed + 646c32e commit ccf86ef

File tree

8 files changed

+204
-38
lines changed

8 files changed

+204
-38
lines changed

.github/workflows/test_pyfans.yaml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
name: Test PyFans
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- "*"
411

512
jobs:
6-
pyfans-run-test:
13+
test-pyfans:
714
runs-on: ubuntu-latest
815
container: unistuttgartdae/fans-ci:noble
916
defaults:
@@ -23,15 +30,27 @@ jobs:
2330
- name: Install dependencies
2431
run: |
2532
apt update
26-
apt install -y cmake make g++ python3 python3-numpy python3.12-dev
33+
apt install -y wget python3-venv
34+
35+
- name: Install preCICE
36+
run: |
37+
wget https://github.com/precice/precice/releases/download/v3.2.0/libprecice3_3.2.0_noble.deb
38+
apt install -y ./libprecice3_3.2.0_noble.deb
39+
40+
- name: Install the Micro Manager
41+
run: |
42+
python3 -m venv .venv
43+
. .venv/bin/activate
44+
pip install micro-manager-precice
2745
2846
- name: Configure
2947
working-directory: ${{ env.FANS_BUILD_DIR }}
3048
run: |
3149
cmake .. -DFANS_LIBRARY_FOR_MICRO_MANAGER=ON
3250
make
3351
34-
- name: Run FANS as a library via a Python script
52+
- name: Run a dummy macro-micro coupling test
3553
run: |
54+
. .venv/bin/activate
3655
cd test/test_pyfans
37-
python3 run_fans_as_library.py
56+
python3 macro-cube.py & micro-manager-precice micro-manager-config.json

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## latest
44

55
- Add grain boundary diffusion material model for polycrystals https://github.com/DataAnalyticsEngineering/FANS/pull/52
6+
- Remove MPI initialization from pyFANS and add an integration test for it https://github.com/DataAnalyticsEngineering/FANS/pull/46
67
- Native support for MacOS https://github.com/DataAnalyticsEngineering/FANS/pull/25
78
- Remove Ubuntu 20.04 from testing and Docker support https://github.com/DataAnalyticsEngineering/FANS/pull/51
89
- Add support for `--version` command line argument for checking the version of FANS

pyfans/micro.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// In this file we solve a micro problem with FANS which is controlled by the Micro Manager
33
// This file is compiled with pybind11 to be available as a python module
44
//
5-
// To check if python is able to import it, run:
6-
// python3 -c "import micro; micro.MicroSimulation(1)"
7-
// from the same directory
85

96
#include "micro.hpp"
107
#include "setup.h"
@@ -29,8 +26,6 @@ py::array_t<double> merge_arrays(py::array_t<double> array1, py::array_t<double>
2926

3027
MicroSimulation::MicroSimulation(int sim_id, char *input_file)
3128
{
32-
MPI_Init(NULL, NULL);
33-
3429
// initialize fftw mpi
3530
fftw_mpi_init();
3631

test/test_pyfans/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ Test pyFANS as standalone library called from a Python script.
66

77
Configure the FANS CMake build with the variable `FANS_LIB` set to `ON`.
88

9+
## Dependencies
10+
11+
Install the following dependencies
12+
913
## Run the test
1014

11-
Run
15+
The test runs a dummy macro problem (unit cube) which is coupled via preCICE to the Micro Manager. The Micro Manager controls micro simulations created using pyFANS. Run the test by running
1216

1317
```bash
14-
python3 run_fans_as_library.py
18+
python macro-cube.py & micro-manager-precice micro-manager-config.json
1519
```
16-
17-
The script creates a pyFANS object and calls the `solve()` method. The script only checks if the pyFANS object is created and the solve function is callable. The result is not checked for correctness.

test/test_pyfans/macro-cube.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
Run FANS as a Python callable library.
3+
"""
4+
import numpy as np
5+
import precice
6+
7+
8+
def main():
9+
np_axis = 2
10+
11+
# preCICE setup
12+
participant = precice.Participant("macro-cube", "precice-config.xml", 0, 1)
13+
mesh_name = "cube"
14+
15+
# Coupling mesh - unit cube
16+
x_coords, y_coords, z_coords = np.meshgrid(
17+
np.linspace(0, 1, np_axis),
18+
np.linspace(0, 1, np_axis),
19+
np.linspace(0, 1, np_axis),
20+
)
21+
22+
nv = np_axis ** participant.get_mesh_dimensions(mesh_name)
23+
coords = np.zeros((nv, participant.get_mesh_dimensions(mesh_name)))
24+
25+
# Define unit cube coordinates
26+
for z in range(np_axis):
27+
for y in range(np_axis):
28+
for x in range(np_axis):
29+
n = x + y * np_axis + z * np_axis * np_axis
30+
coords[n, 0] = x_coords[x, y, z]
31+
coords[n, 1] = y_coords[x, y, z]
32+
coords[n, 2] = z_coords[x, y, z]
33+
34+
vertex_ids = participant.set_mesh_vertices(mesh_name, coords)
35+
36+
participant.initialize()
37+
38+
dt = participant.get_max_time_step_size()
39+
40+
strains1to3 = np.full((nv, 3), 0.005)
41+
strains4to6 = np.full((nv, 3), 0.0005)
42+
43+
# time loop
44+
while participant.is_coupling_ongoing():
45+
stress1to3 = participant.read_data(mesh_name, "stresses1to3", vertex_ids, dt)
46+
stress4to6 = participant.read_data(mesh_name, "stresses4to6", vertex_ids, dt)
47+
cmat1 = participant.read_data(mesh_name, "cmat1", vertex_ids, dt)
48+
cmat2 = participant.read_data(mesh_name, "cmat2", vertex_ids, dt)
49+
cmat3 = participant.read_data(mesh_name, "cmat3", vertex_ids, dt)
50+
cmat4 = participant.read_data(mesh_name, "cmat4", vertex_ids, dt)
51+
cmat5 = participant.read_data(mesh_name, "cmat5", vertex_ids, dt)
52+
cmat6 = participant.read_data(mesh_name, "cmat6", vertex_ids, dt)
53+
cmat7 = participant.read_data(mesh_name, "cmat7", vertex_ids, dt)
54+
55+
participant.write_data(mesh_name, "strains1to3", vertex_ids, strains1to3)
56+
participant.write_data(mesh_name, "strains4to6", vertex_ids, strains4to6)
57+
58+
participant.advance(dt)
59+
dt = participant.get_max_time_step_size()
60+
61+
participant.finalize()
62+
63+
64+
if __name__ == "__main__":
65+
main()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"micro_file_name": "PyFANS",
3+
"coupling_params": {
4+
"precice_config_file_name": "precice-config.xml",
5+
"macro_mesh_name": "cube",
6+
"read_data_names": {"strains1to3": "vector",
7+
"strains4to6": "vector"
8+
},
9+
"write_data_names": {"stresses1to3": "vector",
10+
"stresses4to6": "vector",
11+
"cmat1":"vector",
12+
"cmat2":"vector",
13+
"cmat3":"vector",
14+
"cmat4":"vector",
15+
"cmat5":"vector",
16+
"cmat6":"vector",
17+
"cmat7":"vector"
18+
}
19+
},
20+
"simulation_params": {
21+
"micro_dt": 1e-1,
22+
"macro_domain_bounds": [0, 1, 0, 1, 0, 1]
23+
}
24+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0"?>
2+
3+
<precice-configuration experimental="true">
4+
5+
<log>
6+
<sink type="stream" output="stdout" filter= "%Severity% > debug" enabled="true" />
7+
</log>
8+
9+
<data:vector name="stresses1to3"/>
10+
<data:vector name="stresses4to6"/>
11+
<data:vector name="strains1to3"/>
12+
<data:vector name="strains4to6"/>
13+
<data:vector name="cmat1"/>
14+
<data:vector name="cmat2"/>
15+
<data:vector name="cmat3"/>
16+
<data:vector name="cmat4"/>
17+
<data:vector name="cmat5"/>
18+
<data:vector name="cmat6"/>
19+
<data:vector name="cmat7"/>
20+
21+
<mesh name="cube" dimensions="3">
22+
<use-data name="stresses1to3"/>
23+
<use-data name="stresses4to6"/>
24+
<use-data name="strains1to3"/>
25+
<use-data name="strains4to6"/>
26+
<use-data name="cmat1"/>
27+
<use-data name="cmat2"/>
28+
<use-data name="cmat3"/>
29+
<use-data name="cmat4"/>
30+
<use-data name="cmat5"/>
31+
<use-data name="cmat6"/>
32+
<use-data name="cmat7"/>
33+
</mesh>
34+
35+
<participant name="macro-cube">
36+
<provide-mesh name="cube"/>
37+
<read-data name="stresses1to3" mesh="cube"/>
38+
<read-data name="stresses4to6" mesh="cube"/>
39+
<read-data name="cmat1" mesh="cube"/>
40+
<read-data name="cmat2" mesh="cube"/>
41+
<read-data name="cmat3" mesh="cube"/>
42+
<read-data name="cmat4" mesh="cube"/>
43+
<read-data name="cmat5" mesh="cube"/>
44+
<read-data name="cmat6" mesh="cube"/>
45+
<read-data name="cmat7" mesh="cube"/>
46+
<write-data name="strains1to3" mesh="cube"/>
47+
<write-data name="strains4to6" mesh="cube"/>
48+
</participant>
49+
50+
<participant name="Micro-Manager">
51+
<receive-mesh name="cube" from="macro-cube" api-access="true" safety-factor="0.0"/>
52+
<read-data name="strains1to3" mesh="cube"/>
53+
<read-data name="strains4to6" mesh="cube"/>
54+
<write-data name="stresses1to3" mesh="cube"/>
55+
<write-data name="stresses4to6" mesh="cube"/>
56+
<write-data name="cmat1" mesh="cube"/>
57+
<write-data name="cmat2" mesh="cube"/>
58+
<write-data name="cmat3" mesh="cube"/>
59+
<write-data name="cmat4" mesh="cube"/>
60+
<write-data name="cmat5" mesh="cube"/>
61+
<write-data name="cmat6" mesh="cube"/>
62+
<write-data name="cmat7" mesh="cube"/>
63+
</participant>
64+
65+
<m2n:sockets acceptor="macro-cube" connector="Micro-Manager"/>
66+
67+
<coupling-scheme:serial-explicit>
68+
<participants first="Micro-Manager" second="macro-cube"/>
69+
<max-time value="0.2"/>
70+
<time-window-size value="0.1"/>
71+
<exchange data="stresses1to3" mesh="cube" from="Micro-Manager" to="macro-cube"/>
72+
<exchange data="stresses4to6" mesh="cube" from="Micro-Manager" to="macro-cube"/>
73+
<exchange data="cmat1" mesh="cube" from="Micro-Manager" to="macro-cube"/>
74+
<exchange data="cmat2" mesh="cube" from="Micro-Manager" to="macro-cube"/>
75+
<exchange data="cmat3" mesh="cube" from="Micro-Manager" to="macro-cube"/>
76+
<exchange data="cmat4" mesh="cube" from="Micro-Manager" to="macro-cube"/>
77+
<exchange data="cmat5" mesh="cube" from="Micro-Manager" to="macro-cube"/>
78+
<exchange data="cmat6" mesh="cube" from="Micro-Manager" to="macro-cube"/>
79+
<exchange data="cmat7" mesh="cube" from="Micro-Manager" to="macro-cube"/>
80+
<exchange data="strains1to3" mesh="cube" from="macro-cube" to="Micro-Manager"/>
81+
<exchange data="strains4to6" mesh="cube" from="macro-cube" to="Micro-Manager"/>
82+
</coupling-scheme:serial-explicit>
83+
84+
</precice-configuration>

test/test_pyfans/run_fans_as_library.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)