openFoam: Trouble reporting turbulence fields - openfoam

I run openFoam 4.1, and have a problem extracting the turbulent stress tensor, R, in my k-eps simulation. I asked the same question on cfd-online.com 4 days ago, and have not received a reply, so I am now hoping that maybe someone can help me here.
To extract R, I have only modified the controlDict, which looks like the following:
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 4.0 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application simpleFoam;
startTime 0;
stopAt endTime;
endTime 5000;
deltaT 1;
writeControl timeStep;
writeInterval 100;
purgeWrite 2;
writeFormat ascii;
writePrecision 8;
writeCompression uncompressed;
timeFormat general;
timePrecision 6;
runTimeModifiable yes;
functions
{
#includeFunc residuals
turbulenceFields1
{
type turbulenceFields;
libs ("libfieldFunctionObjects.so");
field R;
}
}
// ************************************************************************* //
When I try solving with the above controlDict, I get the following:
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 4.1 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 4.1
Exec : simpleFoam
Date : May 18 2017
Time : 07:08:01
Host : "..."
PID : 11073
Case : /home...
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Create mesh for time = 0
SIMPLE: convergence criteria
field p tolerance 0.001
field U tolerance 0.001
field "(k|epsilon|omega|f|v2)" tolerance 0.001
Reading field p
Reading field U
Reading/calculating face flux field phi
Selecting incompressible transport model Newtonian
Selecting turbulence model type RAS
Selecting RAS turbulence model kEpsilon
kEpsilonCoeffs
{
Cmu 0.09;
C1 1.44;
C2 1.92;
C3 -0.33;
sigmak 1;
sigmaEps 1.3;
}
No MRF models present
No finite volume options present
Starting time loop
turbulenceFields turbulenceFields1: storing fields:
turbulenceProperties:R
Time = 1
smoothSolver: Solving for Ux, Initial residual = 1, Final residual = 0.068919891, No Iterations 6
smoothSolver: Solving for Uy, Initial residual = 1, Final residual = 0.094423261, No Iterations 4
smoothSolver: Solving for Uz, Initial residual = 1, Final residual = 0.065365879, No Iterations 6
GAMG: Solving for p, Initial residual = 1, Final residual = 0.0086113464, No Iterations 26
time step continuity errors : sum local = 0.51812432, global = -0.07783965, cumulative = -0.07783965
smoothSolver: Solving for epsilon, Initial residual = 0.59675441, Final residual = 0.051409907, No Iterations 3
smoothSolver: Solving for k, Initial residual = 1, Final residual = 0.092548244, No Iterations 2
ExecutionTime = 0.81 s ClockTime = 1 s
--> FOAM FATAL ERROR:
object of type N4Foam9Function1INS_10SymmTensorIdEEEE is not allocated
From function T* Foam::autoPtr<T>::operator->() [with T = Foam::Function1<Foam::SymmTensor<double> >]
in file /home/ubuntu/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/autoPtrI.H at line 176.
FOAM aborting
#0 Foam::error::printStack(Foam::Ostream&) at ??:?
#1 Foam::error::abort() at ??:?
#2 Foam::timeVaryingMappedFixedValueFvPatchField<Foam::SymmTensor<double> >::write(Foam::Ostream&) const at ??:?
#3 Foam::GeometricField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh>::Boundary::writeEntry(Foam::word const&, Foam::Ostream&) const at ??:?
#4 Foam::GeometricField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh>::writeData(Foam::Ostream&) const at ??:?
#5 Foam::regIOobject::writeObject(Foam::IOstream::streamFormat, Foam::IOstream::versionNumber, Foam::IOstream::compressionType) const at ??:?
#6 Foam::functionObjects::regionFunctionObject::writeObject(Foam::word const&) at ??:?
#7 Foam::functionObjects::turbulenceFields::write() at ??:?
#8 Foam::functionObjectList::execute() at ??:?
#9 Foam::Time::loop() at ??:?
#10 Foam::simpleControl::loop() at ??:?
#11 ? at ??:?
#12 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#13 ? at ??:?
Aborted (core dumped)
It seems from the above like openFoam solves for the first time step, and then something goes wrong. In the the catalog "1" there is now only one file, "turbulenceProperties:R", which seams to contain the 6 elements of the stress tensor for each point.
Does anybody know how to fix this?

