CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

CX_Find_Cell_With_Point: problem

Register Blogs Community New Posts Updated Threads Search

Like Tree10Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 12, 2010, 18:11
Default CX_Find_Cell_With_Point: problem
  #1
Member
 
Francesco Capuano
Join Date: May 2010
Posts: 81
Rep Power: 16
francesco_capuano is on a distinguished road
Hi everyone,
I've got a problem with the function CX_Find_Cell_With_Point, which I've found right in this forum (it is not mentioned in the UDF manual): you give it the coordinates of the point, it gives you back the cell index in which the point is. The example given by the user Gearboy was:

#include "udf.h"
DEFINE_ON_DEMAND(find_cell)
{
cell_t c;
Thread *t;
CX_Cell_Id cx_cell;
real NV_VEC(pt);
real c_centroid[ND_ND];
NV_D(pt, =, 0.5, 0.3, 0.2); //coordinate of your specified location,it must be in the domain coordinate range
CX_Start_ND_Point_Search();
cx_cell=*CX_Find_Cell_With_Point(pt);
CX_End_ND_Point_Search();
c=RP_CELL(&cx_cell); //the right cell number
t = RP_THREAD(&cx_cell); // the thread
C_CENTROID(c_centroid,c,t);
Message0("coordinate of the specified point: x=%g,y=%g,z=%g\n",pt[0],pt[1],pt[2]);
Message0("coordinate of the cell found: x=%g,y=%g,z=%g\n",c_centroid[0],c_centroid[1],c_centroid[2]);
}

The problem is: if I use this function for a single point, or for a loop of points in a flat-plate mesh, it works perfectly; if I use this function inside a loop of points for any other case, even very simple (like an airfoil), Fluent simply goes off after a while (during the elaboration), despite all the points in the loop are in the domain coordinate range and, apparently, there are no other problems with the case and the rest of the function. It seems like a memory limit is reached, or something like that. I'm quite new to Fluent and UDFs world, so I really don't know what to do, I really appreciate any suggestion.
Thanks in advance!
wc34071209 likes this.
francesco_capuano is offline   Reply With Quote

Old   May 13, 2010, 15:36
Default
  #2
Member
 
Francesco Capuano
Join Date: May 2010
Posts: 81
Rep Power: 16
francesco_capuano is on a distinguished road
I precise that after some seconds of elaboration Fluent gives ACCESS VIOLATION error... help me please!
francesco_capuano is offline   Reply With Quote

Old   May 15, 2010, 09:28
Default
  #3
New Member
 
Join Date: Nov 2009
Posts: 8
Rep Power: 17
psc3 is on a distinguished road
try to replace real NV_VEC(pt);

with

float NV_VEC(pt);

I had a problem with this UDF and that change solved it...

Pedro
mm.abdollahzadeh likes this.

Last edited by psc3; May 15, 2010 at 14:39.
psc3 is offline   Reply With Quote

Old   May 16, 2010, 16:51
Default
  #4
Member
 
Francesco Capuano
Join Date: May 2010
Posts: 81
Rep Power: 16
francesco_capuano is on a distinguished road
Thank you Pedro for your suggestion, that's a good idea, but it doesn't work for my case.
Anyway, I've fixed the bug: I realized that the problem for the function was to analyze the points belonging to the boundary face (probably it is unable to judge whether they belong to the computational domain or not), so excluding that points from the loop the UDF works fine.
francesco_capuano is offline   Reply With Quote

Old   May 17, 2010, 08:30
Default
  #5
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Are you sure it works ok?
This instruction:
Code:
cx_cell=*CX_Find_Cell_With_Point(pt);
doesn't look right. It should give you a syntax error. At first glance I would write it as:
Code:
cx_cell = CX_Find_Cell_With_Point(pt);
dmoroian is offline   Reply With Quote

Old   May 17, 2010, 10:55
Default
  #6
Member
 
Francesco Capuano
Join Date: May 2010
Posts: 81
Rep Power: 16
francesco_capuano is on a distinguished road
Thanks for helping, dmoroian, but the function CX_Find_Cell_With_Point(pt) requires the asterisk. As I said, the problem does not regard the syntax, but the point you ask the function to analyze. It seems not to work fine for the boundary points...
francesco_capuano is offline   Reply With Quote

Old   August 26, 2013, 16:08
Default
  #7
New Member
 
Join Date: Aug 2013
Posts: 3
Rep Power: 13
deluge is on a distinguished road
Hi,

