CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [swak4Foam] Using lookuptables in momentumSourceDict with swak4Foam (https://www.cfd-online.com/Forums/openfoam-community-contributions/102606-using-lookuptables-momentumsourcedict-swak4foam.html)

gschaider October 10, 2013 12:43

Quote:

Originally Posted by alighaffari (Post 456183)
Hello Bernhard
Do you have any tutorial or example that teach me how to define a source term from solving a PDE and how to apply it to interFoam solver. If could kindly send me any example related to this field it will be very helpful for me.
Regards
Ali Ghaffari

There isn't a ready-made example for this (and I can't guarantee that it will work for you): examples for using the PDF-functionObjects are (amongst others) in Examples/groovyBC/pulsedPitzDaily. The solution field can then be used like any other field in the expressions of the source term

alighaffari October 27, 2013 10:07

Create a new field from an expression
 
Hi Dear Bernhard
thanks for your posts, replies and "swak4Foam". I could solve a PDE using "solveLaplacianPDE" function But I have another question on the "expessionField" function. I am trying to create and calculate a new transformed velocity field using this function. I followed ,for starting, the example available in slides on swak4Foam (No C++, please. We’re users!, Bernhard F.W. Gschaider, June 2011, slide number 61/176):
---------------------------------------------------------------------------------------------------------------------------------
libs (
" libswakFunctionObjects .so"
);
functions (
liquidVel
{
type expressionField;
outputControl outputTime;
//outputInterval 1;

fieldName Uliquid;
expression "U*alpha1";
autowrite true
}
) ;
---------------------------------------------------------------------------------------------------------------------------------------

but it does not work and OpenFoam gives the following error:

---------------------------------------------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.1.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 2.1.x-0cbac23c1af5
Exec : interFoamWithSources
Date : Oct 27 2013
Time : 17:53:21
Host : "ali-pc"
PID : 2918
Case : /home/ali/OpenFOAM/ali-2.1.x/run/Afkhami2008/cylinder-radius0.2-sourceterm-PDE
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0


PIMPLE: Operating solver in PISO mode

Reading field p_rgh

Reading field alpha1

Reading field U

Reading/calculating face flux field phi

Reading transportProperties

Selecting incompressible transport model Newtonian
Selecting incompressible transport model Newtonian
Selecting turbulence model type laminar

Reading g
Calculating field g.h

time step continuity errors : sum local = 0, global = 0, cumulative = 0
DICPCG: Solving for pcorr, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 0, global = 0, cumulative = 0
Courant Number mean: 0 max: 0

Starting time loop



--> FOAM FATAL IO ERROR:
attempt to read beyond EOF

file: /home/ali/OpenFOAM/ali-2.1.x/run/Afkhami2008/cylinder-radius0.2-sourceterm-PDE/system/controlDict::functions at line 88.

From function ITstream::read(token&)
in file db/IOstreams/Tstreams/ITstream.C at line 83.

FOAM exiting
-----------------------------------------------------------------------------------------------------------------------------------
I have created the "Uliquid" file in the "0" folder based on the "U" file. I have no idea on this error message.
I'm Looking forward to some directions. your valuable time is highly appreciated.

thanks,
Ali Ghaffari

nimasam October 28, 2013 04:13

you missed semicolon in your expression, it should be like that:
Quote:

expression "U*alpha1;";

alighaffari October 28, 2013 09:23

Quote:

Originally Posted by nimasam (Post 459370)
you missed semicolon in your expression, it should be like that:

Hi Dear Nima Sam
thanks for your reply. I modified it by semicolon But again exactly the same error message appears. What else may be wrong?
thanks

gschaider October 28, 2013 18:25

Quote:

Originally Posted by alighaffari (Post 459432)
Hi Dear Nima Sam
thanks for your reply. I modified it by semicolon But again exactly the same error message appears. What else may be wrong?
thanks