I think I found the answer, in the this link from the cfd-online forum.

Related

StandardML factorial evaluation enters infinite loop in Poly/ML REPL

The following factorial function is well and good...
Poly/ML 5.8.3 Development (Git version v5.8.2-297-g8185978a)
> fun fact 0 = 1
# | fact n = n * fact(n-1);
val fact = fn: int -> int
> fact 2;
val it = 2: int
>
But the following takes the Poly REPL into infinite loop.
Poly/ML 5.8.3 Development (Git version v5.8.2-297-g8185978a)
> fun fact 0 = 1
# | fact n = n * fact n-1;
val fact = fn: int -> int
> fact 2;
Wondering what could be causing this??
n * fact n-1 is the same as n * (fact n) - 1 - thus, n is never decreased, and your code ends up calling fact 2 over and over and over again.
Since ForceBru already gave an adequate answer, for completion, here is an example of evaluating this by hand that should reveal the infinite recursion:
fact 2 ~> 2 * fact 2-1
~> 2 * (2 * fact 2-1)-1
~> 2 * (2 * (2 * fact 2-1)-1)-1
~> 2 * (2 * (2 * (2 * fact 2-1)-1)-1)-1
~> ...

Appropriately using go to algorithm in R

I have an algorithm written as follows but I need to write that code into R. I have included the algorithm and the R code. I am not sure if that is represented well enough. To write the R code in the sequential order is not straight forward. I am sorry for not providing all the values of the variables here. I am not sure of the output yet which is the reason I am unable to show the required. It is more of a theoretical question.
Algorithm
VBDMAX = (va - VG) * 0.79 * (dep / D) ^ -1.21
VBOWMAX = -0.7 * VBDMAX
VBOWX = 0
' SKIP BOW IF -10D<X<15D OR OUTSIDE EDGE OF BARGES
If Y > B / 2 Then GoTo 200
If X < -10 * D Then GoTo 200
If X >= 15 * D Then GoTo 200
VBOWX = X * VBOWMAX / (10 * D) + VBOWMAX
If X <= 0 Then GoTo 200
VBOWX = X * (VBDMAX - VBOWMAX) / (5 * D) + VBOWMAX
If X <= 5 * D Then GoTo 200
VBOWX = -X * VBDMAX / (10 * D) + 15 * VBDMAX / 10
200 ' end bow
This is the R code that I have written
VBDMAX = (va - VG) * 0.79 * (dep / D) ^ -1.21
VBOWMAX = -0.7 * VBDMAX
VBOWX = 0
# SKIP BOW IF -10D<X<15D OR OUTSIDE EDGE OF BARGES
VBOWX <- ifelse ((Y>B/2 | X < -10*D | X>=15*D), 0,X*VBOWMAX/(10*D)+VBOWMAX)
VBOWX <- ifelse (X<=0 , X * (VBDMAX - VBOWMAX) / (5 * D) + VBOWMAX,
ifelse(x <=5*D, -X * VBDMAX / (10 * D) + 15 * VBDMAX / 10))
You can use ifelse constructs but you will need to nest those:
VBDMAX = (va - VG) * 0.79 * (dep / D) ^ -1.21
VBOWMAX = -0.7 * VBDMAX
VBOWX =
ifelse(Y > B / 2 || X < -10 * D || X >= 15 * D,
0,
ifelse(X <= 0,
X * VBOWX / (10 * D) + VBOWMAX,
ifelse(X <= 5 * D,
X * (VBDMAX - VBOWMAX) / (5 * D) + VBOWMAX,
-X * VBDMAX / (10 * D) + 15 * VBDMAX / 10
)
)
)
Understanding your question as how to translate "goto" statements to R, there are the following posibilities (if really needed) besides or in adjunction to the (often more appropriate) if/ifelse constructions as you already did:
a) entire code (for severe errors or if problem is solved): if (condition) stop("explain why...") or stopifnot(condition)
b) from within loops: see next and break
c) from within function: if (condition) return(), stopping the function here

