|
[Sponsors] |
Issues with mass source macros in a multiphase system |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 8, 2015, 17:43 |
Issues with mass source macros in a multiphase system
|
#1 |
New Member
Christina P.
Join Date: Oct 2012
Posts: 22
Rep Power: 14 |
Hi everyone,
I'm trying to write a UDF that describes phase change (just working on getting evaporation right now). I've been trying out my UDF on a "1D" Stefan problem (see attached PDF). My biggest problem right now is with an if statement in the mass source macro (DEFINE_SOURCE) that is hooked to my primary phase, the vapor. Here's the macro in question: Code:
DEFINE_SOURCE(gas, cell, thread, dS, eqn) { real source = 0.0; /* Initialize the variable "source"*/ real a_c = 0.04; real a_c_coeff=(2.0*a_c)/(2.0-a_c); real M = 0.018015; /* molar mass [kg/mol] */ real R = 8.314; /* universal gas constant [J/molK] */ real Tsat = 373.1; /* saturation temperature [K] */ real Psat = 101325.0; /* saturation pressure [Pa] */ real DeltaH = 2256560.0; /*vaporization enthalpy [J/kg] */ real rho_L = 958.4; /* liquid density [kg/m3] */ real rho_V = 0.597; /* vapor density [kg/m3] */ /* Initialize and define thread pointer/pointer array */ Thread *tm = THREAD_SUPER_THREAD(thread); /* *tm is a pointer to the mixture-level thread */ Thread **pt = THREAD_SUB_THREADS(tm); /* **pt is a pointer ARRAY, whose elements contain pointers to the phase-level threads */ /* If the temperature of the cell (located in a primary phase cell thread) is greater than Tsat */ /* AND the volume fraction of the primary phase is less than one (i.e. there is some liquid in the cell), then... */ if (C_T(cell, thread) > 373.1 && C_VOF(cell,thread) < 1.0) { source = C_UDMI(cell,tm,0)*a_c_coeff*sqrt(M/(2.0*M_PI*R))*((C_P(cell,thread)/sqrt(C_T(cell,thread)))-(Pvaporavg/sqrt(Tvaporavg))); } else { source = 0.0; } /* Set the user-defined memory location, labeled 1, as the mass source term for the vapor phase*/ C_UDMI(cell, tm, 1) = source; /* Set the user-defined memory location, labeled 2, as the energy source term, which is just the mass source term multiplied */ /* by the latent heat of vaporization. */ C_UDMI(cell, tm, 2) = -1.*source*DeltaH; dS[eqn] = 0; return source; } My specific issue is that the solver doesn't always enter into the if statement when it should. When the interface temperature gets above 373.1K, I would expect a mass source to appear along the entire length interface. However, I don't see that at all. Instead, it's just one localized circular region where a mass source appears. Does anyone have any experience with if statements inside DEFINE_SOURCE macros for a mass source in a multiphase simulation? Have I formatted it correctly? I've been trying to figure out if it's something to do with the data structures in multiphase situations, i.e. phase-level threads versus mixture-level threads, or a data type problem, or a problem with the if statement syntax. I haven't been able to find anything helpful in the UDF manual or elsewhere online. I've submitted my question to ANSYS but am waiting to hear back. Thank you!! |
|
April 8, 2015, 20:00 |
|
#2 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
You're multiplying C_UDMI(cell,tm,0) by other terms to evaluate 'source'. If this UDM value is zero, then your 'source' would also be zero: could this case be true, and what does your UDM-0 represent?
I see no reason for the solver not to enter the if statement when it should; try some debugging to be sure this logic isn't the cause of your problem. Add in a Message(); line where 'source' is evaluated in the if statement to print the cell details to screen and compare the number of these messages with the number of nonzero source terms in your simulation. |
|
April 9, 2015, 10:35 |
|
#3 | |
New Member
Christina P.
Join Date: Oct 2012
Posts: 22
Rep Power: 14 |
Quote:
Thanks for your idea re: debugging the if statement. Could you clarify how to add in the Message(); line? I've never used that before, and I haven't seen it in the UDF manual. Thank you again! |
||
April 9, 2015, 20:20 |
|
#4 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
The Message() function is similar to printf() where you can print text to the screen. Note that in parallel every process will print this same message (for example on DEFINE_ADJUST outside a cell loop), so you could use Message0() for only node 0 to print the message to screen (and has the same functions as Message() in serial mode).
Start with adding these lines of code (I've assumed you're running in 3-D, if you're solving in 2-D remove the z-direction components) to see at which cells your DEFINE_SOURCE macro is being called: Code:
real cellcentroid[ND_ND]; ... if (C_T(cell, thread) > 373.1 && C_VOF(cell,thread) < 1.0) { C_CENTROID(cellcentroid,cell,thread); Message("This cell has T > 373.1 and VOF < 1.0 and is located at [x,y,z] = [%e,%e,%e]\n",cellcentroid[0],cellcentroid[1],cellcentroid[2]); source = C_UDMI(cell,tm,0)*a_c_coeff*sqrt(M/(2.0*M_PI*R))*((C_P(cell,thread)/sqrt(C_T(cell,thread)))-(Pvaporavg/sqrt(Tvaporavg))); Message("This cell has a source term = %e\n",source); } else { source = 0.0; } |
|
April 14, 2015, 04:34 |
store_vof_norm
|
#5 |
New Member
mostafa
Join Date: Jun 2013
Posts: 22
Rep Power: 13 |
hi every body
I'm modeling a three-phase problem with Eulerian (+Multi fluid VOF model) model. I also use Population balance model. I want to use a UDF for nucleation rate for third phase (second secondary phase). bellow are some part of this UDF: #include "udf.h" #include "sg_pb.h" #include "sg_mphase.h" DEFINE_PB_NUCLEATION_RATE(nuc, cell, thread) { real Epsilon_Entrainment; real Vof_CutOff = 0.05; int phase1_domain_index = 0; int phase2_domain_index = 1; Thread *mixture_thread = THREAD_SUPER_THREAD(thread); Thread *ContinuousPhaseThread = THREAD_SUB_THREAD(mixture_thread,phase1_domain_ind ex); Thread *LargeBubbles = THREAD_SUB_THREAD(mixture_thread,phase2_domain_ind ex); Vof_CutOff= C_VOF(cell, LargeBubbles); if (C_U(cell,LargeBubbles) > 8) { Epsilon_Entrainment = 100000; } return (Epsilon_Entrainment); } But when I interpret this UDF, I encounter this error: Error: D:\\xxx: line 20: label "store_vof_norm" not found (pc=74). this UDF has 19 lines. this error refers to line 20.I found that this error is from sg_mphase.h file. In this file there is "store_vof_norm", But I don't know what is the problem???? please help me. it is very important to me. thanks of all |
|
October 14, 2015, 08:18 |
|
#6 |
Senior Member
Join Date: Jun 2014
Location: Taiwan
Posts: 100
Rep Power: 12 |
should C_UDMI(cell,tm,0) be re-calculated in DEFINE_SOURCE if it is not global variable?
Or should it be in a begin_c_loop? |
|
October 17, 2015, 01:59 |
|
#7 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
User-defined memory is stored within Fluent and C_UDMI is a macro which accesses this memory (it's not a variable which would require initialising or being globally defined).
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
wmake compiling new solver | mksca | OpenFOAM Programming & Development | 14 | June 22, 2018 07:29 |
SparceImage v1.7.x Issue on MAC OS X | rcarmi | OpenFOAM Installation | 4 | August 14, 2014 07:42 |
Trouble compiling utilities using source-built OpenFOAM | Artur | OpenFOAM Programming & Development | 14 | October 29, 2013 11:59 |
Version 15 on Mac OS X | gschaider | OpenFOAM Installation | 113 | December 2, 2009 11:23 |
DecomposePar links against liblamso0 with OpenMPI | jens_klostermann | OpenFOAM Bugs | 11 | June 28, 2007 18:51 |