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   December 26, 2016, 12:47
Default
  #21
New Member
 
Anders Simonsen
Join Date: Sep 2013
Posts: 18
Rep Power: 13
ASimonsen is on a distinguished road
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
}
ASimonsen is offline   Reply With Quote

Old   December 26, 2016, 20:33
Smile
  #22
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
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.
ASimonsen likes this.
youjfwhu is offline   Reply With Quote

Old   July 12, 2018, 00:05
Default Trouble in running this code
  #23
New Member
 
Siddani Bhargav Sriram
Join Date: Feb 2017
Posts: 2
Rep Power: 0
siddanibhargav 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);
}
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
siddanibhargav is offline   Reply With Quote

Old   October 16, 2018, 09:34
Default
  #24
New Member
 
anonymous
Join Date: May 2018
Posts: 2
Rep Power: 0
T.Nagata is on a distinguished road
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.
T.Nagata is offline   Reply With Quote

Old   January 16, 2020, 02:27
Default
  #25
New Member
 
Ba Liming
Join Date: Jan 2020
Posts: 1
Rep Power: 0
stepheneall is on a distinguished road
Quote:
Originally Posted by siddanibhargav View Post
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".
stepheneall 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 16:35.