CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   Couple CFX with in-house code via user Fortran (https://www.cfd-online.com/Forums/cfx/228907-couple-cfx-house-code-via-user-fortran.html)

hcs129 July 19, 2020 11:53

Couple CFX with in-house code via user Fortran
 
Dear all,
Recently, I am trying to couple CFX with my code and what I need is the velocity field.
So my question is how to obtain the velocity field, i.e., the cell coordinates and the corresponding velocity.
Alternatively, it would be a better way if I can obatin the fluid velocity at any user specified position.
I have read the guide book for CFX modeling, but still have no idea.
Any one can help?

Stel July 19, 2020 13:09

Could you provide us more details? Do you want the velocity field cell by cell during the solution or just the final results? What do you need that cant be done directly in cfd post?

hcs129 July 19, 2020 18:03

Quote:

Originally Posted by Stel (Post 778170)
Could you provide us more details? Do you want the velocity field cell by cell during the solution or just the final results? What do you need that cant be done directly in cfd post?

Hi, Stel. I want the transient velocity field during the solution. My in-house code is used for particle simulation and the fluid velocity field is needed to calculate the momentum and energy source terms for both fluid and solid phases.

ghorrocks July 19, 2020 19:03

You will probably need to do this with user fortran.

Stel July 20, 2020 07:24

So far I've only worked with user fortran for particle tracking in Ansys, but I assume it is the same logic for any user fortran routine: when you call an external function for particle tracking via user fortran, new options become available in CFX Pre. One of them is the variable list you have to provide as arguments for the user fortran Routine, such as velocity, pressure, etc. At the beginning of your routine, you define and call those arguments. By default, any calculation you do with those variables within your routine will be performed cell by cell throughout your domain. Then, the output from your routine returns to the calculation both as a global value or a field variable, depending on how you define it.

You will have to read the user fortran documentation and search for some examples there or here in the forum to get used to the syntax, library generation, etc, but I guess this is the way to go.

ghorrocks July 20, 2020 07:38

I am no expert in CFX User Fortran, but I know there is more to fortran in CFX than that. Somebody please correct me I am wrong, but you have two main approaches (described in the CFX Solver Modelling Guide, Chapter 19):
* User defined CEL
* Junction Box routines

User defined CEL are similar to normal CEL functions but user fortran to calculate it rather than the CFX interpreter. This is what Stel describes. These are quite simple to use and can be done with only a moderate amount of CFX fortran knowledge.

But there are also Junction Box routines. These give lower level at different points in the solution process. This allows much more complex models to be implemented such as interaction with other software, but require a detailed knowledge of CFX fortran and memory structures (MMS) to get to work. It is not for the weak hearted. From what Cs Hu describes I think he will need Junction Box routines for his model.

I did a CFX user fortran course run by ANSYS years ago and recall it was quite complex. (Unfortunately I have not used it much since so have forgotten most of it.) If the course still exists it would be a big help for you.

Stel July 20, 2020 07:55

Quote:

Originally Posted by ghorrocks (Post 778236)
I am no expert in CFX User Fortran, but I know there is more to fortran in CFX than that. Somebody please correct me I am wrong, but you have two main approaches (described in the CFX Solver Modelling Guide, Chapter 19):
* User defined CEL
* Junction Box routines

User defined CEL are similar to normal CEL functions but user fortran to calculate it rather than the CFX interpreter. This is what Stel describes. These are quite simple to use and can be done with only a moderate amount of CFX fortran knowledge.

But there are also Junction Box routines. These give lower level at different points in the solution process. This allows much more complex models to be implemented such as interaction with other software, but require a detailed knowledge of CFX fortran and memory structures (MMS) to get to work. It is not for the weak hearted. From what Cs Hu describes I think he will need Junction Box routines for his model.

I did a CFX user fortran course run by ANSYS years ago and recall it was quite complex. (Unfortunately I have not used it much since so have forgotten most of it.) If the course still exists it would be a big help for you.

So basically his fortan code is the main program and he makes use of CFX as a parallel solver to provide data for his fortran routine, is that right?

Well, Glenn is right, fortran routines for particle tracking for example are kind of straightforward programs you run just to generate a library to be used in CFX to perform other calculations.

Well, if putting two codes to work in parallel via user fortran is what he wants then I believe he will indeed need some fancier user fortran programming to do so. To be honest with you I didn't even know this was possible in the first place.

hcs129 July 20, 2020 09:40

Quote:

Originally Posted by Stel (Post 778239)
So basically his fortan code is the main program and he makes use of CFX as a parallel solver to provide data for his fortran routine, is that right?

Well, Glenn is right, fortran routines for particle tracking for example are kind of straightforward programs you run just to generate a library to be used in CFX to perform other calculations.

Well, if putting two codes to work in parallel via user fortran is what he wants then I believe he will indeed need some fancier user fortran programming to do so. To be honest with you I didn't even know this was possible in the first place.

So far I have finished the first step, that is, to share data between my program and CFX dynamicly. However, it is challenge to obtain the fluid velocity field.

hcs129 July 20, 2020 09:41

Quote:

Originally Posted by ghorrocks (Post 778236)
I am no expert in CFX User Fortran, but I know there is more to fortran in CFX than that. Somebody please correct me I am wrong, but you have two main approaches (described in the CFX Solver Modelling Guide, Chapter 19):
* User defined CEL
* Junction Box routines

User defined CEL are similar to normal CEL functions but user fortran to calculate it rather than the CFX interpreter. This is what Stel describes. These are quite simple to use and can be done with only a moderate amount of CFX fortran knowledge.

But there are also Junction Box routines. These give lower level at different points in the solution process. This allows much more complex models to be implemented such as interaction with other software, but require a detailed knowledge of CFX fortran and memory structures (MMS) to get to work. It is not for the weak hearted. From what Cs Hu describes I think he will need Junction Box routines for his model.

I did a CFX user fortran course run by ANSYS years ago and recall it was quite complex. (Unfortunately I have not used it much since so have forgotten most of it.) If the course still exists it would be a big help for you.

Glenn, do you remember the name of the course? Thanks.

Opaque July 20, 2020 12:02

Quote:

Originally Posted by hcs129 (Post 778254)
So far I have finished the first step, that is, to share data between my program and CFX dynamicly. However, it is challenge to obtain the fluid velocity field.

Could we ask what is the challenging part?

Have you selected the location in the algorithm where to gather the information?

Do you know the variable name you are trying to gather?

Do you know where the variable is located in the memory system?

ghorrocks July 20, 2020 18:36

Quote:

Glenn, do you remember the name of the course? Thanks.
I have searched the ANSYS webpage and I cannot see any CFX Fortran courses. Only Fluent UDF courses. Also I can't find my course notes :(

hcs129 August 20, 2020 09:16

Quote:

Originally Posted by Opaque (Post 778271)
Could we ask what is the challenging part?

Have you selected the location in the algorithm where to gather the information?

Do you know the variable name you are trying to gather?

Do you know where the variable is located in the memory system?

Opaque, I've managed to obtain velocity field, i.e., the velocity components along with its coordinates. I used the getvar subroutine in the junction box routine.
My challenging part now is to quickly find the neighboring vertices for any specified position. For example, there're three points ((0,0,0),(1,1,1),(2,2,2)) and how to find their nearest neighboring vertices (or elements).
I tried the subroutine CAL_MESHMAP but it works only when the points overlap with mesh vertices.
Do you have any suggestion?


All times are GMT -4. The time now is 23:51.