Which is line 88 in your controlDict (that is the one that is mentioned in the error message you quoted. I must stress that this message means that your file is syntactically wrong. swak hasn't even seen it yet)

Is it maybe the line "autowrite true" without the semicolon?

alighaffari October 29, 2013 09:52

Hi Dear Bernhard Gschaider
yes it was the reason for error : "autowrite true" without the semicolon. thanks so much.

alighaffari November 4, 2013 11:07

Hi Dear Bernhard Gschaider
Its me again with another question. I have calculated the magnitude of the gradient of a scalar field in two ways:
1) by using the "magGrad" from "foamCalc" utility:

foamCalc magGrad distance


2) by defining a new Field in "controldict" file:
functions(
distGrad {
type expressionField;
outputControl timeStep;
outputInterval 1;
fieldName graddistance;
expression "-grad(distance)";
autowrite true;
}
);

and finally I have calculated the magnitude of the new field "graddistance".
("distance" is a new scalar field which is calculated from solving the Laplaces equation via "solveLaplacianPDE" function.)

But the results are very much different (in order of 1000000). It is so strange and confusing for me. Which way is more reliable?
I need the gradient of "distance" in the solution time. Is there any better method for its calculation?

Thank you
Regards

gschaider November 4, 2013 11:19

Quote:

Originally Posted by alighaffari (Post 460490)
Hi Dear Bernhard Gschaider
Its me again with another question. I have calculated the magnitude of the gradient of a scalar field in two ways:
1) by using the "magGrad" from "foamCalc" utility:

foamCalc magGrad distance


2) by defining a new Field in "controldict" file:
functions(
distGrad {
type expressionField;
outputControl timeStep;
outputInterval 1;
fieldName graddistance;
expression "-grad(distance)";
autowrite true;
}
);

and finally I have calculated the magnitude of the new field "graddistance".
("distance" is a new scalar field which is calculated from solving the Laplaces equation via "solveLaplacianPDE" function.)

But the results are very much different (in order of 1000000). It is so strange and confusing for me. Which way is more reliable?
I need the gradient of "distance" in the solution time. Is there any better method for its calculation?

Thank you
Regards

Could you check WHERE these differences occur? For instance by calculating the diff between the two fields with funkySetFields? My guess is that the difference is in boundary cells

alighaffari November 5, 2013 09:05

Quote:

Originally Posted by gschaider (Post 460492)
Could you check WHERE these differences occur? For instance by calculating the diff between the two fields with funkySetFields? My guess is that the difference is in boundary cells

the difference is all over the solution domain. It seems that the results from magGrad function from "foamCalc" are true. But I need the gradient over the solution time. What can I do? Is there any other Method?

gschaider November 8, 2013 17:31

Quote:

Originally Posted by alighaffari (Post 460649)
the difference is all over the solution domain. It seems that the results from magGrad function from "foamCalc" are true. But I need the gradient over the solution time. What can I do? Is there any other Method?

That's strange. "mag(grad(T))" in swak uses the same functions as magGrad. I think I need to see pictures of the differences to tell what might be the problem

alighaffari November 9, 2013 09:18

Dear Bernhard Gschaider
Thanks for your attention. I could finally find the reason of the differences. It was due to the "writePrecision" in the controlDict file. The differences were existed when the default value ,6, was chosen. But by increasing the "writePrecision" the differences decreased. finally no differences were observed by choosing the "20" for "writePrecision". I think that the "magGrad" function from "foamCalc" reads the data from written results files But the "grad" function from "swak" reads data from RAM. Please correct me if I am wrong?
thanks
Ali

gschaider November 9, 2013 19:08

Quote:

Originally Posted by alighaffari (Post 461311)
Dear Bernhard Gschaider
Thanks for your attention. I could finally find the reason of the differences. It was due to the "writePrecision" in the controlDict file. The differences were existed when the default value ,6, was chosen. But by increasing the "writePrecision" the differences decreased. finally no differences were observed by choosing the "20" for "writePrecision". I think that the "magGrad" function from "foamCalc" reads the data from written results files But the "grad" function from "swak" reads data from RAM. Please correct me if I am wrong?
thanks
Ali

Depends. funkySetFields reads from disc. But the function Objects use the field from memory.

So that problem solved itself? Fine.


All times are GMT -4. The time now is 20:12.