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/)
-   -   CX_Find_Cell_With_Point: problem (https://www.cfd-online.com/Forums/fluent-udf/76058-cx_find_cell_with_point-problem.html)

francesco_capuano May 12, 2010 17:11

CX_Find_Cell_With_Point: problem
 
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!

francesco_capuano May 13, 2010 14:36

I precise that after some seconds of elaboration Fluent gives ACCESS VIOLATION error... help me please!

psc3 May 15, 2010 08:28

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

francesco_capuano May 16, 2010 15:51

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.

dmoroian May 17, 2010 07:30

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);

francesco_capuano May 17, 2010 09:55

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...

deluge August 26, 2013 15:08

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?

blackmask August 27, 2013 01:17

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.

deluge August 27, 2013 03:37

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?

dmoroian August 27, 2013 05:11

Yes it is in
Code:

fluent/fluent14.5.7/cortex/src/cxndsearch.h

deluge August 28, 2013 04:21

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.

KingSt April 5, 2014 21:35

Quote:

Originally Posted by deluge (Post 448467)
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!

garvitgoel June 24, 2014 13:14

Quote:

Originally Posted by deluge (Post 448467)
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.

marialhm January 18, 2016 04:57

Quote:

Originally Posted by garvitgoel (Post 498480)
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 January 18, 2016 05:01

Quote:

Originally Posted by KingSt (Post 484093)
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!

ASimonsen July 19, 2016 03:09

Solution for v. 17.1
 
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);
}


wond October 19, 2016 01:15

so good job!!


All times are GMT -4. The time now is 20:02.