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

forAll loop getting stuck? I'm stuck too!

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 10, 2013, 20:25
Default forAll loop getting stuck? I'm stuck too!
  #1
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 12
CHARLES is on a distinguished road
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)
    )
This is the part from my .C file that isn't working (the .C is attached too)

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);
    }
}
I tried defining alphadCheck_ as 'const volScalarField& alphadCheck_(fvc::grad(k_) & fvc::grad(omega_));' and that caused the following error:
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$
I also tried changing the second 'if' for an 'else' and it made no difference.

Thank you for your help... I've been stuck on this for a month and have nobody to ask questions to!
Attached Files
File Type: txt y_direction_upto_0.03.txt (14.6 KB, 2 views)
File Type: txt y_direction_whole_domain.txt (18.1 KB, 2 views)
File Type: c kOmega2006.C (7.9 KB, 6 views)
CHARLES is offline   Reply With Quote

Old   October 11, 2013, 03:14
Default
  #2
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
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.
Bernhard is offline   Reply With Quote

Old   October 11, 2013, 11:12
Default
  #3
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 12
CHARLES is on a distinguished road
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> >)’
When I try to get rid of the for loop and use:
Code:
if (alphadCheck_ <= 0.0)
    {
    alphad_=scalar(0);
    }else 
    {
    alphad_=scalar(0.125);
    }
I get another compile error:
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!
CHARLES is offline   Reply With Quote

Old   October 11, 2013, 11:20
Default
  #4
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
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.
Bernhard is offline   Reply With Quote

Old   October 11, 2013, 12:14
Default
  #5
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 12
CHARLES is on a distinguished road
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.
CHARLES is offline   Reply With Quote

Old   October 11, 2013, 13:59
Default
  #6
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
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
Apparently, the other one calls a nameless function (see also the error message). My C++ knowledge is not that developed, but I think it calls the "()" operator of the type volScalarField (since Foam:) is probably not defined), which does not accept the given arguments. I am very unsure about this, so I hope some-one can correct/confirm something here
Bernhard is offline   Reply With Quote

Old   October 11, 2013, 16:46
Default
  #7
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 12
CHARLES is on a distinguished road
Gotcha! Thank you again for helping me out.
CHARLES is offline   Reply With Quote

Reply


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
[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


All times are GMT -4. The time now is 00:02.