precice / openfoam-adapter

OpenFOAM-preCICE adapter
https://precice.org/adapter-openfoam-overview.html
GNU General Public License v3.0
134 stars 77 forks source link

Generic writer/reader for volume coupling #279

Open MakisH opened 1 year ago

MakisH commented 1 year ago

In the context of #255, we discussed whether a generic reader/writer would make sense (@tirgendetwas). An additional use case (as discussed with Sergio Roget at the preCICE Workshop 2023) would be coupling forces over a porous medium. These forces should already be available in the objects registry, so a generic reader/writer should be able to access it.

To make it very generic, we could use a template for any (or even constrained) type.

Later on, we could also add a generic reader/writer for surface fields.

Potentially also related to #277 and related to #77, #150.

sroget commented 1 year ago

Hello. I comment my "progress" and my problems. I have to say that I am a newbie in this field and I don't understand perfectly what the code does. What I want to do is to extract the drag and lift forces from a porous medium and apply them to a structural model. So this is a FSI case as I see it.

After talking with @MakisH I have tried to replicate the structure of the CHT/Temperature.C file in the FSI/Force.C file, since the chanel-transport tutorial is the closest to what I want to do.

It compiles correctly so from a machine point of view it seems to be fine. I have created a simple case from the perpendicular-flap tutorial for testing. Where I create a openFOAM case with a porous medium in the middle of the domain. Also I modified the structural case made also in openFOAM to set the flap in the same position of the porous medium. It seems that there is communication between fluid-openfoam and solid-openfoam. When I open the cases with paraview I get the force field. The problem is that the values of that field are practically zero. I guess I am not reading the forces produced by the porous medium. I know that openfoam calculates them with the functionObject force so I understand that somehow it could be used with preCICE.

Could you give me a path to follow and go fordward in this project?

Thank you in advance

MakisH commented 1 year ago

I have tried to replicate the structure of the CHT/Temperature.C file in the FSI/Force.C file, since the chanel-transport tutorial is the closest to what I want to do.

@sroget could you please link to your code? You can fork this repository and push to a branch. I am not sure I understand what you have done.

Which branches of the adapter are you based upon? We have not yet merged the volume coupling related changes (see https://github.com/precice/openfoam-adapter/pull/255 and https://github.com/precice/openfoam-adapter/pull/270, as well as https://github.com/precice/tutorials/pull/315).

When I open the cases with paraview I get the force field. The problem is that the values of that field are practically zero. I guess I am not reading the forces produced by the porous medium. I know that openfoam calculates them with the functionObject force so I understand that somehow it could be used with preCICE.

Try checking where this force field comes from. For surface coupling, we are computing the forces explicitly in the adapter (that's why you also need to provide a density in the preciceDict, at least for incompressible solvers). I am not sure what happens when you also use the Forces function object at the same time, since both the adapter and the Forces function object would write into the same field.

I am not sure if or how we can access fields computed by other function objects, but we had such an idea before. Related: https://github.com/precice/openfoam-adapter/issues/143 I assume one would need to remove our own forces calculation and then check for forces objects registered in the OpenFOAM Objects Registry.

sroget commented 1 year ago

Thank you very much for your time @MakisH . I am sorry for not expressing correctly what I have done. I will try to write it better.

Summary I have copied the main branch of the adapter and compiled and installed it. I have modified the tutorial perpendicular flap where I have kept the structural part and modified the fluid participant by a case with porous medium.

And I have followed two paths:

1 Path: Modify FSI/Forces

1.1 First I tried to run preCICE modifying only precicedict as in the tutorial channel-transport with openfoam. In the following image you can see the expected error.

image

1.2 Modify FSI/Forces file to avoid the error. The code compiles but I get a Force field that does not read the forces that I am able to get through functionObject.

image

1.3 I modify functionObject/force --> functionObject/myForce to save the forces produced by the porous medium to try to visualize in paraview how it should look like. I only modified NO_WRITE to AUTO_WRITE.

image

At this point preCICE still gives me an empty force field. I don't know how to solve this and stop here. In the following image you can see what I get with the functionObject/myForce

image

2 Path:Create FSI/porousForce

2.1 I copy VV/Velocity and modify it to get a file called porousForce that does not give errors when I compiled it.

2.2 I run it to see what happens. It does not detect that there is a vectorField other than U.

image

2.3 I try to modify porousForce with no progress, the best I get back was an empty field as in 1.2.

As I see it I am not able to read the result of functionObject/myForce and send it to the structural solver. How can I do this? Also It seems that myForce is not saved in the ObjectRegistry

I will see how can I do that: --> Done. My files are in Sergio-openfoam-adapter inside the fork of this issue. You have the test case and the FSI with the files that I modified

@sroget could you please link to your code? You can fork this repository and push to a branch. I am not sure I understand what you have done.

MakisH commented 1 year ago

Thanks for the details! Link to your fork: https://github.com/sroget/openfoam-adapter

Note that it does not look like the code would compile the changes from https://github.com/sroget/openfoam-adapter/tree/develop/Sergio-openfoam-adapter (the Make/files is not modified). I understand that you put it in a separate directory to be able to easily look at the original state, but I would strongly recommend that you just make another branch and modify the original files. This would make comparisons much much easier.

The error you get (failed lookup of porousForce (objectRegistry region0)) is something I expected. I don't know if that is because of your changes, or because of how OpenFOAM function objects work. I always had this question: can we access the objects created by one function object via another function object? This is what we need to answer first.