CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

How to calculate the Gradient of velocity fields?

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By Yann
  • 1 Post By nnprashant
  • 1 Post By Yann
  • 1 Post By Yann
  • 1 Post By Nafiz375

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 22, 2024, 13:10
Default How to calculate the Gradient of velocity fields?
  #1
New Member
 
Nafiz Ahmed Khan
Join Date: Nov 2023
Location: Canada
Posts: 27
Rep Power: 2
Nafiz375 is on a distinguished road
I'm using openFoam v2306 and trying to calculate the gradients of velocity fields during each iteration. I have used the code below in system/controlDict:

Code:
grad1
{
        type            grad; 
        libs            (fieldFunctionObjects); 
        field
        {
            U; 
        }
		enabled         true;
		log             true;
		timeStart       0;
		timeEnd         4000;
		executeControl  timeStep;
		executeInterval 1;
		writeControl    timeStep;
		writeInterval   100;    
}
But I couldn't find any results in the saving files (i.e., 100,200 ... iterations). How can I solve this issue, any suggestions?
Nafiz375 is offline   Reply With Quote

Old   July 23, 2024, 03:17
Default
  #2
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,169
Rep Power: 27
Yann will become famous soon enough
Hello Nafiz,

There is a syntax error in your function definition. You should not even be able to run the solver.

Your field parameter should be defined like this:

Code:
field			U;
You can have a look at the documentation, and check the tutorials mentioned in it: https://doc.openfoam.com/2306/tools/...ts/field/grad/

Cheers,
Yann
Nafiz375 likes this.
Yann is offline   Reply With Quote

Old   July 23, 2024, 10:23
Default
  #3
New Member
 
Engineer
Join Date: Mar 2013
Posts: 27
Rep Power: 13
nnprashant is on a distinguished road
grad1
{
// Mandatory entries
type grad;
libs (fieldFunctionObjects);
field U;

// Optional (inherited) entries
result gradU;
region region0;
enabled true;
log true;
timeStart 0.25;
timeEnd 1000;
executeControl timeStep;
executeInterval 5;
writeControl timeStep;
writeInterval 25;
}

This should resolve your isse
Nafiz375 likes this.
nnprashant is offline   Reply With Quote

Old   July 23, 2024, 10:45
Default
  #4
New Member
 
Nafiz Ahmed Khan
Join Date: Nov 2023
Location: Canada
Posts: 27
Rep Power: 2
Nafiz375 is on a distinguished road
Hello
I've modified the code and still I couldn't find any results. Where should I be able to check the results. The modified code:
Code:
application     simpleFoam;

startFrom       latestTime;
startTime       0;
stopAt          endTime;
endTime         100;
deltaT          1;
writeControl    timeStep;
writeInterval   100;
purgeWrite      0;
writeFormat     binary;
writePrecision  12;
writeCompression uncompressed;
timeFormat      general;
timePrecision   6;
runTimeModifiable yes;

grad1
{
// Mandatory entries
type grad;
libs (fieldFunctionObjects);
field U;

// Optional (inherited) entries
result gradU;
region region0;
enabled true;
log true;
timeStart 0;
timeEnd 100;
executeControl timeStep;
executeInterval 1;
writeControl timeStep;
writeInterval 100;
}
Nafiz375 is offline   Reply With Quote

Old   July 23, 2024, 10:52
Default
  #5
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,169
Rep Power: 27
Yann will become famous soon enough
You should have a new gradU variable (file) in your timestep directories.
Did you re-run your simulation?
Nafiz375 likes this.
Yann is offline   Reply With Quote

Old   July 23, 2024, 10:54
Default
  #6
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,169
Rep Power: 27
Yann will become famous soon enough
Quote:
Originally Posted by Nafiz375 View Post
Code:
application     simpleFoam;

startFrom       latestTime;
startTime       0;
stopAt          endTime;
endTime         100;
deltaT          1;
writeControl    timeStep;
writeInterval   100;
purgeWrite      0;
writeFormat     binary;
writePrecision  12;
writeCompression uncompressed;
timeFormat      general;
timePrecision   6;
runTimeModifiable yes;

grad1
{
// Mandatory entries
type grad;
libs (fieldFunctionObjects);
field U;

// Optional (inherited) entries
result gradU;
region region0;
enabled true;
log true;
timeStart 0;
timeEnd 100;
executeControl timeStep;
executeInterval 1;
writeControl timeStep;
writeInterval 100;
}
This is not the proper syntax. Your function object should be enclosed in a functions {} block.

Please check the syntax here: https://doc.openfoam.com/2306/tools/...ects/#run-time
Nafiz375 likes this.
Yann is offline   Reply With Quote

Old   July 23, 2024, 10:57
Default
  #7
New Member
 
Nafiz Ahmed Khan
Join Date: Nov 2023
Location: Canada
Posts: 27
Rep Power: 2
Nafiz375 is on a distinguished road
Hello Yann,
Yes I rerun the simulation after modifying the code.
Still, I couldn't find any results in the timestep. Only epsilon, K, Nut, P,phi and U are available.
What to do ?
Best Nafiz
Nafiz375 is offline   Reply With Quote

Old   July 23, 2024, 11:10
Default
  #8
New Member
 
Nafiz Ahmed Khan
Join Date: Nov 2023
Location: Canada
Posts: 27
Rep Power: 2
Nafiz375 is on a distinguished road
Hello Yann,
This the modified code:
Code:
functions
{
	gradU
	{
		// Mandatory entries
		type grad;
		libs (fieldFunctionObjects);
		field U;

		// Optional (inherited) entries
		result gradU;
		region region0;
		enabled true;
		log true;
		timeStart 0;
		timeEnd 100;
		executeControl timeStep;
		executeInterval 1;
		writeControl timeStep;
		writeInterval 100;
	}
}
But now my simulation stops after iteration 1. This error appears:
Code:
Time = 1