This line
Code:
cx_cell = CX_Find_Cell_With_Point(pt);
or this one, it doesn't matter which one
Code:
cx_cell=*CX_Find_Cell_With_Point(pt);
always gives me the error:
error C2440: '=' : cannot convert from 'int' to 'CX_Cell_Id'
Does anybody know how to avoid it?
deluge is offline   Reply With Quote

Old   August 27, 2013, 02:17
Default
  #8
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
You do not provide the full warning/error message, do you? It could be misleading. There should be some warning messages tell 'implicit declaration of function CX_Find_Cell_With_Point'. Please include the right header file,
Code:
#include "cxiface.h"
for fluent version 6.x

The interface for this function changed in version 14 so I do not discuss the header file in this version because the above code does not work any way.
blackmask is offline   Reply With Quote

Old   August 27, 2013, 04:37
Default
  #9
New Member
 
Join Date: Aug 2013
Posts: 3
Rep Power: 13
deluge is on a distinguished road
Thank you blackmask,

I'm using the latest version, that's 14.5.7. There is no more cxiface.h and a grep search revealed there is no more CX_Find_Cell_With_Point either.

Has anybody an idea how the corresponding commands are called in 14.x.x?
deluge is offline   Reply With Quote

Old   August 27, 2013, 06:11
Default
  #10
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Yes it is in
Code:
fluent/fluent14.5.7/cortex/src/cxndsearch.h
dmoroian is offline   Reply With Quote

Old   August 28, 2013, 05:21
Default
  #11
New Member
 
Join Date: Aug 2013
Posts: 3
Rep Power: 13
deluge is on a distinguished road
Thanks a lot for that!

But the syntax seems to be a bit more complex than before.

Code:
FLUENT_EXPORT ND_Search *CX_Start_ND_Point_Search(ND_Search *, cxboolean do_domain, int t_id);
FLUENT_EXPORT CX_Cell_Id *CX_Find_Cell_With_Point(ND_Search *, double v[3], double time);
FLUENT_EXPORT ND_Search *CX_End_ND_Point_Search(ND_Search *);
The functions require more inputs.
Code:
CX_Start_ND_Point_Search();
cx_cell=*CX_Find_Cell_With_Point(pt);
CX_End_ND_Point_Search()
doesn't work because of a lack of inputs. Does anybody have an example for that? I find these input datatypes very confusing.
mm.abdollahzadeh likes this.
deluge is offline   Reply With Quote

Old   April 5, 2014, 22:35
Default
  #12
New Member
 
Jason
Join Date: Jul 2013
Posts: 1
Rep Power: 0
KingSt is on a distinguished road
Quote:
Originally Posted by deluge View Post
Thanks a lot for that!

But the syntax seems to be a bit more complex than before.

Code:
FLUENT_EXPORT ND_Search *CX_Start_ND_Point_Search(ND_Search *, cxboolean do_domain, int t_id);
FLUENT_EXPORT CX_Cell_Id *CX_Find_Cell_With_Point(ND_Search *, double v[3], double time);
FLUENT_EXPORT ND_Search *CX_End_ND_Point_Search(ND_Search *);
The functions require more inputs.
Code:
CX_Start_ND_Point_Search();
cx_cell=*CX_Find_Cell_With_Point(pt);
CX_End_ND_Point_Search()
doesn't work because of a lack of inputs. Does anybody have an example for that? I find these input datatypes very confusing.
Hi deluge,

Did you figure out this problem??? I am suffering the exactly same problem as yours. Could you guys give any suggestion? Appreciate!
KingSt is offline   Reply With Quote

Old   June 24, 2014, 14:14
Default
  #13
New Member
 
Garvit Goel
Join Date: May 2014
Posts: 11
Rep Power: 12
garvitgoel is on a distinguished road
Quote:
Originally Posted by deluge View Post
Thanks a lot for that!

But the syntax seems to be a bit more complex than before.

Code:
FLUENT_EXPORT ND_Search *CX_Start_ND_Point_Search(ND_Search *, cxboolean do_domain, int t_id);
FLUENT_EXPORT CX_Cell_Id *CX_Find_Cell_With_Point(ND_Search *, double v[3], double time);
FLUENT_EXPORT ND_Search *CX_End_ND_Point_Search(ND_Search *);
The functions require more inputs.
Code:
CX_Start_ND_Point_Search();
cx_cell=*CX_Find_Cell_With_Point(pt);
CX_End_ND_Point_Search()
doesn't work because of a lack of inputs. Does anybody have an example for that? I find these input datatypes very confusing.
can somebody please explain how to use these search functions.
I cant under stand what t_id and v[3] and time are.
garvitgoel is offline   Reply With Quote

