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/)
-   -   Access Flow variables at an arbitrary location using UDF (https://www.cfd-online.com/Forums/fluent-udf/222085-access-flow-variables-arbitrary-location-using-udf.html)

Abhinand November 11, 2019 07:34

Access Flow variables at an arbitrary location using UDF
 
Hello All,

I need to get the flow quantities inside a rectangular 2d (100mmx50mm) domain at a distance of 50mm from inlet.
I have two case files
One without splitting the domain at the location I need and the other with an interior boundary at the location I need so that I get to access a thread ID from Fluent.
However I get this mysterious error from Fluent where I can't get to access the values inside the domain.
I would really appreciate your help. Thanks


Please find attached code:

CODE:

This code is attached to a domain without any explicit interior lines. I search for a location I need inside the domain. The next code has an explicit thread defined,coz I created the case by splitting the domain at the position I need.

I also made sure I added user defined memory locations before I interpreted this udf

DEFINE_ADJUST(adjcell,d)

{

face_t f;

Thread *th, *r_thread;

real FC[2];

int ctr,ctr1,n_faces;

cell_t c;

d = Get_Domain(1);

th = Lookup_Thread(d,3);

c = F_C0(f,th);

ctr=0;

ctr1=0;

r_thread = Lookup_Thread(d,ID_rplane);

n_faces = THREAD_N_ELEMENTS_INT(r_thread);

begin_c_loop(c,th)

{

C_CENTROID(FC,c,th);

if(FC[0]>51.512e-3&&FC[0]<51.516e-3)

{ if(ctr<5)

{

printf("Xcoor %f Ycoor %f\n",FC[0],FC[1]);

*** printf("Uvel is %f\n",C_U(c,th));

*** C_UDMI(c,th,0) = C_U(c,th);

}

ctr++;

}

}

end_c_loop(c,th)

printf("No of faces in outlet %d\n",n_faces);

printf("No of faces in recycle plane is %d\n",ctr);

}

CODE2:

This code is hooked to a case where, I have a BC condition of a line inside the domain (50mm from inlet) set to Interior

DEFINE_ADJUST(adjface,d)

{

face_t f;

Thread *th, *r_thread;

real FC[2];

int ctr,ctr1,n_faces;

cell_t c;

d = Get_Domain(1);

th = Lookup_Thread(d,12);

c = F_C0(f,th);

ctr=0;

ctr1=0;

r_thread = Lookup_Thread(d,15);

n_faces = THREAD_N_ELEMENTS_INT(r_thread);

begin_f_loop(f,th)

{

F_CENTROID(FC,f,th);

if(ctr<5)

{

printf("Xcoor %f Ycoor %f\n",FC[0],FC[1]);

*** printf("Uvel is %f\n",F_U(f,th));

*** printf("Uvel cell is %f\n",C_U(c,th));

}

ctr++;

}

end_f_loop(f,th)

printf("No of faces in outlet %d\n",n_faces);

printf("No of faces in recycle plane is %d\n",ctr);

}

OUTPUT:

1. When I do not include the *** statements

Xcoor 0.051515 Ycoor 0.000002

Xcoor 0.051515 Ycoor 0.000008

Xcoor 0.051515 Ycoor 0.000013

Xcoor 0.051515 Ycoor 0.000018

Xcoor 0.051515 Ycoor 0.000024

No of faces in outlet 140

No of faces in recycle plane is 140

2. When I include the *** statements

================================================== ============================

Node 0: Process 18176: Received signal SIGSEGV.

================================================== ============================

MPI Application rank 0 exited before MPI_Finalize() with status 2

The fluent process could not be started.

Please tell me what is going wrong with this error. I just cant find a way to access the flow variables at a location i need inside the domain.

I can however access the values at the inlet and outlet though.

pakk November 12, 2019 07:05

And what happens if you only include the first *** lines, where you print?

jbo214 November 12, 2019 18:17

Quote:

I need to get the flow quantities inside a rectangular 2d (100mmx50mm) domain at a distance of 50mm from inlet.

Insert a plane and select the 'Bounded Surface' option. You provide Fluent with the (x,y,z) coordinates of three points that define a rectangle. Figure out the coordinates that define your rectangle and you are good to go.


You can then select that surface to do all the normal reporting stuff with. No need for a UDF or to split the domain.

Additionally, you can split the domain and label the face you want with a named selection (ex 'interior-my-face') and use that instead.

Abhinand November 12, 2019 23:02

Quote:

Originally Posted by pakk (Post 749528)
And what happens if you only include the first *** lines, where you print?

Hi.

If I include any of the *** lines in my code
I get the error which I mentioned above. Only if I remove those lines(essentially I'm not able to print the values inside the domain). However I'm able to print the values of Coordinates in that domain. Nothing other than that.

If I change the thread to either of outlet or inlet plane I'm able to print all the variables. It just wouldn't work only for any other region/thread inside the domain.

Please let me know if you have some ideas to circumvent this

Abhinand November 12, 2019 23:03

Quote:

Originally Posted by jbo214 (Post 749594)
Insert a plane and select the 'Bounded Surface' option. You provide Fluent with the (x,y,z) coordinates of three points that define a rectangle. Figure out the coordinates that define your rectangle and you are good to go.


You can then select that surface to do all the normal reporting stuff with. No need for a UDF or to split the domain.

Additionally, you can split the domain and label the face you want with a named selection (ex 'interior-my-face') and use that instead.

Hi.
This is the usual way to just get the values at any location by creating a line/rake.
However I need to do this over and over for Every iteration and do some calculations based on those values and solve the NS eqns accordingly.

pakk November 13, 2019 03:10

Do you do this in a simulation that has already a solution, or a simulation that is not initialized yet? I can understand that you would get this error when you initialize, but you did not mention anything about initializing.

Abhinand November 13, 2019 11:35

I am not using this during initialization. I read a data file and then hook the udf and then start my calculations again

pakk November 13, 2019 15:37

I just noticed that you talk about 'interpreting'. Don't do that. Compile it.

(Even if it does not solve your current problem, it will help you in the future.)

Otherwise, I have no idea.


All times are GMT -4. The time now is 03:14.