smoothSolver:  Solving for Ux, Initial residual = 1, Final residual = 0.0240735220355, No Iterations 1
smoothSolver:  Solving for Uy, Initial residual = 1, Final residual = 0.02458226803, No Iterations 1
smoothSolver:  Solving for Uz, Initial residual = 0.999999999999, Final residual = 0.0136152165375, No Iterations 1
GAMG:  Solving for p, Initial residual = 1, Final residual = 0.0910537418564, No Iterations 11
time step continuity errors : sum local = 1.04300070627e-05, global = 3.76833088599e-06, cumulative = 3.76833088599e-06
smoothSolver:  Solving for epsilon, Initial residual = 1, Final residual = 0.0561016871376, No Iterations 4
smoothSolver:  Solving for k, Initial residual = 1, Final residual = 0.0604477590299, No Iterations 4
ExecutionTime = 3.45 s  ClockTime = 4 s



--> FOAM FATAL ERROR: (openfoam-2306)
Attempted non-const reference to const object: tmp<N4Foam14GeometricFieldINS_6TensorIdEENS_12fvPatchFieldENS_7volMeshEEE>

    From T& Foam::tmp<T>::ref() const [with T = Foam::GeometricField<Foam::Tensor<double>, Foam::fvPatchField, Foam::volMesh>]
    in file ./src/OpenFOAM/lnInclude/tmpI.H at line 255.

FOAM aborting

[stack trace]
=============
#1  Foam::error::simpleExit(int, bool)sh: 1: addr2line: not found
 addr2line failed
#2  ?sh: 1: addr2line: not found
 addr2line failed
#3  ?sh: 1: addr2line: not found
 addr2line failed
#4  Foam::functionObjects::grad::calc()sh: 1: addr2line: not found
 addr2line failed
#5  Foam::functionObjects::fieldExpression::execute()sh: 1: addr2line: not found
 addr2line failed
#6  Foam::functionObjects::timeControl::execute()sh: 1: addr2line: not found
 addr2line failed
#7  Foam::functionObjectList::execute()sh: 1: addr2line: not found
 addr2line failed
#8  Foam::Time::run() constsh: 1: addr2line: not found
 addr2line failed
#9  Foam::Time::loop()sh: 1: addr2line: not found
 addr2line failed
#10  ?sh: 1: addr2line: not found
 addr2line failed
#11  ?sh: 1: addr2line: not found
 addr2line failed
#12  __libc_start_mainsh: 1: addr2line: not found
 addr2line failed
#13  ?sh: 1: addr2line: not found
 addr2line failed
=============
Aborted (core dumped)
Nafiz375 is offline   Reply With Quote

Old   July 23, 2024, 11:38
Default
  #9
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,169
Rep Power: 27
Yann will become famous soon enough
Not sure about your error.

I don't think this is related, but you can remove these lines:

Code:
timeStart 0;
timeEnd 100;
It doesn't make sense to stop the function at 100 iterations since you are asking to write the result every 100 iterations.

In order to sort things out, you can also try to remove these ones:

Code:
result gradU;
region region0;
Yann is offline   Reply With Quote

Old   July 23, 2024, 11:48
Default
  #10
New Member
 
Nafiz Ahmed Khan
Join Date: Nov 2023
Location: Canada
Posts: 27
Rep Power: 2
Nafiz375 is on a distinguished road
Hello Yann,
Still, the same issue exists. The updated code is:
system/controlDict:

Code:
application     simpleFoam;
startFrom       latestTime;
startTime       0;
stopAt          endTime;
endTime         100;
deltaT          1;
writeControl    timeStep;
writeInterval   50;
purgeWrite      0;
writeFormat     binary;
writePrecision  12;
writeCompression uncompressed;
timeFormat      general;
timePrecision   6;
runTimeModifiable yes;

functions
{
	gradU
	{
		// Mandatory entries
		type grad;
		libs (fieldFunctionObjects);
		field U;
		// Optional (inherited) entries
		enabled true;
		log true;
		executeControl timeStep;
		executeInterval 1;
		writeControl timeStep;
		writeInterval 50;
	}
}
Nafiz375 is offline   Reply With Quote

Old   July 23, 2024, 12:05
Default
  #11
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,169
Rep Power: 27
Yann will become famous soon enough
Not sure what is going on, the function definition looks OK.
Yann is offline   Reply With Quote

Old   July 23, 2024, 12:08
Default
  #12
New Member
 
Nafiz Ahmed Khan
Join Date: Nov 2023
Location: Canada
Posts: 27
Rep Power: 2
Nafiz375 is on a distinguished road
Thanks, YANN, for the comments.

The above problem was solved. I just deleted some lines from system/fvSolution:

Code:
cache
{
    grad(U);
}
Yann likes this.

Last edited by Nafiz375; July 23, 2024 at 16:51.
Nafiz375 is offline   Reply With Quote

Reply

Tags
gradient calculation


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate fields and profiles for velocity time average and standard deviation pbachant OpenFOAM Post-Processing 11 August 16, 2019 06:24
serial udf to parallel udf radioss Fluent UDF and Scheme Programming 10 January 19, 2019 08:56
Same pressure gradient but different velocity field TurbJet Main CFD Forum 22 April 28, 2018 03:35
how to calculate dot product of velocity vector and temperature gradient ramin_rz Fluent UDF and Scheme Programming 2 March 13, 2016 16:57
Variables Definition in CFX Solver 5.6 R P CFX 2 October 26, 2004 02:13


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