Old   January 18, 2016, 04:57
Default
  #14
Member
 
Maria
Join Date: Jul 2013
Posts: 84
Rep Power: 13
marialhm is on a distinguished road
Quote:
Originally Posted by garvitgoel View Post
can somebody please explain how to use these search functions.
I cant under stand what t_id and v[3] and time are.
Dear Garvit,

Have you figured it out? I need to use it now, but I have no idea what those mean.

Thanks.
marialhm is offline   Reply With Quote

Old   January 18, 2016, 05:01
Default
  #15
Member
 
Maria
Join Date: Jul 2013
Posts: 84
Rep Power: 13
marialhm is on a distinguished road
Quote:
Originally Posted by KingSt View Post
Hi deluge,

Did you figure out this problem??? I am suffering the exactly same problem as yours. Could you guys give any suggestion? Appreciate!

Has anybody figured this out??? Please help!
marialhm is offline   Reply With Quote

Old   July 19, 2016, 04:09
Default Solution for v. 17.1
  #16
New Member
 
Anders Simonsen
Join Date: Sep 2013
Posts: 18
Rep Power: 13
ASimonsen is on a distinguished road
Hi

I tool a look at it and figured out how to do it. Ansys has posted a note on their website (required user access):
Macro CX_Find_Cell_With_Point form has
changed from R11 to R14.5/R15.
Problem/Description:
Macro CX_Find_Cell_With_Point form has changed from R11 to R14.5/R15.
Solution:
Please use the following header files and format for new releases
Code:
#include <udf.h>
#include "cxndsearch.h"
static ND_Search *domain_table=NULL;
DEFINE_ON_DEMAND(locate_cell)
{
CX_Cell_Id *cx_cell;
real tmpp[ND_ND];
.
.
.
domain_table = CX_Start_ND_Point_Search( domain_table,TRUE,-1);
cx_cell = CX_Find_Cell_With_Point(domain_table,tmpp,0.0);
domain_table=CX_End_ND_Point_Search(domain_table);
.
.
/* Can save domain table as a static pointer so that you can check if it's
been created yet and not recreate it every time. */
.}
After messing around with it I found a way to locate the cell:

Code:
#include <udf.h>
#include "cxndsearch.h"

static ND_Search *domain_table = NULL;

DEFINE_ON_DEMAND(locate_cell)
{
	cell_t c;
	Thread *t;
	CX_Cell_Id *cx_cell;
	
	real P[3];
	real P_Cell[3];
	
	domain_table = CX_Start_ND_Point_Search(domain_table,TRUE,-1);
	for (int i = 0; i < 100; i++) {
		P[0] = 0.0;
		P[1] = 0.0;
		P[2] = (real)i / 100.0 * 5.0;
		
		cx_cell = CX_Find_Cell_With_Point(domain_table,P,0.0);
		if (cx_cell) {
			c = RP_CELL(cx_cell);
			t = RP_THREAD(cx_cell);
			C_CENTROID(P_Cell,c,t);
			Message("Found cell at [%g,%g,%g] with centroid [%g,%g,%g].\n",P[0],P[1],P[2],P_Cell[0],P_Cell[1],P_Cell[2]);
		} else {
			Message("Could not find cell at [%g,%g,%g]!\n",P[0],P[1],P[2]);
		}
	}
	domain_table = CX_End_ND_Point_Search(domain_table);
}
ASimonsen is offline   Reply With Quote

Old   October 19, 2016, 02:15
Default
  #17
New Member
 
Join Date: Jun 2013
Posts: 18
Rep Power: 13
wond is on a distinguished road
so good job!!
wond is offline   Reply With Quote

Old   December 25, 2016, 22:24
Question Problems running in PARALLEL
  #18
New Member
 
You
Join Date: Dec 2016
Posts: 3
Rep Power: 10
youjfwhu is on a distinguished road
Quote:
Originally Posted by ASimonsen View Post
Hi

I tool a look at it and figured out how to do it. Ansys has posted a note on their website (required user access):
Macro CX_Find_Cell_With_Point form has
changed from R11 to R14.5/R15.
Problem/Description:
Macro CX_Find_Cell_With_Point form has changed from R11 to R14.5/R15.
Solution:
Please use the following header files and format for new releases
Code:
#include <udf.h>
#include "cxndsearch.h"
static ND_Search *domain_table=NULL;
DEFINE_ON_DEMAND(locate_cell)
{
CX_Cell_Id *cx_cell;
real tmpp[ND_ND];
.
.
.
domain_table = CX_Start_ND_Point_Search( domain_table,TRUE,-1);
cx_cell = CX_Find_Cell_With_Point(domain_table,tmpp,0.0);
domain_table=CX_End_ND_Point_Search(domain_table);
.
.
/* Can save domain table as a static pointer so that you can check if it's
been created yet and not recreate it every time. */
.}
After messing around with it I found a way to locate the cell:

