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

Problem accessing material properties in UDF for Multiphase Multispecies

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By pmtgt

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 4, 2013, 05:42
Default Problem accessing material properties in UDF for Multiphase Multispecies
  #1
New Member
 
Tom Tranter
Join Date: Mar 2013
Location: Leeds, UK
Posts: 21
Rep Power: 13
pmtgt is on a distinguished road
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);
}
pmtgt is offline   Reply With Quote

Old   December 4, 2013, 05:50
Default
  #2
New Member
 
Tom Tranter
Join Date: Mar 2013
Location: Leeds, UK
Posts: 21
Rep Power: 13
pmtgt is on a distinguished road
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
pmtgt is offline   Reply With Quote

Old   December 4, 2013, 06:10
Default
  #3
New Member
 
Tom Tranter
Join Date: Mar 2013
Location: Leeds, UK
Posts: 21
Rep Power: 13
pmtgt is on a distinguished road
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);
}
Aj_45 and duraqq44 like this.
pmtgt is offline   Reply With Quote

Old   January 17, 2021, 07:11
Default
  #4
New Member
 
Qi-Zhao-Lu
Join Date: Jan 2021
Posts: 2
Rep Power: 0
luqz is on a distinguished road
Quote:
Originally Posted by pmtgt View Post
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);
}
i was working this problem recently. When using the Mixture_species_loop macros, it required the material thread point to a mixture material, if the thread point to a pure species, i will not work and the fluent wil goes error.
anyway thanks for you anwser.@pmtgt
luqz 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
Material Properties in COMSOL for different domains with different physics TryMyBest COMSOL 0 March 5, 2013 08:23
Problem in using UDF in parallel computing Yogini Fluent UDF and Scheme Programming 0 January 22, 2013 08:23
Fluent is not accepting Modification in Material properties er.mkumar FLUENT 0 September 1, 2012 14:24
Urgent problem - orthotropic material in ICEM Luk CFX 6 August 30, 2006 08:06
parallel UDF problem kerem FLUENT 2 June 20, 2006 06:56


All times are GMT -4. The time now is 23:52.