Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Fortran elastic-tube-1d solvers (precice Fortran module) #607

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

YonatanGM
Copy link

@YonatanGM YonatanGM commented Jan 8, 2025

This PR adds Fortran solvers for the elastic-tube-1d case using the fortran module (precice.f90). I also opened PR #606 that doesn't rely on this module.

The run.sh script downloads precice.f90 from the Fortran module repository to get the latest version and the file gets compiled with the solvers source files using CMake. Since the module is just a wrapper around the precicef functions in the library, which are updated with preCICE release, I imagine it will stay compatible with the precice version used in the solvers (as long as the function names stay consistent)

LAPACK is needed for the fluid solver (same as the C++ case). Just run ./run.sh to build and execute via CMake. The plotting scripts (plot-diameter.sh and plot-all.sh) are updated to show results for the Fortran case. The precommit yaml didnt have hooks for Fortran files, so I maunally formatted them using fprettify.

Results look consistent with the other solvers. I checked the VTK output, and the numbers match up to 5 decimal places on the last timestep. Also tested running the fortran case against the other solves and that seems to work fine too.

tutorials-elastic-tube-1d-all
Figure-fortran
Figure-python

Checklist:

  • I added a summary of any user-facing changes (compared to the last release) in the changelog-entries/<PRnumber>.md.
  • I will remember to squash-and-merge, providing a useful summary of the changes of this PR.
  • Update the image used in readme showing diameter and pressure of running all solvers against cpp to inlcude fortran case

@YonatanGM YonatanGM marked this pull request as draft January 8, 2025 16:16
@YonatanGM YonatanGM marked this pull request as ready for review January 8, 2025 16:20
@MakisH MakisH self-requested a review January 8, 2025 17:18
@MakisH MakisH self-assigned this Jan 8, 2025
Copy link
Member

@MakisH MakisH left a comment

Choose a reason for hiding this comment

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

Hi @YonatanGM,

wearing my preCICE hat here 🤠 (it is a bit unfortunate that I am also supervising your SSE project, maybe @fsimonis can control my conflict of interest).

With a first look, I think we could keep both contributions, since we support both ways of using preCICE via Fortran. Let's start with this one, and at the same time port any changes to the other one as well (should not be too many). Not sure yet how we could reduce duplication, but I have the impression the simplest would be to keep both, in different directories (fluid-fortran and fluid-fortran-module).

I had a first look and I ran the code, mixing languages to check for potential incompatibilities. I arrive at the same results.

tutorials-elastic-tube-1d-all

In terms of the solver source code, I have only reviewed the FluidComputeSolution.f90 so far, as well as the shell scripts and CMakeLists.txt. I will check the rest of the Fortran files during the day.

@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.10)
project(ElasticTube LANGUAGES Fortran C)
Copy link
Member

Choose a reason for hiding this comment

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

Just curious (I don't know): why is the C required here?

cmake_minimum_required(VERSION 3.10)
project(ElasticTube LANGUAGES Fortran C)

set(CMAKE_Fortran_STANDARD 2003)
Copy link
Member

Choose a reason for hiding this comment

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

Does the variable CMAKE_Fortran_STANDARD exist or do anything?
From this CMake issue, I understand that setting Fortran standards is not intrinsically supported by CMake at the moment.

If removed, don't forget to also apply this (and any further changes) to the solid-fortran/CMakeLists.txt and in the other PR.

Comment on lines +7 to +10
if [ ! -f src/precice.f90 ]; then
echo "Fetching precice.f90 (Module for Fortran bindings of preCICE)..."
curl -o src/precice.f90 https://raw.githubusercontent.com/precice/fortran-module/master/precice.f90
fi
Copy link
Member

Choose a reason for hiding this comment

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

I think this step is fine, given that it first checks if the file exists, so one could skip it (we need to document this in a fluid-fortran/README.md, though).

However, what was your motivation for getting the source file, instead of linking to the module, as we do in the example? It is definitely easier for the user, I am just wondering if there are further reasons.

L = 10.0
dx = L/kappa !1.0 / (N * kappa);

! result variable
Copy link
Member

Choose a reason for hiding this comment

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

Since this info is now (in the Fortran version) far away from where it is used, we need a more descriptive comment.

I would argue that we need a better name in all versions, but let's keep it as-is now, for consistency and to keep things simple.

Comment on lines +61 to +62
! Compute residuals
do i = 2, N ! Adjusted for 1-based indexing
Copy link
Member

Choose a reason for hiding this comment

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

I have not checked all the indices here, but I looked at several, and it looks consistent with the C++ version. The bounds make sense.

real(dp), allocatable :: lhs(:, :)
integer, allocatable :: ipiv(:)

nlhs = 2*N + 2
Copy link
Member

Choose a reason for hiding this comment

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

There seems to be a mix-up between n and N. Let's use one of the two forms, as at least it helps text finding. The C++ version uses N.

Same with res/Res, lhs/LHS and maybe more.

(Remember: in Fortran, these two are the same variable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants