|
[Sponsors] |
October 10, 2013, 20:25 |
forAll loop getting stuck? I'm stuck too!
|
#1 |
Member
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 12 |
Hello all,
After a solid 8 hours of trying to figure this out, I have come to you... again I have tried just about everything I could think of and I cannot figure it out so I would really appreciate it if someone could please help me. I would like the forAll loop to assign a value to alphad_ for the corresponding cell, depending on the value of alphadCheck_ for the same cell. When I run simpleFoam and use the 'sample' utility, I can see that alphadCheck_ is a really small value (1.2732e-313) at the first cell, then it is equal to 0 for the rest of the domain (see sample outputs attached)... HOWEVER, alphad_ is being assigned the latter value from the if statement (see code below) for ALL of the domain when it should really be assigned the first since alphadCheck_=0. I know that alphadCheck_ should be 0 for the freestream but it shouldn't be so for the whole domain. In the .H file, I have defined alphad_ and alphadCheck_ as volScalarField under 'protected:' In the .C file, I have defined alphad_ and alphadCheck_ as Code:
alphad_ ( IOobject ( "alphad_", runTime_.timeName(), mesh_, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh_, dimless ), alphadCheck_ ( IOobject ( "alphadCheck_", runTime_.timeName(), mesh_, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh_, dimensionSet(0,0,-3,0,0,0,0) ) Code:
volScalarField alphadCheck_(fvc::grad(k_) & fvc::grad(omega_)); forAll(mesh_.cells(),celli) { if (alphadCheck_[celli] <= 0.0) { alphad_[celli]=scalar(0.0); }if (alphadCheck_[celli] > 0.0) { alphad_[celli]=scalar(0.125); } } Code:
#0 Foam::error::printStack(Foam::Ostream&) in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so" #1 Foam::sigSegv::sigHandler(int) in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so" #2 in "/lib/x86_64-linux-gnu/libc.so.6" #3 Foam::incompressible::RASModels::kOmega2006C12::correct() in "/home/sebastian/OpenFOAM/sebastian-2.2.0/platforms/linux64GccDPOpt/lib/libmyIncompressibleRASModels.so" #4 in "/opt/openfoam220/platforms/linux64GccDPOpt/bin/simpleFoam" #5 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6" #6 in "/opt/openfoam220/platforms/linux64GccDPOpt/bin/simpleFoam" Segmentation fault (core dumped) sebastian@navier1:~/OpenFOAM/sebastian-2.2.0/run/FlatPlates/New/545kOm2006P112$ Thank you for your help... I've been stuck on this for a month and have nobody to ask questions to! |
|
October 11, 2013, 03:14 |
|
#2 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21 |
Does this code compile even?
I am asking this, because you use > volScalarField alphadCheck_(fvc::grad(k_) & fvc::grad(omega_)); While alphadCheck_ is, according to your source file, already initialized during construction, so, you would need, instead > alphadCheck_ = (fvc::grad(k_) & fvc::grad(omega_)); I don't see any problem with your loop, although I would write > forAll( alphad_, cellI) just because it looks nicer, as it clear shows what object you are looping. You probably don't even need a loop for this, as there is probably a single expresion alphad_ = ... that would work. Last edited by Bernhard; October 11, 2013 at 06:50. |
|
October 11, 2013, 11:12 |
|
#3 |
Member
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 12 |
Thank you for replying !
The code compiles and runs... it just doesn't run right. Whenever I try your suggestion and get rid of 'volScalarField' (right before the for loop) and define alphad_ as just Code:
alphadCheck_ = (fvc::grad(k_) & fvc::grad(omega_)); I get a compile error: Code:
kOmega2006C12.C:351:47: error: no match for call to ‘(Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}) (Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >)’ Code:
if (alphadCheck_ <= 0.0) { alphad_=scalar(0); }else { alphad_=scalar(0.125); } Code:
kOmega2006C12.C: In member function ‘virtual void Foam::incompressible::RASModels::kOmega2006C12::correct()’: kOmega2006C12.C:365:22: error: no match for ‘operator<=’ in ‘alphadCheck_ <= 0.0’ kOmega2006C12.C:365:22: note: candidates are: /opt/openfoam220/src/OpenFOAM/lnInclude/UList.C:224:6: note: bool Foam::UList<T>::operator<=(const Foam::UList<T>&) const [with T = double] /opt/openfoam220/src/OpenFOAM/lnInclude/UList.C:224:6: note: no known conversion for argument 1 from ‘double’ to ‘const Foam::UList<double>&’ /opt/openfoam220/src/OpenFOAM/lnInclude/VectorSpaceI.H:693:13: note: template<class Form, class Cmpt, int nCmpt> bool Foam::operator<=(const Foam::VectorSpace<Form, Cmpt, nCmpt>&, const Foam::VectorSpace<Form, Cmpt, nCmpt>&) make: *** [Make/linux64GccDPOpt/kOmega2006C12.o] Error 1 PS:I took your advice on not using a for loop in the other instance (from a different post) and it helped clean up the code. Thank you! |
|
October 11, 2013, 11:20 |
|
#4 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21 |
Ah, you need to remove the brackets (sorry for misleading:
> alphadCheck_ = fvc::grad(k_) & fvc::grad(omega_); This if-statement is wrong, because you are comparing fields with scalars. I think function like min, max, bound are designed to handle fields and scalars as arguments, but this is something you have to find. |
|
October 11, 2013, 12:14 |
|
#5 |
Member
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 12 |
That worked. You are the man! Thank you very much.
I ended up just leaving the for loop for now. Could you explain why what I was doing was causing problems? I'm quite new to modifying OpenFOAM so I don't really understand how removing the brackets or volScalarField solved the problem... I just know that it did. |
|
October 11, 2013, 13:59 |
|
#6 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21 |
It does not really OpenFOAM, but just regular C++.
i.e: Code:
$ cat test.c int main() { int a(10); int a(10); } $ g++ test.c test.c: In function 'int main()': test.c:4: error: redeclaration of 'int a' test.c:3: error: 'int a' previously declared here |
|
October 11, 2013, 16:46 |
|
#7 |
Member
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 12 |
Gotcha! Thank you again for helping me out.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Gmsh] Problem with Gmsh | nishant_hull | OpenFOAM Meshing & Mesh Conversion | 23 | August 5, 2015 02:09 |
basic question with 'ForAll' loop | Pascal_doran | OpenFOAM Post-Processing | 10 | December 14, 2012 17:39 |
ForAll loop and vector comparison | juho | OpenFOAM Running, Solving & CFD | 4 | June 17, 2011 09:51 |
[CAD formats] my stl surface is seen as just a line | rcastilla | OpenFOAM Meshing & Mesh Conversion | 2 | January 6, 2010 01:30 |
NACA0012 geometry/design software needed | Franny | Main CFD Forum | 13 | July 7, 2007 15:57 |