Help with if statement
2 Attachment(s)
Hello,
I am trying to modify the k-omega model to implement Wilcox 2006 version. I want to use an if statement to assign a value to a constant, "alplhad", depending on the sign of partial(k)/partial(x_j)*partial(omega)/partial(x_j) but I keep on getting compile errors caused by the if statement. I know that the solution has to be quite simple but I just can't figure it out! Please help! Below is my definition of alphadCheck and that for the if statement. I have also attached copies of my .C and .H files Code:
const volScalarField alphadCheck Code:
if ( alphadCheck <= scalar(0.0)) Code:
/kOmega2006Changes2$ wmake libso |
Anyone please?
|
What are you trying to do? Your are comparing a volScalarField with a scalar. Looks like that is not defined in OpenFOAM.
|
Maybe you have forgotten to wrap a loop over all cells around the if statement and compare each cell individually?
|
Quote:
Code:
alphad_ = 0.5*(1 - sign(alphaCheck))*alphado_ + 0.5*(1 + sign(alphaCheck))*alphad_; Code:
forAll(alphad_, cellI)) |
2 Attachment(s)
Thank you for replying!
Quote:
I am trying to add a routine that checks the sign of partial(k)/partial(x_j)*partial(omega)/partial(x_j) and assigns a value to "alphad" according on the result of the sign check. However, I have never modified OpenFOAM so I don't know where to place the extra code. Now I understand why I was getting an error comparing the volScalaraField to the scalar though! Jens Höpken's idea to loop over all cells was in fact missing from my routine!! I added the following: Code:
forAll(alphad_, celli) Code:
Making dependency list for source file kOmega2006C2.C The modified .C and .H files are attached if that's of any help. |
Quote:
Code:
alphad_ |
2 Attachment(s)
@alexym
Thank you for your suggestion! Changing them to a VolScalarField solved the error but I have now created new ones... I have some questions that, if answered, may point me in the right direction instead of blindly trying to fix the errors: 1. How should I define a volScalarField? For example, for alphadCheck, I have defined it as : Code:
const volScalarField alphadCheck In order for alphadCheck to go through each cell in the domain, it should be placed within the forAll(alphad_, celli) loop, but first I have to define it somehow, which is where I'm stuck. Should I be defining these volScalarFields in the "void kOmega::correct()" section or outside of it? 2. I want to be able to change the value of alphad_ on each cell (if necessary), depending on the result of alphadCheck. Should alphad_ be defined as a volScalarField since there will be a corresponding alphad_ value for each cell? If so, how can I initialize alphad_ (all of the components should be set equal to .125 for the first iteration and then changed according to results from alphadCheck (if necessary))? 3. How do I define the index for the forAll loop (i.e.: celli)? I would like to use a forAll loop in the following way: Code:
forAll(alphad_,celli) The most recent .C and .H files are attached |
1. Well, you can try to create it as you've described it in the post. Though I'm not quite sure that mag(...) can be negative. Do I get it right and you'd like to check sign of scalar product of two gradient vectors? Then you can define it as volScalarField alphaCheck_(fvc::grad(k_) & fvc::grad(omega_)) or volScalarField alphaCheck_(sign(fvc::grad(k_) & fvc::grad(omega_))). Though as you'll check alphaCheck_[cellI] then maybe additional call to sign is not necessary.
You can define this variables (alphaCheck_ and alphad_) as a private properties of kOmega2006 and create then in constructor. Or as alphaCheck_ is recalculated on every update call you can create it in update method as const volScalarField& alphaCheck_(fvc::grad(k_) & fvc::grad(omega_)). 2. Surely there are more correct ways but for alphad_ you can try to use something like volScalarField alphad_(0.125 + 0.0*nut_). 3. You don't need to define index variable as forAll is the macro (documentation) and it will define index variable for you. So you can just use Code:
forAll(alphad_, cellI) Code:
for (Foam::label cellI=0; cellI<(alphad_).size(); cellI++) |
@alexeym
Thank you for replying quickly! You are correct: I want to check the sign of the scalar product of two gradient vectors. I have defined alphaCheck_ and alphad_ as you suggested: Code:
const volScalarField alphadCheck_ I have also implemented the forAll as: Code:
forAll(alphad_, cellI) Below are the errors I am still getting: Code:
sebastian@navier1:~/OpenFOAM/sebastian-2.2.0/src/turbulenceModels/incompressible/RAS/kOmega2006Changes3$ wmake libso |
1 Attachment(s)
Well...
1. As you'd like to change alphad_ it should not be declared as const. This will fix the last error. 2. On the other hand if you create alphad_ as Code:
volScalarField alphad_ Code:
... 3. And finally the error with very long description. For some strange reason I wasn't able to build library from your source files. So I've taken original kOmega model and added modifications from your source files. After this I was able to compile library. You can find archive with source files and wmake configuration attached to the message. To build library you just run 'wmake libso' in the folder. |
1 Attachment(s)
Thank you! That definitely fixed the last error.
I went through line by line and compared all of the files that you kindly sent to me and I found a few differences which may explain why yours is compiling and mine isn't. Below you'll find segments of your code with comments of how it differs from mine: In kOmega2006.C: Code:
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // Code:
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // On line 262, your file has Code:
volScalarField G(GName(), nut_*2*magSqr(symm(fvc::grad(U_)))); volScalarField G(type() + ".G", nut_*2*magSqr(symm(fvc::grad(U_)))); In kOmega2006.H: Again, I have changed all of my instances from kOmega to kOmega2006 Our files and options in Make are the same. The error that was generated this time around was: Code:
:~/OpenFOAM/sebastian-2.2.0/src/turbulenceModels/incompressible/RAS/kOmega2006Changes3$ wmake libso I have attached my version of your last attachment. |
1 Attachment(s)
You are right, I forgot to change the name in all places. This time I've fixed it.
I don't know why, there's no major differences between our file sets (diff -u kOmega2006.* kOmega2006C2.* gives only lines with names of the classes). Also difference in Code:
volScalarField G(GName(), nut_*2*magSqr(symm(fvc::grad(U_)))); Code:
volScalarField G(type() + ".G", nut_*2*magSqr(symm(fvc::grad(U_)))); As I don't know the reason for error while compiling your sources, so I just attach my variant (with added 2006 in the name, and I think I've changed the name of the class in all necessary places). Hope this will help. |
alexeym,
IT FINALLY COMPILED!!! :0 I found out why I was having problems... In the .C file, I was missing the first "&" in Code:
const volScalarField& alphadCheck_(fvc::grad(k_) & fvc::grad(omega_)); Code:
volScalarField alphaCheck_; Can you explain why you don't have it? |
Quote:
Code:
const volScalarField& alphaCheck_(fvc::grad(k_) & fvc::grad(omega_)); Code:
alphaCheck_ = fvc::grad(k_) & fvc::grad(omega_); |
Got it!
alexeym, Thank you so much for all of your help!! :) I am going to run a few test cases and I will share the results and the source code for the slightly modified model. |
Quote:
Hi, I have to put a if statement in between a volScalarField and dimensionedScalar. The part of the code is : ////////////////////////////////////////////////////////////// volScalarField y = mesh.C().component(vector::Y); volScalarField u = ustar*(((1.0-Y0)/(Y0-Foam::log(Y0)-1.0))*Foam::log(y)/(h*Y0))); if(y >= Y0*h && y <= h ) { u = ustar*(((1.0-Y0)/(Y0-Foam::log(Y0)-1.0))*Foam::log(y/(h*Y0))); } else { u = 0.0; } dimensionedScalar Y0 ( transportProperties.lookup("Y0") ); dimensionedScalar h ( transportProperties.lookup("h") ); ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// After running the code I'm getting this error : .C:82:24: error: no match for ‘operator<=’ (operand types are ‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ and ‘Foam::dimensionedScalar {aka Foam::dimensioned<double>}’) if(y >= Y0*h && y <= h ) |
All times are GMT -4. The time now is 12:12. |