Neumann and Dirichlet conditions in subroutines

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
AHIC
Posts: 12
Joined: Thu Sep 27, 2018 10:31 am

Neumann and Dirichlet conditions in subroutines

Post by AHIC »

hello,

i would like to know how i can to configure an Dirichlet or Neumann condition for temperature and the other scalars.
Usually is made by the GUI but i want to learn how i can use the subroutine.

In the cs_user_boundary_conditons, i have introduced this code in the inlet/outlet loop. Is that right ?
In case it's ok, how i can introduce an other scalar.

Code Saturne 4.0

Thanks for any assistance,


!-------------------------------------------------------
! DIRICHLET TEMPERATURE
!-------------------------------------------------------

if (nscal.gt.0) then

ii = 2
icodcl(ifac, isca(ii)) = 1
rcodcl(ifac, isca(ii),1) = 293.d0
rcodcl(ifac, isca(ii), 2) = 8.d0



endif

!-------------------------------------------------------


!-------------------------------------------------------
! NEUMAN TEMPERATURE
!-------------------------------------------------------
if (nscal.gt.0) then

! If flux prescribed to 4.d0 (scalar ii=3):
ii = 3
icodcl(ifac, isca(ii)) = 3
rcodcl(ifac, isca(ii), 3) = 293.15d0

endif

!-------------------------------------------------------
Yvan Fournier
Posts: 4075
Joined: Mon Feb 20, 2012 3:25 pm

Re: Neumann and Dirichlet conditions in subroutines

Post by Yvan Fournier »

Hello,

It might work, but I do not recommend checks such as

Code: Select all

if (nscal.gt.0) then
followed by:

Code: Select all

ii = 3
Because the two tess are not consistent.

Code: Select all

if (nscal.gt.3) then
would be better in this case.

I recommend looking at examples in the src/user_examples or better using the Doxygen documentation for more details.

Regards,

Yvan
AHIC
Posts: 12
Joined: Thu Sep 27, 2018 10:31 am

Re: Neumann and Dirichlet conditions in subroutines

Post by AHIC »

the syntax in doxygen are they available for 4.0 ?

Thank you for your availability and quick answer
Yvan Fournier
Posts: 4075
Joined: Mon Feb 20, 2012 3:25 pm

Re: Neumann and Dirichlet conditions in subroutines

Post by Yvan Fournier »

Hello,

The Doxygen doc should also be in 4.0 If I remember correctly, but is not installed on this web site.

In any case, this specific file has not changed much between versions 4.0 and 5.0, so the Doxygen doc from version 5.0 should mostly do. Also, in a regular case, in SRC/EXAMPLES you will have user examples.

Also, I recommend switching to version 5.0, unless you want to wait a few months and switch directly to 6.0 (but going through 5.0 should make things smoother). When v6 is released this spring, v4 will be retired and not maintained anymore...

Best regards,

Yvan
AHIC
Posts: 12
Joined: Thu Sep 27, 2018 10:31 am

Re: Neumann and Dirichlet conditions in subroutines

Post by AHIC »

hello Yvan,

Thank you for your prompt reply. My main goal is to convert the boundary conditions from the gui into the subroutine file SRC. The work must be done in CS4.

In my GUI, i have temperature and scalar 2. I have an basic question for you.
ii=1 concerns the scalaire temperature, and ii=2 concerns the scalaire scalar2 ?

Image

Image


I have done the wall and the outlet boundary conditions, can you correct me please ? i'm not an expert in fortran, but i want to progress.

Image
Yvan Fournier
Posts: 4075
Joined: Mon Feb 20, 2012 3:25 pm

Re: Neumann and Dirichlet conditions in subroutines

Post by Yvan Fournier »

Hello,

A few remarks:

- Being careful about indenting code under loops and if tests really helps readability, and helps others (and most of all, yourself) check the code.

- By default, user scalars come first (this to help be more robust in case of incorrect use of some indirections by users), so the scalar numbers seem OK (with temperature last) but it is still safe to check.

- For walls, I think depending on whether you use wall laws or not, prescribed (Dirichlet) values might require icodcl 5 or 1, but I'll let you check the documentation (I use the GUI whenever possible, so I don't remember).

- For mass flows, you need to compute the matching inlet surface (Doxygen should have examples), and be careful in case of parallelism (do not forget to sum over processors). Again, the GUI does this automatically.

Two questions: why do you need to stay with version 4.0 (soon retired), and why do you need to avoid the GUI ? I know this may be imposed by some organizations when they have not validated newer versions internally, but the GUI should not be an issue, unless the code was without libxml2 support (and this constraint has disapeared in version 5.3). As avoiding the GUI is recommended only for "expert" users, we recommend it only for things not feasible with the GUI. And you can combine both. For example, if you have a more complex inlet (such as a swirling profile), you can use use user sources for that inlet, and use the GUI for all the rest. Which makes you code shorter and easier to check.

Also, when moving from one version to another, user subroutines must often be updated manually, while GUI setups are updated automatically. This is one of the main advantages to using the GUI.

So this is why I insist on recommending the GUI. It might have occasional bugs, but makes both usage and support easier. To put it short, if some other person requests that you should not use the GUI, they should be capable of helping you and checking your code by themselves. Otherwise, they are making things more difficult both for you and for the support team without assuming any of the extra work... If you need help convincing them, I can try to help...

And if the general idea is to learn the internals of the code better, we could easily suggest some minor development tasks (beginner-friendly, not difficult but requiring a bit of testing) that could be of use to all :-)

Best regards,

Yvan
AHIC
Posts: 12
Joined: Thu Sep 27, 2018 10:31 am

Re: Neumann and Dirichlet conditions in subroutines

Post by AHIC »

We have already an test case on CS 4.0, developed with an specific methodology, and now, we want to test another way to modelling in order to compare our results. We need to adapt this new way to our previous test case. And this way doesnt use the boundary conditions in the GUI and have a lot subroutines files.

The fist step is to avoid the GUI, and next, we will to implement step by step the new features.

For the mass flow inlet, i will convert them to velocity. It's much easier for me.
About the walls, it's an smooth wall with no law wall.
Yvan Fournier
Posts: 4075
Joined: Mon Feb 20, 2012 3:25 pm

Re: Neumann and Dirichlet conditions in subroutines

Post by Yvan Fournier »

Hello,

By smooth wall with no wall law you mean a no slip condition with a wall-resolved boundary ? In this case I think icodcl = 1 goes, though I recommend checking more examples.

And in any case, whenever in doubt experimenting on a very small mesh is always the best option to get settings right (then switching back to a finer mesh for the "true" computation). It allows immediate feedback, and experimenting always helps learning.

Best regards,

Yvan
AHIC
Posts: 12
Joined: Thu Sep 27, 2018 10:31 am

Re: Neumann and Dirichlet conditions in subroutines

Post by AHIC »

hello Yvan,
Thank for for your advices,
i really appreciate
Post Reply