How can I generate ascii "graphical output" from R?

I believe R can generate stem-and-leaf for ascii histograms, and scatter plots using this code from Matt Shotwell.
Can it also generate ASCII based line graphs, like this from GNUPlot?
You should look at the fairly recent txtplot package. Currently, it includes scatterplot, line plot, density plot, acf, and bar chart.
From the online help,
> txtplot(cars[,1], cars[,2])
+----+------------+------------+-----------+------------+--+
120 + * +
| |
100 + +
| * * |
80 + * * +
| * * * |
60 + * * +
| * * * * * |
40 + * * * * * +
| * * * * * * * |
20 + * * * * * * * +
| * * * * |
| * * * |
0 +----+------------+------------+-----------+------------+--+
5 10 15 20 25
I know there is support for basic interaction between R and GnuPlot in the TeachingDemos package. Perhaps that can achieve what you want.

how to get modulo of a value in exponential form

Question is about the modulo operator on very large numbers.
For example consider a question where the total number of permutations are to be calculated.
Consider a number of 90 digits with each of the 9 numbers (1 to 9) repeating 10 times
so 90!/(10!)^9) is to be calculated
After reading many answers on StackOverflow I used logarithms to do it.
Now consider the log value to be 1923.32877864.
Now my question is how can I display the answer (i.e. 10 ^ log10(value) ) modulo of "m"?
And is this the best method for calculating the possible number of permutations?
Edit
Got the solution :)
Thanks to duedl0r.
Did it the way you specified using Modular Multiplicative Inverse.Thanks :)
I'm not sure whether this is actually possible and correct, but let me summarize my comments and extend the answer from Miky Dinescu.
As Miky already wrote:
a × b ≣m am × bm
You can use this in your equality:
90! / 10!^9 ≣m x
Calculate each term:
90!m / 10!^9m ≣m x
Then find out your multiplicative inverse from 10!^9m. Then multiplicate the inverse with 90!m.
update
This seems to be correct (at least for this case :)). I checked with wolfram:
(90!/10!^9) mod (10^9+7) = 998551163
This leads to the same result:
90! mod (10^9+7) = 749079870
10!^9 mod (10^9+7) = 220052161
do the inverse:
(220052161 * x) mod(10^9+7) = 1 = 23963055
then:
(749079870*23963055) mod (10^9+7) = 998551163
No proof, but some evidence that it might work :)
I would argue that the way to compute the total number of permutations modulo m, where m is an arbitrary integer (usually chosen to be a large prime number) is to use the following property:
(a * b) % m = ((a % m) * (b % m)) % m
Considering that the total number of permutations of N is N! = 1 * 2 * 3 * .. * N, if you need to compute N! % m, you can essentially apply the property above for multiplication modulo m, and you have:
((((1 * (2 % m)) % m) * (3 % m)) % m) * ..
EDIT
In order to compute the 90! / (10! ^ 9) value you could simplify the factors and then use multiplication modulo m to compute the final result modulo m.
Here's what I'm thinking:
90! = 10! * (11 * 12 * .. * 20) * (21 * 22 * .. * 30) * .. * (81 * 82 * .. * 90)
You can then rewrite the original expression as:
(10! * (11 * 12 * .. * 20) * (21 * 22 * .. * 30) * .. * (81 * 82 * .. * 90)) / (10! * 10! * ... * 10!)
At the numerator, you have a product of 9 factors - considering each expression in parenthesis a factor. The same is true for the denominator (you have 9 factors, each equal to 10!).
The first factor at the denominator is trivial to simplify. After that you still have 8 pairs that need simplification.
So, you can factor each term of the products and simplify the denominator away. For example:
11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 <=> 11 * 2 * 2 * 3 * 13 * 2 * 7 * 3 * 5 * 2 * 2 * 2 * 2 * 17 * 2 * 9 * 2 * 2 * 5
The denominator will always be: 2 * 3 * 2 * 2 * 5 * 2 * 3 * 7 * 2 * 2 * 2 * 2 * 3 * 3 * 2 * 5
After the simplification the second pair reduces to : 2 * 2 * 11 * 13 * 17 * 19
The same can be applied to each subsequent pair and you will end up with a simple product that can be computed modulo m using the formula above.
Of course, efficiently implementing the algorithm to perform the simplification will be tricky so ultimately there has to be a better way that eludes me now.

