|
[Sponsors] | |||||
|
|
|
#1 |
|
New Member
Volker Tritschler
Join Date: Jan 2010
Posts: 20
Rep Power: 17 ![]() |
Hi all,
I have a problem with a task, which seemed to be straight-forward to solve at first. I need to program an if-loop in order to compare one volScalarField (P1) to another one (P2), and for each grid point, where P1 >= P2, a certain value (d) has to be written to another volScalarField (N) at exactly the same grid point. I wrote something like: (a, b, c, d are placeholder for arbitrary volScalarFields) Code:
volScalarField P1 = a;
volScalarField P2 = b;
volScalarField N = c;
if (P1 >= P2)
{
N = d;
}
else
{
N = -d;
}
It's more that it just compares just one (the first?!) point of P1 with P2. Right now, I don't have any idea how to get rid of that problem, though it seems to be a very silly one. Thanks for any idea. greets, volker |
|
|
|
|
|
|
|
|
#2 |
|
Senior Member
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,912
Rep Power: 37 ![]() ![]() |
Hi,
you have to loop over your cells to compare information in each point: Code:
forAll(P1, cellI)
{
if (P1[cellI] > P2[cellI])
{
N[cellI] = ...
}
else
{
...
}
}
__________________
Alberto Passalacqua GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as in both physical and virtual formats (current status: http://albertopassalacqua.com/?p=1541) OpenQBMM - An open-source implementation of quadrature-based moment methods. To obtain more accurate answers, please specify the version of OpenFOAM you are using.
|
|
|
|
|
|
|
|
|
#3 |
|
New Member
Volker Tritschler
Join Date: Jan 2010
Posts: 20
Rep Power: 17 ![]() |
hi alberto,
so many thanks for your help!!! It worked great. I wasn't aware of that class 'cell'. Do you know if there is a way to loop over the boundary patches as well? best volker |
|
|
|
|
|
|
|
|
#4 | ||
|
Senior Member
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,912
Rep Power: 37 ![]() ![]() |
Quote:
![]() Quote:
Code:
forAll(p.boundaryField(), patchi)
{
// Check if it's zeroGradient (optional, depending on your case)
if (isA<zeroGradientFvPatchScalarField>(p.boundaryField()[patchi]))
{
otherFieldA.boundaryField()[patchi] = 0.0;
otherFieldB.boundaryField()[patchi] = 0.0;
}
}
__________________
Alberto Passalacqua GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as in both physical and virtual formats (current status: http://albertopassalacqua.com/?p=1541) OpenQBMM - An open-source implementation of quadrature-based moment methods. To obtain more accurate answers, please specify the version of OpenFOAM you are using.
|
|||
|
|
|
|||
|
|
|
#5 |
|
New Member
Volker Tritschler
Join Date: Jan 2010
Posts: 20
Rep Power: 17 ![]() |
perfect, big thanks to you!
|
|
|
|
|
|
|
|
|
#6 |
|
Senior Member
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,912
Rep Power: 37 ![]() ![]() |
You're welcome
__________________
Alberto Passalacqua GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as in both physical and virtual formats (current status: http://albertopassalacqua.com/?p=1541) OpenQBMM - An open-source implementation of quadrature-based moment methods. To obtain more accurate answers, please specify the version of OpenFOAM you are using.
|
|
|
|
|
|
|
|
|
#7 |
|
New Member
tooran
Join Date: Nov 2016
Posts: 23
Rep Power: 11 ![]() |
I am tyring to change a viscoisty model. I need to campare strain rate with a constant parameter (gama)
if strainrate is greater than the gama then do.... so I write : ************************************************** ******************* Foam::viscosityModels::MyHerschelBulkley::calcNu() const { dimensionedScalar tone("tone", dimTime, 1.0); dimensionedScalar rtone("rtone", dimless/dimTime, 1.0); tmp<volScalarField> sr(strainRate()); forAll(calcNu.internalField(), cellI) { if (sr[cellI]< gama_.value()) { ...... It shows me the error: error : calcNu’ does not have class type forAll(calcNu.internalField(), cellI) could you please help me? MyHerschelBulkley.C MyHerschelBulkley.H |
|
|
|
|
|
|
|
|
#8 |
|
New Member
tooran
Join Date: Nov 2016
Posts: 23
Rep Power: 11 ![]() |
Can any one help me?
|
|
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Gmsh] Problem with Gmsh | nishant_hull | OpenFOAM Meshing & Mesh Conversion | 23 | August 5, 2015 03:09 |
| ForAll loop and vector comparison | juho | OpenFOAM Running, Solving & CFD | 4 | June 17, 2011 10:51 |
| [CAD formats] my stl surface is seen as just a line | rcastilla | OpenFOAM Meshing & Mesh Conversion | 2 | January 6, 2010 02:30 |
| for loop inside a cell_loop? | MHDWill | FLUENT | 0 | September 26, 2007 22:24 |
| NACA0012 geometry/design software needed | Franny | Main CFD Forum | 13 | July 7, 2007 16:57 |