Code:
#include <udf.h>
#include "cxndsearch.h"

static ND_Search *domain_table = NULL;

DEFINE_ON_DEMAND(locate_cell)
{
    cell_t c;
    Thread *t;
    CX_Cell_Id *cx_cell;
    
    real P[3];
    real P_Cell[3];
    
    domain_table = CX_Start_ND_Point_Search(domain_table,TRUE,-1);
    for (int i = 0; i < 100; i++) {
        P[0] = 0.0;
        P[1] = 0.0;
        P[2] = (real)i / 100.0 * 5.0;
        
        cx_cell = CX_Find_Cell_With_Point(domain_table,P,0.0);
        if (cx_cell) {
            c = RP_CELL(cx_cell);
            t = RP_THREAD(cx_cell);
            C_CENTROID(P_Cell,c,t);
            Message("Found cell at [%g,%g,%g] with centroid [%g,%g,%g].\n",P[0],P[1],P[2],P_Cell[0],P_Cell[1],P_Cell[2]);
        } else {
            Message("Could not find cell at [%g,%g,%g]!\n",P[0],P[1],P[2]);
        }
    }
    domain_table = CX_End_ND_Point_Search(domain_table);
}
It's a good job and thank for your sharing.

But I've got a problem in parallel running. When I use this UDF in parallel processing, it returns me the error notice like this:

0 (..\src\mpsystem.c@1173): mpt_read: failed: errno = 10054
MPI Application rank 0 exited before MPI_Finalize() with status -1

0: mpt_read: error: read failed trying to read 4 bytes: No such file or directory
The Parallel FLUENT process could not be started.

My benchmark is a 2D rotor problem, a rectangular water channel with a cross blender in it. I used the "Mesh motion" for the rotating zone surrounding the blender and the "interface" boundary condition. What I want to do is MONITORING THE PRESSURE ON A DYNAMIC POINT. This point is initially located in the rotating zone and it will rotate with the zone
synchronously.

Now I have tried many methods, such as the different MPI methods and I have check the RAM and I have made sure the firewall is closed ......by the way, my workstation can run other udfs using the parallel processing, this UDF is the only one that cannot be used in parallel running.

At last I found that the problem result form the macro "RP_CELL" and "RP_THREAD", when I made these two codes as notes , it can run well in parallel.

So please help me .Please.Please. My e_mail is :youjf@whu.edu.cn

My udf is here:

************************************************** ******
#include "udf.h"
#include "surf.h"
#include"cxndsearch.h"
static ND_Search *domain_table=NULL;
real R=0.05;
static float xTheory=0.20535;/*The initial x coordiate of the dynamic monitoring point*/
static float yTheory=0.13535;/*The initial y coordiate */
static float theta=0.785398;/*The initial phase angle */
static float p01=0.0;/*The initial pressure */
static float tim=0.0;
float c_centroid[2];

DEFINE_EXECUTE_AT_END(execute)
{

#if !RP_NODE
FILE *fp_p01;
#endif

double pt[2];
cell_t c;
Thread *t;
CX_Cell_Id *cx_cell;

#if !RP_NODE
tim=RP_Get_Real("flow-time");
theta=theta+0.001*10;/*The angular velocity is 10 rad/s and the timestep is 0.001s */
xTheory=0.17+R*cos(theta);
yTheory=0.1+R*sin(theta);
pt[0]=xTheory;
pt[1]=yTheory;

domain_table = CX_Start_ND_Point_Search(domain_table,TRUE,-1);
cx_cell=CX_Find_Cell_With_Point(domain_table,pt,0. 0);
c=RP_CELL(cx_cell);/*The error should RESULT FROM this macro */
t=RP_THREAD(cx_cell);/*The error should RESULT FROM this macro */
C_CENTROID(c_centroid,c,t);
p01=C_P(c,t);
domain_table = CX_End_ND_Point_Search(domain_table);
#endif

#if !RP_NODE
fp_p01=fopen("p01.txt","a+");
fprintf(fp_p01,"%15.4f\t%d\t%d\t%d\t%15.6f\t%15.6f \t%15.6f\t%15.6f\t%15.6f\t%15.6f\t\n",tim,cx_cell, c,t,theta,xTheory,yTheory,c_centroid[0],c_centroid[1],p01);
fclose(fp_p01);
#endif
}

