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)

ASimonsen December 26, 2016 11:47

Try and delete all the file writing stuff and just display it in the console using Message();

Also, CX_Find_Cell_With_Point might only work with 3d inputs, so try adding a third index to pt (pt[2]);. Also, I'm using "real" values instead of "static double", although "real" and "double" should be the same on 64-bit machines.
You should also have an if-condition, if the cell couldn't be found. Something like this: (I've not tested it).

Code:

#include "udf.h"
#include "cxndsearch.h"
static ND_Search *domain_table = NULL;

static float c_centroid[2];
static cell_t c;
static Thread *t;
static CX_Cell_Id *cx_cell;
real pt[3];
FILE *fp_p01;

DEFINE_EXECUTE_AT_END(execute)
{
#if !RP_HOST
        theta = theta + 0.001 * 10;
        xTheory = 0.17 + R * cos(theta);
        yTheory = 0.10 + R * sin(theta);
       
        pt[0] = xTheory;
        pt[1] = yTheory;
        pt[2] = 0.0;

        domain_table = CX_Start_ND_Point_Search(domain_table,TRUE,-1);
        cx_cell = CX_Find_Cell_With_Point(domain_table,pt,0.0);
       
        if (cx_cell) {
                c = RP_CELL(cx_cell);
                t = RP_THREAD(cx_cell);
                C_CENTROID(c_centroid,c,t);
                p01 = C_P(c,t);
        } else {
                Message("Could not find cell!\n");
        }
        domain_table = CX_End_ND_Point_Search(domain_table);
#endif
}


youjfwhu December 26, 2016 19:33

Quote:

Originally Posted by ASimonsen (Post 631287)
Try and delete all the file writing stuff and just display it in the console using Message();

Also, CX_Find_Cell_With_Point might only work with 3d inputs, so try adding a third index to pt (pt[2]);. Also, I'm using "real" values instead of "static double", although "real" and "double" should be the same on 64-bit machines.
You should also have an if-condition, if the cell couldn't be found. Something like this: (I've not tested it).

Code:

#include "udf.h"
#include "cxndsearch.h"
static ND_Search *domain_table = NULL;

static float c_centroid[2];
static cell_t c;
static Thread *t;
static CX_Cell_Id *cx_cell;
real pt[3];
FILE *fp_p01;

DEFINE_EXECUTE_AT_END(execute)
{
#if !RP_HOST
    theta = theta + 0.001 * 10;
    xTheory = 0.17 + R * cos(theta);
    yTheory = 0.10 + R * sin(theta);
   
    pt[0] = xTheory;
    pt[1] = yTheory;
    pt[2] = 0.0;

    domain_table = CX_Start_ND_Point_Search(domain_table,TRUE,-1);
    cx_cell = CX_Find_Cell_With_Point(domain_table,pt,0.0);
   
    if (cx_cell) {
        c = RP_CELL(cx_cell);
        t = RP_THREAD(cx_cell);
        C_CENTROID(c_centroid,c,t);
        p01 = C_P(c,t);
    } else {
        Message("Could not find cell!\n");
    }
    domain_table = CX_End_ND_Point_Search(domain_table);
#endif
}



Thank you so much. My problem has been solved with your help.

siddanibhargav July 11, 2018 23:05

Trouble in running this code
 
Quote:

Originally Posted by ASimonsen (Post 610172)
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);
}


Hello,
I would be really glad if someone could help me with my issue. I have tried running this code on ANSYS R 19.0 Academic version and it gives me the following error.

error C2664: 'CX_Find_Cell_With_Point' : cannot convert parameter 2 from 'real [3]' to 'double []'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Thanks
Bhargav Sriram Siddani

T.Nagata October 16, 2018 08:34

Hi, youjfwhu!

If running fluent with multiple nodes, your udf code might generate
access-violation because of lacking search error treatment.
You should consider the case cx_cell = NULL.

CX_Find_Cell_With_Point() is run on all nodes containing partial mesh,
and does not always return valid cell ID.

stepheneall January 16, 2020 01:27

Quote:

Originally Posted by siddanibhargav (Post 698933)
Hello,
I would be really glad if someone could help me with my issue. I have tried running this code on ANSYS R 19.0 Academic version and it gives me the following error.

error C2664: 'CX_Find_Cell_With_Point' : cannot convert parameter 2 from 'real [3]' to 'double []'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Thanks
Bhargav Sriram Siddani

i met similar problem and solve it by using "compile" instead of "interpret".


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