CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   Scripting CFX5 (https://www.cfd-online.com/Forums/cfx/198972-scripting-cfx5.html)

mmoelle1 February 21, 2018 12:59

Scripting CFX5
 
Dear all,

We are working on an automatized simulation loop that involves CFX5 for the fluid part and a self-written code for the solid part. In essence, we have a fully configured case (from CFX5-pre) that we want to modify by a script. The modifications are as follows: delete the existing mesh and import another mesh that makes use of a self-written user input executable. The outcome of these actions should be saved to a new case file which is then run by the solver. The imported mesh has the same regions, so no problem with boundary conditions should occur.

I have read a lot about CCL but I miss a simple example that demonstrates how to load a case, delete the mesh, and import a new mesh. Or would you suggest another way of scripting CFX5-pre other than CCL? Any help is appreciated.

Kind regards,
Matthias

ghorrocks February 21, 2018 17:14

There are many ways of doing this:
* Use a script to drive CFX-Pre to load the mesh, solve it output the results and update your code for the mesh on the next loop. This is fairly easy to do but will be very slow as it needs to run CFX-Pre and restart simulations many times.
* You can use the user defined mesh option for remeshing in a multiple configuration run. This will be more efficient.
* You can use user fortran to write a new mesh during run time. There used to be an example of this in the CFX tutorials but it got removed many years ago. I suspect CFX support still has access to it. This will be the most efficient way of doing it, but will require some fortran coding and will be trickier to set up.

mmoelle1 February 21, 2018 17:22

Thanks very much for the quick reply.

Do you mean the ImportTemplate.c (and ExportTemplate.c) codes in <CFXROOT>/examples? Based on that, I have written a C++ program that reads in the data from my own simulation programme and "updates" the mesh. To be correct here, it does not write this data to a mesh file but it imports the mesh into CFX5-pre using the cfxImportXYZ functions. Do you know a better way to directly write a mesh file or, even better, to write a "res" file which would contain the solution from the old mesh projected to the new one? The topology of my meshes does not change only the position of vertices changes slightly.

BTW, I can also switch to Fortran if that simplifies the task.

ghorrocks February 21, 2018 18:18

No, ImportTemplate.c and ExportTemplate.c are for getting meshes into CFX-Pre. There used to be a user fortran example for getting meshes straight into the solver during run time so you could do mesh motion stuff with user defined mesh motion. I have looked at the V19 fortran examples and I can't see it, so I suspect you will need to contact ANSYS support if you want to get it.

As a general comment: in CFX, c++ stuff is only used to get user meshes in and out of CFX-Pre. Fortran stuff is used to add user functions to the solver during a simulation and changing the mesh is one thing you can do here. They are not interchangeable, they act on totally different parts of the CFX workflow. If you want a user function in the solver fortran is your only option (assuming it cannot be done in CEL and CCL).

mmoelle1 February 22, 2018 02:27

Thanks once more. I will contact the ANSYS support for the deleted Fortran examples you mentioned.

In the meantime, do you have (or can point me to) a simple scripting example that shows how to (1) start CFX-pre, (2) load a case, (3) delete the existing mesh, (4) import another mesh from file, and (5) write the updated case to a file all from the command line, i.e. without user-interaction and GUI starting up?

Concerning your final remark
Quote:

If you want a user function in the solver fortran is your only option (assuming it cannot be done in CEL and CCL).
The only modifications of the mesh between several solver runs are the location of the mesh points (the mesh topology does not change). Is this something that could be done via CEL and/or CCL? If so, I would be very happy if you could also point me to an example.

Thanking you very much in advance.

ghorrocks February 22, 2018 04:46

CFX-Pre scripting: Start a session file, record it, and then do the operations you mention. Have a look at the session file and there is your example.

User function: The fortran example used to get called every few time steps to update the mesh. The mesh had the same mesh topology, just the nodal locations moved. This is the user fortran example I mentioned used to be there but got removed several versions of CFX ago.

If you can define a CEL expression which describes your mesh then you can use it. But the expression is almost certainly going to have to call a user fortran function as CEL is a bit limited for complex functions like this.

Opaque February 22, 2018 12:16

While recording your session (as Glenn suggested), try using the "Reload Mesh" option. Once you see how the command is stored in the session file, you will learn how is used.

Then, you only need to create a new mesh with the same file name as the previous mesh, i.e. update its contents, execute the CFX-Pre script with the "Reload" command, write definition file, and you should be set.

mmoelle1 February 25, 2018 10:02

Thanks! Recording the session and extracting the relevant parts worked for me.

I have a (hopefully) final question about mesh/file formats. I received two files from a co-worker (case.def and mesh.cfx5). The DEF-file defines the complete case and uses mesh.cfx5 as the mesh file. The CFX5-file is a binary file. I have read that it is an ICEMCFD mesh but the version of ICEMCFD I am using is not able to open it nor to import it as a mesh. I need to rename a 2D region and create another one in that particular file.

Any help is appreciated.

ghorrocks February 25, 2018 17:15

The def file is a full definition for a simulation, it contains the mesh as well. You do not need another file for the mesh. So open the def file in ICEM and you will be able to edit the mesh.

Mohammadfba April 8, 2021 02:41

Hi
I want to use remeshing in cfx but I do n't know how to write a script for remeshing. How can I do that?
Best regards


All times are GMT -4. The time now is 15:00.