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

Scalar Transport between two phases

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By zobekenobe

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 2, 2018, 15:20
Default Scalar Transport between two phases
  #1
Member
 
zobekenobe
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 72
Rep Power: 17
zobekenobe is on a distinguished road
I am trying to transfer scalar from Phase A into Phase B. Hence I have defined two UDS scalar 0 in Phase A and scalar 1 in Phase B.


In order to mimic mass transfer there is a sink term for the scalar 0 in Phase A and a source term for the scalar 1 in Phase B.


The scalars are for the same solute however are uniquely defined for the each phase so that I can perform the mass transfer.


The initial concentration of the scalar in phase A entering the domain is 0.005837 kg/kg.


However when I run the UDF the amount of the scalar 1 generated is extremely small ~O(-25)


Code:
DEFINE_SOURCE(solute_sink_phase1, cellt,  mixture_cell_thread, dS, eqn)
{
    int phase_domain_index = 0;
    int n = 6;
    int m = 8;
    Domain* mixture_domain = Get_Domain(ROOT_DOMAIN_ID);
    Domain* solute_domain = DOMAIN_SUB_DOMAIN(mixture_domain, phase_domain_index);
    Thread* solute_thread = THREAD_SUB_THREAD(mixture_cell_thread, phase_domain_index);
    Thread* f_thread;
    face_t facet;
    cell_t c;
    real solute_source_value = 0.0;
    real massflow = 0.0;
    

    thread_loop_c(solute_thread, solute_domain)
    {
        begin_c_loop(cellt, solute_thread)
        {
            c_face_loop(cellt, solute_thread, n)
            {
                facet = C_FACE(cellt, solute_thread, n);
                f_thread = C_FACE_THREAD(cellt, solute_thread, n);
                massflow += F_FLUX(facet, f_thread);
            }
             solute_source_value = -0.005837*massflow*1e7*C_VOF(cellt, solute_thread);
        }
        end_c_loop(cellt, solute_thread)
    }
    return solute_source_value;
}

DEFINE_SOURCE(solute_source_phase1, cellt, mixture_cell_thread, ds, eqn)
{
    int phase_domain_index = 0;
    int m = 8;
    Domain* mixture_domain = Get_Domain(ROOT_DOMAIN_ID);
    Domain* solute_domain = DOMAIN_SUB_DOMAIN(mixture_domain, phase_domain_index);
    Thread* solute_thread = THREAD_SUB_THREAD(mixture_cell_thread, phase_domain_index);
    Thread* f_thread;
    face_t facet;

    real source_value = 0.0;
    real massflow = 0.0;
    thread_loop_c(solute_thread, solute_domain)
    {
        begin_c_loop(cellt, solute_thread)
        {
            c_face_loop(cellt, solute_thread, m)
            {
                facet = C_FACE(cellt, solute_thread, m);
                f_thread = C_FACE_THREAD(cellt, solute_thread, m);
                massflow += F_FLUX(facet, f_thread);
            }
            source_value = 0.005837*massflow*1e7*C_VOF(cellt, solute_thread);
        }
        end_c_loop(cellt, solute_thread)
    }
    return source_value;
}

The above code is for the source and sink terms in the respective phases. Could someone help understand if the strategy of a source and sink is incorrect or if there is something incorrect with the code above.



p.s. the equation is nothing legit, I was simply trying different values to see if it has any effect on the solute (apparently it doesn't)
zobekenobe is offline   Reply With Quote

Old   July 3, 2018, 05:09
Default
  #2
Senior Member
 
Cees Haringa
Join Date: May 2013
Location: Delft
Posts: 607
Rep Power: 0
CeesH is on a distinguished road
Why don't you use the mass transfer UDF for this? seems more straightforward than defining sources and sinks yourself (although that's not impossible to be sure)
CeesH is offline   Reply With Quote

Old   July 3, 2018, 07:45
Default
  #3
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Zobekenobe,

I agree with CeesH's comment that it is worth looking at the alternatives.

As for your UDFs, I cannot work out what you are intending them to do, but it is something rather strange.

DEFINE_SOURCE is called for each cell in the cell zone, possibly several times per iteration. It is not a good place for a loop over all cell threads and all cells in each thread. (If you need to calculate a single rate for the whole model, do it in a DEFINE_EXECUTE_AT_END and store it in a static global.) It is intended that the UDF will return the source rate for the single cell that is pointed to.

My guess as to why you get a (near-)zero rate is that you visit every single interior face in the model twice (every time the DEFINE_SOURCE is called), and the inwards F_FLUX on one side is balanced out by the outwards flux on the other.

I think you should go back to some of the examples for DEFINE_SOURCE and rethink your plan.

I hope this helps a little. Good luck!
Ed
obscureed is offline   Reply With Quote

Old   July 3, 2018, 09:59
Default
  #4
Member
 
zobekenobe
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 72
Rep Power: 17
zobekenobe is on a distinguished road
Thanks Ceesh and Ed,


I recently read somewhere (either the UDF manual or some example) where Fluent requires one to define the source terms for mass transfer of user defined scalars. The define_mass_transfer does not do this.

(I'll try and find the reference and paste it here)


Assuming the above is required,
Fluent then specifies that to define the source for the UDS in a multiphase simulation using the VOF model, the threads passed on to DEFINE_SOURCE is that of the mixture and hence one would have to pull the required phase thread and then operate on it.



Probably I should not loop over all the cells in the domain for the required phase. Thanks for that.




Thanks
souza.emer likes this.
zobekenobe is offline   Reply With Quote

Old   January 4, 2019, 08:20
Default
  #5
Member
 
Emerson
Join Date: May 2018
Posts: 35
Rep Power: 8
souza.emer is on a distinguished road
Quote:
Originally Posted by zobekenobe View Post
Thanks Ceesh and Ed,


I recently read somewhere (either the UDF manual or some example) where Fluent requires one to define the source terms for mass transfer of user defined scalars. The define_mass_transfer does not do this.

(I'll try and find the reference and paste it here)


Assuming the above is required,
Fluent then specifies that to define the source for the UDS in a multiphase simulation using the VOF model, the threads passed on to DEFINE_SOURCE is that of the mixture and hence one would have to pull the required phase thread and then operate on it.



Probably I should not loop over all the cells in the domain for the required phase. Thanks for that.




Thanks
Could you paste this reference that you saw? Because I'm facing a problem with the DEFINE_MASS_TRANSFER macro, and your approach could help me.
souza.emer 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
problem during mpi in server: expected Scalar, found on line 0 the word 'nan' muth OpenFOAM Running, Solving & CFD 3 August 27, 2018 05:18
Division by zero exception - loop over scalarField Pat84 OpenFOAM Programming & Development 6 February 18, 2017 06:57
Issue symmetryPlane 2.5d extruded airfoil simulation 281419 OpenFOAM Running, Solving & CFD 5 November 28, 2015 14:09
Diverging solution in transonicMRFDyMFoam tsalter OpenFOAM Running, Solving & CFD 30 July 7, 2014 07:20
compressible flow in turbocharger riesotto OpenFOAM 50 May 26, 2014 02:47


All times are GMT -4. The time now is 15:55.