|
[Sponsors] |
November 23, 2010, 07:16 |
Conditional statement over the entire mesh
|
#1 |
Member
|
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)); } } Cheers Carlos |
|
November 23, 2010, 09:33 |
|
#2 |
New Member
Patricia
Join Date: Oct 2010
Posts: 22
Rep Power: 16 |
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:
|
|
November 23, 2010, 09:43 |
|
#3 |
Member
|
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 |
|
November 23, 2010, 10:14 |
|
#4 |
Member
|
Dear Patricia,
Your solution for the problem works. Thanks Carlos |
|
November 24, 2010, 10:11 |
|
#5 |
Member
|
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]; } } |
|
November 24, 2010, 10:13 |
|
#6 |
Member
|
I forgot to say that the error occurs in the following line:
P5_pos[faceI] = M1_pos[faceI]/ML_N[faceI]; |
|
November 24, 2010, 13:13 |
|
#7 |
New Member
Patricia
Join Date: Oct 2010
Posts: 22
Rep Power: 16 |
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 |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Dynamic Mesh Problem. | Tom Clark | FLUENT | 10 | June 21, 2021 05:27 |
[ICEM] Hexa Mesh Smoothing | Jules | ANSYS Meshing & Geometry | 6 | December 4, 2010 19:00 |
2d irregular grid | Remy | Main CFD Forum | 1 | December 22, 2008 05:49 |
basic of mesh refinement | arya | CFX | 4 | June 19, 2007 13:21 |
Mesh Refinement | JY | Siemens | 7 | September 19, 2002 14:37 |