Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: aste Replay Mode tutorial on elastic flap case #73

Open
wants to merge 57 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
36e9aca
commit so i can pull the master from upstream
richahert Nov 4, 2019
bcce54b
Merge remote-tracking branch 'upstream/master'
richahert Nov 4, 2019
c7cb07d
add readme
richahert Nov 4, 2019
d3cd8a0
create first Readme
richahert Nov 4, 2019
91e0ea0
Merge remote-tracking branch 'upstream/master' into aste
richahert Dec 17, 2019
e4f848d
precice config for aste fsi
richahert Jan 24, 2020
05bf42b
precice config for aste fsi
richahert Feb 19, 2020
72df6ca
precice config for aste fsi
richahert Feb 19, 2020
d41a002
new precice config
richahert Feb 21, 2020
06dd4db
Merge remote-tracking branch 'upstream/master'
richahert Feb 21, 2020
d08175e
Merge branch 'master' into aste
richahert Feb 21, 2020
7f0ceb1
Add basic files for aste tutorial
richahert Feb 21, 2020
83b3199
add gitignore, rename forced to data
richahert Feb 21, 2020
0e687c2
adds in gitignore
richahert Feb 21, 2020
82714d7
Add instructions. Extended way not finished yet.
richahert Feb 28, 2020
d14b8ff
add links and missing infos
richahert Mar 4, 2020
4252031
Update README.md
richahert Mar 9, 2020
09f2ce5
Merge remote-tracking branch 'upstream/develop' into aste
richahert Mar 9, 2020
8079715
Merge remote-tracking branch 'upstream/develop' into aste
richahert Apr 15, 2020
dcd542c
revert changes
richahert Apr 15, 2020
4664cbe
delete strange file
richahert Apr 15, 2020
e322513
remove file that is not relevant
richahert Apr 15, 2020
9a8c315
Update FSI/flap_perp/ASTE/README.md
richahert Apr 15, 2020
af988d7
Update FSI/flap_perp/ASTE/README.md formatting
richahert Apr 15, 2020
b8db4f6
Apply suggestions from code review
richahert Apr 15, 2020
1545b58
delete unnecessary comments
richahert Apr 15, 2020
25ea047
revert changes to upstream develop
richahert Apr 15, 2020
b7acb41
revert to upstream/develop
richahert Apr 15, 2020
85b5cbb
commit suggestion
richahert Apr 15, 2020
50581d1
PEP8 formatting
richahert Apr 15, 2020
0769086
revert to upstream
richahert Apr 15, 2020
b5a1212
remove profiling
richahert Apr 15, 2020
1487550
formatting
richahert Apr 15, 2020
06e174d
remove export
richahert Apr 15, 2020
061c212
add solvername and some formatting
richahert Apr 15, 2020
724efaf
-f flag was chaged to --tag or -t
richahert May 1, 2020
86624c0
avoid from fenics import *
BenjaminRodenberg May 8, 2020
4cc08c1
Wording and formatting
BenjaminRodenberg May 8, 2020
b8bb3ae
Remove perp-flap.py
BenjaminRodenberg May 8, 2020
5b5c9bc
Merge branch 'aste' of github.com:richahert/tutorials into richahert_…
BenjaminRodenberg May 8, 2020
5866b20
Clearify modifications of precice-config.xml
BenjaminRodenberg May 8, 2020
a7a3dd5
Remove unneeded --vectordata option
BenjaminRodenberg May 8, 2020
302ff0f
Merge branch 'develop' into aste
BenjaminRodenberg Jul 1, 2021
a4c83f4
Migrating FSI/flap_perp/ASTE to the new tutorials structure
BenjaminRodenberg Jul 1, 2021
2f412b0
Update obvious changes. Whitespaces etc.
BenjaminRodenberg Jul 1, 2021
c2e2437
Some more obvious changes.
BenjaminRodenberg Jul 1, 2021
95be62b
Update configs to new naming scheme.
BenjaminRodenberg Jul 1, 2021
a9f7e1a
Update solver.
BenjaminRodenberg Jul 1, 2021
36a76fd
Clean up the diff.
BenjaminRodenberg Jul 1, 2021
0a71b77
Partially update to new tutorials structure
BenjaminRodenberg Jul 1, 2021
330dce5
More cleaning up of the diff.
BenjaminRodenberg Jul 1, 2021
fdbd5f8
Fix md file formatting.
BenjaminRodenberg Jul 1, 2021
4bf84b0
Fix ShellCheck.
BenjaminRodenberg Jul 1, 2021
41d5e44
Fix dead links.
BenjaminRodenberg Jul 1, 2021
77c91fc
Fix format.
BenjaminRodenberg Jul 1, 2021
e7764ac
Remove unnecessary clean script.
BenjaminRodenberg Jul 1, 2021
2eefa05
Fix link.
BenjaminRodenberg Jul 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions perpendicular-flap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
preCICE-output/
Solid-fenics*
*.log
vtk*
Solid/FSI-S
96 changes: 96 additions & 0 deletions perpendicular-flap/fluid-aste/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Tutorial for replay mode

