integrate several fields
Hi foamers,
I'm doing a RTD (Residence Time Distribution) of a 3D cylinder. I solved the velocity part by using simpleFoam in a steady state. Then, with this converged velocity I created a similar case (with scalarTransportFoam, transient), including a step experiment at the beginning. By measuring the Heat flux at the "outlet" patch, I would manage to study this RTD. (Hope you got everything:D) My case briefly presented, here's my question: in the controlDict file, I want to use a function to calculate the integral for the product (Ux*T) during the whole calculation (t= 0 -> 3 with dt=2.5e-3) I was trying to use "libsimpleFunctionObjects.so" with the type "patchIntegrate" as follows Code:
flux There is no way to do what I exposed above. Note: U isn't in the integral as it's constant for the whole calculation (already established). Apparently you need a scalar and not Ux... Code:
--> FOAM FATAL IO ERROR: 2) Does it exist another utility to multiply 2 scalarfields? Then I'll be able to use the result of this one in my integral. Thank you :) |
My bad
I don't know what I was thinking about...:o
The integral is spatial and not temporal. Therefore, Ux isn't constant (as there is a laminar profile in the tube)! I must multiply, then both Ux and T before integrating more or less as follows: Code:
flux |
Quote:
As what you're trying to compute isn't THAT uncommon SFO has a functionObject patchFieldFlow to do it (for compressible flow there is also a rho there, but that's alright I guess) simpleFunctionObjects can't do arbitray calculations (Ux*T or so) on patches BUT swak4Foam can. The functionObjects there that can do that are patchExpression or swakExpression and they are based on SFO Bernhard |
Quote:
First of all: thanks for your answer ! I was doing some tries with swak4foam before I saw your reply. First of them, I tried to change (naively...) the "functionObjectsLibs" into that: Code:
flux I was then looking at the wiki page (nice job for this contrib, btw) checking for examples. I couldn't find one that can help me. Do you have any hints considering that? Meanwhile, I'll continue to dig all of this. Best Regards, |
Quote:
I hope to find the time to update the swak-Wiki-page when I find time (which should be hopefully before my retirement). Until then I welcome any contributions on it Bernhard |
Thank you so much. I was just about to leave a message saying I did use this example. I'm waiting for the calculation results.
I'll post what I did if effective (hopefully!) |
Quote:
|
If you don't mind, I'd rather post it here (or send you by email) first because if it works, it's a highly not straight forward way to do it I fear... :-p
Let's wait and see |
I finally manage to realize my RTD! :)
The problem I had about integrating Ux and T together is solved. Here's what I used (it's definitely not the best way to do so, but that's a start): First thing, in my case I admitted that Ux=magU (as the flow is almost perfectly unidirectional). In controlDict, I input: Code:
functions 2) I'm not sure if the dflux "patches" is correct or if the calculation is made everywhere... As I said, it's highly inefficient compare to what's possible to do, but that's a start. I wait for your comments before putting my example in the swak4foam wiki (if it's not too crappy:D) Have a nice weekend :) |
Quote:
You don't have to go through the expressionField. libsimpleSwakFunctionObjects.so already has what you need: Code:
temperatureSum Code:
temperatureSum Bernhard |
thanks for your answer.
I didn't want to use the patchExpression with "sum" because I thought it was only for an addition. I didn't push it further...:o Quote:
[EDIT]: I tried to use your expression (to compare results) but I'm having some trouble with. It can't find the "linsimpleSwakFunctionObjects.so" apparently. Don't know what's wrong, I did "wclean" and "wmake" again, but it seems there's a problem with it. With OF1.7, I guess that's normal (as you put in your README) but with OF1.6dev, it should work... |
Hi,
To get to grips with the simpleFunctionObjects and swak4Foam I created a modified PD case to pisoFoam and injected scalarTransport into it - scalar T. I want to track the very uninteresting change of T in the domain and on the boundary. In the blockMeshDict I named all my blocks "domain". I failed to create an expression for the difference of patchFieldFlow @ the inlet and outlet - main aim is to replicate the sumT expression with only boundary information only. Later I realized that I cannot reproduce the patchFieldFlow simpleFuncuntionObject with swak ... At first I tried to somehow name (save) the two patchFieldFlow and make a subtraction. Is it possible to name / save it or to combine this with swak4Foam? My pure swak was crap as well ... For the new sumT expression the timeStep information is necessary, how can one obtain the timeStep within swak? There's some very similar stuff in the Examples / groovyBC / pulsedPitzDaily but I couldn't put it into practise. Code:
functions |
Quote:
http://openfoamwiki.net/index.php/Ma...ver_is_writing That means multiplying the surface is not necessary (actually it is wrong). Also remote variables only work correctly if they are uniform. So for your difference you'll have to do the sums on the patches (inFlowT{inlet}=sum(phi*T)) and on the internalField accumulate the difference with min, max or average (they all should give the same result). Whether checking for the "conservation of temperature" makes physical sense of course depends on your solver |
4 Attachment(s)
Thank for the assistance!
With your advices I managed to pull it through, big thank you! The only thing that still puzzles me is the slight difference in the the values - volume integration of the scalar and the calculated value based on the boundary flows. The latter gets accumulated in a variable, so there will be some error as the simulation progresses. But what causes the relatively big difference at the start, and the error wouldn't grow afterward, albeit it is not constant - quite strange! Attached the plots. I attach the case since I usually find them quite useful if there's an attached project on the threads. So, the attachment contains a very simple extended pisoFoam solver with a scalar transport equation in it. The case is the pitzDaily with a scalar injected on the inlet. I used groovyBC to partition just the middle section of the inlet. I use simpleFunctionObjects and swakExpressions to track the evolution of the T scalar in the domain. I tried to replicate some functionalities with swak just to get some things sorted and learn a bit. At the end of the simulation pyFoam generates the plots. |
Quote:
Anyway: I don't think that the initial error is something to worry about. The relative error at the first time-step is (judging from your diagram) approx 10% and rapidly becoming smaller. Possible explanations are: the solution is not "totally correct" (try changing the tolerances of the linear solver and see if that error changes), error in the interpolation to the patches, time discretization: the summation at the patches is a pure explicit Euler while the other stuff depends on whatever scheme you chose for ddt |
Quote:
I am wondering how swak4foam and the libsimpleSwakFunctionObjects.so library compute exactly the integrals, I mean accuracy and method. Thanks! Best! |
Quote:
|
Quote:
Now I'm trying to integrate an expression on a patch via swak4foam. To do it I'd need the value of a field on another patch... I wonder if you could tell me how to do it with swakExpression. Also, I'd need the time derivative of the velocity as I set an uniform velocity ramp at the inlet but I got the next message when I use the "ddt" function: Code:
--> FOAM FATAL ERROR: Code:
dUdt Thanks for your attention!! Best! |
Quote:
- which OF-version - which swak-version - the fatal-error is without any context (so I could only guess what is going on). Try the following: "export FOAM_ABORT=1" and rerun. This should yield a stacktrace which would be helpful to see WHERE this is happening - what is "expected results" and what are the results you get? |
Quote:
Code:
{ Thank you so much, Bernhard!! Best! |
Quote:
|
Quote:
Best, |
Quote:
Usually the best way is to sit down with a piece of paper "If the flow goes the BC is a Dirichlet condition with this expression else a Neuman with this gradient expression". Implementing this in groovyBC is then pretty straightforward (if you understand the meaning of the phi-field - but this has been explained numerous times here on the MessageBoard and on the Wiki) |
Hello everyone
I'm facing similar problem, I want to calculate surface integral of velocity multiplied by temperature in order to compute bulk temperature at each longitudinal position of a heated pipe and therefore Nusselt number in flow direction. Do you have any idea how to implement it by swak4foam? Thanks in advance |
Dear Bernhard,
I am troubling you again... I want to create a new/derived field and write it at the output time. lets visualize a new volScalarField of mag(U). I found out there three ways to do it--- 1. edit the application/code (I want to omit this option) 2. using Swak4foam with expressionField. I tried the following in controlDict, Quote: velocityMagSquared { type expressionField; //outputControl outputTime; //outputInterval 1; fieldName UMag2; expression "U&U"; autowrite true; } I also get the output file written in the corresponding output/time directory. But problem is paraview do not import thes new field, it do not have this information. (also how do swak4Foam decide weather to create a volScalarfield or volVectorfield ) the last way is using coded function/dynamic code, I tried this, by adding the following lines in controlDict Quote: compute_ptot { functionObjectLibs ( "libutilityFunctionObjects.so" ); type coded; enabled true; redirectType ptot; // outputControl outputTime; // outputInterval 1; code #{ const volVectorField& U = mesh().lookupObject<volVectorField>("U"); volScalarField ptot ( IOobject ( "ptot", mesh().time().timeName(), U.mesh(), IOobject::NO_READ, IOobject::AUTO_WRITE ), mag(U) ); #}; } I neither get any new file in the corresponding output/time directory nor any visualization..:confused::confused::confused: Please give me some suggesions with option 2 or 3. I am trying this in OF 3.x and using following libraries, Quote: libs ( "libOpenFOAM.so" "libsimpleSwakFunctionObjects.so" "libswakFunctionObjects.so" "libgroovyBC.so" "mylibfvOptions.so" ); Thanks, |
Quote:
Quote:
Quote:
Quote:
|
Hi again Bernhard,
I'd like to integrate a velocity component across an interpolated plane in a 2D, O-grid. I usually dealt with swakExpressions and patch or volumes integrations. In this case, I have to fix the plane where integrating across. Can you tell me how to proceed with your tool? Thanks in advance! Best |
All times are GMT -4. The time now is 05:48. |