youjfwhu is offline   Reply With Quote

Old   December 26, 2016, 05:42
Default
  #19
New Member
 
Anders Simonsen
Join Date: Sep 2013
Posts: 18
Rep Power: 13
ASimonsen is on a distinguished road
Hi youjfwhu

I haven't tried anything in Fluent, but I'm pretty sure the problem is that you're using (#if !RP_NODE) instead of (#if !RP_HOST). Remember that when you're running Fluent in parallel, the cells are located on the computer nodes. The host is only there to do some communication stuff etc. So when you're trying to locate cells using CX_Find_Cell_With_Point in a section of your code, which is only running on the host (!RP_NODE), you'll get an error.

I've used my own piece of code on a parallel process as well, where it works just fine. But in my code, the CX_Find_Cell_With_Point is located within a (!RP_HOST)-section.
ASimonsen is offline   Reply With Quote

Old   December 26, 2016, 10:47
Question Problem still exists
  #20
New Member
 
You
Join Date: Dec 2016
Posts: 3
Rep Power: 10
youjfwhu is on a distinguished road
Quote:
Originally Posted by ASimonsen View Post
Hi youjfwhu

I haven't tried anything in Fluent, but I'm pretty sure the problem is that you're using (#if !RP_NODE) instead of (#if !RP_HOST). Remember that when you're running Fluent in parallel, the cells are located on the computer nodes. The host is only there to do some communication stuff etc. So when you're trying to locate cells using CX_Find_Cell_With_Point in a section of your code, which is only running on the host (!RP_NODE), you'll get an error.

I've used my own piece of code on a parallel process as well, where it works just fine. But in my code, the CX_Find_Cell_With_Point is located within a (!RP_HOST)-section.
Thank you for your advice and I've changed (RP_NODE) into (RP_HOST),but the new problem is that it can ONLY RUN ONE TIMESTEP and the same error notice appears on the window.

MPI Application rank 0 exited before MPI_Finalize() with status -1073741819

999999 (..\src\mpsystem.c@1173): mpt_read: failed: errno = 10054

999999: mpt_read: error: read failed trying to read 4 bytes: Invalid argument
The Parallel FLUENT process could not be started.

Actually I think your suggestion is very important and useful. The first timestep is finished and the whole udf is processed(since the last 3 sentences of the udf is about printing some messages on a *.txt file and the results shows that it is correct).

I paste my new udf here, could you please help me again? Thank you so much.

**************************************************
#include "udf.h"
#include"cxndsearch.h"
static ND_Search *domain_table;
real R=0.05;
static float xTheory=0.20535;
static float yTheory=0.13535;
static float theta=0.785398;
static float p01=0.0;
static float tim=0.0;
static float c_centroid[2];
static cell_t c;
static Thread *t;
static CX_Cell_Id *cx_cell;
static double pt[2];

DEFINE_EXECUTE_AT_END(execute)
{
#if !RP_HOST
FILE *fp_p01;
#endif

#if !RP_HOST
tim=RP_Get_Real("flow-time");
#endif

#if !RP_HOST
theta=theta+0.001*10;
xTheory=0.17+R*cos(theta);
yTheory=0.1+R*sin(theta);
pt[0]=xTheory;
pt[1]=yTheory;
#endif

#if !RP_HOST
domain_table = CX_Start_ND_Point_Search(domain_table,TRUE,-1);
cx_cell=CX_Find_Cell_With_Point(domain_table,pt,0. 0);
c=RP_CELL(cx_cell);
t=RP_THREAD(cx_cell);
C_CENTROID(c_centroid,c,t);
p01=C_P(c,t);
domain_table = CX_End_ND_Point_Search(domain_table);
#endif

#if !RP_HOST
fp_p01=fopen("p01.txt","a+");
fprintf(fp_p01,"%15.4f\t%15.6f\t%15.6f\t%15.6f\t%1 5.6f\t%15.6f\t%15.6f\t\n",tim,theta,xTheory,yTheor y,c_centroid[0],c_centroid[1],p01);
fclose(fp_p01);
#endif
}
youjfwhu is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF compiling problem Wouter Fluent UDF and Scheme Programming 6 June 6, 2012 05:43
Incoherent problem table in hollow-fiber spinning Gianni FLUENT 0 April 5, 2008 11:33
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 07:29
Adiabatic and Rotating wall (Convection problem) ParodDav CFX 5 April 29, 2007 20:13
Is this problem well posed? Thomas P. Abraham Main CFD Forum 5 September 8, 1999 15:52


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