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

Need help with udf

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 10, 2023, 01:24
Unhappy Need help with udf
  #1
New Member
 
Ivan Ehsan
Join Date: Aug 2023
Posts: 6
Rep Power: 2
bondscar is on a distinguished road
#include "udf.h"
#include "mem.h"
#define MN(a, c) ((a) < (c) ? (a) : (c))
#define MX(a, c) ((a) > (c) ? (a) : (c))
#define MNMX(a, b, c) ((a) < (b) ? (b) : ((a) > (c) ? (c) : (a)))
int nCV2, nVAR, iCV2, iSCV2;
int iDENS, iVISC, iPRANDTL, iTEMP, iCOND, iH2, iH2O, iCO, iCO2, iPVMN_PVns, iPVMX_PVns;
int iOH, iCH4, iSCH4, iSH2, iSH2O, iSCO2, iSCO, iSOH;
float LowBoundPV, UpBoundPV;
float ChemDat[55000][150];
/************************************************** *****/


enum { CV1, CV2 };
/*#define nCV2 216*/
#define LowBoundPV 0.0
#define UpBoundPV 1.0


typedef struct { float cv2min; float cv2max; float variable; } struct_interpol;


struct_interpol Interpol_data(float cv2i, int index)
{
* * int j;
* * double cv2min, cv2max;
* * struct_interpol outputdata;


* * /********** MEAN REACTION PROGRESS VARIABLE **********/
* * j = MNMX((201 - 1) * (cv2i - LowBoundPV) / MX((UpBoundPV - LowBoundPV), 1.0e-6), 0, 201 - 2);


* * /********** INTERPOLATION VARIABLE FROM TABLE **********/
* * double f20 = (201 - 1) * (cv2i - LowBoundPV) / (UpBoundPV - LowBoundPV) - j;
* * double f21 = 1.0 - f20;


* * outputdata.cv2min = 10.0 * (j + 1); // Some sample data, replace with your actual data
* * outputdata.cv2max = 10.0 * (j + 2); // Some sample data, replace with your actual data


* * outputdata.variable = f20 * (10.0 * (j + 2)) + f21 * (10.0 * (j + 1)); // Linear interpolation, replace with your actual data


* * return outputdata;
}
/************************************************** **********/
DEFINE_ON_DEMAND(ReadData_FGM)
{
* * FILE *dat, *check;
* * char str[22];
* * struct_interpol input_data;


* * check = fopen("check.txt", "w");
* * /* READ CHEMICAL DATA FROM FGM.dat */
* * dat = fopen("FGM.dat", "r");
* * if (dat == 0) { fprintf(check, "Error: requested FGM datafile NOT found!\n"); }
* * else {
* * * * fscanf(dat, "%s\n", str);
* * * * while (strcmp(str, "[DATA]") != 0) {
* * * * * * if (strcmp(str, "[NUMBER_PV]") == 0) { fscanf(dat, "%i\n", &nCV2); }
* * * * * * else if (strcmp(str, "[NUMBER_VARIABLES]") == 0) { fscanf(dat, "%i\n", &nVAR); }
* * * * * * fscanf(dat, "%s\n", str);
* * * * }
* * * * fprintf(check, "GENERAL PARAMETERS FGM_PDF.dat:\n");
* * * * fprintf(check, "Number means CV2: %i\n", nCV2);
* * * * fprintf(check, "Number variables: %i\n\n", nVAR);
* * * * fprintf(check, "CHEMICAL DATABASE:\n");


* * * * for (i = 0; i < nVAR; i++) {
* * * * * * fscanf(dat, "%s", str);
* * * * * * fprintf(check, "%12s\t", str);
* * * * * * if (strncmp(str, "PV", 2) == 0) { iCV2 = i; }
* * * * * * else if (strncmp(str, "SourcePV", 8) == 0) { iSCV2 = i; }
* * * * * * else if (strncmp(str, "Density", 7) == 0) { iDENS = i; }
* * * * * * else if (strncmp(str, "Temperature", 11) == 0) { iTEMP = i; }
* * * * }
* * * * fprintf(check, "\n");


* * * * /* Scan chemical data from FGM.dat: */
* * * * for (i = 0; i < nCV2 * nVAR; i++) {
* * * * * * for (j = 0; j < nVAR; j++) {
* * * * * * * * fscanf(dat, "%e", &ChemDat[i][j]);
* * * * * * * * fprintf(check, "%e\t", ChemDat[i][j]);
* * * * * * }
* * * * * * fprintf(check, "\n");
* * * * }
* * * * fclose(dat); fprintf(check, "\n");
* * }
* * fprintf(check, "INDICES CHEMICAL DATABASE:\n");
* * fprintf(check, "Index CV2: %i\n", iCV2);
* * fprintf(check, "Index SCV2: %i\n", iSCV2);
* * fprintf(check, "Index Density: %i\n", iDENS);
* *
* * fclose(check);


}
/************************************************** ************************************/
DEFINE_PROPERTY(Density_FGM, c, t) {
* * double Rho;
* * struct_interpol input_data;


* * input_data = Interpol_data(C_UDSI(c, t, CV2), iDENS);
* * Rho = MNMX(input_data.variable, 1.0e-2, 1.0e1);


* * return Rho;
}