Maths help with exponentials [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Evaluate
(z x^-1 y)^5 y^5
~~~~~~~~~~~~~~~~~~~~~~~ OVER
x^-4 z^-4
How would I evaluate this if X = 10, y = -3 and z = 3? I would like a step-by-step solution to help me fully understand it.
Numerator evaluates as (z*y*x^-1)^5 * y^5
further rewriting ((z^5*y^5)*y^5)/x^5
Denominator ((1/x^4)*(1/z^4))
Final Answer would be ((y^10)*(z^9))/x
as per your values it (3^19)/10
Exponentials have higher priority in most computer languages, so adding parentheses like this should make it clearer. I'm assuming that you're dividing the first polynomial by the second. It's simple algebra.
(z x^-1 y)^5 y^5
---------------- =
x^-4 z^-4
(y^10)(z^9)/x
You substitute the numbers.
Start with:
((z * x^-1 * y)^5 * y^5)/(x^-4 * z^-4)
Commute the exponent to the z factor: (A * B)^N => A^N * B^N
(z^5 * (x^-1 * y)^5 * y^5)/(x^-4 * z^-4)
Commute the exponent to the x and y factors: (A * B)^N => A^N * B^N
(z^5 * (x^-1)^5 * y^5 * y^5)/(x^-4 * z^-4)
Simplify the exponenet on the x factor: (A^N)^M => A^(N*M)
(z^5 * x^-5 * y^5 * y^5)/(x^-4 * z^-4)
Combine the y factors: A^N * A^M => A^(N+M)
(z^5 * x^-5 * y^10)/(x^-4 * z^-4)
Remove the negative exponent on x: 1/A^-N => A^N
(z^5 * x^-5 * y^10 * x^4) / (z^-4)
Remove the negative exponenet on z: 1/A^-N => A^N
z^5 * x^-5 * y^10 * x^4 * z^4
Combine the z factors: A^N * A^M => A^(N+M)
z^9 * x^-5 * y^10 * x^4
Combine the x factors: A^N * A^M => A^(N+M)
z^9 * x^-1 * y^10
Remove the negative exponent on x: A^(-N) => 1/A^N
(z^9 * y^10)/(x^1)
Simplify the x factor: A^1 => A
(z^9 * y^10)/(x)
And that's the algebraic form of your answer.
Next, subsitute the values:
3^9 * (-3)^10 / 10
Factor the exponents:
(3^3)^3 * (-3)^10 / 10
(3^3)^3 * ((-3)^2)^5 / 10
Evalutate the innermost exponents:
(3 * 3 * 3)^3 * ((-3)^2)^5 / 10
(9 * 3)^3 * ((-3)^2)^5 / 10
27^3 * ((-3)^2)^5 / 10
27^3 * 9^5 / 10
Continue evaluation exponents, breaking them down for simplicity:
27 * 27 * 27 * 9^5 / 10
27 * 27 * 27 * 9^5 / 10
729 * 27 * 9^5 / 10
19683 * 9^5 / 10
19683 * 9^2 * 9^2 * 9 / 10
19683 * 81 * 81 * 9 / 10
Then multiply the factors:
19683 * 81 * 729 / 10
19683 * 59049 / 10
1162261467 / 10
116226146.7
And there's your final answer.
You could also take advantage of the fact that X^N = (-X)^N if N is even by replacing -3 with 3 since 10 is even.
3^9 * (-3)^10 / 10
3^9 * 3^10 / 10
3^19 / 10
3 * 3^18 / 10
3 * (3^9)^2 / 10
3 * (3 * 3^8)^2 / 10
3 * (3 * (3^2)^4)^2 / 10
3 * (3 * ((3^2)^2)^2)^2 / 10
3 * (3 * (9^2)^2)^2 / 10
3 * (3 * 81^2)^2 / 10
3 * (3 * 6561)^2 / 10
3 * (19683)^2 / 10
3 * 387420489 / 10
1162261467 / 10
116226146.7

Resources