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

Conditional statement over the entire mesh

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   November 23, 2010, 07:16
Default Conditional statement over the entire mesh
  #1
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 7
xisto is on a distinguished road
Send a message via MSN to xisto
Dear All,

I want to do an if conditional statement for two variables witch are surfaceScalarFields (MR_N and ML_N).

The code compile without erros, on the other and this will result in a infinite loop.


Code:
forAll(mesh.faces(),faceI)   


  {

 if(mag(MR_N[faceI]) >= scalar(1.0)) 
     {
      
         surfaceScalarField            M4_neg = M1_neg; 
         surfaceScalarField            P5_neg = 1.0/(2.0*MR_N)*(MR_N-mag(MR_N)); 

    

   if(mag(ML_N[faceI]) >= scalar(1.0)) /

      {
         surfaceScalarField     M4_pos = M1_pos; 
         surfaceScalarField     P5_pos = 1.0/(2.0*ML_N)*(ML_N+mag(ML_N)); 
      }
      
  }
Any suggestions?

Cheers

Carlos
xisto is offline   Reply With Quote

Old   November 23, 2010, 09:33
Default
  #2
New Member
 
Patricia
Join Date: Oct 2010
Posts: 22
Rep Power: 6
schmittp54 is on a distinguished road
I didn't run the example, but I don't see why it should be an infinite loop. Is it just your impression? Did you debug the loop, printing faceI and mesh.faces().size()?

The first if-clause is missing a "}" which can result in weird effects. Besides that, it should give a compiler error.

The real problem seems to be that you create up to four new surfaceScalarFields per iteration. Depending on the implementation and your mesh size this can be extremely slow. You didn't mention the purpose of this code. But M4_neg...M5_pos are only visible in their surrounding if-clauses and go out of scope again.

Maybe what you want is:
  • Create M4_neg...P5_pos outside of the for-loop
  • Inside the if-clauses set M4_neg[faceI] = M1_neg[faceI]; and respectively the other fields
Patricia
schmittp54 is offline   Reply With Quote

Old   November 23, 2010, 09:43
Default
  #3
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 7
xisto is on a distinguished road
Send a message via MSN to xisto
Dear Patricia,

Thanks for your reply

The missing a "}" is just a typo.

I didn't run a debug, I'm not an expert in C++ and I'm just trying to understand if mine implementation is correct.

I will follow your suggestion.

Carlos
xisto is offline   Reply With Quote

Old   November 23, 2010, 10:14
Default
  #4
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 7
xisto is on a distinguished road
Send a message via MSN to xisto
Dear Patricia,

Your solution for the problem works.

Thanks

Carlos
xisto is offline   Reply With Quote

Old   November 24, 2010, 10:11
Default
  #5
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 7
xisto is on a distinguished road
Send a message via MSN to xisto
Dear Patricia,

I follow your solution and my first impression was that it works.

But now Its giving me the following error:

#0 Foam::error:rintStack(Foam::Ostream&) in "/opt/openfoam171/lib/linux64GccDPOpt/libOpenFOAM.so"
#1 Foam::sigSegv::sigSegvHandler(int) in "/opt/openfoam171/lib/linux64GccDPOpt/libOpenFOAM.so"
#2 in "/lib/libc.so.6"
#3
in "/opt/openfoam171/applications/bin/linux64GccDPOpt/ausmFoam"
#4 __libc_start_main in "/lib/libc.so.6"
#5
in "/opt/openfoam171/applications/bin/linux64GccDPOpt/ausmFoam"
Segmentation fault


Which normally is caused by an application accessing memory outside the allocated space.

Any suggestion?

The code:

Code:
         surfaceScalarField     M1_pos = (ML_N+mag(ML_N))/2.0; //Funcao do lado esquerdo
         surfaceScalarField     M1_neg = (MR_N-mag(MR_N))/2.0; //Funcao do lado direito

         surfaceScalarField     M4_neg = -1.0/4.0*magSqr(MR_N-1.0)-1.0/8.0*magSqr(magSqr(MR_N)-1.0); 
         surfaceScalarField     P5_neg =  1.0/4.0*magSqr(MR_N-1.0)*(2.0+MR_N)-3.0/16.0*MR_N*magSqr(magSqr(MR_N)-1); 

         surfaceScalarField     M4_pos = 1.0/4.0*magSqr(ML_N+1.0)+1.0/8.0*magSqr(magSqr(ML_N)-1.0);  
         surfaceScalarField     P5_pos = 1.0/4.0*magSqr(ML_N+1.0)*(2.0-ML_N)+3.0/16.0*ML_N*magSqr(magSqr(ML_N)-1);




forAll(mesh.faces(),faceI)   

  {

 if(mag(MR_N[faceI]) >= scalar(1.0)) //valores do lado direito

     {
      
            M4_neg[faceI] = M1_neg[faceI]; //Funcao do lado direito
            P5_neg[faceI] = M1_neg[faceI]/MR_N[faceI]; 
     }

    

   if(mag(ML_N[faceI]) >= scalar(1.0)) //valores do lado esquerdo

      {
         M4_pos[faceI] = M1_pos[faceI]; //Funcao do lado esquerdo
         P5_pos[faceI] = M1_pos[faceI]/ML_N[faceI];   
      }


      
  }
Carlos
xisto is offline   Reply With Quote

Old   November 24, 2010, 10:13
Default
  #6
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 7
xisto is on a distinguished road
Send a message via MSN to xisto
I forgot to say that the error occurs in the following line:


P5_pos[faceI] = M1_pos[faceI]/ML_N[faceI];
xisto is offline   Reply With Quote

Old   November 24, 2010, 13:13
Default
  #7
New Member
 
Patricia
Join Date: Oct 2010
Posts: 22
Rep Power: 6
schmittp54 is on a distinguished road
Can't help. You'd have to attach a complete example.

Use a debugger to find the value of faceI where the segmentation fault happens. Check that faceI<P5_pos.size() and faceI<M1_pos.size() and faceI<ML_N.size(). I guess that these conditions are violated.
The problem may be different addressing of either only internal or all faces in the fvMesh and surfaceScalarField classes.

Patricia
schmittp54 is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ICEM] Hexa Mesh Smoothing Jules ANSYS Meshing & Geometry 6 December 4, 2010 19:00
Dynamic Mesh Problem. Tom Clark FLUENT 9 July 7, 2010 07:56
2d irregular grid Remy Main CFD Forum 1 December 22, 2008 05:49
basic of mesh refinement arya CFX 4 June 19, 2007 12:21
Mesh Refinement JY CD-adapco 7 September 19, 2002 13:37


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