Custom viscosity model
Hi, I'm trying to implement a precise viscosity model from experimental measurements.
I've created a folder "Spline" and two files "Spline.C" and "Spline.H". I've redefined calcNu() method in the following was: Code:
Foam::tmp<Foam::volScalarField> Code:
#0 Foam::error::printStack(Foam::Ostream&) at ??:? |
Greetings Svensen,
I've come to this thread, after looking for it due to the following bug report: http://bugs.openfoam.org/view.php?id=2316 In that bug report you have a slightly different source code: Code:
Foam::tmp<Foam::volScalarField> Quote:
If we take a look at the printed stack trace, the first tell-tale sign is this: Code:
#1 Foam::sigFpe::sigHandler(int) at ??:? Quote:
When we take into account this signal for a bad mathematical operation and that the stack trace indicates that this occurs when the transport model is being created for the first time, I'm guessing that something wrong is going on with the initialization of the other fields:
Code:
Info << "size visc: " << sizeof(visc) << endl; Code:
forAll(strain, itemi) Bruno |
2 Attachment(s)
Thanks, wyldcat.
The first error was with sizeof. I forgot that sizeof returns a number of bytes instead of number of elements. However, the main problem was in the way of how "visc" array was initialized. I defined it as a private member of a class and initialized it in the body of constructor. BUT OpenFOAM uses a constructor with initialization list, where nu_ object initializes before body of constructor is executed. That's why calcNu() method executes first and only after this my constructor will initialize a "visc" array. This produces "strange" values in "visc" array during execution of calcNu() method. I've tried to move an initialization of nu_ object from initialization list to body of constructor, but compilation failed. To overcome this, I've simply moved an initialization of "visc" array to the code of calcNu() method. It compiles without errors and executes first step without error, but then crashes. I need some time to check my code to find out why it crashes. But nevertheless, can I initialize a "visc" array outside from calcNu() method ? Because it seems weird to initialize it every time the calcNu() method executes. I've attached the sources below. |
About crash...
First of all, I've started with Newtonian viscosity, i.e. I've set all elements of visc array to 4.1 mPa*s, which corresponds to kinematic viscosity of 3.9e-6 m2/s. I've checked that every element of "strain" object is initialized by this value during calcNu() method. However the simulation crashes again. The return command looks like this: Code:
return dimensionedScalar("one", pow(dimLength, 2), 1.0)*strain; Code:
Courant Number mean: 0.970093 max: 303.708 |
Code:
Foam::tmp<Foam::volScalarField> Code:
Foam::viscosityModels::Spline::Spline |
3 Attachment(s)
Dear Zeppo,
thank you very much for help ! I've inserted your code in Spline.C and fixed some syntax issues in it. It compiles fine, however during execution the error with reference occurred. I've tried to comment every line of code from end to beginning and it seems that something wrong with this line: Code:
tmp<volScalarField> tNu Code:
Selecting incompressible transport model Spline |
Ok. Then replace your calcNu() with the code following below:
Code:
Foam::tmp<Foam::volScalarField> |
3 Attachment(s)
Dear Zeppo, thank you very much for help !
You suggestion is right and I was able to implement just a simple Newtonian model: Code:
forAll(nu, i){ Code:
forAll(nu, i){ It seems to me that i-index for nu is not the same as i-index for strain_Rate. Maybe you know how the correct index for strain_Rate can be obtained ? The sources as well as log file are attached below |
Both strain_Rate and nu have the same number of elements, so the code like this
Code:
forAll(nu, i) |
Finally I've figured out a problem. I' found that this code works properly on a normal execution like "pimpleFoam", but code crashes on parallel run "pimpleFoam -parallel".
Maybe you know if there are some additional changes are required to source code to support parallel execution ? Thanks ! |
Which line triggers the error? This one?
Code:
double n = strain_Rate[i] / dn; |
Yes, you are right. Something wrong here.
|
run this
Code:
forAll(nu, i) |
1 Attachment(s)
In the first step for every nu it prints i: 1 1 like
Code:
10380: 1 1 At the beginning of second step it crashes before any output starts. The full log is attached |
I am not an expert but what I see is that the error message never mentions your library file (.so-file). You built your custom viscosity class into a user library, right? It is libOpenFOAM.so that is mensioned in the error message as the sourse where the error comes from.
You said that the very same code runs flawlessly in serial, correct? |
Yes, serial execution works fine.
I will post this issue on issue tracker. Thanks a lot for help ! |
Quick answer:
Quote:
I need to understand what is the "visc" vector meant to be. Is it a lookup table? |
Yes, it is just a viscosity data. visc[0] contains the kinematic viscosity for shearRate=0; visc[1] contains the kinematic viscosity for shearRate=0.125; visc[2] contains viscosity for shearRate=0.250 and so on.
for shearRate between points, for example for shearRate=0.2 the linear interpolation will be used to compute nu for this point. The sources are attached above. |
Can this problem be treated ?
|
Greetings Svensen,
There are a few boundary conditions that demonstrate how lookup tables can be used. Using lookup tables as OpenFOAM already does, would ensure that the bug is not coming from a possibly flawed implementation of the lookup mechanism you currently have implemented. The boundary "src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue" has such an example:
If you still have trouble implementing it, please do the following steps, so it's easier to help you:
Bruno |
All times are GMT -4. The time now is 11:37. |