I am reading a data file which contains 201 rows and 116 columns of variables with headers as the names of those variables. Reading the file and storing is working also the interpolation function performs fine with a normal c compiler. I need to pass the interpolated values from the dat file to the fluent solver which is the function of this udf but it is getting the error mentioned below.



Node 0: Process 9812: Received signal SIGSEGV.




================================================== ============================




999999: mpt_accept: error: accept failed: No error




999999: mpt_accept: error: accept failed: No error


Also I liked to mention that chemdat array size is not required to be [550000][150] but some reason if the change the size it totally stoped working. In my file which is like 201*116 2D matrix.

Last edited by bondscar; August 16, 2023 at 01:52.
bondscar is offline   Reply With Quote

Old   August 10, 2023, 03:58
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
what is this?
Code:
* * input_data = Interpol_data(C_UDSI(c, t, CV2), iDENS);
how and when are you going to obtain CV2? whats the range of possible values?

segmentation fault means you are trying to access value which doesn't exist
bondscar likes this.
__________________
best regards


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

Old   August 10, 2023, 07:07
Default
  #3
New Member
 
Ivan Ehsan
Join Date: Aug 2023
Posts: 6
Rep Power: 2
bondscar is on a distinguished road
From the dat file it should get the values. I have 201 CV2s which start from 0 and end at 1 with a 0.005 increment and for all those values I have corresponding density values in the data file, others can be calculated through the interpolation function. If those lines don't gonna work, can you suggest another line of code?
bondscar is offline   Reply With Quote

Old   August 11, 2023, 00:54
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
C_UDSI is a scalar macro at the specific finite volume (cell) , let's say velocity, pressure and so on

to be honest, your logic of reading from file is not clear for me
in general, I would read data from file to arrays
then I would somehow interpolate that data to my mesh (probably based on coordinates)
__________________
best regards


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

Old   August 16, 2023, 01:49
Question
  #5
New Member
 
Ivan Ehsan
Join Date: Aug 2023
Posts: 6
Rep Power: 2
bondscar is on a distinguished road
input_data = Interpol_data(0.5, iDENS);
Rho = input_data.variable;

When I used the interpolation function like above it worked and no error occurred. But when I try to use C_UDSI(c,t,CV2) to get the return from the solver it brokes, and gives this:

Node 0: Process 13388: Received signal SIGSEGV.

================================================== ============================
The fl process could not be started.
Can anyone please help me to fix this line of code?
bondscar is offline   Reply With Quote

Old   August 16, 2023, 04:13
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
did you allocate memory for scalars in Fluent gui& you need to allocate 2 scalars
__________________
best regards


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

Old   August 16, 2023, 06:05
Default
  #7
New Member
 
Ivan Ehsan
Join Date: Aug 2023
Posts: 6
Rep Power: 2
bondscar is on a distinguished road
I allocated one scalar and one memory from the GUI.

DEFINE_SOURCE(SourceCV2_FGM, c, t, dS, eqn) {
double scv2;
struct_interpol input_data;
input_data = Interpol_data(0.5, iSCV2);
scv2 = MNMX(input_data.variable, -1.0e6, 1.0e6);
C_UDMI(c, t, 7) = scv2;

dS[eqn] = 0.0e0;
return scv2;
}


I also have these lines of code, In this part, I can select from the fluid zone source term "User Scalar" where I have selected this particular source from the drop-down. But that also leads to the same error. Should I try with 2 scalars and then what number of User-defined Memory Locations is to be selected?
bondscar is offline   Reply With Quote

Old   August 16, 2023, 06:15
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Code:
enum { CV1, CV2 };
means CV2 = 2, so you have to define 2 scalars, as you are using second one

Code:
C_UDMI(c, t, 7)
means you need at least 8 memory locations for udmi
bondscar likes this.
__________________
best regards


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

Old   September 1, 2023, 05:41
Unhappy Please help
  #9
New Member
 
Ivan Ehsan
Join Date: Aug 2023
Posts: 6
Rep Power: 2
bondscar is on a distinguished road
Still, I'm unable to set up the problem, I tried every viable process that I know to do it, but I am still getting the same error message
Node 1: Process 1580: Received signal SIGSEGV.
and in the end
The fl process could not be started.
please help me, set up the simulation in order because I think I am doing something wrong while setting up, the order in which the simulation must be set. In fluent I think that's a big concern.
bondscar is offline   Reply With Quote

Old   December 4, 2023, 01:24
Default
  #10
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
show your code
describe in details how are you hooking functions in fluent gui
__________________
best regards


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

Old   December 5, 2023, 02:03
Default problem sloved
  #11
New Member
 
Ivan Ehsan
Join Date: Aug 2023
Posts: 6
Rep Power: 2
bondscar is on a distinguished road
thank you sir for your reply.
The problem I was facing was solved.

Regards
Ivan
bondscar 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 for one dimensional linear motion based on force maccheese Fluent UDF and Scheme Programming 2 September 1, 2019 02:18
Save output of udf in another udf! JuanJoMex FLUENT 0 February 8, 2018 12:43
UDF Compilation Error - Loading Library - COMMON Problem! Help! robtheslob Fluent UDF and Scheme Programming 8 July 24, 2015 00:53
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 22:14
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 04:01


All times are GMT -4. The time now is 19:54.