Reduce() and Size() functions
Dear Fellows
I have few questions regarding the following snippet: Code:
scalar ULeft = 0.0; I assume the size of fvp is non-zero, so the "if" loop executes. My first question is on Code:
ULeft = fvp[0].x(); here, fvp is an array of vectors, since it keeps the velocity vectors of a patch, but the above command just stores the first component ".x()" of first vector "[0]" in the array of vectors. Am I correct? For example assume fvp = { (1 2 3) (4 5 6) (7 8 9)} then fvp[0].x means 1 then why using the Code:
reduce(ULeft, maxOp<scalar>()); I assume that reduce() function with maxOp<scalar> finds the biggest scalar in an array of scalars, but here ULeft just has one member!!! (in my example 1) Am I missing sth?:confused::confused: Regards |
Hey,
i assume you have this snippet from the potentialFoam/cylinder tutorial ?! In the 0/U file you can see that they use a uniformFixedValue velocity (1 0 0) on the left boundary condition. Because you have the same velocity on each boundary face of the left BC itīs ok to just ask for a single element of fvp. Because you just have the x-component of velocity itīs also ok to just ask for fvp[0].x() ! Of course this is not very generic or reusable for other cases. When you decompose the domain (parallel computing with MPI) you just get the correct velocity from the process (or processes) which compute the subdomain containing the left BC. Other processes will return a null velocity. The reduce operation searches for the maximum value in your parallel processes on the left BC which will be a 1. By not using the reduce operation there is a risk that the master process is not computing the part which contains the left-BC and hence returns a null velocity. |
Hey Traction,
Yeah, I was reading the code snippet available in OpenFOAM Programmers guide 3.0.1. Thanks for your clarification. Since I did not go through the whole sample case.:) I just read the code. But with your suggestions, my questions regarding the code snippet is responded. |
Dear Fellows
I have another question regarding this snippet inside O.F. programmers guide version 3 (page 49) . Code:
dimensionedScalar uInfX Code:
volScalarField error("error", mag(U-UA)/mag(UA)); Here, just a 0 folder was present, However in case of more time steps what would happen? |
Hey babakflame,
Quote:
Quote:
The OpenFOAM C++ Documentation says that objectPath() is a function to return the complete object path and the name of the object (in this case of the object error which is located in the current time directory). In this case it just produces an output on your screen / log file to find the location of the written error file. Keep in mind that potentialFoam is independent of the time. If there would be a suitable solver with time dependency OpenFOAM would write the calculation results for the fields "UA" and "error" for every timeStep. |
Hey Traction,
Thanks bro for your comprehensive response.:cool: |
Quote:
For example U-UA is computed with this code: Code:
//-- src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C |
Thanks sergei.
I read this part that you send me.:) It seems that both add and subtract operations are done by this snippet. (overloading operators) Am I correct? |
Yes, that code is a part of a macro which generates both
Code:
operator + Code:
operator - |
All times are GMT -4. The time now is 14:18. |