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

UDF to read large file and store it in C_UDMI

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 18, 2022, 09:05
Default UDF to read large file and store it in C_UDMI
  #1
New Member
 
Join Date: May 2020
Posts: 23
Rep Power: 6
Bibill is on a distinguished road
Dear all,

I ran a first simulation on a mesh and i have exported a quantity of interest (QoI) at each cell center of my CFD domain in a ASCII file type. It is thus a very large file (millions of lines):

cellNumber, x-coordinate, y-coordinate, z-coordinate, QoI
.
.
.


I would like to re-use this result for a second simulation on the same mesh. How can I read the file and store the QoI inside a C_UDMI(c,t) ?

I guess the following option is naive
Code:
DEFINE_ON_DEMAND(read_QoI)
{

#if !RP_NODE /* serial or host process */

char line[100];
int index;
float f1, f2, f3, f4;
int number_cell = 13786084;

float *QoI;
QoI = (float *)malloc((number_cell -1)*sizeof(float));

FILE* file_r;
	file_r = fopen("QoI_ascii", "r");
	if(file_r==NULL)
	{
		Message("\n");
		Message("Error opening file \n");
		Message(" \n");
	}


    /* Skip one line by reading one line and ignoring */
    fgets(line, 100, file_r);
	
	
    while (fscanf(file_r, "%d%f%f%f%f", &index, &f1, &f2, &f3, &f4) > 0)
    {
		QoI[index-1] = f4;
    }

fclose(file_r);


Domain *d;
d = Get_Domain(1);
Thread *t;
cell_t c;

thread_loop_c(t,d)
{
    begin_c_loop(c,t)
    {
	int ID = C_ID(c,t);
        C_UDMI(c,t,0) = QoI[ID-1];
    }
    end_c_loop(c,t)
}

free(signal);

#endif


}
I would be highly interested if anyone could help!

Thanks in advance !
Bibill is offline   Reply With Quote

Old   January 19, 2022, 03:55
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
1. you may write profile and later read it without any UDF

2. on the other hand for single core your code should work well in case you are storing the same cell index as C_ID(c,t) macro returns.
Bibill likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   January 19, 2022, 05:01
Default
  #3
New Member
 
Join Date: May 2020
Posts: 23
Rep Power: 6
Bibill is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
1. you may write profile and later read it without any UDF

2. on the other hand for single core your code should work well in case you are storing the same cell index as C_ID(c,t) macro returns.
Thanks AlexanderZ!

1. Can the profile tool also be used with field data? Or should it be used for surface ?

2. Ok thanks a lot, I'll give a try with a smaller file then!
Bibill is offline   Reply With Quote

Reply

Tags
udf, udf and programming


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
How to read a Value from Text File and store it in Variables Amirreza_pro Fluent UDF and Scheme Programming 5 April 5, 2024 16:14
How to read a Value from Text File and store it in Variables (writing in UDF) Amirreza_pro FLUENT 0 October 26, 2020 04:50
simple UDF doesn't read input from external file. interprets/compiles without errors ahmad_xjtu Fluent UDF and Scheme Programming 5 March 23, 2018 03:03
UDF macro to read the name of the case file polaritus Fluent UDF and Scheme Programming 2 March 23, 2015 05:59
Results saving in CFD hawk Main CFD Forum 16 July 21, 2005 21:51


All times are GMT -4. The time now is 22:35.