Residence time distribution (RTD) for dummies
Hello foamers,
I'm a total newbie in OpenFOAM and I'm supposed to do a RTD analysis for static mixers with quite a complex geometry. I searched the internet for a week now and I couldn't find the desired information so I'm turning to you, more advanced users. So far I followed a procedure: 1. Steadystate solution of laminar flow with simpleFoam (which I would like to edit in future to calculate also a temperature transfer). 2. I took the U file from the last time folder and copied it into new case folder into 0. 3. I used scalarTransportFoam on calculated velocity field to inject a tracer T at the inlet boundary. And now I got stuck with how to evaluate a concentration of the tracer at the outlet boundary so I could create RTD plot. Could any of you give me a "cook book for dummies" how to proceed with the rest and if there would be any simpler way to deal with it then copying the U file by hand? Thank you very much for any suggestions. 
Quote:
Copying over U: not that I know. There are functionObjects that solve the tracer during the solution of the regular fluid equations, but these won't help you 
Hello Vanekp,
Maybe a different approach: if you include a unit source in your scalar transport equation, you get your residence time distribution for the entire volume. In that case, set the value at the inlet at 0, and you will see "fresh" fluid entering. Regards, Tom 
Hi Vanekp,
I have done passive scalar transport in a manner similar to what you are doing. To answer your question about the concentration at the boundary:
If you decide to move on to turbulent flow modeling, you need a few more things to correctly calculate the RTD. In scalarTransportFoam, you will need to add the affects of turbulence on your passive scalar through a transport equation similar to Code:
fvm::ddt(C) 
Thank you all for the advice.
I was told the same thing about the patchMassFlowAverage by my colleague. So far I'm interested only in laminar flows, so the adjustment is not yet necessary but in the future I'll have to do it. So I've set up everything according to the advice, I wrote a very simple shell script, which runs the sequence mySimpleFoam (simpleFoam with added solution of temperature) > copying the velocity fields U and phi > running scalarTransportFoam with patchMassFlowAverage function object included. So I'm now able to get the RTD curve quite nicely. But now I'm dealing with problems with the solution. The velocity fields seem to be calculated well and when I run the scalarTransportFoam at the beginning everything seems to go right and at one point the solution goes totally 'bananas' and the Flow Average gets even negative (and even into range of 1e15) which I don't even understant how is it possible to go negative. Do any of you have experince with this kind of behaviour and how to resolve it? 
Hello Vanekp,
Did you also copy the phi file from the latest timestep your simpleFoam run? It is calculated during the simple loop and corrected for conservation of mass instead of interpolated from the velocity field at the startup of scalarTransportFoam. This means you have a divergence free field to start with. You can test this quite easily by running the solver twice, once with and once without the copied phi field. Regards, Tom 
Thank you for the advice.
But yes I have copied both U and phi files. But I found out, that the problem is with the solution as the solution starts to oscilate, so I'm trying to figure out where is the problem, why the solution oscilates 
Hello Foamers!!
I'm calculating the RTD as described by Daniel, using patchMassFlowAverged. However, I need these values to calculate the variance. I made a python script to perform these calculations, but I'm having trouble reading the output file, as shown below: Code:
# Time f_in f_out Code:
massFlowAverageC 
Hello Foamers!!
I'm calculating the RTD as described by Daniel, using patchMassFlowAverged. However, I need these values to calculate the variance. I made a python script to perform these calculations, but I'm having trouble reading the output file, because some columns are getting together, as shown below: Code:
# Time f_in f_out Code:
massFlowAverageC 
what about making two function objects, one for f_in and another for f_out? they will be in separate folders and files.

Hi Daniel!
Thank you for your prompt reply. I already tried that. The result was as shown below: :( Code:
# Time f_out Jonas 
Quote:

Good idea vanekp!!!
I did this and worked. Follows the python script to read this archive. Code:
import numpy as np 
Quote:
Can anybody help me?,, How should I implement the patchMassFlowAverage function object? 
Quote:
By reading through the post online and trying example like the one at http://www.cfdonline.com/Forums/ope...tml#post416812 and looking at the wiki page here. You will need to compile the libraries outlined in the other post http://www.cfdonline.com/Forums/ope...tml#post491866 
All times are GMT 4. The time now is 00:55. 