How should i do to set the boundary conditions by python scripts

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
Yvonne
Posts: 23
Joined: Sat Oct 02, 2021 7:53 am

How should i do to set the boundary conditions by python scripts

Post by Yvonne »

hello!

Recently I want to use python scripts to set the boundary conditions.
but when I simulate the simple case, I saw the result is not my want.

first, I set the boundary conditions in GUI ==boundary conditions ->velocity v=3m/s (normal direction to the inlet). in the code, I also set the rcodcl(ifac,iu,1) = 3. when I see the result, it seems the same.

second, i want to set the v and w direction of the inlet face, so i set the rcodcl(ifac,iv,1) = 4, rcodcl(ifac,iw,1) = 5.
and I didn't find the v and w direction set in GUI. (because I think the first in GUI is only in u direction). so I can not prove my result is correct. I don't know the code is right? can I set the three directions by this code?

for another question, should I set the icodcl? (like the under code). I am not clear about this one.
{{ icodcl(ifac,iu) = 1
icodcl(ifac,iv) = 1
icodcl(ifac,iw) = 1}}

if it is right, I want to read the txt to set the boundary. just like picture 1

i don't know if i describe clear. forgive my poor english!
can you help me?? please~~~ I am so sad that I can not solve this problem :(
Attachments
picture1.png
Luciano Garelli
Posts: 283
Joined: Fri Dec 04, 2015 1:42 pm

Re: How should i do to set the boundary conditions by python scripts

Post by Luciano Garelli »

Hello,
Yvonne wrote: Tue Nov 09, 2021 12:58 pm Recently I want to use python scripts to set the boundary conditions.
but when I simulate the simple case, I saw the result is not my want.
The code that you post uses Fortran, not python.
Yvonne wrote: Tue Nov 09, 2021 12:58 pm I didn't find the v and w direction set in GUI
To set the x,y,z directions for the velocity in the GUI you have two options in the menu "direction", you can choose specified coordinates or user profile.

Yvonne wrote: Tue Nov 09, 2021 12:58 pm should I set the icodcl? (like the under code)
About the icodcl it defines the type of boundary condition for the variable, you can check it in de user documentation "Manage boundary conditions" and also in the user example like cs_user_boundary_conditions-advanced.f90.

Best regards,
Luciano
Yvonne
Posts: 23
Joined: Sat Oct 02, 2021 7:53 am

Re: How should i do to set the boundary conditions by python scripts

Post by Yvonne »

hello!

thank you for your answer~
you can choose specified coordinates or user profile
. I had used the specified coordinates, but I am so confuse about this set. maybe when I set the coordinates x=1, y=-1, z=1, it means that the coordinate is like the picture ?
and the coordinate x=3, y=-3, z=3 is equal to the x=1, y=-1, z=1 ? or 3 is the unit length?

and I have another question, is the user profile is equal to the specified coordiantes. because I saw the dir_x, I think the dir_x is equal to the the coordinates x?
About the icodcl it defines the type of boundary condition for the variable
. for this one, I have checked the document, but I am a beginner of the CFD, so I am not sure this is a must-have?

and have you seen my FORTRAN code? is it right? can I set the velocity by this method?

Best wish,
Yvonne
Attachments
picture.jpg
Luciano Garelli
Posts: 283
Joined: Fri Dec 04, 2015 1:42 pm

Re: How should i do to set the boundary conditions by python scripts

Post by Luciano Garelli »

Hello,
Yvonne wrote: Wed Nov 10, 2021 9:15 am I had used the specified coordinates, but I am so confuse about this set. maybe when I set the coordinates x=1, y=-1, z=1, it means that the coordinate is like the picture ?
and the coordinate x=3, y=-3, z=3 is equal to the x=1, y=-1, z=1 ? or 3 is the unit length?
You have to set the norm of the velocity (mass or vol flow rate) and the coordinates give you the proportion in each direction. For example, if you set norm=1 m/s and (x=3, y=-3, z=3) or (x=1, y=-1, z=1) will give you the same result, because not depend on the magnitude of the direction vector. For me, the easiest way is to use the velocity in each component as a direction and then compute the norm (x=ux=3; y=uy=2, z=uz=1, norm=sqrt(14)), but it depends on the case.

The code seems to be Ok, because you set the BC type and the Dirichlet condition for each velocity component. Run a very simple case and check it graphically with paravis(salome).

Regards,
Luciano
Yvonne
Posts: 23
Joined: Sat Oct 02, 2021 7:53 am

Re: How should i do to set the boundary conditions by python scripts

Post by Yvonne »

Dear Luciano,
thank you for your answer!

and I still have the question :(, the method you say
For me, the easiest way is to use the velocity in each component as a direction and then compute the norm
that is use the specified coordinates or the user profiles?
is two methods are the same? because I see the three-dimensional set that both all have. or the specified coordinates has only defined the direction, not the length of all?
[for example, in specified coordinates method,I set the norm= 2m/s and the x=1,y=-1,z=1. the result is that the velocityis equal to (2,-2,2), or the 2 is the velocity, is the norm of three dimension. 3√a=2, a is the velocity component.].

the user profiles, no matter the norm what to set? I can define the value of velocity in the profiles.
[like dir_x=3,dir_y=4,dir_z=5, the norm=2, then i can get the velocity (2*3,4*2,5*2)].

I don't know the relationship between the norm and the dir or specified

my English is poor, please forgive me~~~
Last edited by Yvonne on Fri Nov 12, 2021 3:37 am, edited 1 time in total.
Yvonne
Posts: 23
Joined: Sat Oct 02, 2021 7:53 am

Re: How should i do to set the boundary conditions by python scripts

Post by Yvonne »

hello!

as you advise, I can understand the user profiles and the specified coordinates. I try to set something to compare, but the result is not fine. could you spend some time?

In GUI, I choose the specified coordinates to set the velocity. in my opinion, I want to set the 3 m/s as the x、y and z these three dimensions, so I set the norm=3 (because the cubic root 27 is three , so in the three dimensions, the velocity component is 3、3 、3, so the norm velocity= 3√(3^2+3^2+3^2)=3 )

so in the code, i set the u=3,v=3,w=3, the velocity= 3√(3^2+3^2+3^2)=3.
I think the result which set by GUI should same as the code set, but in reality, it is different. I can't understand the reason, could you tell me why?

it is so important for me!! is there the code has wrong? thank you very much~ :D

Best wish,
Yvonne.
Attachments
code set.png
(10.87 KiB) Not downloaded yet
compare.png
gui set.png
Luciano Garelli
Posts: 283
Joined: Fri Dec 04, 2015 1:42 pm

Re: How should i do to set the boundary conditions by python scripts

Post by Luciano Garelli »

Hello,

The difference between solutions is because you are running two different cases. Please check the definition of the norm of a vector(). When you use the GUI the norm is set to 3 m/s (vx=vy=vz=0.707m/s) and when you use the user define function you are setting a velocity norm of 5.2 m/s (vx=vy=vz=3 m/s).

Regards
Luciano
Yvonne
Posts: 23
Joined: Sat Oct 02, 2021 7:53 am

Re: How should i do to set the boundary conditions by python scripts

Post by Yvonne »

hello
thank you for your help! I can understand the coordinates.
Post Reply