Problem / Misunderstanding with mesh.C() : get the cell centers
Hej,
This is probably very simple but I experienced unexpected results with the .C() function. It is supposed to return the cell centers of the mesh it is applied to. I think that I am right so far... However i have a 2D geometry defined for x between 0.0 and 0.0127 and y between 0.0 and 1.7, as you can see from my blockMeshDict below : Code:
vertices However, i wrote this piece of code : Code:
volVectorField centres = Ua.mesh().C(); min(x)=0.0 max(x)=0.0127 So basically it means that there are cell centers located at the boundaries, which is nonsense! Could you please help me and tell me what i have not properly understood, and how to solve it. Thanks in advance. Best /Ed |
Hi, mesh.C() gives you a slicedVolVectorField which has internalField and boundaryField, the values in the internalField are the cell centres and in the boundaryField you have the face centres of boundary patches, so the min value of this field will be the x coordinate of a face centre. The code in fvMeshGeometry.C reads:
Code:
00115 void fvMesh::makeC() const Regards. |
Hi Santiago,
Thanks for your answer. I understand what the problem is. But do you have any trick to solve this? Because I would like to obtain a field of the cell centers without the values at the boundaries, and then use this field and multiply it by other parameters to obtain a volVectorField that is used in my UEqns. Thanks in advance! /Edouard |
Hi Edouard, I was doing a similar work some months ago and used:
Code:
// Cell centroid coordinates Regards. |
Hi again,
Thanks again Santiago. I have solved the problem changing the x-values at the boundary, as can be seen below. Code:
// Take the cell centres |
In this case you are losing info, I think is more clear to extract the internalField because FOAM already gives you what are looking for.
Regards. |
Hi,
You're right. I lose info even if I dont need it. Your solution is "cleaner", i will use it. Thanks again for your very quick and useful answers! Best, /Edouard |
Quote:
EDIT: Alas, the shell command Code:
writeCellCentres |
writing to internalField
Hi all,
Just like reading values of the internal field, is it possible to write (assign) linearly increasing values of a scalar to the internalField on all the cell centres along one coordinate direction? |
Hi Srivaths,
You can extract the coordinates in one direction with Code:
scalarField Xcoord = mesh.C().component(Vector::X); Cheers, L |
Quote:
|
Alternating scalar value on boundaryField
Dear all, especially dear Lieven,
I'm currently looking for something similar like Srivathsan. For simulating a super focus mixer, I need to assign a scalar value to my boundary faces depending on their x and z coordinate. Since the BC is assignes locally face by face in my 0/T-file, I can only access one face's coordinates at a time. So the question is simply: When the expression I use is evaluated face by face, can I access the face center coordinates via Quote:
|
Dear Yeru,
You can access the x-coordinates (and similarly y and z) of a patch through: Code:
const vectorField& c = patch().Cf(); Code:
forAll(coord,faceI) I think this should do the trick. I haven't checked it... Cheers, L |
Dear Lieven,
at first, huge thanks for this express answer. I'm afraid, it doesn't apply to my problem. I described it in this thread as well. The moment I want to access the coordinates, I'm "inside" the 0/T-file Code:
// 0/T-file Your code would globally define a matrix with the face indices and their x/y-values, right? The problem is that I can't access those via my T-file. Confusing? I hope, I could describe the problem properly. Dominik EDIT: SOLVED! Code:
variables "circ=<value>;d_2=<value>;n=5;Xcoord=pos().x;Zcoord=pos().z;"; |
Dear Dominik,
My apologies, indeed the method I describe above can be used when adding a new BC to the sources, not by directly writing it in the e.g. 0/T-file. I missed this small detail ;-) I have to disappoint you however, I'm not familiar with groovyBC so I won't be able to help you any further. But I'm sure there are people at this forum who can do so. L |
Saving coordinates in a seperate file
Hello again,
I gave it some more thoughts. Lieven, I have an idea how to still use your code and then use it for the BC. What if: -I write a script that prints every boundary face (index x y z) in a n-4-matrix -> I add a fifth column with the calculated value for the BC -> I load this fifth column into my 0/T-file and thereby neglect implementing the calculation in groovyBC Since I'm fairly new to OF, my questions are: 1. Where should this file be located? /constant/polyMesh or 0/T? 2. Can I easily load the fifth column via a command of by saving it as .csv? I hope that there are some threads about the 2nd question already. Anyway, feel invited to tell me what you think |
Hye can you describe how will you define Ua????? i cant understand it
Quote:
|
Hi,
Is there any Header files to be included to use "Vector::X" because I have been getting the error, error: ‘template<class Cmpt> class Foam::Vector’ used without template parameters. |
#include "Vector.H"
|
how you declare mesh in other scope?
I am trying to access mesh for the sentence "forAll(mesh.C(), celli)" in other scope (another source file), but the compiler keeps telling me I have not declare mesh in the scope.
How am I gonna fix this? |
All times are GMT -4. The time now is 21:27. |