## Overview

This tutorial is an example how the Artificial Solver Testing Environment (aste) can be used. The idea is that you run a coupled simulation with two regular solvers and save the coupling data in every timestep. Then, this data is converted to aste-format. Finally, aste replaces one of the solvers and the simulation can be "replayed" using only one solver and aste with the previously computed results.

This tutorial uses the results from the [OpenFOAM-FEniCS perpendicular flap tutorial](https://github.com/precice/tutorials/tree/master/perpendicular-flap) as a basis. aste then replaces OpenFOAM.

## Requirements

To run this tutorial you need to install the following components:

- [preCICE](https://github.com/precice/precice/wiki/Get-preCICE)
- [aste](https://github.com/precice/aste/tree/develop)
- [FEniCS](https://fenicsproject.org/)
- [FEniCS-Adapter](https://github.com/precice/fenics-adapter)
- OpenFOAM, e.g. [OpenFOAM 7](https://openfoam.org/version/7/)
- [OpenFOAM Adapter](https://github.com/precice/openfoam-adapter/wiki/Building) matching the OpenFOAM version.

Make sure to add `aste/build` to the `PATH` such that the python scripts and `preciceMap` can be found from anywhere on your system.

## Step-by-Step explanations

### Generating vtk output during a simulation

The base case for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. So let's start in the the root-directory of the perpendicular flap case: [`tutorials/perpendicular-flap`](https://github.com/precice/tutorials/tree/master/perpendicular-flap).

To generate vtk output in preCICE, add the statement `<export:vtk directory="preCICE-output" />` to the `precice-config.xml` in `tutorials/perpendicular-flap` in the Solid participant. The result should look the following way:

```xml
<participant name="Solid">
<use-mesh name="Solid-Mesh" provide="yes"/>
<read-data name="Force" mesh="Solid-Mesh"/>
<write-data name="Displacement" mesh="Solid-Mesh"/>
<export:vtk directory="preCICE-output" />
</participant>
```

Then, run the simulation as explained in the [`README.md`](https://github.com/precice/tutorials/blob/develop/perpendicular-flap/README.md) of the case.

The exports can be found in the `preCICE-output` directory.

### Converting the output to aste format

Copy the `preCICE-output` folder to the root directory of the aste tutorial `tutorials/perpendicular-flap/fluid-aste`.
To convert the files to the correct format, open the `preCICE-output` folder and run

`precice_to_aste.py Solid-fenics -n 500 -t Forces0 --datadim 3`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently getting stuck here. Where is the script precice_to_aste.py? I cannot find it in https://github.com/precice/aste/tree/develop. @fsimonis any idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


### Replay of the simulation with aste

#### The quick way to run

1. Open two terminals and navigate to `solid-fenics` and `fluid-aste`.
1. Run `.../solid-fenics$ python3 solid.py` and `.../fluid-aste$ preciceMap -v -c ../precice-config-aste.xml -p Fluid --mesh preCICE-output/Solid-fenics` in two terminals.

Read on if you want to know what to change in the configuration files starting from the OpenFOAM-FEniCS tutorial.

#### The way to do it yourself

The aste-FEniCS tutorial provides its own `precice-config.xml` and `precice-adapter-config-fsi-s.json` for getting started quickly. They are called `precice-config-aste.xml` and `precice-adapter-config-fsi-s-aste.json`.

However, these can also be generated by modifiying the files from the original `perpendicular-flap` case. The main purpose of this tutorial is to explain how the replay mode with aste can be used for arbirtrary simulation setups.

1. Copy the files `perpendicular-flap/precice-config.xml` and `perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s.json` from the original `perpendicular-flap` tutorial into the respective directories.
2. Remove the line `"write_data_name": "Displacement"` from `precice-adapter-config-fsi-s.json`, because we will not write any data to aste.
3. Change the `read_data_name` from `Force` to `Data` since aste works with the general data name `Data`.
4. In ```precice-config.xml``` we require some more changes:
1. Rename `Force` to `Data` throughout the whole file.
2. Delete all lines where `Displacement` occurs, since we are only coupling in one direction (from aste to FEniCS).
5. Then we process the Fluid meshes to fake the Fluid participant using aste:
1. Rename `Fluid-Mesh` to `MeshA` throughout the whole file.
2. Delete the `mesh` `"Fluid-Mesh-Nodes"` and all lines where `"Fluid-Mesh-Nodes"` occurs.
3. Rename the participant `Fluid` to `A`
6. Change the coupling scheme to an explicit scheme:
1. Change `serial-implicit` to `serial-explicit`.
2. Explicit schemes don't iterate such that they don't need convergence measures, extrapolation or acceleration. Delete everything in the coulping scheme except for

```xml
<participants first="A" second="Solid" />
<max-time value="5.0" />
<time-window-size value="1.e-2" />
<exchange data="Data" mesh="Solid-Mesh" from="A" to="Solid" />
```

#### Run

After applying these preparations, we are now able to run the tutorial in two terminals as described above.

### Play Around

If you want to explore more possibilities of the Replay-Mode here are some ideas:

- Export the output at the Fluid participant. Instead of `preCICE-output/Solid-fenics.*` the files containing the forces will be `preCICE-output/Fluid-Mesh-Faces-Fluid.*`
- Export the forces in the [Calculix-Openfoam-tutorial](https://github.com/precice/tutorials/tree/master/perpendicular-flap) with the same geometry and feed them to FEniCS with aste.
- If you are familiar with the OpenFOAM-Adapter you can also replace FEniCS with aste such that aste writes previously exported displacements to OpenFOAM.
50 changes: 50 additions & 0 deletions perpendicular-flap/precice-config-aste.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>

<precice-configuration>

<log enabled="true">
<sink type="stream" output="stdout" filter="%Severity% > debug" enabled="true" />
<sink type="file" output="filtered.log" filter= "(%Severity% > debug) or (%Severity% >= trace and %Module% contains SolverInterfaceImpl)" enabled="true" />
<sink type="file" output="debug.log" filter="" enabled="true"/>
</log>

<solver-interface dimensions="2">

<!-- Data fields that are exchanged between the solvers -->
<data:vector name="Force" />

<!-- A common mesh that uses these data fields -->
<mesh name="Fluid-Mesh" flip-normals="no">
<use-data name="Force" />
</mesh>

<mesh name="Solid-Mesh" flip-normals="no">
<use-data name="Force" />
</mesh>

<participant name="Fluid">
<use-mesh name="Fluid-Mesh" provide="yes" />
<use-mesh name="Solid-Mesh" provide="no" from="Solid" />
<write-data name="Force" mesh="Fluid-Mesh"/>
<mapping:nearest-neighbor constraint="conservative" direction="write" from="Fluid-Mesh" to="Solid-Mesh" />
<export:vtk every-n-time-windows="1" directory="vtkFluid/" normals="0"/>
</participant>

<participant name="Solid">
<use-mesh name="Solid-Mesh" provide="yes" />
<read-data name="Force" mesh="Solid-Mesh" />
<export:vtk every-n-time-windows="1" directory="vtkSolid/" normals="0"/>
</participant>

<m2n:sockets from="Fluid" to="Solid" exchange-directory=".." />

<coupling-scheme:serial-explicit>
<participants first="Fluid" second="Solid" />
<max-time value="5.0" />
<time-window-size value="1.e-2" />
<exchange data="Force" mesh="Solid-Mesh" from="Fluid" to="Solid" />
</coupling-scheme:serial-explicit>

</solver-interface>

</precice-configuration>
11 changes: 10 additions & 1 deletion perpendicular-flap/precice-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@
<use-mesh name="Solid-Mesh" provide="yes" />
<write-data name="Displacement" mesh="Solid-Mesh" />
<read-data name="Force" mesh="Solid-Mesh" />
<watch-point mesh="Solid-Mesh" name="Flap-Tip" coordinate="0.0;1" />
<export:vtk directory="preCICE-output" />
</participant>

<m2n:sockets from="Fluid" to="Solid" exchange-directory=".." />
<!--
<coupling-scheme:serial-explicit>
<time-window-size value="1e-2"/>
<max-time value="5"/>
<participants first="Fluid" second="Solid"/>
<exchange data="Force" mesh="Solid-Mesh" from="Fluid" to="Solid"/>
<exchange data="Displacement" mesh="Solid-Mesh" from="Solid" to="Fluid"/>
</coupling-scheme:serial-explicit>
-->

<coupling-scheme:parallel-implicit>
<time-window-size value="0.01" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"participant_name": "Solid",
"config_file_name": "../precice-config-aste.xml",
"interface": {
"coupling_mesh_name": "Solid-Mesh",
"read_data_name": "Force"
}
}
91 changes: 66 additions & 25 deletions perpendicular-flap/solid-fenics/solid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Import required libs
from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \
TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, project, \
Identity, inner, dx, ds, sym, grad, lhs, rhs, dot, File, solve, PointSource, assemble_system
Identity, inner, dx, ds, sym, grad, lhs, rhs, dot, File, solve, PointSource, assemble_system, TensorFunctionSpace, XDMFFile
from ufl import nabla_div
import numpy as np
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -66,12 +66,12 @@ def neumann_boundary(x, on_boundary):
coupling_boundary = AutoSubDomain(neumann_boundary)
fixed_boundary = AutoSubDomain(clamped_boundary)

precice = Adapter(adapter_config_filename="precice-adapter-config-fsi-s.json")
precice = Adapter(adapter_config_filename="precice-adapter-config-fsi-s-aste.json")

# Initialize the coupling interface
precice_dt = precice.initialize(coupling_boundary, read_function_space=V, write_object=V, fixed_boundary=fixed_boundary)
precice_dt = precice.initialize(coupling_boundary, read_function_space=V, fixed_boundary=fixed_boundary)

fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
# fenics_dt = 0.02 # if fenics_dt < precice_dt, subcycling is applied
dt = Constant(np.min([precice_dt, fenics_dt]))

Expand Down Expand Up @@ -168,6 +168,12 @@ def avg(x_old, x_new, alpha):
# parameters for Time-Stepping
t = 0.0
n = 0

time = []
u_tip = []
time.append(0.0)
u_tip.append(0.0)

E_ext = 0

displacement_out = File("Solid/FSI-S/u_fsi.pvd")
Expand All @@ -176,10 +182,35 @@ def avg(x_old, x_new, alpha):
u_np1.rename("Displacement", "")
displacement_out << u_n

while precice.is_coupling_ongoing():
# stress computation
def local_project(v, V, u=None):
"""Element-wise projection using LocalSolver"""
dv = TrialFunction(V)
v_ = TestFunction(V)
a_proj = inner(dv, v_)*dx
b_proj = inner(v, v_)*dx
solver = LocalSolver(a_proj, b_proj)
solver.factorize()
if u is None:
u = Function(V)
solver.solve_local_rhs(u)
return u
else:
solver.solve_local_rhs(u)
return

Vsig = TensorFunctionSpace(mesh, "CG", 1)
sig = Function(Vsig, name="sigma")

xdmf_file = XDMFFile("elastodynamics-results.xdmf")
xdmf_file.parameters["flush_output"] = True
xdmf_file.parameters["functions_share_mesh"] = True
xdmf_file.parameters["rewrite_function_mesh"] = False

if precice.is_action_required(precice.action_write_iteration_checkpoint()): # write checkpoint
precice.store_checkpoint(u_n, t, n)
# time loop for coupling


while precice.is_coupling_ongoing():

# read data from preCICE and get a new coupling expression
read_data = precice.read_data()
Expand All @@ -201,29 +232,39 @@ def avg(x_old, x_new, alpha):

dt = Constant(np.min([precice_dt, fenics_dt]))

# Write new displacements to preCICE
precice.write_data(u_np1)

# Call to advance coupling, also returns the optimum time step value
precice_dt = precice.advance(dt(0))

# Either revert to old step if timestep has not converged or move to next timestep
if precice.is_action_required(precice.action_read_iteration_checkpoint()): # roll back to checkpoint
u_cp, t_cp, n_cp = precice.retrieve_checkpoint()
u_n.assign(u_cp)
t = t_cp
n = n_cp
else:
u_n.assign(u_np1)
t += float(dt)
n += 1
u_n.assign(u_np1)
t += float(dt)
n += 1

if precice.is_time_window_complete():
local_project(sigma(u_n), Vsig, sig)

# Plot tip displacement evolution
displacement_out << u_n

xdmf_file.write(u_n,t)
xdmf_file.write(sig,t)
update_fields(u_np1, saved_u_old, v_n, a_n)
if n % 10 == 0:
displacement_out << (u_n, t)

# Plot tip displacement evolution
displacement_out << u_n
if n % 10==0:
local_project(sigma(u_n), Vsig, sig)

displacement_out << (u_n,t)
xdmf_file.write(u_n,t)
xdmf_file.write(sig,t)

u_tip.append(u_n(0.,1.)[0])
time.append(t)


precice.finalize()

# Plot tip displacement evolution
displacement_out << u_n
plt.figure()
plt.plot(time, u_tip)
plt.xlabel("Time")
plt.ylabel("Tip displacement")
plt.show()