CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   writing a udf for a specific body force (https://www.cfd-online.com/Forums/fluent-udf/142864-writing-udf-specific-body-force.html)

rima_se2003 October 10, 2014 20:01

writing a udf for a specific body force
 
hi
i managed to solve a problem with matlab and now i have a matrix which consists of magnitude of a force which is applied to the particles in all of the domain. in this matrix i component is equivalent to x position and j component is equivalent to y position. now if want to write a udf to take this force file and apply it to particles as a body force. could anyone help me how to write this udf ? should i use define_dpm_body_ force or another macro? how could i read this matrix file? thanks

pakk October 13, 2014 10:04

Basic steps for your udf file:

1. Define a global array to contain your force. If you have a two-dimensional problem, and the matrix that you calculated is 400x600, your global array should be 400x600x2 (x2 because you need two components of the force).
2. Write a DEFINE_ON_DEMAND macro to read the contents of your data file into the global array.
3. Write a DEFINE_DPM_BODY_FORCE macro. This macro should:
A. Find the location of the particle using P_POS(p).
B. Calculate from the position which entry of your matrix should be used.
C. Get the corresponding force from the global array.
D. Assign the force to the particle.

When you do the real calculation, you should first execute the DEFINE_ON_DEMAND macro, before you do the dpm calculations. In this way, the data file will only be read once, which will speed up your calculations a lot.

Good luck!

rima_se2003 October 15, 2014 01:13

Quote:

Originally Posted by pakk (Post 514107)
Basic steps for your udf file:

1. Define a global array to contain your force. If you have a two-dimensional problem, and the matrix that you calculated is 400x600, your global array should be 400x600x2 (x2 because you need two components of the force).
2. Write a DEFINE_ON_DEMAND macro to read the contents of your data file into the global array.
3. Write a DEFINE_DPM_BODY_FORCE macro. This macro should:
A. Find the location of the particle using P_POS(p).
B. Calculate from the position which entry of your matrix should be used.
C. Get the corresponding force from the global array.
D. Assign the force to the particle.

When you do the real calculation, you should first execute the DEFINE_ON_DEMAND macro, before you do the dpm calculations. In this way, the data file will only be read once, which will speed up your calculations a lot.

Good luck!

thank you very much pakk for your very useful guidance. how could i read a global array file with the define_on_demand macro? is there exists any prepared code to use?

pakk October 15, 2014 02:37

That is standard programming with arrays in c. There are many websites that explain it better than I can, just google for "arrays in c".


All times are GMT -4. The time now is 06:29.