
[Sponsors] 
May 22, 2014, 05:34 
if (magSqr(fvc::grad(T)) != 0)

#1 
New Member
Gennaro
Join Date: May 2014
Posts: 23
Rep Power: 12 
Dear all,
I need to solve the following equation in OpenFOAM as a part of an algorithm: Keff = (Foam:ow(fInv/magSqr(fvc::grad(T)),scalar(1.)/scalar(3.)))/(rho*Cp); The problem is that when grad(T) = (0 0 0), e.g on the first iteration, the ratio becomes infinite and the solver understandably crashes. Therefore I tried to to something like: if (magSqr(fvc::grad(T)) != 0) { Keff = (Foam:ow(fInv/magSqr(fvc::grad(T)),scalar(1.)/scalar(3.)))/(rho*Cp); } else { Keff = (Foam:ow(fInv/(dimensionedScalar("small", dimensionSet(0,2,0,2,0), 1e4)),scalar(1.)/scalar(3.)))/(rho*Cp); } Unfortunately this won't compile returning the error error: no match for ‘operator==’ in ‘Foam::magSqr(const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]() == 0’ Please find the whole solver in attachment and a case to test it. Please note that I'm not a programmer and I'm just starting to learn C++. Forgive me if the answer is too obvious. Thanks and best regards Gennaro 

May 22, 2014, 07:25 

#2  
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 
Quote:
That template error says that there is no 'operator==' in GeometricField that takes '0' scalar value as the second argument. If you want to stabilize your gradient, don't use ifthenelse, you can stabilize it using SMALL (1e15 for a double scalar). For example, check out Code:
$WM_PROJECT_DIR/src/finiteVolume/cfdTools/general/include/setDeltaT.H Code:
scalar maxDeltaTFact = maxCo/(CoNum + SMALL);
__________________
When asking a question, prepare a SSCCE. 

May 22, 2014, 08:53 

#3 
New Member
Gennaro
Join Date: May 2014
Posts: 23
Rep Power: 12 
Thanks Tomi,
Actually both != and == were attempts returning the same error message: no match for ‘operator==’or no match for ‘operator!='. So, the operator itself was not the problem. Thanks a lot for your tip, it's very interesting. However, while SMALL is nondimensional, I need a SMALL scalar with the right dimensions. Indeed, while with SMALL the solver would still compile, then when I run the case I get: > FOAM FATAL ERROR: LHS and RHS of + have different dimensions dimensions : [0 2 0 2 0 0 0] + [0 0 0 0 0 0 0] Any tips on how to apply dimensions to SMALL? Thanks Gennaro 

May 22, 2014, 09:48 

#4  
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 
Quote:
To give a scalar a dimension, include "dimensionedType.H" in the library code. Do not insert it into 'Make/files' for compilation  it's a class template. Then you can instantiate a dimensionedScalar: Code:
dimensionedScalar smallGrad ("small", gradT.dimensions(), SMALL);
__________________
When asking a question, prepare a SSCCE. 

May 23, 2014, 11:12 

#5 
New Member
Gennaro
Join Date: May 2014
Posts: 23
Rep Power: 12 
Thanks Tomi,
your help is incredibly valuable. Congratulations! I gave it a try, but it doesn't work. With reference to the case in attachment, I added Code:
#include "dimensionedType.H Then I added Code:
dimensionedScalar smallGrad ("small", gradT.dimensions(), SMALL); Finally, I changed the formula in Eeqn.H to Code:
Keff = (Foam::pow(fInv/magSqr(fvc::grad(T) + small),scalar(1.)/scalar(3.)))/(rho*Cp); Can you please advise? Thanks Genn 

May 26, 2014, 08:46 

#6  
New Member
Gennaro
Join Date: May 2014
Posts: 23
Rep Power: 12 
Hi Tomi, any news?
The error is: Code:
createFields.H:123:40: error: ‘gradT’ was not declared in this scope Code:
#include "dimensionedType.H" I look forward to hearing from you Thanks Genn Quote:


February 4, 2016, 11:32 

#7  
Member
Avdeev Evgeniy
Join Date: Jan 2011
Location: Togliatty, Russia
Posts: 69
Blog Entries: 1
Rep Power: 21 
Quote:
Hi, Genn. I am not sure, that it optimal way to get gradT, but you can try Code:
surfaceVectorField gradT = fvc::interpolate(fvc::grad(T)); surfaceScalarField sumGradT = gradT.component(vector::X)+gradT.component(vector::Y)+gradT.component(vector::Z); 

Tags 
algorithm, c++, grad(t), operator 
Thread Tools  Search this Thread 
Display Modes  

