Problem accessing material properties in UDF for Multiphase Multispecies
Hi,
I am simulating a fuel cell and have written a series of UDFs which work for a single phase gas-mixture. Now I am trying to simulate multiphase with an additional liquid water phase and I have a problem with accessing the material properties in order to populate a series of integers that I use later in other UDFs. The UDF is an EXECUTE_ON_LOADING so I am not passed any threads to start with and I'm sure it's a problem with getting the right thread for the gas_mixture phase. Please could anyone suggest how to correctly work through the domain and thread structure. Thanks in advance Tom Here is the UDF: /* Species Variables */ int i_H2 = 99; int i_O2 = 99; int i_H2O = 99; int i_N2 = 99; char hydrogen[2] = "h2"; char water[3] = "h2o"; char oxygen[2] = "o2"; char nitrogen[2] = "n2"; DEFINE_EXECUTE_ON_LOADING(record_species, libname) { int i; char *spe_name; Domain *d=NULL; Material *mix_mat=NULL, *sp; d=Get_Domain(1); mix_mat= mixture_material(d); mixture_species_loop(mix_mat,sp,i) { spe_name=MIXTURE_SPECIE_NAME(mix_mat,i); if(strcmp(spe_name,hydrogen)==0) i_H2 = i; else if(strcmp(spe_name,oxygen)==0) i_O2 = i; else if(strcmp(spe_name,water)==0) i_H2O = i; else if(strcmp(spe_name,nitrogen)==0) i_N2 = i; else Message("Unidentified Species in List, %s\n",spe_name); } Message("H2: %d O2: %d H2O: %d N2: %d\n",i_H2,i_O2,i_H2O,i_N2); } |
Sorry I forgot to include a section of code at the top of the UDF in case anyone thinks that may be the problem
#include "udf.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include "materials.h" #include "string.h" Thanks |
I have now figured it out. the UDF manual had the answer after all - although it was quite difficult to find (excuses excuses)...
The correct code is below if anyone reading back finds this post DEFINE_EXECUTE_ON_LOADING(record_species, libname) { int i; int phase_domain_index = 0; char *spe_name; Domain *d=NULL,*sub_d=NULL; Material *mix_mat=NULL, *sp, *gas_phase; if(NULL == (d=Get_Domain(1))) Error("NULL pointer assignment on domain!\n"); if(NULL == (sub_d=DOMAIN_SUB_DOMAIN(d,phase_domain_index))) Error("NULL pointer assignment on subdomain!\n"); if(NULL == (mix_mat= mixture_material(sub_d))) Error("NULL pointer assignment on mixture!\n"); //mix_mat= mixture_material(d); mixture_species_loop(mix_mat,sp,i) { spe_name=MIXTURE_SPECIE_NAME(mix_mat,i); if(strcmp(spe_name,hydrogen)==0) i_H2 = i; else if(strcmp(spe_name,oxygen)==0) i_O2 = i; else if(strcmp(spe_name,water)==0) i_H2O = i; else if(strcmp(spe_name,nitrogen)==0) i_N2 = i; else Message("Unidentified Species in List, %s\n",spe_name); } Message("H2: %d O2: %d H2O: %d N2: %d\n",i_H2,i_O2,i_H2O,i_N2); } |
Quote:
anyway thanks for you anwser.@pmtgt |
All times are GMT -4. The time now is 07:17. |