From 36e9aca8b67046073a6a3e5c133d82ab938f0085 Mon Sep 17 00:00:00 2001 From: richy Date: Mon, 4 Nov 2019 14:05:18 +0100 Subject: [PATCH 01/49] commit so i can pull the master from upstream --- .../Fluid/system/controlDict | 4 +- .../Postprocessing/plot_tip.py | 5 +- .../OpenFOAM-FEniCS/Solid/cyl-flap.py | 26 +++++++- .../Fluid/system/controlDict | 4 +- .../precice-config_serial.xml | 6 +- .../OpenFOAM-FEniCS/Solid/perp-flap.py | 59 ++++++++++++++++--- .../OpenFOAM-FEniCS/precice-config_serial.xml | 2 +- 7 files changed, 86 insertions(+), 20 deletions(-) diff --git a/FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict b/FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict index 8694980dc..511c00da6 100644 --- a/FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict +++ b/FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict @@ -10,8 +10,8 @@ FoamFile // Note: With OpenFOAM v1806 and OpenFOAM 6, the DyM solvers // were marked deprecated and merged into their respective standard solvers. -application pimpleFoam; // OpenFOAM v1806, OpenFOAM 6, or newer -// application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older +// application pimpleFoam; // OpenFOAM v1806, OpenFOAM 6, or newer +application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older startFrom startTime; diff --git a/FSI/cylinderFlap/OpenFOAM-FEniCS/Postprocessing/plot_tip.py b/FSI/cylinderFlap/OpenFOAM-FEniCS/Postprocessing/plot_tip.py index 41450a811..4dc919439 100644 --- a/FSI/cylinderFlap/OpenFOAM-FEniCS/Postprocessing/plot_tip.py +++ b/FSI/cylinderFlap/OpenFOAM-FEniCS/Postprocessing/plot_tip.py @@ -10,9 +10,10 @@ import matplotlib.pyplot as plt fenics_watchpoint = np.loadtxt('../precice-fenics-watchpoint-point1.log', skiprows = 1) -ccx_watchpoint = np.loadtxt('/home/richyrich/Bachelorarbeit/OpenFOAM-CalculiX/precice-Fluid-watchpoint-point1.log', skiprows = 1) +#ccx_watchpoint = np.loadtxt('/home/richyrich/Bachelorarbeit/OpenFOAM-CalculiX/precice-Fluid-watchpoint-point1.log', skiprows = 1) -plt.plot(fenics_watchpoint[:,0],fenics_watchpoint[:,8]) +plt.plot(fenics_watchpoint[:,0],fenics_watchpoint[:,7]) +plt.show() #plt.plot(ccx_watchpoint[:,0],ccx_watchpoint[:,8]) diff --git a/FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py b/FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py index a3ebce39b..75d79b9d9 100644 --- a/FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py +++ b/FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py @@ -206,6 +206,27 @@ def avg(x_old, x_new, alpha): displacement_out << u_n +# 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, "DG", 0) +sig = Function(Vsig, name="sigma") + + #time loop for coupling @@ -231,7 +252,9 @@ def avg(x_old, x_new, alpha): update_fields(u_np1, saved_u_old, v_n, a_n) if n % 20==0: - displacement_out << (u_n,t) + local_project(sigma(u_n), Vsig, sig) + displacement_out << (u_n,sig,t) + u_tip.append(u_n(0.6,0.2)[1]) time.append(t) @@ -247,4 +270,3 @@ def avg(x_old, x_new, alpha): plt.ylabel("Tip displacement") plt.show() - diff --git a/FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict b/FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict index 19433cd34..9a19b3673 100644 --- a/FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict +++ b/FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict @@ -10,8 +10,8 @@ FoamFile // Note: With OpenFOAM v1806 and OpenFOAM 6, the DyM solvers // were marked deprecated and merged into their respective standard solvers. -application pimpleFoam; // OpenFOAM v1806, OpenFOAM 6, or newer -// application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older +//application pimpleFoam; // OpenFOAM v1806, OpenFOAM 6, or newer + application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older startFrom startTime; diff --git a/FSI/flap_perp/OpenFOAM-CalculiX/precice-config_serial.xml b/FSI/flap_perp/OpenFOAM-CalculiX/precice-config_serial.xml index e5b095ce8..e31024612 100644 --- a/FSI/flap_perp/OpenFOAM-CalculiX/precice-config_serial.xml +++ b/FSI/flap_perp/OpenFOAM-CalculiX/precice-config_serial.xml @@ -42,7 +42,7 @@ - + @@ -74,7 +74,7 @@ - --> + diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py index 180f5d910..6f45b5caa 100644 --- a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py +++ b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py @@ -10,6 +10,7 @@ import matplotlib.pyplot as plt from fenicsadapter import Adapter from enum import Enum +import cProfile, pstats #define the two kinds of boundary: clamped and coupling Neumann Boundary @@ -23,7 +24,8 @@ def Neumann_Boundary(x, on_boundary): """ return on_boundary and ((abs(x[1]-1) - + From c7cb07dca9147fb721011d896bdf86b8700a7840 Mon Sep 17 00:00:00 2001 From: richy Date: Mon, 4 Nov 2019 14:25:17 +0100 Subject: [PATCH 02/49] add readme --- FSI/flap_perp/ASTE/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 FSI/flap_perp/ASTE/README.md diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md new file mode 100644 index 000000000..e69de29bb From d3cd8a0902768ad81b53aab7b5142671a30da27a Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Mon, 4 Nov 2019 16:17:09 +0100 Subject: [PATCH 03/49] create first Readme --- FSI/flap_perp/ASTE/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index e69de29bb..e49339af4 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -0,0 +1,21 @@ +## Overview + +This tutorial is an example how the Artificial Solver Testing Environment (ASTE) can be used. + +It consists of 3 parts: + +1. Running a coupled simulation with 2 solvers that generates ```vtk``` output. +2. Transform the ```vtk``` files into the ASTE specific file format. +3. Exchanging one solver with ASTE. + +## Requirements + +To run this tutorial you need to install the following software: +- preCICE +- ASTE +- FEniCS +- FEniCS-Adapter +- OpenFOAM +- OpenFOAM Adapter + +## Step-by-Step From e4f848d87bbc46e19ea0e69f2d167b90d798b554 Mon Sep 17 00:00:00 2001 From: richy Date: Fri, 24 Jan 2020 11:03:27 +0100 Subject: [PATCH 04/49] precice config for aste fsi --- FSI/flap_perp/ASTE/precice-config.xml | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 FSI/flap_perp/ASTE/precice-config.xml diff --git a/FSI/flap_perp/ASTE/precice-config.xml b/FSI/flap_perp/ASTE/precice-config.xml new file mode 100644 index 000000000..5dbb13e75 --- /dev/null +++ b/FSI/flap_perp/ASTE/precice-config.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 05bf42b77715a3bf958bcfa3a6b22b9c03a79feb Mon Sep 17 00:00:00 2001 From: richy Date: Wed, 19 Feb 2020 13:30:11 +0100 Subject: [PATCH 05/49] precice config for aste fsi --- FSI/flap_perp/ASTE/precice-config.xml | 29 ++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/FSI/flap_perp/ASTE/precice-config.xml b/FSI/flap_perp/ASTE/precice-config.xml index 5dbb13e75..8e9930212 100644 --- a/FSI/flap_perp/ASTE/precice-config.xml +++ b/FSI/flap_perp/ASTE/precice-config.xml @@ -14,7 +14,7 @@ - + @@ -22,35 +22,32 @@ - + - - - - - - + + + + + + - - - + - - + - + - + - + From 72df6ca0af1863e61274a7eaa1c7d893b930173c Mon Sep 17 00:00:00 2001 From: richy Date: Wed, 19 Feb 2020 13:30:37 +0100 Subject: [PATCH 06/49] precice config for aste fsi --- .../OpenFOAM-FEniCS/.gitignore | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 FSI/cylinderFlap/OpenFOAM-FEniCS-bigdt/OpenFOAM-FEniCS/.gitignore diff --git a/FSI/cylinderFlap/OpenFOAM-FEniCS-bigdt/OpenFOAM-FEniCS/.gitignore b/FSI/cylinderFlap/OpenFOAM-FEniCS-bigdt/OpenFOAM-FEniCS/.gitignore new file mode 100644 index 000000000..49e223957 --- /dev/null +++ b/FSI/cylinderFlap/OpenFOAM-FEniCS-bigdt/OpenFOAM-FEniCS/.gitignore @@ -0,0 +1,13 @@ +Fluid +!Fluid/0 +!Fluid/0.orig +!Fluid/constant +!Fluid/system +!Fluid/Fluid.foam +!Fluid/precice-adapter-config.yml +Solid +!Solid/cyl-flap.py +!Solid/precice-adapter-config-fsi-s.json +*.log +precice-fenics-events.json +precice-Fluid-events.json From d41a002326028cf085d1a2d78914178f388b023c Mon Sep 17 00:00:00 2001 From: richahert Date: Fri, 21 Feb 2020 14:45:51 +0100 Subject: [PATCH 07/49] new precice config --- .../OpenFOAM-FEniCS/precice-config.xml | 83 ++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) mode change 120000 => 100644 FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml b/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml deleted file mode 120000 index f12083976..000000000 --- a/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml +++ /dev/null @@ -1 +0,0 @@ -precice-config_serial.xml \ No newline at end of file diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml b/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml new file mode 100644 index 000000000..055aa9921 --- /dev/null +++ b/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 7f0ceb1ea36e2b3d675a4ca688afae4a3312f070 Mon Sep 17 00:00:00 2001 From: richahert Date: Fri, 21 Feb 2020 15:35:42 +0100 Subject: [PATCH 08/49] Add basic files for aste tutorial --- FSI/flap_perp/ASTE/Allclean | 64 ++++ FSI/flap_perp/ASTE/Solid/perp-flap.py | 281 ++++++++++++++++++ .../Solid/precice-adapter-config-fsi-s.json | 9 + 3 files changed, 354 insertions(+) create mode 100755 FSI/flap_perp/ASTE/Allclean create mode 100644 FSI/flap_perp/ASTE/Solid/perp-flap.py create mode 100644 FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json diff --git a/FSI/flap_perp/ASTE/Allclean b/FSI/flap_perp/ASTE/Allclean new file mode 100755 index 000000000..335e4274b --- /dev/null +++ b/FSI/flap_perp/ASTE/Allclean @@ -0,0 +1,64 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +echo "Cleaning..." + +# Source tutorial clean functions +. $WM_PROJECT_DIR/bin/tools/CleanFunctions + +# Participant 1: Fluid +Participant1="Fluid" +cd ${Participant1} + # Clean the case + cleanCase + rm -rfv 0 + # Create an empty .foam file for ParaView + # Note: ".foam" triggers the native OpenFOAM reader of ParaView. + # Change to ".OpenFOAM" to use the OpenFOAM reader provided with OpenFOAM. + touch ${Participant1}.foam +cd .. +# Remove the log files +rm -fv ${Participant1}_blockMesh.log +rm -fv ${Participant1}_checkMesh.log +rm -fv ${Participant1}_potentialFoam.log +rm -fv ${Participant1}_decomposePar.log +rm -fv ${Participant1}.log +rm -fv ${Participant1}_reconstructPar.log + +# Participant 2: Solid +Participant2="Solid" +cd ${Participant2} +cd FSI-S + # Clean the case + rm -fv *.vtu + rm -fv *.pvd + rm -fv *.log +cd .. +cd .. +# Remove the log files +rm -fv spooles.out +rm -fv ${Participant2}.log + +# Remove the precice-events-files +rm -fv precice-fenics-events.json +rm -fv precice-Fluid-events.json + +# Remove the preCICE-related log files +echo "Deleting the preCICE log files..." +rm -fv \ + precice-*.log \ + precice-postProcessingInfo.log + +# Output files for preCICE versions before 1.2: +rm -fv \ + iterations-${Participant1}.txt iterations-${Participant2}.txt \ + convergence-${Participant1}.txt convergence-${Participant2}.txt \ + Events-${Participant1}.log Events-${Participant2}.log \ + EventTimings-${Participant1}.log EventTimings-${Participant2}.log + +# Remove the preCICE address files +rm -rfv precice-run +rm -fv .*.address + +echo "Cleaning complete!" +#------------------------------------------------------------------------------ diff --git a/FSI/flap_perp/ASTE/Solid/perp-flap.py b/FSI/flap_perp/ASTE/Solid/perp-flap.py new file mode 100644 index 000000000..6f45b5caa --- /dev/null +++ b/FSI/flap_perp/ASTE/Solid/perp-flap.py @@ -0,0 +1,281 @@ +#Import required libs +from fenics import * +from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \ +TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad,\ +Identity, inner,dx, ds, sym, grad, lhs, rhs, dot, File, solve, PointSource +import dolfin + +from ufl import nabla_div +import numpy as np +import matplotlib.pyplot as plt +from fenicsadapter import Adapter +from enum import Enum +import cProfile, pstats + + +#define the two kinds of boundary: clamped and coupling Neumann Boundary +def clamped_boundary(x, on_boundary): + return on_boundary and abs(x[1])u_old + v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec + u_old.vector()[:] = u.vector() + + +def avg(x_old, x_new, alpha): + return alpha*x_old + (1-alpha)*x_new + +# residual +a_np1 = update_a(du, u_n, v_n, a_n, ufl=True) +v_np1 = update_v(a_np1, u_n, v_n, a_n, ufl=True) + +res = m(avg(a_n,a_np1,alpha_m), v) + k(avg(u_n,du, alpha_f), v) #TODO: Wext(v) needs to be replaced by coupling + +Forces_x, Forces_y = precice.create_force_boundary_condition(V) + +a_form= lhs(res) +L_form= rhs(res) + +# Prepare for time-stepping + +#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") + +u_n.rename("Displacement", "") +u_np1.rename("Displacement", "") +displacement_out << u_n + +# 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 + +#time loop for coupling + + +while precice.is_coupling_ongoing(): + A, b = assemble_system(a_form, L_form, bc) + + b_forces = b.copy() # b is the same for every iteration, only forces change + + for ps in Forces_x: + ps.apply(b_forces) + for ps in Forces_y: + ps.apply(b_forces) + + assert(b is not b_forces) + solve(A, u_np1.vector(), b_forces) + + t, n, precice_timestep_complete, precice_dt, Forces_x, Forces_y = precice.advance(u_np1, u_np1, u_n, t, float(dt), n) + + + if precice_timestep_complete: + + update_fields(u_np1, saved_u_old, v_n, a_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 +pr.disable() +pr.dump_stats('prof_data') +pr2=pstats.Stats('prof_data') +pr2.sort_stats('cumulative') +pr2.print_stats() +displacement_out << u_n +plt.figure() +plt.plot(time, u_tip) +plt.xlabel("Time") +plt.ylabel("Tip displacement") +plt.show() + + diff --git a/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json b/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json new file mode 100644 index 000000000..3726bea9f --- /dev/null +++ b/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json @@ -0,0 +1,9 @@ +{ + "solver_name": "fenics", + "config_file_name": "../precice-config.xml", + "interface": { + "coupling_mesh_name": "Solid", + "write_data_name": "Displacements0", + "read_data_name": "Forces0" + } +} From 83b319907675c8847ba95a562f256dfeb21a777c Mon Sep 17 00:00:00 2001 From: richahert Date: Fri, 21 Feb 2020 16:55:41 +0100 Subject: [PATCH 09/49] add gitignore, rename forced to data --- FSI/flap_perp/ASTE/.gitignore | 3 +++ .../ASTE/Solid/precice-adapter-config-fsi-s.json | 3 +-- FSI/flap_perp/ASTE/precice-config.xml | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 FSI/flap_perp/ASTE/.gitignore diff --git a/FSI/flap_perp/ASTE/.gitignore b/FSI/flap_perp/ASTE/.gitignore new file mode 100644 index 000000000..69f69f641 --- /dev/null +++ b/FSI/flap_perp/ASTE/.gitignore @@ -0,0 +1,3 @@ +preCICE-output/ +Solid-fenics* +*.log diff --git a/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json b/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json index 3726bea9f..4538ca27e 100644 --- a/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json +++ b/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json @@ -3,7 +3,6 @@ "config_file_name": "../precice-config.xml", "interface": { "coupling_mesh_name": "Solid", - "write_data_name": "Displacements0", - "read_data_name": "Forces0" + "read_data_name": "Data" } } diff --git a/FSI/flap_perp/ASTE/precice-config.xml b/FSI/flap_perp/ASTE/precice-config.xml index 8e9930212..e0882612c 100644 --- a/FSI/flap_perp/ASTE/precice-config.xml +++ b/FSI/flap_perp/ASTE/precice-config.xml @@ -11,15 +11,15 @@ - + - + - + @@ -27,14 +27,14 @@ - + - + @@ -43,10 +43,10 @@ - + - + From 0e687c2d88f48df886321568cf8aed23f15e58a0 Mon Sep 17 00:00:00 2001 From: richahert Date: Fri, 21 Feb 2020 17:27:21 +0100 Subject: [PATCH 10/49] adds in gitignore --- FSI/flap_perp/ASTE/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FSI/flap_perp/ASTE/.gitignore b/FSI/flap_perp/ASTE/.gitignore index 69f69f641..493b6986c 100644 --- a/FSI/flap_perp/ASTE/.gitignore +++ b/FSI/flap_perp/ASTE/.gitignore @@ -1,3 +1,5 @@ preCICE-output/ Solid-fenics* *.log +vtk* +Solid/FSI-S From 82714d78eaac87e2afba07a60f05347929b12c5b Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Fri, 28 Feb 2020 14:21:09 +0100 Subject: [PATCH 11/49] Add instructions. Extended way not finished yet. --- FSI/flap_perp/ASTE/README.md | 62 +++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index e49339af4..d69c6fd6c 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -1,16 +1,12 @@ ## Overview -This tutorial is an example how the Artificial Solver Testing Environment (ASTE) can be used. +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 substitutes one of the solvers and the simulation can be "replayed" using only one solver and aste with the prior results. -It consists of 3 parts: - -1. Running a coupled simulation with 2 solvers that generates ```vtk``` output. -2. Transform the ```vtk``` files into the ASTE specific file format. -3. Exchanging one solver with ASTE. +The base simulation for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. aste then substitutes OpenFOAM. ## Requirements -To run this tutorial you need to install the following software: +To run this tutorial you need to install the following components: - preCICE - ASTE - FEniCS @@ -18,4 +14,54 @@ To run this tutorial you need to install the following software: - OpenFOAM - OpenFOAM Adapter -## Step-by-Step +Make sure to add aste/build to the path such that the python scripts can be found from anywhere. + +## Step-by-Step explanations + +### Generating vtk output during a simulation + +The base case for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. So we start in the the root-directory of that simulation. +To generate a vtk output in preCICE, we add the following line to ```precice-config.xml``` after [line 41](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml#L41) in the Solid participant: +`````` + +Then, the simulation can be run in two terminals with ```bash ./runFluid``` and ```python3 Solid/perp_flap.py```. +The exports are in the ```preCICE-output``` directory. + +### Converting the output to aste format. + +We copy the ```preCICE-output``` folder to the root directory of the aste tutorial. +To convert the files to the correct format we open the ```preCICE-output``` folder and run + +```precice_to_aste.py -n 500 -f Forces0 --datadim 3``` + +### Replay of the simulation with aste + +#### The quick way to run +Copy perp_flap.py from OpenFOAM-FEniCS/Solid to aste/Solid + +run in two terminals ```python3 Solid/perp_flap.py``` and ```preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata``` + +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 simulation has its own ```precice-config.xml``` and ```precice-adapter-config-fsi-s.json```. +However, these can be generated by modifiying the files from the OpenFOAM-FEniCS case. + +For ```precice-adapter-config-fsi-s.json``` we remove the line ```"write_data_name": "Displacements0",``` because we don't write data to aste. +Plus, we change to the ```read_data_name``` from ```Forces0``` to ```Data``` since aste works with the general data name ```Data```. + +In ```precice-config.xml``` we need more changes +Again, we rename ```Forces0``` to ```Data``` throughout the whole file. + +Then, we substitute the Fluid meshes and the Fluid participant with aste: + +- Rename ```Fluid-Mesh-Faces``` to ```MeshA``` throughout the whole file. This is the mesh where +- Delete the ```mesh``` ```"Fluid-Mesh-Nodes"``` and all lines where ```"Fluid-Mesh-Nodes"``` occurs. +- Rename + + + + + + From d14b8ffa5a51e6980680d9b342ebc09cba96472f Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 4 Mar 2020 17:50:55 +0100 Subject: [PATCH 12/49] add links and missing infos --- FSI/flap_perp/ASTE/README.md | 52 +++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index d69c6fd6c..5c94fb3bd 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -7,21 +7,21 @@ The base simulation for this tutorial is the OpenFOAM-FEniCS perpendicular flap ## Requirements To run this tutorial you need to install the following components: -- preCICE -- ASTE -- FEniCS -- FEniCS-Adapter -- OpenFOAM -- OpenFOAM Adapter +- [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 can be found from anywhere. +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 we start in the the root-directory of that simulation. -To generate a vtk output in preCICE, we add the following line to ```precice-config.xml``` after [line 41](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml#L41) in the Solid participant: +The base case for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. So let's start in the the root-directory of that simulation. +To generate a vtk output in preCICE, add the following line to ```precice-config.xml``` after [line 41](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml#L41) in the Solid participant: `````` Then, the simulation can be run in two terminals with ```bash ./runFluid``` and ```python3 Solid/perp_flap.py```. @@ -29,8 +29,8 @@ The exports are in the ```preCICE-output``` directory. ### Converting the output to aste format. -We copy the ```preCICE-output``` folder to the root directory of the aste tutorial. -To convert the files to the correct format we open the ```preCICE-output``` folder and run +Copy the ```preCICE-output``` folder to the root directory of the aste tutorial. +To convert the files to the correct format, open the ```preCICE-output``` folder and run ```precice_to_aste.py -n 500 -f Forces0 --datadim 3``` @@ -48,17 +48,37 @@ Read on if you want to know what to change in the configuration files starting f The aste-FEniCS simulation has its own ```precice-config.xml``` and ```precice-adapter-config-fsi-s.json```. However, these can be generated by modifiying the files from the OpenFOAM-FEniCS case. +First, copy the files from the OpenFOAM-FEniCS tutorial into the respective directory of the aste-tutorial. + For ```precice-adapter-config-fsi-s.json``` we remove the line ```"write_data_name": "Displacements0",``` because we don't write data to aste. Plus, we change to the ```read_data_name``` from ```Forces0``` to ```Data``` since aste works with the general data name ```Data```. -In ```precice-config.xml``` we need more changes -Again, we rename ```Forces0``` to ```Data``` throughout the whole file. +In ```precice-config.xml``` we need more changes: + +- Again, we rename ```Forces0``` to ```Data``` throughout the whole file. +- We delete all lines where ```Displacements0``` occurs, since we are only coupling in the other direction. -Then, we substitute the Fluid meshes and the Fluid participant with aste: -- Rename ```Fluid-Mesh-Faces``` to ```MeshA``` throughout the whole file. This is the mesh where +Then, you substitute the Fluid meshes and the Fluid participant with aste: + +- Rename ```Fluid-Mesh-Faces``` to ```MeshA``` throughout the whole file. - Delete the ```mesh``` ```"Fluid-Mesh-Nodes"``` and all lines where ```"Fluid-Mesh-Nodes"``` occurs. -- Rename +- Rename the participant ```Fluid``` to ```A``` + +Last, you need to change the coupling scheme to an explicit scheme: + +- Change ```serial-implicit``` to ```serial-explicit```. +- Explicit schemes don't iterate such that they don't need convergence measures, extrapolation or acceleration. Delete everything in the coulping scheme except for +``` + + + + +``` + +### Run +Finally, run the tutorial in two shells with ```python3 Solid/perp_flap.py``` and ```preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata```. + From 42520317205946803bdffd8b17c675e357bf9e41 Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Mon, 9 Mar 2020 12:52:53 +0100 Subject: [PATCH 13/49] Update README.md --- FSI/flap_perp/ASTE/README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index 5c94fb3bd..8887c77e1 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -8,7 +8,7 @@ The base simulation for this tutorial is the OpenFOAM-FEniCS perpendicular flap 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) +- [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/) @@ -39,7 +39,7 @@ To convert the files to the correct format, open the ```preCICE-output``` folder #### The quick way to run Copy perp_flap.py from OpenFOAM-FEniCS/Solid to aste/Solid -run in two terminals ```python3 Solid/perp_flap.py``` and ```preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata``` +run in two terminals ```python3 Solid/perp-flap.py``` and ```preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata``` Read on if you want to know what to change in the configuration files starting from the OpenFOAM-FEniCS tutorial. @@ -77,10 +77,18 @@ Last, you need to change the coupling scheme to an explicit scheme: ``` ### Run -Finally, run the tutorial in two shells with ```python3 Solid/perp_flap.py``` and ```preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata```. +Finally, run the tutorial in two shells with ```python3 Solid/perp-flap.py``` and ```preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata```. +### 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/FSI/flap_perp/OpenFOAM-CalculiX) with the same geometry and feed them to FEniCS with aste. + +- If you are familiar with the OpenFOAM-Adapter you can also substitute FEniCS with aste such that aste writes previously exported displacements to OpenFOAM. From dcd542c1f82a8fa21c3ee152e315803b8e7480a5 Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 15 Apr 2020 13:50:56 +0200 Subject: [PATCH 14/49] revert changes --- FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict b/FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict index 511c00da6..8694980dc 100644 --- a/FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict +++ b/FSI/cylinderFlap/OpenFOAM-CalculiX/Fluid/system/controlDict @@ -10,8 +10,8 @@ FoamFile // Note: With OpenFOAM v1806 and OpenFOAM 6, the DyM solvers // were marked deprecated and merged into their respective standard solvers. -// application pimpleFoam; // OpenFOAM v1806, OpenFOAM 6, or newer -application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older +application pimpleFoam; // OpenFOAM v1806, OpenFOAM 6, or newer +// application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older startFrom startTime; From 4664cbe30fbbb17990a97343e9c8f9119a7b40de Mon Sep 17 00:00:00 2001 From: richahert Date: Wed, 15 Apr 2020 14:31:47 +0200 Subject: [PATCH 15/49] delete strange file --- .../OpenFOAM-FEniCS/.gitignore | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 FSI/cylinderFlap/OpenFOAM-FEniCS-bigdt/OpenFOAM-FEniCS/.gitignore diff --git a/FSI/cylinderFlap/OpenFOAM-FEniCS-bigdt/OpenFOAM-FEniCS/.gitignore b/FSI/cylinderFlap/OpenFOAM-FEniCS-bigdt/OpenFOAM-FEniCS/.gitignore deleted file mode 100644 index 49e223957..000000000 --- a/FSI/cylinderFlap/OpenFOAM-FEniCS-bigdt/OpenFOAM-FEniCS/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -Fluid -!Fluid/0 -!Fluid/0.orig -!Fluid/constant -!Fluid/system -!Fluid/Fluid.foam -!Fluid/precice-adapter-config.yml -Solid -!Solid/cyl-flap.py -!Solid/precice-adapter-config-fsi-s.json -*.log -precice-fenics-events.json -precice-Fluid-events.json From e3225133dd500e1bc42035c6ea462762835f1e4b Mon Sep 17 00:00:00 2001 From: richahert Date: Wed, 15 Apr 2020 14:36:18 +0200 Subject: [PATCH 16/49] remove file that is not relevant --- .../Postprocessing/plot_tip.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 FSI/cylinderFlap/OpenFOAM-FEniCS/Postprocessing/plot_tip.py diff --git a/FSI/cylinderFlap/OpenFOAM-FEniCS/Postprocessing/plot_tip.py b/FSI/cylinderFlap/OpenFOAM-FEniCS/Postprocessing/plot_tip.py deleted file mode 100644 index 4dc919439..000000000 --- a/FSI/cylinderFlap/OpenFOAM-FEniCS/Postprocessing/plot_tip.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Thu May 23 15:07:54 2019 - -@author: richyrich -""" - -import numpy as np -import matplotlib.pyplot as plt - -fenics_watchpoint = np.loadtxt('../precice-fenics-watchpoint-point1.log', skiprows = 1) -#ccx_watchpoint = np.loadtxt('/home/richyrich/Bachelorarbeit/OpenFOAM-CalculiX/precice-Fluid-watchpoint-point1.log', skiprows = 1) - - -plt.plot(fenics_watchpoint[:,0],fenics_watchpoint[:,7]) - -plt.show() -#plt.plot(ccx_watchpoint[:,0],ccx_watchpoint[:,8]) From 9a8c315d36cfe015fc24f4bde619007a48878a00 Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 15 Apr 2020 14:37:50 +0200 Subject: [PATCH 17/49] Update FSI/flap_perp/ASTE/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Benjamin Rüth --- FSI/flap_perp/ASTE/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index 8887c77e1..18a4027b6 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -1,6 +1,7 @@ ## 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 substitutes one of the solvers and the simulation can be "replayed" using only one solver and aste with the prior results. +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 substitutes one of the solvers and the simulation can be "replayed" using only one solver and aste with the previously computed results. + The base simulation for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. aste then substitutes OpenFOAM. @@ -92,4 +93,3 @@ If you want to explore more possibilities of the Replay-Mode here are some ideas - From af988d71001df5dd1f77adb0393222d8fd16ed22 Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 15 Apr 2020 14:41:13 +0200 Subject: [PATCH 18/49] Update FSI/flap_perp/ASTE/README.md formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Benjamin Rüth --- FSI/flap_perp/ASTE/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index 18a4027b6..823f12e17 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -15,7 +15,8 @@ To run this tutorial you need to install the following components: - 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. +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 @@ -92,4 +93,3 @@ If you want to explore more possibilities of the Replay-Mode here are some ideas - If you are familiar with the OpenFOAM-Adapter you can also substitute FEniCS with aste such that aste writes previously exported displacements to OpenFOAM. - From b8db4f660bd7e6e476d6db26b031150371c149c3 Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 15 Apr 2020 14:45:29 +0200 Subject: [PATCH 19/49] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Benjamin Rüth --- FSI/flap_perp/ASTE/README.md | 50 +++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index 823f12e17..62822b401 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -3,7 +3,8 @@ 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 substitutes one of the solvers and the simulation can be "replayed" using only one solver and aste with the previously computed results. -The base simulation for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. aste then substitutes OpenFOAM. +This tutorial uses the results from the OpenFOAM-FEniCS perpendicular flap tutorial as a basis. aste then substitutes OpenFOAM. + ## Requirements @@ -22,16 +23,18 @@ Make sure to add `aste/build` to the `PATH` such that the python scripts and `pr ### 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 that simulation. -To generate a vtk output in preCICE, add the following line to ```precice-config.xml``` after [line 41](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml#L41) in the Solid participant: -`````` +The base case for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. So let's start in the the root-directory of that simulation `tutorials/FSI/flap_perp/OpenFOAM-FEniCS`. + +To generate a vtk output in preCICE, add the following line to the `precice-config.xml` in `tutorials/FSI/flap_perp/OpenFOAM-FEniCS` after [line 41](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml#L41) in the Solid participant: +`` + +Then, the simulation can be run in two terminals with `bash ./runFluid` and `python3 Solid/perp_flap.py`. -Then, the simulation can be run in two terminals with ```bash ./runFluid``` and ```python3 Solid/perp_flap.py```. The exports are in the ```preCICE-output``` directory. ### Converting the output to aste format. -Copy the ```preCICE-output``` folder to the root directory of the aste tutorial. +Copy the `preCICE-output` folder to the root directory of the aste tutorial ``tutorials/FSI/flap_perp/ASTE`. To convert the files to the correct format, open the ```preCICE-output``` folder and run ```precice_to_aste.py -n 500 -f Forces0 --datadim 3``` @@ -39,37 +42,43 @@ To convert the files to the correct format, open the ```preCICE-output``` folder ### Replay of the simulation with aste #### The quick way to run -Copy perp_flap.py from OpenFOAM-FEniCS/Solid to aste/Solid +Copy `perp_flap.py` from `tutorials/FSI/flap_perp/OpenFOAM-FEniCS/Solid` to `tutorials/FSI/flap_perp/ASTE/Solid` + +run in two terminals `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata` -run in two terminals ```python3 Solid/perp-flap.py``` and ```preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata``` 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 simulation has its own ```precice-config.xml``` and ```precice-adapter-config-fsi-s.json```. +The aste-FEniCS simulation has its own `precice-config.xml` and `precice-adapter-config-fsi-s.json`. + However, these can be generated by modifiying the files from the OpenFOAM-FEniCS case. First, copy the files from the OpenFOAM-FEniCS tutorial into the respective directory of the aste-tutorial. -For ```precice-adapter-config-fsi-s.json``` we remove the line ```"write_data_name": "Displacements0",``` because we don't write data to aste. -Plus, we change to the ```read_data_name``` from ```Forces0``` to ```Data``` since aste works with the general data name ```Data```. +For `precice-adapter-config-fsi-s.json` we remove the line `"write_data_name": "Displacements0",` because we don't write data to aste. + +Plus, we change to the `read_data_name` from `Forces0` to `Data` since aste works with the general data name `Data`. + In ```precice-config.xml``` we need more changes: -- Again, we rename ```Forces0``` to ```Data``` throughout the whole file. -- We delete all lines where ```Displacements0``` occurs, since we are only coupling in the other direction. +- Again, we rename `Forces0` to `Data` throughout the whole file. +- We delete all lines where `Displacements0` occurs, since we are only coupling in the other direction. + Then, you substitute the Fluid meshes and the Fluid participant with aste: -- Rename ```Fluid-Mesh-Faces``` to ```MeshA``` throughout the whole file. -- Delete the ```mesh``` ```"Fluid-Mesh-Nodes"``` and all lines where ```"Fluid-Mesh-Nodes"``` occurs. -- Rename the participant ```Fluid``` to ```A``` +- Rename `Fluid-Mesh-Faces` to `MeshA` throughout the whole file. +- Delete the `mesh` `"Fluid-Mesh-Nodes"` and all lines where `"Fluid-Mesh-Nodes"` occurs. +- Rename the participant `Fluid` to `A` Last, you need to change the coupling scheme to an explicit scheme: -- Change ```serial-implicit``` to ```serial-explicit```. +- Change `serial-implicit` to `serial-explicit`. + - Explicit schemes don't iterate such that they don't need convergence measures, extrapolation or acceleration. Delete everything in the coulping scheme except for ``` @@ -80,16 +89,17 @@ Last, you need to change the coupling scheme to an explicit scheme: ### Run -Finally, run the tutorial in two shells with ```python3 Solid/perp-flap.py``` and ```preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata```. +Finally, run the tutorial in two shells with `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata`. + ### 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 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/FSI/flap_perp/OpenFOAM-CalculiX) with the same geometry and feed them to FEniCS with aste. - If you are familiar with the OpenFOAM-Adapter you can also substitute FEniCS with aste such that aste writes previously exported displacements to OpenFOAM. - From 1545b5827a9bfb0d796a08ad2f28295ff356d8db Mon Sep 17 00:00:00 2001 From: richahert Date: Wed, 15 Apr 2020 14:49:42 +0200 Subject: [PATCH 20/49] delete unnecessary comments --- FSI/flap_perp/ASTE/precice-config.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/FSI/flap_perp/ASTE/precice-config.xml b/FSI/flap_perp/ASTE/precice-config.xml index e0882612c..6ce5e7237 100644 --- a/FSI/flap_perp/ASTE/precice-config.xml +++ b/FSI/flap_perp/ASTE/precice-config.xml @@ -35,9 +35,7 @@ - - - + From 25ea047392837e480ec77999a4e1a876e0b24f5a Mon Sep 17 00:00:00 2001 From: richahert Date: Wed, 15 Apr 2020 14:51:41 +0200 Subject: [PATCH 21/49] revert changes to upstream develop --- FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py b/FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py index b1c893fe7..d513c880d 100644 --- a/FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py +++ b/FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py @@ -249,3 +249,4 @@ def avg(x_old, x_new, alpha): plt.ylabel("Tip displacement") plt.show() + From b7acb41b95fce49ee7796ce55a274dff150799ec Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 15 Apr 2020 14:53:47 +0200 Subject: [PATCH 22/49] revert to upstream/develop --- FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict b/FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict index 9a19b3673..19433cd34 100644 --- a/FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict +++ b/FSI/flap_perp/OpenFOAM-CalculiX/Fluid/system/controlDict @@ -10,8 +10,8 @@ FoamFile // Note: With OpenFOAM v1806 and OpenFOAM 6, the DyM solvers // were marked deprecated and merged into their respective standard solvers. -//application pimpleFoam; // OpenFOAM v1806, OpenFOAM 6, or newer - application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older +application pimpleFoam; // OpenFOAM v1806, OpenFOAM 6, or newer +// application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older startFrom startTime; From 85b5cbbd71bae26472b28e095f86d702d0f7e1cd Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 15 Apr 2020 14:55:51 +0200 Subject: [PATCH 23/49] commit suggestion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Benjamin Rüth --- FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py index 6f45b5caa..9f48fae5f 100644 --- a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py +++ b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py @@ -13,7 +13,7 @@ import cProfile, pstats -#define the two kinds of boundary: clamped and coupling Neumann Boundary +# define the two kinds of boundary: clamped and coupling Neumann Boundary def clamped_boundary(x, on_boundary): return on_boundary and abs(x[1]) Date: Wed, 15 Apr 2020 14:57:00 +0200 Subject: [PATCH 24/49] PEP8 formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Benjamin Rüth --- FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py index 9f48fae5f..dd9626212 100644 --- a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py +++ b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py @@ -24,6 +24,7 @@ def Neumann_Boundary(x, on_boundary): """ return on_boundary and ((abs(x[1]-1) Date: Wed, 15 Apr 2020 14:59:42 +0200 Subject: [PATCH 25/49] revert to upstream --- FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py index dd9626212..ae3c9e0cd 100644 --- a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py +++ b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py @@ -41,8 +41,8 @@ def Neumann_Boundary(x, on_boundary): lambda_ = Constant(E*nu / ((1.0 + nu)*(1.0 - 2.0*nu))) # create Mesh -n_x_Direction=4 -n_y_Direction=40 +n_x_Direction=5 +n_y_Direction=50 mesh = RectangleMesh(Point(-W/2,0), Point(W/2,H), n_x_Direction,n_y_Direction) h=Constant(H/n_y_Direction) From b5a12126145d0c65fa401ae4bc310ee7b994ba37 Mon Sep 17 00:00:00 2001 From: richahert Date: Wed, 15 Apr 2020 15:08:47 +0200 Subject: [PATCH 26/49] remove profiling --- .../OpenFOAM-FEniCS/Solid/perp-flap.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py index ae3c9e0cd..97ef311d6 100644 --- a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py +++ b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py @@ -10,7 +10,6 @@ import matplotlib.pyplot as plt from fenicsadapter import Adapter from enum import Enum -import cProfile, pstats # define the two kinds of boundary: clamped and coupling Neumann Boundary @@ -25,8 +24,7 @@ def Neumann_Boundary(x, on_boundary): return on_boundary and ((abs(x[1]-1) Date: Wed, 15 Apr 2020 15:11:16 +0200 Subject: [PATCH 27/49] formatting --- FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py index 97ef311d6..c315c18e1 100644 --- a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py +++ b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py @@ -25,7 +25,6 @@ def Neumann_Boundary(x, on_boundary): - # Geometry and material properties dim=2 #number of dimensions H = 1 @@ -71,9 +70,9 @@ def Neumann_Boundary(x, on_boundary): coupling_boundary = AutoSubDomain(Neumann_Boundary) -## get the adapter ready +# get the adapter ready -#read fenics-adapter json-config-file) +# read fenics-adapter json-config-file) adapter_config_filename = "precice-adapter-config-fsi-s.json" @@ -95,7 +94,7 @@ def Neumann_Boundary(x, on_boundary): # clamp the beam at the bottom bc = DirichletBC(V, Constant((0,0)), clamped_boundary) -#alpha method parameters +# alpha method parameters alpha_m = Constant(0.0) alpha_f = Constant(0.0) @@ -180,7 +179,7 @@ def avg(x_old, x_new, alpha): # Prepare for time-stepping -#parameters for Time-Stepping +# parameters for Time-Stepping t=0.0 n=0 time = [] @@ -221,7 +220,7 @@ def local_project(v, V, u=None): xdmf_file.parameters["functions_share_mesh"] = True xdmf_file.parameters["rewrite_function_mesh"] = False -#time loop for coupling +# time loop for coupling while precice.is_coupling_ongoing(): From 06e174da379a097b9f03ca24ff4d369753216cd6 Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 15 Apr 2020 15:16:34 +0200 Subject: [PATCH 28/49] remove export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Benjamin Rüth --- FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml b/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml index ab66df822..7b3febf81 100644 --- a/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml +++ b/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml @@ -39,7 +39,6 @@ - From 061c21237000f4993abb3e3395371943ccbab8b2 Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Wed, 15 Apr 2020 15:38:17 +0200 Subject: [PATCH 29/49] add solvername and some formatting --- FSI/flap_perp/ASTE/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index 62822b401..d7f862278 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -30,14 +30,14 @@ To generate a vtk output in preCICE, add the following line to the `precice-conf Then, the simulation can be run in two terminals with `bash ./runFluid` and `python3 Solid/perp_flap.py`. -The exports are in the ```preCICE-output``` directory. +The exports are 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/FSI/flap_perp/ASTE`. -To convert the files to the correct format, open the ```preCICE-output``` folder and run +Copy the `preCICE-output` folder to the root directory of the aste tutorial `tutorials/FSI/flap_perp/ASTE`. +To convert the files to the correct format, open the `preCICE-output` folder and run -```precice_to_aste.py -n 500 -f Forces0 --datadim 3``` +`precice_to_aste.py Solid-fenics -n 500 -f Forces0 --datadim 3` ### Replay of the simulation with aste @@ -87,7 +87,7 @@ Last, you need to change the coupling scheme to an explicit scheme: ``` -### Run +#### Run Finally, run the tutorial in two shells with `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata`. From 724efafa1f23c6e4ef0e53c3a59da13cd0696d4b Mon Sep 17 00:00:00 2001 From: richahert <33255175+richahert@users.noreply.github.com> Date: Fri, 1 May 2020 13:50:12 +0200 Subject: [PATCH 30/49] -f flag was chaged to --tag or -t --- FSI/flap_perp/ASTE/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index d7f862278..b4f9190cb 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -37,7 +37,7 @@ The exports are in the `preCICE-output` directory. Copy the `preCICE-output` folder to the root directory of the aste tutorial `tutorials/FSI/flap_perp/ASTE`. To convert the files to the correct format, open the `preCICE-output` folder and run -`precice_to_aste.py Solid-fenics -n 500 -f Forces0 --datadim 3` +`precice_to_aste.py Solid-fenics -n 500 -t Forces0 --datadim 3` ### Replay of the simulation with aste From 86624c0f4c6e9c42a8cea036defdaaf4e130a373 Mon Sep 17 00:00:00 2001 From: BenjaminRueth Date: Fri, 8 May 2020 14:03:05 +0200 Subject: [PATCH 31/49] avoid from fenics import * --- FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py index c315c18e1..55557e1c7 100644 --- a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py +++ b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py @@ -1,10 +1,8 @@ #Import required libs -from fenics import * from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \ -TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad,\ -Identity, inner,dx, ds, sym, grad, lhs, rhs, dot, File, solve, PointSource + TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, Identity, inner,dx, ds, sym, grad, lhs, \ + rhs, dot, File, solve, PointSource, XDMFFile, TensorFunctionSpace, LocalSolver, assemble_system import dolfin - from ufl import nabla_div import numpy as np import matplotlib.pyplot as plt From 4cc08c12f95300889365cde88472d686769a89ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20R=C3=BCth?= Date: Fri, 8 May 2020 14:17:47 +0200 Subject: [PATCH 32/49] Wording and formatting --- FSI/flap_perp/ASTE/README.md | 78 ++++++++++++++---------------------- 1 file changed, 31 insertions(+), 47 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index b4f9190cb..65f737d49 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -1,10 +1,8 @@ ## 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 substitutes 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 as a basis. aste then substitutes OpenFOAM. +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/FSI/flap_perp/OpenFOAM-FEniCS) as a basis. aste then replaces OpenFOAM. ## Requirements @@ -18,19 +16,19 @@ To run this tutorial you need to install the following components: 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 that simulation `tutorials/FSI/flap_perp/OpenFOAM-FEniCS`. +The base case for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. So let's start in the the root-directory of that simulation [`tutorials/FSI/flap_perp/OpenFOAM-FEniCS`](https://github.com/precice/tutorials/tree/master/FSI/flap_perp/OpenFOAM-FEniCS). -To generate a vtk output in preCICE, add the following line to the `precice-config.xml` in `tutorials/FSI/flap_perp/OpenFOAM-FEniCS` after [line 41](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml#L41) in the Solid participant: -`` - -Then, the simulation can be run in two terminals with `bash ./runFluid` and `python3 Solid/perp_flap.py`. +To generate vtk output in preCICE, add the following line to the `precice-config.xml` in `tutorials/FSI/flap_perp/OpenFOAM-FEniCS` after [line 41](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml#L41) in the Solid participant: +``` + +``` +Then, run the simulation as explained in the [`README.md`](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/README.md) of the case. -The exports are in the `preCICE-output` directory. +The exports can be found in the `preCICE-output` directory. ### Converting the output to aste format. @@ -42,55 +40,42 @@ To convert the files to the correct format, open the `preCICE-output` folder and ### Replay of the simulation with aste #### The quick way to run -Copy `perp_flap.py` from `tutorials/FSI/flap_perp/OpenFOAM-FEniCS/Solid` to `tutorials/FSI/flap_perp/ASTE/Solid` -run in two terminals `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata` +1. Copy `perp_flap.py` from `tutorials/FSI/flap_perp/OpenFOAM-FEniCS/Solid` into `tutorials/FSI/flap_perp/ASTE/Solid`. +2. Run `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata` 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 simulation has its own `precice-config.xml` and `precice-adapter-config-fsi-s.json`. - -However, these can be generated by modifiying the files from the OpenFOAM-FEniCS case. - -First, copy the files from the OpenFOAM-FEniCS tutorial into the respective directory of the aste-tutorial. - -For `precice-adapter-config-fsi-s.json` we remove the line `"write_data_name": "Displacements0",` because we don't write data to aste. - -Plus, we change to the `read_data_name` from `Forces0` to `Data` since aste works with the general data name `Data`. - - -In ```precice-config.xml``` we need more changes: - -- Again, we rename `Forces0` to `Data` throughout the whole file. -- We delete all lines where `Displacements0` occurs, since we are only coupling in the other direction. - - - -Then, you substitute the Fluid meshes and the Fluid participant with aste: - -- Rename `Fluid-Mesh-Faces` to `MeshA` throughout the whole file. -- Delete the `mesh` `"Fluid-Mesh-Nodes"` and all lines where `"Fluid-Mesh-Nodes"` occurs. -- Rename the participant `Fluid` to `A` - -Last, you need to change the coupling scheme to an explicit scheme: - -- Change `serial-implicit` to `serial-explicit`. - -- Explicit schemes don't iterate such that they don't need convergence measures, extrapolation or acceleration. Delete everything in the coulping scheme except for -``` +The aste-FEniCS tutorial provides its own `precice-config.xml` and `precice-adapter-config-fsi-s.json` for getting started quickly. + +However, these can also be generated by modifiying the files from the OpenFOAM-FEniCS 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 from the OpenFOAM-FEniCS tutorial into the respective directory of the aste-tutorial. +2. Remove the line `"write_data_name": "Displacements0" ` from `precice-adapter-config-fsi-s.json`, because we don't write data to aste. +3. Change the `read_data_name` from `Forces0` to `Data` since aste works with the general data name `Data`. +4. In ```precice-config.xml``` we require some more changes: + 1. Rename `Forces0` to `Data` throughout the whole file. + 2. Delete all lines where `Displacements0` 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-Faces` 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 + ``` -``` + ``` #### Run -Finally, run the tutorial in two shells with `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata`. - +After applying these preparations, we are now able to run the tutorial in two terminals with `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata`. ### Play Around @@ -98,7 +83,6 @@ 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/FSI/flap_perp/OpenFOAM-CalculiX) with the same geometry and feed them to FEniCS with aste. - If you are familiar with the OpenFOAM-Adapter you can also substitute FEniCS with aste such that aste writes previously exported displacements to OpenFOAM. From b8bb3ae5d1d19e29918e02e068f7884b3153ef7a Mon Sep 17 00:00:00 2001 From: BenjaminRueth Date: Fri, 8 May 2020 14:21:27 +0200 Subject: [PATCH 33/49] Remove perp-flap.py Should be copied from the OpenFOAM-FEniCS tutorial to this location accordinato the the README.md --- FSI/flap_perp/ASTE/Solid/perp-flap.py | 281 -------------------------- 1 file changed, 281 deletions(-) delete mode 100644 FSI/flap_perp/ASTE/Solid/perp-flap.py diff --git a/FSI/flap_perp/ASTE/Solid/perp-flap.py b/FSI/flap_perp/ASTE/Solid/perp-flap.py deleted file mode 100644 index 6f45b5caa..000000000 --- a/FSI/flap_perp/ASTE/Solid/perp-flap.py +++ /dev/null @@ -1,281 +0,0 @@ -#Import required libs -from fenics import * -from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \ -TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad,\ -Identity, inner,dx, ds, sym, grad, lhs, rhs, dot, File, solve, PointSource -import dolfin - -from ufl import nabla_div -import numpy as np -import matplotlib.pyplot as plt -from fenicsadapter import Adapter -from enum import Enum -import cProfile, pstats - - -#define the two kinds of boundary: clamped and coupling Neumann Boundary -def clamped_boundary(x, on_boundary): - return on_boundary and abs(x[1])u_old - v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec - u_old.vector()[:] = u.vector() - - -def avg(x_old, x_new, alpha): - return alpha*x_old + (1-alpha)*x_new - -# residual -a_np1 = update_a(du, u_n, v_n, a_n, ufl=True) -v_np1 = update_v(a_np1, u_n, v_n, a_n, ufl=True) - -res = m(avg(a_n,a_np1,alpha_m), v) + k(avg(u_n,du, alpha_f), v) #TODO: Wext(v) needs to be replaced by coupling - -Forces_x, Forces_y = precice.create_force_boundary_condition(V) - -a_form= lhs(res) -L_form= rhs(res) - -# Prepare for time-stepping - -#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") - -u_n.rename("Displacement", "") -u_np1.rename("Displacement", "") -displacement_out << u_n - -# 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 - -#time loop for coupling - - -while precice.is_coupling_ongoing(): - A, b = assemble_system(a_form, L_form, bc) - - b_forces = b.copy() # b is the same for every iteration, only forces change - - for ps in Forces_x: - ps.apply(b_forces) - for ps in Forces_y: - ps.apply(b_forces) - - assert(b is not b_forces) - solve(A, u_np1.vector(), b_forces) - - t, n, precice_timestep_complete, precice_dt, Forces_x, Forces_y = precice.advance(u_np1, u_np1, u_n, t, float(dt), n) - - - if precice_timestep_complete: - - update_fields(u_np1, saved_u_old, v_n, a_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 -pr.disable() -pr.dump_stats('prof_data') -pr2=pstats.Stats('prof_data') -pr2.sort_stats('cumulative') -pr2.print_stats() -displacement_out << u_n -plt.figure() -plt.plot(time, u_tip) -plt.xlabel("Time") -plt.ylabel("Tip displacement") -plt.show() - - From 5866b2077462bdf3bfaebf6cff88937aeba17ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20R=C3=BCth?= Date: Fri, 8 May 2020 15:48:39 +0200 Subject: [PATCH 34/49] Clearify modifications of precice-config.xml --- FSI/flap_perp/ASTE/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index 65f737d49..3f9a8c442 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -22,9 +22,14 @@ Make sure to add `aste/build` to the `PATH` such that the python scripts and `pr The base case for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. So let's start in the the root-directory of that simulation [`tutorials/FSI/flap_perp/OpenFOAM-FEniCS`](https://github.com/precice/tutorials/tree/master/FSI/flap_perp/OpenFOAM-FEniCS). -To generate vtk output in preCICE, add the following line to the `precice-config.xml` in `tutorials/FSI/flap_perp/OpenFOAM-FEniCS` after [line 41](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml#L41) in the Solid participant: +To generate vtk output in preCICE, add the statement `` to the `precice-config.xml` in `tutorials/FSI/flap_perp/OpenFOAM-FEniCS` in the Solid participant. The result should look the following way: ``` - + + + + + + ``` Then, run the simulation as explained in the [`README.md`](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/README.md) of the case. From a7a3dd5a35d2ad98d71bd04794113b811dc2d489 Mon Sep 17 00:00:00 2001 From: BenjaminRueth Date: Fri, 8 May 2020 15:52:13 +0200 Subject: [PATCH 35/49] Remove unneeded --vectordata option --- FSI/flap_perp/ASTE/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FSI/flap_perp/ASTE/README.md b/FSI/flap_perp/ASTE/README.md index 3f9a8c442..201197088 100644 --- a/FSI/flap_perp/ASTE/README.md +++ b/FSI/flap_perp/ASTE/README.md @@ -48,7 +48,7 @@ To convert the files to the correct format, open the `preCICE-output` folder and 1. Copy `perp_flap.py` from `tutorials/FSI/flap_perp/OpenFOAM-FEniCS/Solid` into `tutorials/FSI/flap_perp/ASTE/Solid`. -2. Run `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata` in two terminals. +2. Run `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --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. @@ -80,7 +80,7 @@ However, these can also be generated by modifiying the files from the OpenFOAM-F #### Run -After applying these preparations, we are now able to run the tutorial in two terminals with `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics --vectordata`. +After applying these preparations, we are now able to run the tutorial in two terminals with `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics`. ### Play Around From a4c83f430f81d265d0602b1e9a7a474ae1df93bc Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 09:04:32 +0200 Subject: [PATCH 36/49] Migrating FSI/flap_perp/ASTE to the new tutorials structure * Moves files that are not conflicting from FSI/flap_perp/ASTE to perpendicular-flap * perpendicular-flap/fluid-aste/README.md describes usage of aste for replay mode. This information needs to be incorporated into the new structure or moved to preCICE.org. * FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json is moved to perpendicular-flap/solid-fenic. Here integration is still a TODO. * Overwrites perpendicular-flap/solid-fenics/solid.py with FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py. Here integration into new structure is still a TODO. * Overwrites perpendicular-flap/precice-confix.xml with FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml. Here integration into new structure is still a TODO. --- .../OpenFOAM-FEniCS/Solid/perp-flap.py | 262 ----------------- .../OpenFOAM-FEniCS/precice-config.xml | 81 ------ .../ASTE => perpendicular-flap}/.gitignore | 0 .../Allclean_aste | 0 .../fluid-aste}/README.md | 0 .../precice-config-aste.xml | 0 perpendicular-flap/precice-config.xml | 129 +++++---- .../precice-adapter-config-fsi-s-aste.json | 2 +- perpendicular-flap/solid-fenics/solid.py | 269 ++++++++++-------- 9 files changed, 222 insertions(+), 521 deletions(-) delete mode 100644 FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py delete mode 100644 FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml rename {FSI/flap_perp/ASTE => perpendicular-flap}/.gitignore (100%) rename FSI/flap_perp/ASTE/Allclean => perpendicular-flap/Allclean_aste (100%) rename {FSI/flap_perp/ASTE => perpendicular-flap/fluid-aste}/README.md (100%) rename FSI/flap_perp/ASTE/precice-config.xml => perpendicular-flap/precice-config-aste.xml (100%) rename FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json => perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s-aste.json (84%) diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py b/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py deleted file mode 100644 index 55557e1c7..000000000 --- a/FSI/flap_perp/OpenFOAM-FEniCS/Solid/perp-flap.py +++ /dev/null @@ -1,262 +0,0 @@ -#Import required libs -from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \ - TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, Identity, inner,dx, ds, sym, grad, lhs, \ - rhs, dot, File, solve, PointSource, XDMFFile, TensorFunctionSpace, LocalSolver, assemble_system -import dolfin -from ufl import nabla_div -import numpy as np -import matplotlib.pyplot as plt -from fenicsadapter import Adapter -from enum import Enum - - -# define the two kinds of boundary: clamped and coupling Neumann Boundary -def clamped_boundary(x, on_boundary): - return on_boundary and abs(x[1])u_old - v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec - u_old.vector()[:] = u.vector() - - -def avg(x_old, x_new, alpha): - return alpha*x_old + (1-alpha)*x_new - -# residual -a_np1 = update_a(du, u_n, v_n, a_n, ufl=True) -v_np1 = update_v(a_np1, u_n, v_n, a_n, ufl=True) - -res = m(avg(a_n,a_np1,alpha_m), v) + k(avg(u_n,du, alpha_f), v) #TODO: Wext(v) needs to be replaced by coupling - -Forces_x, Forces_y = precice.create_force_boundary_condition(V) - -a_form= lhs(res) -L_form= rhs(res) - -# Prepare for time-stepping - -# 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") - -u_n.rename("Displacement", "") -u_np1.rename("Displacement", "") -displacement_out << u_n - -# 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 - -# time loop for coupling - - -while precice.is_coupling_ongoing(): - A, b = assemble_system(a_form, L_form, bc) - - b_forces = b.copy() # b is the same for every iteration, only forces change - - for ps in Forces_x: - ps.apply(b_forces) - for ps in Forces_y: - ps.apply(b_forces) - - assert(b is not b_forces) - solve(A, u_np1.vector(), b_forces) - - t, n, precice_timestep_complete, precice_dt, Forces_x, Forces_y = precice.advance(u_np1, u_np1, u_n, t, float(dt), n) - - - if precice_timestep_complete: - - update_fields(u_np1, saved_u_old, v_n, a_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() diff --git a/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml b/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml deleted file mode 100644 index 7b3febf81..000000000 --- a/FSI/flap_perp/OpenFOAM-FEniCS/precice-config.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/FSI/flap_perp/ASTE/.gitignore b/perpendicular-flap/.gitignore similarity index 100% rename from FSI/flap_perp/ASTE/.gitignore rename to perpendicular-flap/.gitignore diff --git a/FSI/flap_perp/ASTE/Allclean b/perpendicular-flap/Allclean_aste similarity index 100% rename from FSI/flap_perp/ASTE/Allclean rename to perpendicular-flap/Allclean_aste diff --git a/FSI/flap_perp/ASTE/README.md b/perpendicular-flap/fluid-aste/README.md similarity index 100% rename from FSI/flap_perp/ASTE/README.md rename to perpendicular-flap/fluid-aste/README.md diff --git a/FSI/flap_perp/ASTE/precice-config.xml b/perpendicular-flap/precice-config-aste.xml similarity index 100% rename from FSI/flap_perp/ASTE/precice-config.xml rename to perpendicular-flap/precice-config-aste.xml diff --git a/perpendicular-flap/precice-config.xml b/perpendicular-flap/precice-config.xml index 97ebd5afc..7b3febf81 100644 --- a/perpendicular-flap/precice-config.xml +++ b/perpendicular-flap/precice-config.xml @@ -1,70 +1,81 @@ - + + - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - + + + - - - - - - + + + + + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json b/perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s-aste.json similarity index 84% rename from FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json rename to perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s-aste.json index 4538ca27e..d01ded499 100644 --- a/FSI/flap_perp/ASTE/Solid/precice-adapter-config-fsi-s.json +++ b/perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s-aste.json @@ -1,5 +1,5 @@ { - "solver_name": "fenics", + "solver_name": "solid", "config_file_name": "../precice-config.xml", "interface": { "coupling_mesh_name": "Solid", diff --git a/perpendicular-flap/solid-fenics/solid.py b/perpendicular-flap/solid-fenics/solid.py index 66bcb3a62..55557e1c7 100644 --- a/perpendicular-flap/solid-fenics/solid.py +++ b/perpendicular-flap/solid-fenics/solid.py @@ -1,51 +1,53 @@ -# Import required libs +#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 + TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, Identity, inner,dx, ds, sym, grad, lhs, \ + rhs, dot, File, solve, PointSource, XDMFFile, TensorFunctionSpace, LocalSolver, assemble_system +import dolfin from ufl import nabla_div import numpy as np import matplotlib.pyplot as plt -from fenicsprecice import Adapter +from fenicsadapter import Adapter from enum import Enum # define the two kinds of boundary: clamped and coupling Neumann Boundary def clamped_boundary(x, on_boundary): - return on_boundary and abs(x[1]) < tol + return on_boundary and abs(x[1])u_old + + #assign u->u_old v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec u_old.vector()[:] = u.vector() def avg(x_old, x_new, alpha): - return alpha * x_old + (1 - alpha) * x_new - + return alpha*x_old + (1-alpha)*x_new # residual a_np1 = update_a(du, u_n, v_n, a_n, ufl=True) v_np1 = update_v(a_np1, u_n, v_n, a_n, ufl=True) -res = m(avg(a_n, a_np1, alpha_m), v) + k(avg(u_n, du, alpha_f), v) +res = m(avg(a_n,a_np1,alpha_m), v) + k(avg(u_n,du, alpha_f), v) #TODO: Wext(v) needs to be replaced by coupling -a_form = lhs(res) -L_form = rhs(res) +Forces_x, Forces_y = precice.create_force_boundary_condition(V) + +a_form= lhs(res) +L_form= rhs(res) + +# Prepare for time-stepping # parameters for Time-Stepping -t = 0.0 -n = 0 +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") +displacement_out = File("Solid/FSI-S/u_fsi.pvd") + u_n.rename("Displacement", "") u_np1.rename("Displacement", "") displacement_out << u_n -while precice.is_coupling_ongoing(): - - if precice.is_action_required(precice.action_write_iteration_checkpoint()): # write checkpoint - precice.store_checkpoint(u_n, t, n) +# 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") - # read data from preCICE and get a new coupling expression - read_data = precice.read_data() +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 - # Update the point sources on the coupling boundary with the new read data - Forces_x, Forces_y = precice.get_point_sources(read_data) +# time loop for coupling + +while precice.is_coupling_ongoing(): A, b = assemble_system(a_form, L_form, bc) - b_forces = b.copy() # b is the same for every iteration, only forces change - + b_forces = b.copy() # b is the same for every iteration, only forces change + for ps in Forces_x: ps.apply(b_forces) for ps in Forces_y: ps.apply(b_forces) - - assert (b is not b_forces) + + assert(b is not b_forces) solve(A, u_np1.vector(), b_forces) - - 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 - - if precice.is_time_window_complete(): + + t, n, precice_timestep_complete, precice_dt, Forces_x, Forces_y = precice.advance(u_np1, u_np1, u_n, t, float(dt), n) + + + if precice_timestep_complete: + 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() From 2f412b0fbc134a3398c809edc281f61c9a29d4c4 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 09:27:36 +0200 Subject: [PATCH 37/49] Update obvious changes. Whitespaces etc. --- perpendicular-flap/solid-fenics/solid.py | 44 +++++++++++------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/perpendicular-flap/solid-fenics/solid.py b/perpendicular-flap/solid-fenics/solid.py index 55557e1c7..bc1816d15 100644 --- a/perpendicular-flap/solid-fenics/solid.py +++ b/perpendicular-flap/solid-fenics/solid.py @@ -1,53 +1,51 @@ -#Import required libs +# Import required libs from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \ - TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, Identity, inner,dx, ds, sym, grad, lhs, \ - rhs, dot, File, solve, PointSource, XDMFFile, TensorFunctionSpace, LocalSolver, assemble_system -import dolfin + TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, project, \ + Identity, inner, dx, ds, sym, grad, lhs, rhs, dot, File, solve, PointSource, assemble_system from ufl import nabla_div import numpy as np import matplotlib.pyplot as plt -from fenicsadapter import Adapter +from fenicsprecice import Adapter from enum import Enum # define the two kinds of boundary: clamped and coupling Neumann Boundary def clamped_boundary(x, on_boundary): - return on_boundary and abs(x[1]) Date: Thu, 1 Jul 2021 09:31:10 +0200 Subject: [PATCH 38/49] Some more obvious changes. --- perpendicular-flap/solid-fenics/solid.py | 96 +++++++++++++----------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/perpendicular-flap/solid-fenics/solid.py b/perpendicular-flap/solid-fenics/solid.py index bc1816d15..8bce113f4 100644 --- a/perpendicular-flap/solid-fenics/solid.py +++ b/perpendicular-flap/solid-fenics/solid.py @@ -60,10 +60,11 @@ def neumann_boundary(x, on_boundary): a_n = Function(V) -f_N_function = interpolate(Expression(("1","0"), degree=1), V) -u_function = interpolate(Expression(("0","0"), degree=1), V) +f_N_function = interpolate(Expression(("1", "0"), degree=1), V) +u_function = interpolate(Expression(("0", "0"), degree=1), V) -coupling_boundary = AutoSubDomain(Neumann_Boundary) +coupling_boundary = AutoSubDomain(neumann_boundary) +fixed_boundary = AutoSubDomain(clamped_boundary) # get the adapter ready @@ -88,79 +89,85 @@ def neumann_boundary(x, on_boundary): force_boundary = AutoSubDomain(Neumann_Boundary) # clamp the beam at the bottom -bc = DirichletBC(V, Constant((0,0)), clamped_boundary) +bc = DirichletBC(V, Constant((0, 0)), fixed_boundary) # alpha method parameters +alpha_m = Constant(0) +alpha_f = Constant(0) +gamma = Constant(0.5 + alpha_f - alpha_m) +beta = Constant((gamma + 0.5)**2 / 4.) -alpha_m = Constant(0.0) -alpha_f = Constant(0.0) -gamma = Constant(0.5+alpha_f-alpha_m) -beta = Constant((gamma+0.5)**2/4.) - -#Define strain +# Define strain def epsilon(u): - return 0.5*(nabla_grad(u) + nabla_grad(u).T) + return 0.5 * (nabla_grad(u) + nabla_grad(u).T) + # Define Stress tensor def sigma(u): - return lambda_*nabla_div(u)*Identity(dim) + 2*mu*epsilon(u) + return lambda_ * nabla_div(u) * Identity(dim) + 2 * mu * epsilon(u) + # Define Mass form -def m(u,v): - return rho*inner(u,v)*dx +def m(u, v): + return rho * inner(u, v) * dx + # Elastic stiffness form -def k(u,v): +def k(u, v): return inner(sigma(u), sym(grad(v))) * dx + # External Work def Wext(u_): - return dot(u_,p)*ds + return dot(u_, p) * ds # Update functions -# Update accelleration -def update_a(u, u_old,v_old, a_old, ufl=True): +# Update acceleration +def update_a(u, u_old, v_old, a_old, ufl=True): if ufl: - dt_=dt - beta_=beta + dt_ = dt + beta_ = beta else: - dt_=float(dt) - beta_=float(beta) - - return ((u - u_old - dt_*v_old)/beta/dt_**2 - - (1-2*beta_)/2/beta_*a_old) + dt_ = float(dt) + beta_ = float(beta) + + return ((u - u_old - dt_ * v_old) / beta / dt_ ** 2 + - (1 - 2 * beta_) / 2 / beta_ * a_old) + # Update velocity -def update_v(a,u_old,v_old,a_old, ufl = True): +def update_v(a, u_old, v_old, a_old, ufl=True): if ufl: - dt_=dt - gamma_=gamma + dt_ = dt + gamma_ = gamma else: - dt_=float(dt) - gamma_=float(gamma) - - return v_old + dt_*((1-gamma_)*a_old + gamma_*a) + dt_ = float(dt) + gamma_ = float(gamma) + + return v_old + dt_ * ((1 - gamma_) * a_old + gamma_ * a) + def update_fields(u, u_old, v_old, a_old): - '''Update all fields at the end of a timestep.''' - + """Update all fields at the end of a timestep.""" + u_vec, u0_vec = u.vector(), u_old.vector() v0_vec, a0_vec = v_old.vector(), a_old.vector() - - #call update functions + + # call update functions a_vec = update_a(u_vec, u0_vec, v0_vec, a0_vec, ufl=False) v_vec = update_v(a_vec, u0_vec, v0_vec, a0_vec, ufl=False) - - #assign u->u_old + + # assign u->u_old v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec u_old.vector()[:] = u.vector() def avg(x_old, x_new, alpha): - return alpha*x_old + (1-alpha)*x_new + return alpha * x_old + (1 - alpha) * x_new + # residual a_np1 = update_a(du, u_n, v_n, a_n, ufl=True) @@ -184,9 +191,8 @@ def avg(x_old, x_new, alpha): u_tip.append(0.0) E_ext = 0 - displacement_out = File("Solid/FSI-S/u_fsi.pvd") - + u_n.rename("Displacement", "") u_np1.rename("Displacement", "") displacement_out << u_n @@ -222,14 +228,14 @@ def local_project(v, V, u=None): while precice.is_coupling_ongoing(): A, b = assemble_system(a_form, L_form, bc) - b_forces = b.copy() # b is the same for every iteration, only forces change - + b_forces = b.copy() # b is the same for every iteration, only forces change + for ps in Forces_x: ps.apply(b_forces) for ps in Forces_y: ps.apply(b_forces) - - assert(b is not b_forces) + + assert (b is not b_forces) solve(A, u_np1.vector(), b_forces) t, n, precice_timestep_complete, precice_dt, Forces_x, Forces_y = precice.advance(u_np1, u_np1, u_n, t, float(dt), n) From 95be62b52796379886ca9e5ac36b248a85707660 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 10:17:08 +0200 Subject: [PATCH 39/49] Update configs to new naming scheme. --- perpendicular-flap/precice-config-aste.xml | 44 +++--- perpendicular-flap/precice-config.xml | 128 ++++++++++-------- .../precice-adapter-config-fsi-s-aste.json | 8 +- perpendicular-flap/solid-fenics/solid.py | 47 ++++--- 4 files changed, 121 insertions(+), 106 deletions(-) diff --git a/perpendicular-flap/precice-config-aste.xml b/perpendicular-flap/precice-config-aste.xml index 6ce5e7237..68048db4c 100644 --- a/perpendicular-flap/precice-config-aste.xml +++ b/perpendicular-flap/precice-config-aste.xml @@ -1,4 +1,4 @@ - + @@ -8,43 +8,41 @@ - + - + - - + + - - + + - - - - - - - - + + + + + + - - - - - + + + + - + + - + - + diff --git a/perpendicular-flap/precice-config.xml b/perpendicular-flap/precice-config.xml index 7b3febf81..772850755 100644 --- a/perpendicular-flap/precice-config.xml +++ b/perpendicular-flap/precice-config.xml @@ -1,81 +1,91 @@ - + - - - + + + - - - - + + + - + - + - - - + + + - - - - - - - - + + + + + + + - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + --> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s-aste.json b/perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s-aste.json index d01ded499..1c478caad 100644 --- a/perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s-aste.json +++ b/perpendicular-flap/solid-fenics/precice-adapter-config-fsi-s-aste.json @@ -1,8 +1,8 @@ { - "solver_name": "solid", - "config_file_name": "../precice-config.xml", + "participant_name": "Solid", + "config_file_name": "../precice-config-aste.xml", "interface": { - "coupling_mesh_name": "Solid", - "read_data_name": "Data" + "coupling_mesh_name": "Solid-Mesh", + "read_data_name": "Force" } } diff --git a/perpendicular-flap/solid-fenics/solid.py b/perpendicular-flap/solid-fenics/solid.py index 8bce113f4..65da52033 100644 --- a/perpendicular-flap/solid-fenics/solid.py +++ b/perpendicular-flap/solid-fenics/solid.py @@ -71,23 +71,13 @@ def neumann_boundary(x, on_boundary): # read fenics-adapter json-config-file) -adapter_config_filename = "precice-adapter-config-fsi-s.json" - -precice = Adapter(adapter_config_filename) +precice = Adapter(adapter_config_filename="precice-adapter-config-fsi-s-aste.json") clamped_boundary_domain=AutoSubDomain(clamped_boundary) -precice_dt = precice.initialize(coupling_subdomain=coupling_boundary, - mesh=mesh, - read_field=f_N_function, - write_field=u_function, - u_n=u_n, - dimension=dim, - dirichlet_boundary=clamped_boundary_domain) +precice_dt = precice.initialize(coupling_boundary, read_function_space=V, fixed_boundary=clamped_boundary_domain) dt = Constant(precice_dt) -force_boundary = AutoSubDomain(Neumann_Boundary) - # clamp the beam at the bottom bc = DirichletBC(V, Constant((0, 0)), fixed_boundary) @@ -175,20 +165,18 @@ def avg(x_old, x_new, alpha): res = m(avg(a_n,a_np1,alpha_m), v) + k(avg(u_n,du, alpha_f), v) #TODO: Wext(v) needs to be replaced by coupling -Forces_x, Forces_y = precice.create_force_boundary_condition(V) - a_form= lhs(res) L_form= rhs(res) -# Prepare for time-stepping - # parameters for Time-Stepping -t=0.0 -n=0 +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") @@ -226,6 +214,13 @@ def local_project(v, V, u=None): while precice.is_coupling_ongoing(): + + # read data from preCICE and get a new coupling expression + read_data = precice.read_data() + + # Update the point sources on the coupling boundary with the new read data + Forces_x, Forces_y = precice.get_point_sources(read_data) + A, b = assemble_system(a_form, L_form, bc) b_forces = b.copy() # b is the same for every iteration, only forces change @@ -238,11 +233,22 @@ def local_project(v, V, u=None): assert (b is not b_forces) solve(A, u_np1.vector(), b_forces) - t, n, precice_timestep_complete, precice_dt, Forces_x, Forces_y = precice.advance(u_np1, u_np1, u_n, t, float(dt), n) + dt = Constant(np.min([precice_dt, fenics_dt])) + + precice_dt = precice.advance(dt(0)) + u_n.assign(u_np1) + t += float(dt) + n += 1 - if precice_timestep_complete: + 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: @@ -251,6 +257,7 @@ def local_project(v, V, u=None): 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) From a9f7e1ad845ea286b54e49de091b60dc5997d106 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 10:18:02 +0200 Subject: [PATCH 40/49] Update solver. --- perpendicular-flap/solid-fenics/solid.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/perpendicular-flap/solid-fenics/solid.py b/perpendicular-flap/solid-fenics/solid.py index 65da52033..608854683 100644 --- a/perpendicular-flap/solid-fenics/solid.py +++ b/perpendicular-flap/solid-fenics/solid.py @@ -66,15 +66,10 @@ def neumann_boundary(x, on_boundary): coupling_boundary = AutoSubDomain(neumann_boundary) fixed_boundary = AutoSubDomain(clamped_boundary) - -# get the adapter ready - -# read fenics-adapter json-config-file) - precice = Adapter(adapter_config_filename="precice-adapter-config-fsi-s-aste.json") clamped_boundary_domain=AutoSubDomain(clamped_boundary) -precice_dt = precice.initialize(coupling_boundary, read_function_space=V, fixed_boundary=clamped_boundary_domain) +precice_dt = precice.initialize(coupling_boundary, read_function_space=V, fixed_boundary=fixed_boundary) dt = Constant(precice_dt) From 36a76fdf5cc1702b0e2d3cece1b5fe8c285e24e5 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 10:20:14 +0200 Subject: [PATCH 41/49] Clean up the diff. --- perpendicular-flap/solid-fenics/solid.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/perpendicular-flap/solid-fenics/solid.py b/perpendicular-flap/solid-fenics/solid.py index 608854683..46358081f 100644 --- a/perpendicular-flap/solid-fenics/solid.py +++ b/perpendicular-flap/solid-fenics/solid.py @@ -68,9 +68,11 @@ def neumann_boundary(x, on_boundary): precice = Adapter(adapter_config_filename="precice-adapter-config-fsi-s-aste.json") -clamped_boundary_domain=AutoSubDomain(clamped_boundary) +# Initialize the coupling interface 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 = 0.02 # if fenics_dt < precice_dt, subcycling is applied dt = Constant(precice_dt) # clamp the beam at the bottom @@ -158,10 +160,10 @@ def avg(x_old, x_new, alpha): a_np1 = update_a(du, u_n, v_n, a_n, ufl=True) v_np1 = update_v(a_np1, u_n, v_n, a_n, ufl=True) -res = m(avg(a_n,a_np1,alpha_m), v) + k(avg(u_n,du, alpha_f), v) #TODO: Wext(v) needs to be replaced by coupling +res = m(avg(a_n, a_np1, alpha_m), v) + k(avg(u_n, du, alpha_f), v) -a_form= lhs(res) -L_form= rhs(res) +a_form = lhs(res) +L_form = rhs(res) # parameters for Time-Stepping t = 0.0 @@ -215,7 +217,7 @@ def local_project(v, V, u=None): # Update the point sources on the coupling boundary with the new read data Forces_x, Forces_y = precice.get_point_sources(read_data) - + A, b = assemble_system(a_form, L_form, bc) b_forces = b.copy() # b is the same for every iteration, only forces change @@ -227,7 +229,7 @@ def local_project(v, V, u=None): assert (b is not b_forces) solve(A, u_np1.vector(), b_forces) - + dt = Constant(np.min([precice_dt, fenics_dt])) precice_dt = precice.advance(dt(0)) From 0a71b77c89acb4e36e4f216527f69d99e22a483b Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 16:18:40 +0200 Subject: [PATCH 42/49] Partially update to new tutorials structure --- perpendicular-flap/fluid-aste/README.md | 43 ++++++++++++------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/perpendicular-flap/fluid-aste/README.md b/perpendicular-flap/fluid-aste/README.md index 201197088..953409e48 100644 --- a/perpendicular-flap/fluid-aste/README.md +++ b/perpendicular-flap/fluid-aste/README.md @@ -22,22 +22,22 @@ Make sure to add `aste/build` to the `PATH` such that the python scripts and `pr The base case for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. So let's start in the the root-directory of that simulation [`tutorials/FSI/flap_perp/OpenFOAM-FEniCS`](https://github.com/precice/tutorials/tree/master/FSI/flap_perp/OpenFOAM-FEniCS). -To generate vtk output in preCICE, add the statement `` to the `precice-config.xml` in `tutorials/FSI/flap_perp/OpenFOAM-FEniCS` in the Solid participant. The result should look the following way: +To generate vtk output in preCICE, add the statement `` to the `precice-config.xml` in `tutorials/perpendicular-flap` in the Solid participant. The result should look the following way: ``` - - - - + + + + ``` -Then, run the simulation as explained in the [`README.md`](https://github.com/precice/tutorials/blob/develop/FSI/flap_perp/OpenFOAM-FEniCS/README.md) of the case. +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/FSI/flap_perp/ASTE`. +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` @@ -46,41 +46,40 @@ To convert the files to the correct format, open the `preCICE-output` folder and #### The quick way to run -1. Copy `perp_flap.py` from `tutorials/FSI/flap_perp/OpenFOAM-FEniCS/Solid` into `tutorials/FSI/flap_perp/ASTE/Solid`. - -2. Run `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics` in two terminals. +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. +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 OpenFOAM-FEniCS case. The main purpose of this tutorial is to explain how the replay mode with aste can be used for arbirtrary simulation setups. +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 from the OpenFOAM-FEniCS tutorial into the respective directory of the aste-tutorial. -2. Remove the line `"write_data_name": "Displacements0" ` from `precice-adapter-config-fsi-s.json`, because we don't write data to aste. -3. Change the `read_data_name` from `Forces0` to `Data` since aste works with the general data name `Data`. +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 `Forces0` to `Data` throughout the whole file. - 2. Delete all lines where `Displacements0` occurs, since we are only coupling in one direction (from aste to FEniCS). + 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-Faces` to `MeshA` throughout the whole file. + 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 ``` - + - + ``` #### Run -After applying these preparations, we are now able to run the tutorial in two terminals with `python3 Solid/perp-flap.py` and `preciceMap -v -c precice-config.xml -p A --mesh preCICE-output/Solid-fenics`. +After applying these preparations, we are now able to run the tutorial in two terminals as described above. ### Play Around @@ -90,5 +89,5 @@ If you want to explore more possibilities of the Replay-Mode here are some ideas - Export the forces in the [Calculix-Openfoam-tutorial](https://github.com/precice/tutorials/tree/master/FSI/flap_perp/OpenFOAM-CalculiX) with the same geometry and feed them to FEniCS with aste. -- If you are familiar with the OpenFOAM-Adapter you can also substitute FEniCS with aste such that aste writes previously exported displacements to OpenFOAM. +- If you are familiar with the OpenFOAM-Adapter you can also replace FEniCS with aste such that aste writes previously exported displacements to OpenFOAM. From 330dce501b4a5aef2623c800b63045279fc076f5 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 16:53:28 +0200 Subject: [PATCH 43/49] More cleaning up of the diff. --- perpendicular-flap/precice-config.xml | 52 +++++++++--------------- perpendicular-flap/solid-fenics/solid.py | 28 ++++++------- 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/perpendicular-flap/precice-config.xml b/perpendicular-flap/precice-config.xml index 772850755..9469529cd 100644 --- a/perpendicular-flap/precice-config.xml +++ b/perpendicular-flap/precice-config.xml @@ -1,7 +1,5 @@ - - - - + + - - - - - - + + + - - + + - - - - - + + + + - - - - + + + + @@ -68,24 +62,18 @@ - - - - - + + + - - - - diff --git a/perpendicular-flap/solid-fenics/solid.py b/perpendicular-flap/solid-fenics/solid.py index 46358081f..1c89d7421 100644 --- a/perpendicular-flap/solid-fenics/solid.py +++ b/perpendicular-flap/solid-fenics/solid.py @@ -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 @@ -73,7 +73,7 @@ def neumann_boundary(x, on_boundary): 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(precice_dt) +dt = Constant(np.min([precice_dt, fenics_dt])) # clamp the beam at the bottom bc = DirichletBC(V, Constant((0, 0)), fixed_boundary) @@ -168,7 +168,7 @@ def avg(x_old, x_new, alpha): # parameters for Time-Stepping t = 0.0 n = 0 - + time = [] u_tip = [] time.append(0.0) @@ -231,38 +231,38 @@ def local_project(v, V, u=None): solve(A, u_np1.vector(), b_forces) dt = Constant(np.min([precice_dt, fenics_dt])) - + precice_dt = precice.advance(dt(0)) - + 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: 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 +# Plot tip displacement evolution +displacement_out << u_n plt.figure() plt.plot(time, u_tip) plt.xlabel("Time") From fdbd5f8fc1e5a780e4c549fe999ebb49c0e54c40 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 17:16:24 +0200 Subject: [PATCH 44/49] Fix md file formatting. --- perpendicular-flap/fluid-aste/README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/perpendicular-flap/fluid-aste/README.md b/perpendicular-flap/fluid-aste/README.md index 953409e48..6ef5aac9d 100644 --- a/perpendicular-flap/fluid-aste/README.md +++ b/perpendicular-flap/fluid-aste/README.md @@ -1,3 +1,5 @@ +# 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. @@ -7,6 +9,7 @@ This tutorial uses the results from the [OpenFOAM-FEniCS perpendicular flap tuto ## 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/) @@ -23,7 +26,8 @@ Make sure to add `aste/build` to the `PATH` such that the python scripts and `pr The base case for this tutorial is the OpenFOAM-FEniCS perpendicular flap tutorial. So let's start in the the root-directory of that simulation [`tutorials/FSI/flap_perp/OpenFOAM-FEniCS`](https://github.com/precice/tutorials/tree/master/FSI/flap_perp/OpenFOAM-FEniCS). To generate vtk output in preCICE, add the statement `` to the `precice-config.xml` in `tutorials/perpendicular-flap` in the Solid participant. The result should look the following way: -``` + +```xml @@ -31,11 +35,12 @@ To generate vtk output in preCICE, add the statement ` ``` + 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. +### 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 @@ -44,7 +49,7 @@ To convert the files to the correct format, open the `preCICE-output` folder and ### Replay of the simulation with aste -#### The quick way to run +#### 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. @@ -58,7 +63,7 @@ The aste-FEniCS tutorial provides its own `precice-config.xml` and `precice-adap 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. +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. @@ -69,8 +74,9 @@ However, these can also be generated by modifiying the files from the original ` 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 - ``` + 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 From 4bf84b0842808468ca2a04377279c75b9d23a39d Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 17:19:01 +0200 Subject: [PATCH 45/49] Fix ShellCheck. --- perpendicular-flap/Allclean_aste | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/perpendicular-flap/Allclean_aste b/perpendicular-flap/Allclean_aste index 335e4274b..ace45fa2b 100755 --- a/perpendicular-flap/Allclean_aste +++ b/perpendicular-flap/Allclean_aste @@ -16,7 +16,7 @@ cd ${Participant1} # Note: ".foam" triggers the native OpenFOAM reader of ParaView. # Change to ".OpenFOAM" to use the OpenFOAM reader provided with OpenFOAM. touch ${Participant1}.foam -cd .. +cd .. || exit # Remove the log files rm -fv ${Participant1}_blockMesh.log rm -fv ${Participant1}_checkMesh.log @@ -33,8 +33,8 @@ cd FSI-S rm -fv *.vtu rm -fv *.pvd rm -fv *.log -cd .. -cd .. +cd .. || exit +cd .. || exit # Remove the log files rm -fv spooles.out rm -fv ${Participant2}.log From 41d5e44f591ce63853d0e8d3a544056835a747b5 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 17:21:42 +0200 Subject: [PATCH 46/49] Fix dead links. --- perpendicular-flap/fluid-aste/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/perpendicular-flap/fluid-aste/README.md b/perpendicular-flap/fluid-aste/README.md index 6ef5aac9d..a4076cba5 100644 --- a/perpendicular-flap/fluid-aste/README.md +++ b/perpendicular-flap/fluid-aste/README.md @@ -4,7 +4,7 @@ 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/FSI/flap_perp/OpenFOAM-FEniCS) as a basis. aste then replaces OpenFOAM. +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 @@ -93,7 +93,7 @@ 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/FSI/flap_perp/OpenFOAM-CalculiX) with the same geometry and feed them to FEniCS with aste. +- 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. From 77c91fcb5ff1cbc049828559cba9bcfb2961ea30 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 17:23:19 +0200 Subject: [PATCH 47/49] Fix format. --- perpendicular-flap/fluid-aste/README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/perpendicular-flap/fluid-aste/README.md b/perpendicular-flap/fluid-aste/README.md index a4076cba5..7c6be82a9 100644 --- a/perpendicular-flap/fluid-aste/README.md +++ b/perpendicular-flap/fluid-aste/README.md @@ -75,7 +75,7 @@ However, these can also be generated by modifiying the files from the original ` 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 @@ -92,8 +92,5 @@ After applying these preparations, we are now able to run the tutorial in two te 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. - +- 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. - From e7764acf7550e25d660c08d06fbf8964e29c8732 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 17:24:27 +0200 Subject: [PATCH 48/49] Remove unnecessary clean script. --- perpendicular-flap/Allclean_aste | 64 -------------------------------- 1 file changed, 64 deletions(-) delete mode 100755 perpendicular-flap/Allclean_aste diff --git a/perpendicular-flap/Allclean_aste b/perpendicular-flap/Allclean_aste deleted file mode 100755 index ace45fa2b..000000000 --- a/perpendicular-flap/Allclean_aste +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -echo "Cleaning..." - -# Source tutorial clean functions -. $WM_PROJECT_DIR/bin/tools/CleanFunctions - -# Participant 1: Fluid -Participant1="Fluid" -cd ${Participant1} - # Clean the case - cleanCase - rm -rfv 0 - # Create an empty .foam file for ParaView - # Note: ".foam" triggers the native OpenFOAM reader of ParaView. - # Change to ".OpenFOAM" to use the OpenFOAM reader provided with OpenFOAM. - touch ${Participant1}.foam -cd .. || exit -# Remove the log files -rm -fv ${Participant1}_blockMesh.log -rm -fv ${Participant1}_checkMesh.log -rm -fv ${Participant1}_potentialFoam.log -rm -fv ${Participant1}_decomposePar.log -rm -fv ${Participant1}.log -rm -fv ${Participant1}_reconstructPar.log - -# Participant 2: Solid -Participant2="Solid" -cd ${Participant2} -cd FSI-S - # Clean the case - rm -fv *.vtu - rm -fv *.pvd - rm -fv *.log -cd .. || exit -cd .. || exit -# Remove the log files -rm -fv spooles.out -rm -fv ${Participant2}.log - -# Remove the precice-events-files -rm -fv precice-fenics-events.json -rm -fv precice-Fluid-events.json - -# Remove the preCICE-related log files -echo "Deleting the preCICE log files..." -rm -fv \ - precice-*.log \ - precice-postProcessingInfo.log - -# Output files for preCICE versions before 1.2: -rm -fv \ - iterations-${Participant1}.txt iterations-${Participant2}.txt \ - convergence-${Participant1}.txt convergence-${Participant2}.txt \ - Events-${Participant1}.log Events-${Participant2}.log \ - EventTimings-${Participant1}.log EventTimings-${Participant2}.log - -# Remove the preCICE address files -rm -rfv precice-run -rm -fv .*.address - -echo "Cleaning complete!" -#------------------------------------------------------------------------------ From 2eefa05ef49893ae71a06b4ab91b699e634bc3c6 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 1 Jul 2021 17:27:20 +0200 Subject: [PATCH 49/49] Fix link. --- perpendicular-flap/fluid-aste/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perpendicular-flap/fluid-aste/README.md b/perpendicular-flap/fluid-aste/README.md index 7c6be82a9..d2b3c5358 100644 --- a/perpendicular-flap/fluid-aste/README.md +++ b/perpendicular-flap/fluid-aste/README.md @@ -23,7 +23,7 @@ Make sure to add `aste/build` to the `PATH` such that the python scripts and `pr ### 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 that simulation [`tutorials/FSI/flap_perp/OpenFOAM-FEniCS`](https://github.com/precice/tutorials/tree/master/FSI/flap_perp/OpenFOAM-FEniCS). +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 `` to the `precice-config.xml` in `tutorials/perpendicular-flap` in the Solid participant. The result should look the following way: