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

First prototype of the dune-precice module (dune-adapter) for preCICE #1

Merged
merged 13 commits into from
Dec 7, 2021

Conversation

maxfirmbach
Copy link
Collaborator

Hello preCICE-team and developers,

this is a prototype of a module inside the DUNE framework, representing an adapter for the preCICE-library.
For now this module is mainly used for FE calculations, enabling multi-physics simulations within DUNE.

Literature references can be found in the README inside the dune-precice folder.

@uekerman
Copy link
Member

uekerman commented Oct 1, 2021

Thanks for the contribution, @maxfirmbach 🎉
Why did you put everything in the subfolder dune-precice? Feel free to completely overwrite the preliminary README that is already on the main branch.

@MakisH
Copy link
Member

MakisH commented Oct 6, 2021

@maxfirmbach thank you very much for the contribution! Before reviewing it, do you maybe have a case that we can run it with? If you want, you can also open a separate PR in the tutorials.

@ajaust
Copy link
Collaborator

ajaust commented Oct 6, 2021

This looks like a great addition to the adapter repositories. I have worked on an adapter for DuMuX which shares quite some functionality with the DUNE adapter. I tried to give an extensive overview in #2 .

@maxfirmbach
Copy link
Collaborator Author

@MakisH I can create a tutorial case and will do a PR in the tutorials (might however take some time). To run a test case the DUNE core modules and some extension modules are needed and the first installation of the whole DUNE environment can be a bit cumbersome.

@ajaust
Copy link
Collaborator

ajaust commented Oct 7, 2021

Regarding the installation of DUNE. There is a Spack recipe for DUNE. Alternatively, there is an installation script for DuMuX. The installation script also installs DUNE dependencies. The dependency list in line 134 needs to be adapted for the DUNE adapter to contain common, functions and istl (functions is currently missing as DuMuX does not need it). If one is not interested in DuMuX, one can comment out the corresponding parts or simply remove the dumux directory after the installation.

@maxfirmbach
Copy link
Collaborator Author

I added a case, where Dune acts as solid-participant in the perpendicular-flap tutorial case. The corresponding folder inside the tutorial directory should also be ready.

@davidscn davidscn self-requested a review October 20, 2021 11:28
Copy link
Member

@davidscn davidscn left a comment

Choose a reason for hiding this comment

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

I tried to install the module but there was a problem (see below)

The directory structure is actually fine (dune-precice).

https://github.com/maxfirmbach/dune-elastodynamics

The adapter can be build with:
`<path-to-dune-common/bin/dunecontrol> --current all`
Copy link
Member

Choose a reason for hiding this comment

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

I installed dune from apt, where dunecontrol is in the global searchpath:

Suggested change
`<path-to-dune-common/bin/dunecontrol> --current all`
`dunecontrol --current all`

Copy link
Member

Choose a reason for hiding this comment

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

Maybe link here also to the module installation instructions provided by DUNE itself. Is the dunecontrol make install command missing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess that are the instructions on the website: https://www.dune-project.org/doc/installation/

README.md Outdated Show resolved Hide resolved

// setup looping
double t = 0.0;
double dt = 0.0001;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to select such a small time-step size? The tutorial uses actually 1e-2?!

Copy link
Collaborator Author

@maxfirmbach maxfirmbach Oct 20, 2021

Choose a reason for hiding this comment

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

An explicit RKN-method is used in this case and for larger time steps I had difficulties with stability. I guess the tutorial cases use an implicit method.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok. This probably explains the deviation of the displacement amplitude as well (I can run a brief comparison tomorrow). You don't have any other time-stepping methods available, right? All in all, I can run the tutorial case andI will have a closer look at the code tomorrow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There should also be a family of Newmark methods (might have to clean that up a bit) and adaptive explicit RKN methods. But great that the thing runs at least.

@maxfirmbach
Copy link
Collaborator Author

I added a implicit time stepping case dune-perpendicular-flap-implicit.cc using Newmark's method and a time step size of 0.01, which should be the same as the openfoam fluid case.

I also cleaned up the time stepping method in dune-elastodynamics so before trying the new case, get a fresh pull of that please. I did a simulation, which looked fine ... I hope it works for you too.

@davidscn
Copy link
Member

I added a implicit time stepping case dune-perpendicular-flap-implicit.cc using Newmark's method and a time step size of 0.01, which should be the same as the openfoam fluid case.

I also cleaned up the time stepping method in dune-elastodynamics so before trying the new case, get a fresh pull of that please. I did a simulation, which looked fine ... I hope it works for you too.

Yes, this works as well and it is faster and more compliant to the other tutorials. However, there is still some deviation between our other tutorials and the dune code here, even with the implicit time-stepper (as you probably know)

Do you have any ideas about the reasoning? Method-wise, you use continuous finite-elements of polynomial degree 2 and an implicit Newmark time-stepping with gamma=0.5 and beta=0.25, right?

@maxfirmbach
Copy link
Collaborator Author

maxfirmbach commented Oct 21, 2021

Yes, I use continuous finite-elements of polynomial degree 2 and an implicit Newmark time-stepping with gamma=0.5 and beta=0.25. To be honest, I'm not sure why the result is different ... I already had a close look at all parts and to my best knowledge the structural part is correct. Still I couldn't figure out till now where the deviation comes from ...

Maybe a short remark, there's a file called hooketensor.hh. Due to the fact that the simulation is 2D there can be a plane stress or plane strain, right now plane stress is active ... maybe that also makes a difference.

@davidscn
Copy link
Member

Ah that's nice, we use plane-strain. Switching this for the dune adapter give actually the correct results:

so please change this in your elastodynamics module. I will wait for the feedback of @ajaust here for now.

@maxfirmbach
Copy link
Collaborator Author

maxfirmbach commented Oct 21, 2021

That looks really nice! I can't just change it ... cause for beam bending problems I need plane stress ... but I will find a way to call the right one.

Thanks for the help so far!

Copy link
Collaborator

@ajaust ajaust left a comment

Choose a reason for hiding this comment

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

Thank you again for the adapter and sorry for the late response. I like your work, but nevertheless left some critical remarks. You do not have to fix everything now, but I think there are some things we have to think about and maybe create issues for them to track them. I can also help with some things if needed. I left some remarks in the code.

In short, these are some of the general remarks:

  • Make function parameters constant where possible. C++ core guidelines
  • Mark functions that do not change any members as const. C++ core guidelines
  • Trivial types do not have to be passed by reference. C++ core guidelines
  • Could we add some simple test (maybe with a solver dummy)? Ideally with some test that might be run via a GitHub action (I would help with that). We can also move this into an issue for a future version.
  • The module name dune-preciceis good. I would call the repository dune-precice instead of dune-adapter. This would follow the standard nomenclature used by DUNE projects. It would make sense to change the layout as well by moving everything from the directory dune-precice in the root of the repository. This would be follow structure of other DUNE modules.
  • dune-precice should not depend on dune-elastodynamics in my opinion as the adapter itself does not depend on it. Only the supplied example depends on dune-elastodynamics and dune-preciceThis means we should do something with the supplied example in src/.
  • I did not try to compile or work with the supplied example yet.
  • Document the dependency on a preCICE version. Does it work with preCICE v1 or v2? Does it work with both version?
  • We should maybe add more documentation and some test (solverdummies)?!

@@ -1,2 +1,31 @@
# dune-adapter
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the whole repository should be called dune-precice to follow standard DUNE notation. At the same time the structure of the repository should be adapted accordingly. Namely, all the content in the folder dune-precice should be in the root of the repository.

Version: 1.0
Maintainer: [email protected]
#depending on
Depends: dune-common (>= 2.7) dune-istl (>= 2.7) dune-functions (>= 2.7) dune-elastodynamics
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently, this repository depends on dune-elastodynamics which does not make sense to me. This increases the number of dependencies while I would vote for dune-precice being a baseline implementation that can be used in other DUNE modules with minimum dependencies. Why would I care installing dune-elastodynamics if I do want to use dune-precice for a completely different type of application?

Therefore I would suggest

Suggested change
Depends: dune-common (>= 2.7) dune-istl (>= 2.7) dune-functions (>= 2.7) dune-elastodynamics
Depends: dune-common (>= 2.7) dune-istl (>= 2.7) dune-functions (>= 2.7)

and adding a simple example (dummysolver?) that purely relies on dune-precice and its dependencies.

I can see three scenarios at the moment:

  1. Relaxing the current dependency Make the current example a suggested dependency and prevent automatic building of the example.
Suggested change
Depends: dune-common (>= 2.7) dune-istl (>= 2.7) dune-functions (>= 2.7) dune-elastodynamics
Depends: dune-common (>= 2.7) dune-istl (>= 2.7) dune-functions (>= 2.7)
Suggests: dune-elastodynamics (>=1.0)

In this case I would also rename the directory. src/ is not very verbose. Something like examples/elastodynamic/ would be better.

  1. Move all examples that require further dependencis into its one DUNE module (dune-precice-examples?).
  2. The current example could live in dune-elastodynamics and one could add dune-precice as a suggested dependency there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The dune-precice module is now only depending on the core modules. I moved the examples to dune-precice-howto as this naming convention is also used for tutorial modules of certain core modules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Considering dune-precice-examples I was thinking about cutting the dependency to dune-elastodynamics completely in the future and replacing it by dune-pdelab. A linear-elasticity example should be rather easy to construct there.

dune-precice/CMakeLists.txt Outdated Show resolved Hide resolved
dune-precice/CMakeLists.txt Outdated Show resolved Hide resolved
dune-precice/CMakeLists.txt Outdated Show resolved Hide resolved
dune-precice/dune/precice/couplinginterface.hh Outdated Show resolved Hide resolved
dune-precice/dune/precice/couplinginterface.hh Outdated Show resolved Hide resolved
dune-precice/dune/precice/couplinginterface.hh Outdated Show resolved Hide resolved
dune-precice/dune/precice/couplinginterface.hh Outdated Show resolved Hide resolved
Comment on lines 174 to 178
for(int i=0; i<dune_to_precice.N(); i++) {
for(int j=0; j<dim; j++) {
if(isBoundary[i][j]) { write_data[iteration_count] = dune_to_precice[i][j]; ++iteration_count; }
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Could we avoid raw loops here and instead used std::for_each, for example? See Slide 3 or the actual talk. 😄
  • Is isBoundary[i] not true for all j? I do not know/understand the indexing?! I would expect i to be the index of the degree of freedom and j refer to the coordinates or so.

@davidscn
Copy link
Member

@maxfirmbach do you have any idea which parts you want to address or if you want to address parts at all? Do you need help with some comments? If you don't want to keep working on this we could also merge and add a TODO list.

@maxfirmbach
Copy link
Collaborator Author

maxfirmbach commented Oct 27, 2021

I can address the changes to the code, but I work quite unregulary on the dune-adapter ... so it always takes some time. Considering the dependencies and the structure of the tutorial examples etc., I guess that's a part, which shouldn't be decided by me. If a merge + ToDo List is ok, I'm fine with that, I will work on the adapter from time to time.

@davidscn
Copy link
Member

Alright that's totally fine, then let's keep it as it is. I just want to prevent that things become stale.

@maxfirmbach
Copy link
Collaborator Author

I restructured the adapter and the tutorial cases. Now there are two DUNE modules inside the dune-adapter, namely dune-precice containing the adapter (depending only on the core modules) and dune-precice-howto containing the tutorial case (and it's dependencies). For now I think that is a good structure and separation.

Copy link
Collaborator

@ajaust ajaust left a comment

Choose a reason for hiding this comment

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

Thank you very much for the work. I went through the main adapter part and did not check the dune-precice. I like the state of the adapter a lot. I have just some minor remarks.

dune-precice/dune-precice/couplinginterface.hh Outdated Show resolved Hide resolved
dune-precice/dune-precice/couplinginterface.hh Outdated Show resolved Hide resolved
dune-precice/dune-precice/couplinginterface.hh Outdated Show resolved Hide resolved
dune-precice/dune-precice/couplinginterface.hh Outdated Show resolved Hide resolved
dune-precice/dune-precice/couplinginterface.hh Outdated Show resolved Hide resolved

#include <dune/functions/functionspacebases/interpolate.hh>

#include <precice/SolverInterface.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to include it inside the Dune::preCICE namespace to keep the scope of preCICE more narrow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure, does it make a big difference?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure what would be the best here. Including it within the namespace would hide preCICE and its precice namespace a bit more from users. From my perspective this would be something good since we want people to use the adapter. However, I did not find any examples regarding good and bad practices. This is for sure a small thing we can also easily change later. I just wanted to mention it.

Maybe @fsimonis has an idea/suggestion regarding the best practices regarding includes inside/outside namespaces?!

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 we can just keep this way, it is also more clear from an outside view (at least in my opinion), because you have all headers before starting to do anything.

dune-precice/dune-precice/couplinginterface.hh Outdated Show resolved Hide resolved
dune-precice/dune-precice/couplinginterface.hh Outdated Show resolved Hide resolved
@davidscn
Copy link
Member

davidscn commented Dec 6, 2021

I didn't follow the discussions, but I think this PR is ready to merge, @maxfirmbach any concerns? Is the tutorial ready as well?

@ajaust
Copy link
Collaborator

ajaust commented Dec 6, 2021

I agree that it is ready. If there are problems, we can still discuss and change/fix things later.

@maxfirmbach
Copy link
Collaborator Author

From my side there are no concerns, at least for now. The tutorial should also be ready.

@davidscn davidscn merged commit 5f2364d into precice:main Dec 7, 2021
@davidscn
Copy link
Member

davidscn commented Dec 7, 2021

Thank you for your contribution!

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.

5 participants