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] Problem to calculate grad(U) using swak4Foam (https://www.cfd-online.com/Forums/openfoam-community-contributions/98667-problem-calculate-grad-u-using-swak4foam.html)

Hugoles March 15, 2012 16:43

Problem to calculate grad(U) using swak4Foam
 
Dear Foamers,

I need to calculate the strain rate tensor S_ij . In OpenFOAM this is made using the relation S_ij = symm(grad(U)). I am trying do this with swak4Foam (funkyDoCalc) but I just can't calculate grad(U). The error is the following:
Code:

Time = 1100
strainRate : swak4Foam: Allocating new repository for sampledGlobalVariables


--> FOAM FATAL ERROR:
 Parser Error at "1.7" :"syntax error, unexpected ')'"
"grad(U)"
"      ^"

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 718.

FOAM exiting

I can calculate grad(U.x), so I wonder if this problem has to do with how swak4Foam handles tensors. OpenFOAM can handle this expression without a problem, but it would be nice to avoid the (little) programming. Any ideas?

Thanks,

Hugo

gschaider March 15, 2012 18:06

Quote:

Originally Posted by Hugoles (Post 349726)
Dear Foamers,

I need to calculate the strain rate tensor S_ij . In OpenFOAM this is made using the relation S_ij = symm(grad(U)). I am trying do this with swak4Foam (funkyDoCalc) but I just can't calculate grad(U). The error is the following:
Code:

Time = 1100
strainRate : swak4Foam: Allocating new repository for sampledGlobalVariables


--> FOAM FATAL ERROR:
 Parser Error at "1.7" :"syntax error, unexpected ')'"
"grad(U)"
"      ^"

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 718.

FOAM exiting

I can calculate grad(U.x), so I wonder if this problem has to do with how swak4Foam handles tensors. OpenFOAM can handle this expression without a problem, but it would be nice to avoid the (little) programming. Any ideas?

Thanks,

Hugo

Had a quick look at the grammar. Seems that the gradient of a vector is currently not supported. Can't fix that today. Could you please write a bug-report so that I don't forget

Hugoles March 15, 2012 18:52

Quote:

Originally Posted by gschaider (Post 349737)
Had a quick look at the grammar. Seems that the gradient of a vector is currently not supported. Can't fix that today. Could you please write a bug-report so that I don't forget

Done! Likewise, can swak make operations over tensors such as mag(symm(grad(U))) ? Not sure if the feature is about only the grad of vectors or about tensors in general.

Thanks Bernhard,

Hugo

Hugoles March 19, 2012 16:16

2 Attachment(s)
Thanks for the patch!

I applied it to 1.6 but I still get the

Code:

Parser Error at "1.1-4" :"field grad not existing or of wrong type"
"grad(U)"
" ^^^^  "

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 724.

FOAM exiting

when I try to calculate grad(U).

Furthermore, I pulled the developing version with mercurial and I get errors when trying to recompile in OF 1.7.1 on OS X 10.6.8. I tried in a desktop and in a laptop with the same result. The recompilation in Ubuntu 11.04 showed -apparently- no errors.

Could you please take a look at the attachment ?

Thanks!

h

gschaider March 20, 2012 18:43

Quote:

Originally Posted by Hugoles (Post 350292)
Thanks for the patch!

I applied it to 1.6 but I still get the

Code:

Parser Error at "1.1-4" :"field grad not existing or of wrong type"
"grad(U)"
" ^^^^  "

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 724.

FOAM exiting

when I try to calculate grad(U).

Furthermore, I pulled the developing version with mercurial and I get errors when trying to recompile in OF 1.7.1 on OS X 10.6.8. I tried in a desktop and in a laptop with the same result. The recompilation in Ubuntu 11.04 showed -apparently- no errors.

Could you please take a look at the attachment ?

Thanks!

h

The Mac-Problem: seems like the compiler can't find any of the .H-files in your OF-installation. I can only guess why that is. Try at least removing all deb-files with rmdeball. If that still happens have a look whether directories like $FOAM_SRC/OpenFOAM/lnINclude are there

Tushar@cfd August 28, 2014 04:23

Quote:

Originally Posted by gschaider (Post 349737)
Had a quick look at the grammar. Seems that the gradient of a vector is currently not supported. Can't fix that today. Could you please write a bug-report so that I don't forget

Dear Bernhard,

I wish to use the "grad(U)" function for the inlet boundary condition for "Tau" using groovyBC. Where, U is fully developed flow.

I am getting following error message:

Code:

--> FOAM FATAL ERROR:
 Parser Error for driver PatchValueExpressionDriver at "1.18-21" :"field grad not existing or of wrong type"
"2*pow(mag(symm(grad(U))),2)"
                ^^^^
----------------|

Context of the error:

I found that very similar question was put forward in this thread, I would like to know How to overcome it?
Is "grad(U)" boundary condition possible using groovyBC?

I am using OF-2.1.x installed on Ubuntu 11.04

Thanks in advance!

gschaider August 28, 2014 05:07

Quote:

Originally Posted by Tushar@cfd (Post 508127)
Dear Bernhard,

I wish to use the "grad(U)" function for the inlet boundary condition for "Tau" using groovyBC. Where, U is fully developed flow.

I am getting following error message:

Code:

--> FOAM FATAL ERROR:
 Parser Error for driver PatchValueExpressionDriver at "1.18-21" :"field grad not existing or of wrong type"
"2*pow(mag(symm(grad(U))),2)"
                ^^^^
----------------|

Context of the error:

I found that very similar question was put forward in this thread, I would like to know How to overcome it?
Is "grad(U)" boundary condition possible using groovyBC?

I am using OF-2.1.x installed on Ubuntu 11.04

Thanks in advance!

grad is not available on patches (simply because OF doesn't have it). snGrad is. That is the gradient in the direction of the surface normal

Tushar@cfd August 28, 2014 05:46

Thank you for quick reply.

frantov September 22, 2014 21:32

Hi Hugo
I need to develop a similar script to plot the strain rates. did you have any success?
Regards
f

Tushar@cfd September 23, 2014 00:16

Quote:

Originally Posted by frantov (Post 511386)
Hi Hugo
I need to develop a similar script to plot the strain rates. did you have any success?
Regards
f

Use snGrad(U) instead of grad(U) as pointed out by Bernhard in his post.

Quote:

grad is not available on patches (simply because OF doesn't have it). snGrad is.
-
Best Luck!

Hugoles September 24, 2014 22:38

Quote:

Originally Posted by frantov (Post 511386)
Hi Hugo
I need to develop a similar script to plot the strain rates. did you have any success?
Regards
f

Hello Frantov,

Yes, you can calculate grad(U) using expressionField and then manipulate the result as with any other field. This way, you could calculate the instantaneous rate of strain and then control the averaging process as convenient. I do this in controlDict and not with funkyDoCalc as I tried originally.

Hope it helps,

ArathoN September 25, 2014 19:07

doesn't openfoam have the utility to calculate the velocity gradient? what does swakfoam do more that the preloaded utility?

JM27 November 24, 2020 10:28

what is the difference between this swak function and surfaceFieldValue?
 
Sorry to revive an old post but I am encountering a related problem.

I have been trying to compute grad(U) on wall patches using swak4Foam and built-in OF function surfaceFieldValue and compare the results. After looking at this post, I realise I have been trying to do the impossible as grad(U) is not defined on patches:

Quote:

grad is not available on patches (simply because OF doesn't have it). snGrad is. That is the gradient in the direction of the surface normal
This explains why:

Code:

extremesGradU {
        type                  swakExpression;
        valueType                        patch;
        patchName                      walls;
        verbose                            true;
        expression                "grad(U)";
        accumulations          (min max);
        outputControlMode    timeStep;
        outputInterval                      1;
        writeStartTime                  yes;
}

does not work. So far so good.

Now, if I use surfaceFieldValue to compute grad(U) on the "walls" patch, I do get an output:
Code:

maxGradUOnWalls
{
    // Mandatory entries (unmodifiable)
    type            surfaceFieldValue;
    libs            (fieldFunctionObjects);

    // Mandatory entries (runtime modifiable)
    fields          (grad(U));
    operation      max;
    regionType      patch;
    name            walls;

    // Optional entries (runtime modifiable)
    postOperation  none;
    // weightField    alpha1;
    scaleFactor    1.0;
    writeArea      false;
    surfaceFormat  none;

    // Optional (inherited) entries
    writeFields    false;
    scalingFactor  1.0;
    writePrecision  8;
    writeToFile    true;
    useUserTime    true;
    region          region0;
    enabled        true;
    log            true;
    // timeStart      0;
    // timeEnd        1000;
    executeControl  timeStep;
    executeInterval 1;
    writeControl    timeStep;
    writeInterval  1;
}


Therefore my question is: why does surfaceFieldValue compute grad(U) if grad(U) not defined on boundary patches? Perhaps I have misunderstood what surfaceFieldValue does.
Strangely enough then, if I try to compute snGrad(U) using surfaceFieldValue I do not get an output, but I do get an output for snGrad(U) in swak.

p.s. I have tested these on depthCharge2D tutorial.


All times are GMT -4. The time now is 06:10.