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/)
-   -   Error C2223 when compiling UDRGM (occuring when using cell macros) (https://www.cfd-online.com/Forums/fluent-udf/222958-error-c2223-when-compiling-udrgm-occuring-when-using-cell-macros.html)

c_023 December 16, 2019 08:45

Error C2223 when compiling UDRGM (occuring when using cell macros)
 
Hello,

I have been Looking for a solution to this Problem across this Forum but did not find anything helpful. I wrote a User Defined Real Gas Model and want to compile this UDF. When Compiling, Fluent Returns the following error:
'error C2223: left of "->storage" must point to struct/union'
I get the error for every line where I have the following Code:
double PP = C_P(c,t);

is it not possible to declare and assign a local variable in that way inside something like this:

double_RGP_density(c,t)
{
double PP = C_P(c,t);

}

inside a UDRGM UDF?

I also tried declaring and then assigning, like this:
double PP;
PP = C_P(c,t);
buit this also yields an error…

Has anyone experienced the same compilation error?

Thanks in advance

AlexanderZ December 17, 2019 01:26

pp is reserved name use my_pp for instance

c_023 December 17, 2019 03:33

Quote:

Originally Posted by AlexanderZ (Post 752597)
pp is reserved name use my_pp for instance

Thanks for the answer. I changed PP to MY_PP but the error is still the same. Is there Maybe a certain header I need to include for C_P(c,t) to work?
So far, I included the following:
#include "udf.h"
#include "stdio.h"
#include "ctype.h"
#include "stdarg.h"
#include "mem.h"
#include "arrays.h"

AlexanderZ December 17, 2019 06:34

show your code

replace double type with real and run case in double precision

c_023 December 18, 2019 05:12

Quote:

Originally Posted by AlexanderZ (Post 752628)
show your code

replace double type with real and run case in double precision

my Code:

#include "udf.h"
#include "stdio.h"
#include "ctype.h"
#include "stdarg.h"
#include "mem.h"
#include "arrays.h"

#define numPressure 100
#define numTemp 100

#define MW 28.96546
#define RGAS (UNIVERSAL_GAS_CONSTANT/MW)

static int (*usersMessage)(char *,...);
static void (*usersError)(char *,...);

DEFINE_ON_DEMAND(I_do_nothing)
{
/* This is a dummy function to allow us to use */
/* the Compiled UDFs utility */
}

void RGP_error(int err, char *f, char *msg)
{
if (err)
usersError("Real_error (%d) from function: %s\n%s\n",err,f,msg);
}

void RGP_Setup(Domain *domain, cxboolean vapor_phase, char *filename,
int (*messagefunc)(char *format, ...),
void (*errorfunc)(char *format, ...))
{ /* Use this function for any initialization or model setups*/
usersMessage = messagefunc;
usersError = errorfunc;
usersMessage("\nLoading Real Library: %s\n", filename);
}


double RGP_density(c,t)
{

int iP;
int iT;
double P[numPressure];
double T[numTemp];
double RHO[numPressure][numTemp];
double T1;
double T2;
double P1;
double P2;
double MY_PP = C_P(c,t);
double MY_TT = C_T(c,t);
double RHO11;
double RHO12;
double RHO21;
double RHO22;
double T2T1;
double P2P1;
double P2MY_PP;
double MY_PPP1;
double MY_TTT1;
double T2MY_TT;
double interpRHO;
double R1;
double R2;

FILE *Tfile;
FILE *Pfile;
FILE *RHOfile;
Tfile = fopen("Tstruct.csv","r");
Pfile = fopen("Pstruct.csv","r");
RHOfile = fopen("RHOstruct.csv","r");

int counter1 = 0;
float buffer;
while (counter1 < numPressure)
{
fscanf(Pfile,"%f",&buffer);
P[counter1] = buffer;
counter1 += 1;
}
int counter2 = 0;
while (counter2 < numTemp)
{
fscanf(Tfile,"%f",&buffer);
T[counter2] = buffer;
counter2 += 1;
}
int counterP = 0;
int counterT = 0;

for (counterP = 0; counterP < numPressure; ++counterP)
{
for (counterT = 0; counterT < numTemp; ++counterT)
{
fscanf(RHOfile,"%f,",&buffer);
RHO[counterP][counterT] = buffer;
}

}

for (iP = 0; iP < numPressure; ++iP)
{
if (MY_PP <= P[iP] && MY_PP >= P[iP-1])
{
for (iT = 0; iT < numTemp; ++iT)
{
if (MY_TT <= T[iT] && MY_TT >= T[iT-1])
{
T1 = T[iT - 1];
T2 = T[iT];
P1 = P[iP - 1];
P2 = P[iP];
RHO11 = RHO[iP - 1][iT - 1];
RHO12 = RHO[iP - 1][iT];
RHO21 = RHO[iP][iT - 1];
RHO22 = RHO[iP][iT];
break;
}
}
}
}

T2T1 = T2 - T1;
P2P1 = P2 - P1;
T2MY_TT = T2 - MY_TT;
P2MY_PP = P2 - MY_PP;
MY_PPP1 = MY_PP - P1;
MY_TTT1 = MY_TT - T1;

interpRHO = 1.0 / (P2P1 * T2T1) * (
RHO11 * P2MY_PP * T2MY_TT +
RHO21 * MY_PPP1 * T2MY_TT +
RHO12 * P2MY_PP * MY_TTT1 +
RHO22 * MY_PPP1 * MY_TTT1
);

return interpRHO;

fclose(Tfile);
fclose(Pfile);
fclose(RHOfile);

}


[then the same for all other properties, and in the end:]

UDF_EXPORT RGAS_Functions RealGasFunctionList =
{
RGP_Setup, /* initialize */
RGP_density, /* density */
RGP_enthalpy, /* enthalpy */
RGP_entropy, /* entropy */
RGP_specific_heat, /* specific_heat */
RGP_mw, /* molecular_weight */
RGP_speed_of_sound, /* speed_of_sound */
RGP_viscosity, /* viscosity */
RGP_thermal_conductivity, /* thermal_conductivity */
RGP_rho_t, /* drho/dT |const p */
RGP_rho_p, /* drho/dp |const T */
RGP_enthalpy_t, /* dh/dT |const p */
RGP_enthalpy_p /* dh/dp |const T */
};




"Tstruct.csv" and "Pstruct.csv" are 1D-arrays with pressure and temperature Points, "RHOstruct.csv" is a 2D-array with Density[i,j] corresponding to the P[i] and T[j] Pressure and Temperature. The UDF takes the Pressure and Temperature and performs bilinear Interpolation to return the Density (and all other properties which i excluded because it is >1000 lines of Code.
The Code works well when just used within a C-Compiler without the UDF-specific commands. I know the Code will be very slow but this is not an issue as it will only be called once to create lookup tables.

P.S. I tried changing "double" to "real" and run in double precision but the error message stays the same...

AlexanderZ December 19, 2019 00:34

function names are define wrong
was
double RGP_density(c,t)
to be
double RGP_density(cell_t c,Thread *t)

also all variables should be define in the top all function, for instance this will be a problem:
int counter2 = 0;
to be
int counter2;
counter2 = 0;

c_023 December 19, 2019 04:28

Quote:

Originally Posted by AlexanderZ (Post 752842)
function names are define wrong
was
double RGP_density(c,t)
to be
double RGP_density(cell_t c,Thread *t)

also all variables should be define in the top all function, for instance this will be a problem:
int counter2 = 0;
to be
int counter2;
counter2 = 0;

Thanks for the help, with your tips I got rid of the C2223 error. Now a bunch of new Errors turned up, like "C2081: "Thread": Name is not valid". I'll try to fix the Errors and will post the working Code if I get it to work.

c_023 December 19, 2019 05:05

Quote:

Originally Posted by AlexanderZ (Post 752842)
function names are define wrong
was
double RGP_density(c,t)
to be
double RGP_density(cell_t c,Thread *t)

This solution that you pointed out worked for me. The Code compiled now without Errors. The remaining Errors were just typos. Thanks again for the help.

djamila77 December 19, 2019 13:11

Help
 
hi all :),

I need you help please :( :confused: , my question is:

How plotting a curve as a function of time on fluent in the steady case? :confused:

Thanks

AlexanderZ December 20, 2019 01:59

Quote:

Originally Posted by djamila77 (Post 752908)
hi all :),

I need you help please :( :confused: , my question is:

How plotting a curve as a function of time on fluent in the steady case? :confused:

Thanks

in steady case there is no time, that's why it has name steady


All times are GMT -4. The time now is 03:51.