-
-
November 30, 2022 at 9:38 am
Venkata Teja Sai Perala
Subscriber/**sccs id: @(#)real_ideal.c 1.10 Copyright 1900/11/09 ANSYS, Inc.*//** Copyright 1988-1998 ANSYS, Inc.* All Rights Reserved** This is unpublished proprietary source code of ANSYS, Inc.* It is protected by U.S. copyright law as an unpublished work* and is furnished pursuant to a written license agreement. It* is considered by ANSYS, Inc. to be confidential and may not be* used, copied, or disclosed to others except in accordance with* the terms and conditions of the license agreement.*//** Windows Warning!!! Including udf.h is for getting definitions for* ANSYS FLUENT constructs such as Domain. You must* NOT reference any ANSYS FLUENT globals directly from* within this module nor link this against any ANSYS* FLUENT libs, doing so will cause dependencies on a* specific ANSYS FLUENT binary such as fl551.exe and* thus won't be version independent.*/#include "udf.h"#include "stdio.h"#include "ctype.h"#include "stdarg.h"#if RP_DOUBLE#define SMALL 1.e-20#else#define SMALL 1.e-10#endif#define NCMAX 20#define NSPECIE_NAME 80static int (*usersMessage)(char *,...);static void (*usersError)(char *,...);static double ref_p, ref_T;static char gas[NCMAX][NSPECIE_NAME];static int n_specs;double Mixture_Rgas(double yi[]);double Mixture_pressure(double Temp, double Rho, double yi[]);double Mw_i(int i);double Cp_i(double T, double r, int i);double K_i(double T, double r, int i);double Mu_i(double T, double r, int i);double Rgas_i(double T, double r, int i);double Gm_i(double T, double r, int i);DEFINE_ON_DEMAND(I_do_nothing){/*This is a dummy functionmust be included to allow for the use of theANSYS FLUENT UDF compilation utility*/}void Mixture_error(int err, char *f, char *msg){if (err)usersError("Mixture_error (%d) from function: %s\n%s\n",err,f,msg);}/*******************************************************************//* Mixture Functions *//* These are the only functions called from ANSYS FLUENT Code *//*******************************************************************/void MIXTURE_Setup(Domain *domain, cxboolean vapor_phase, char *specielist,int (*messagefunc)(char *format, ...),void (*errorfunc)(char *format, ...)){/* This function will be called from ANSYS FLUENT after theUDF library has been loaded.User must enter the number of species in the mixtureand the name of the individual species.*/int i ;usersMessage = messagefunc;usersError = errorfunc;ref_p = ABS_P(RP_Get_Real("reference-pressure"),op_pres);ref_T = RP_Get_Real("reference-temperature");if (ref_p == 0.0){Message0("\n MIXTURE_Setup: reference-pressure was not set by user \n");Message0("\n MIXTURE_Setup: setting reference-pressure to 101325 Pa \n");ref_p = 101325.0 ;}/*====================================================*//*========= User Input Section =====================*//*====================================================*//*Define Number of species & Species name.DO NOT use space for naming species*/n_specs = 5 ;(void)strcpy(gas[0],"H2O") ;(void)strcpy(gas[1],"N2") ;(void)strcpy(gas[2],"O2") ;(void)strcpy(gas[3],"CO2") ;(void)strcpy(gas[4],"H2") ;/*====================================================*//*========= End Of User Input Section ==============*//*====================================================*/Message0("\n MIXTURE_Setup: RealGas mixture initialization \n");Message0("\n MIXTURE_Setup: Number of Species = %d \n",n_specs);for (i=0; i{Message0("\n MIXTURE_Setup: Specie[%d] = %s \n",i,gas[i]);}/*concatenate species name into one stringand send back to fluent*/strcat(specielist,gas[0]);for (i=1; i{strcat(specielist," ");strcat(specielist,gas[i]);}}double MIXTURE_density(double Temp, double P, double yi[]){double Rgas = Mixture_Rgas(yi) ;double r = P/(Rgas*Temp); /* Density at Temp & P */return r; /* (Kg/m^3) */}double MIXTURE_specific_heat(double Temp, double density, double P,double yi[]){double cp=0.0 ;int i ;for (i=0; icp += yi[i]*Cp_i(Temp,density,i);return cp; /* (J/Kg/K) */}double MIXTURE_enthalpy(double Temp, double density, double P, double yi[]){double h=0.0;int i ;for (i=0; ih += yi[i]*(Temp*Cp_i(Temp,density,i));return h; /* (J/Kg) */}double MIXTURE_entropy(double Temp, double density, double P, double yi[]){double s = 0.0 ;double Rgas=0.0 ;Rgas = Mixture_Rgas(yi);s = MIXTURE_specific_heat(Temp,density,P,yi)*log(Temp/ref_T) -Rgas*log(P/ref_p) ;return s; /* (J/Kg/K) */}double MIXTURE_mw(double yi[]){double MW, sum=0.0 ;int i ;for (i=0; isum += (yi[i]/Mw_i(i)) ;MW = 1.0/MAX(sum,SMALL) ;return MW; /* (Kg/Kmol) */}double MIXTURE_speed_of_sound(double Temp, double density, double P,double yi[]){double a, cp, Rgas ;cp = MIXTURE_specific_heat(Temp,density,P,yi) ;Rgas = Mixture_Rgas(yi) ;a = sqrt(Rgas*Temp* cp/(cp-Rgas) ) ;return a ; /* m/s */}double MIXTURE_viscosity(double Temp, double density, double P, double yi[]){double mu=0;int i ;for (i=0; imu += yi[i]*Mu_i(Temp,density,i);return mu; /* (Kg/m/s) */}double MIXTURE_thermal_conductivity(double Temp, double density, double P,double yi[]){double kt=0;int i ;for (i=0; ikt += yi[i]*K_i(Temp,density,i);return kt; /* W/m/K */}double MIXTURE_rho_t(double Temp, double density, double P, double yi[]){double drdT ; /* derivative of rho w.r.t. Temp */double p ;double dT=0.01;p = Mixture_pressure(Temp,density, yi);drdT = (MIXTURE_density(Temp+dT,p,yi) - MIXTURE_density(Temp,p,yi) ) /dT;return drdT; /* (Kg/m^3/K) */}double MIXTURE_rho_p(double Temp, double density, double P, double yi[]){double drdp ;double p ;double dp= 5.0 ;p = Mixture_pressure(Temp,density, yi);drdp = (MIXTURE_density(Temp,p+dp,yi) - MIXTURE_density(Temp,p,yi) ) /dp;return drdp; /* (Kg/m^3/Pa) */}double MIXTURE_enthalpy_t(double Temp, double density, double P, double yi[]){double dhdT ;double p ;double rho2 ;double dT= 0.01 ;p = Mixture_pressure(Temp,density, yi);rho2 = MIXTURE_density(Temp+dT,p,yi) ;dhdT = (MIXTURE_enthalpy(Temp+dT,rho2,P,yi) - MIXTURE_enthalpy(Temp,density,P,yi)) /dT ;return dhdT ; /* J/(Kg.K) */}double MIXTURE_enthalpy_p(double Temp, double density, double P, double yi[]){double dhdp ;double p ;double rho2 ;double dp= 5.0 ;p = Mixture_pressure(Temp,density, yi);rho2 = MIXTURE_density(Temp,p+dp,yi) ;dhdp = (MIXTURE_enthalpy(Temp,rho2,P,yi) - MIXTURE_enthalpy(Temp,density,P,yi)) /dp;return dhdp ; /* J/ (Kg.Pascal) */}/*******************************************************************//* Auxiliary Mixture Functions *//*******************************************************************/double Mixture_Rgas(double yi[]){double Rgas=0.0 ;int i ;for (i=0; iRgas += yi[i]*(UNIVERSAL_GAS_CONSTANT/Mw_i(i)) ;return Rgas ;}double Mixture_pressure(double Temp, double Rho, double yi[]){double Rgas = Mixture_Rgas(yi) ;double P = Rho*Rgas*Temp ; /* Pressure at Temp & P */return P; /* (Kg/m^3) */}/*******************************************************************//* Species Property Functions *//*******************************************************************/double Mw_i(int i){double mi[20];mi[0] = 18.01534 ; /*H2O*/mi[1] = 28.01340 ; /*N2 */mi[2] = 31.99880 ; /*O2 */mi[3] = 44.00995 ; /*CO2*/mi[4] = 02.01588 ; /*H2*/return mi[i] ;}double Cp_i(double T, double r, int i){double cpi[20] ;cpi[0] = 2014.00 ; /*H2O*/cpi[1] = 1040.67 ; /*N2 */cpi[2] = 919.31 ; /*O2 */cpi[3] = 840.37 ; /*CO2*/cpi[4] = 14194.0 ; /*H2*/return cpi[i] ;}double K_i(double T, double r, int i){double ki[20] ;ki[0] = 0.02610 ; /*H2O*/ki[1] = 0.02420 ; /*N2 */ki[2] = 0.02460 ; /*O2 */ki[3] = 0.01450 ; /*CO2*/ki[4] = 0.17332 ; /*H2*/return ki[i] ;}double Mu_i(double T, double r, int i){double mui[20] ;mui[0] = 1.340E-05 ; /*H2O*/mui[1] = 1.663E-05 ; /*N2 */mui[2] = 1.919E-05 ; /*O2 */mui[3] = 1.370E-05 ; /*CO2*/mui[4] = 8.376E-06 ; /*H2*/return mui[i] ;}double Rgas_i(double T, double r, int i){double Rgasi ;Rgasi = UNIVERSAL_GAS_CONSTANT/Mw_i(i) ;return Rgasi ;}double Gm_i(double T, double r, int i){double gammai ;gammai = Cp_i(T,r,i)/(Cp_i(T,r,i) - Rgas_i(T,r,i));return gammai ;}/*******************************************************************//* Mixture Functions Structure *//*******************************************************************/UDF_EXPORT RGAS_Functions RealGasFunctionList ={MIXTURE_Setup, /* initialize */MIXTURE_density, /* density */MIXTURE_enthalpy, /* enthalpy */MIXTURE_entropy, /* entropy */MIXTURE_specific_heat, /* specific_heat */MIXTURE_mw, /* molecular_weight */MIXTURE_speed_of_sound, /* speed_of_sound */MIXTURE_viscosity, /* viscosity */MIXTURE_thermal_conductivity, /* thermal_conductivity */MIXTURE_rho_t, /* drho/dT |const p */MIXTURE_rho_p, /* drho/dp |const T */MIXTURE_enthalpy_t, /* dh/dT |const p */MIXTURE_enthalpy_p /* dh/dp |const T */};/*******************************************************************//*******************************************************************/December 2, 2022 at 12:29 pmDrAmine
Ansys EmployeeAre you using an updated example from the customization manual or User's Guide?
-
December 2, 2022 at 12:55 pm
Venkata Teja Sai Perala
SubscriberI am using the 2021 User's guide
December 2, 2022 at 2:42 pmDrAmine
Ansys EmployeeDoes it compile at your end but it stops when iterating? If the latter is true: at which iteration or straight from start?
-
December 2, 2022 at 3:30 pm
Venkata Teja Sai Perala
SubscriberI am not getting any errors while compiling, when I am doing initialization I am getting this error
December 2, 2022 at 4:13 pmDrAmine
Ansys EmployeeI am using 22R2 and cannot compile your UDF. The one from User's Guide did compile as it should. Adding the H2 component does work too and dummy case can run.
Viewing 3 reply threads- You must be logged in to reply to this topic.
Ansys Innovation SpaceEarth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.
Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
Trending discussions- Suppress Fluent to open with GUI while performing in journal file
- Floating point exception in Fluent
- What are the differences between CFX and Fluent?
- Heat transfer coefficient
- Getting graph and tabular data from result in workbench mechanical
- The solver failed with a non-zero exit code of : 2
- Difference between K-epsilon and K-omega Turbulence Model
- Time Step Size and Courant Number
- Mesh Interfaces in ANSYS FLUENT
- error in cfd post
Top Contributors-
2524
-
2066
-
1279
-
1096
-
457
Top Rated Tags© 2023 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.Please Login to Report Topic
Please Login to Share Feed
New Post - Fluids
Edit Discussion
-