CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Plotting strainRate (http://www.cfd-online.com/Forums/openfoam-programming-development/109107-plotting-strainrate.html)

Studi November 9, 2012 06:09

strainRate values
 
Hello everybody! :)

Basically I am simulating a polymer flow in an easy curved channel. I am using the nonNewtonianIcoFoam solver to do so (Changed stock dictionarys copied from tutorial). The solver uses the pressure p and the velocity U as boundary conditions. So far no problems.
What I want/need is the written values of the StrainRate (which OF is using during calculating the solutions), so that I can plot them in ParaFoam like the values for p and U, which is possible by default. Every time step folder contains phi and nu in addition to p and U already, so I conclude that there must be a possibilty to tell OF which values to plot in the time step folders, that I don't know.
Can you, the professionals, help me with that? Hopefully I could set straight the things I want.

Any help is much appreciated!


Regards
Sebastian

bioexplore November 10, 2012 06:50

Hi, Studi!

I think what u want is the return value of member function strainRate() of viscosityModel, the calculating is finished in this function. So may be the source code of this function in source file "transportmodels/incompressible/viscosityModels/viscositymodel/viscosityModel.C" Line58.
that is "sqrt(2.0)*mag(symm(fvc::grad(U_)));"

You can get this value at postprocessing step by coding, reference code is located in "OpenFOAM-2.1.1\applications\utilities\postProcessing\stress Field\stressComponents\stressComponents.C"

Here shortly, you can use
volScalarField strainRate
(
IOobject
(
"StrainRate",
runTime.timeName(),
mesh,
IOobject::NO_READ
),
sqrt(2.0)*mag(symm(fvc::grad(U_))); //this command will calcualte strainRate
);
StrainRate.write();//this will write file "StrainRate" in each time dir!!

HOPE it will help!

Studi November 12, 2012 11:45

Hi bioexplore! Thanks for your hints...

You understand correctly. Unfortunately your method didn't work. And I can't find any connection between the nonNewtonianIcoFoam solver and the stressComponents.H file. Why do I have to place it there? Or is ParaFoam using this file?
Another question: The time step folders are containing 4 files! U, p, nu and Phi. Why can't ParaFoam show the values of Phi but all other values?:confused:

According to the Wiki here:
http://openfoamwiki.net/index.php/In...ect_and_fields
the code differs a little from yours. Any idea on this? I already tried it like this, but my time folders don't contain anything else when simulating the case again.:mad:

Thanks!

Regards
Sebastian

bioexplore November 13, 2012 04:53

Hi, Studi
You must write code and compile it as a tool, just like the tool of stressComponets done. You can use stressComponents.C as template and write your own code to do what you want (like the code I wrote) into the template source file, use wmake to compile it, You can put the new source file to $WM_PROJECT_USER_DIR/application/ and rename it as you wish, then following compiling instruction in user manual. After compile you own tool, you can get the tool.
Run your simulation, then at the case dir, run you new compiled tool and it will generate the field in each time directory, after that you can postprocessing with the strainrate field.

Hope it will help you!

Studi November 13, 2012 10:22

Hi bioexplore!

Thanks to enlighten me! :)
Now a lot more things are clear.

Unfortunately I am not capable op compiling my new tool. Typing wmake shows up an error.
Code:

stressComponents.C: In Funktion »int main(int, char**)«:
stressComponents.C:217:10: Fehler: Aufruf des überladenen »sqrt(double)« ist nicht eindeutig

The translation means as much as "Error: Call of overloaded 'sqrt (double)' is ambiguous"
The adressed line 217 contains the calculation of my strainRate:
Code:

sqrt(2.0)*mag(symm(fvc::grad(U)))
Do you have any idea how to manage this? I am not well-versed with c++ and a websearch didn't bring up the wanted solution. Thanks a lot again! :)

Regards
Sebastian

bioexplore November 13, 2012 23:40

Hi, Studi

I am not quite sure what cause this compiling error, I guess maybe compiler is confused between std::sqrt(double) and foam::sqrt(double) ???

bioexplore

Studi November 14, 2012 02:55

Well, right now I don't know why it gives this error, but I managed to compile it by replacing the
Code:

sqrt(2.0)
with the static value
Code:

1.414213562
Thanks to your help, the new utility works fine now! ;)
I just have to confirm the new results.


Regards
Sebastian

emil November 14, 2012 04:11

Hello Sebastian,

sorry to bother you but I would need the same thing and I am quite new to OF. So I would kindly ask you if you could send me this piece of code and explain the procedure a little bit. Also is the nonNewtonianIcoFoam working ok with your case? because I have the problem already with the pressure equation doing 1001 it. to achieve accuracy.

Regards,

Emil

Studi November 14, 2012 04:13

I got it working now with a little change...
Placing the value in the sqrt function as a float makes the compiler work.
My code looks as follows for now.

Code:

volScalarField strainRate
        (
        IOobject
        (
        "strainRate",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ
        ),
        sqrt(2.0f)*mag(symm(fvc::grad(U))) //this command will calculate strainRate
        );
        strainRate.write();//this will write file "StrainRate" in each time dir!!

Regards
Sebastian

Studi November 14, 2012 04:23

Quote:

Originally Posted by emil (Post 391998)
Hello Sebastian,

sorry to bother you but I would need the same thing and I am quite new to OF. So I would kindly ask you if you could send me this piece of code and explain the procedure a little bit. Also is the nonNewtonianIcoFoam working ok with your case? because I have the problem already with the pressure equation doing 1001 it. to achieve accuracy.

Regards,

Emil

I have sent you a PM.

Sebastian

bagherij July 22, 2015 20:24

where should add
 
Quote:

Originally Posted by Studi (Post 391999)
I got it working now with a little change...
Placing the value in the sqrt function as a float makes the compiler work.
My code looks as follows for now.

Code:

volScalarField strainRate
    (
    IOobject
    (
    "strainRate",
    runTime.timeName(),
    mesh,
    IOobject::NO_READ
    ),
    sqrt(2.0f)*mag(symm(fvc::grad(U))) //this command will calculate strainRate
    );
    strainRate.write();//this will write file "StrainRate" in each time dir!!

Regards
Sebastian

Dear Sebastian
i have same problem ,where should i add this code.
Thanks


All times are GMT -4. The time now is 14:09.