CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to calculate the divergence of velocity at the grid vertex (https://www.cfd-online.com/Forums/openfoam-programming-development/122930-how-calculate-divergence-velocity-grid-vertex.html)

xiaof September 1, 2013 01:10

How to calculate the divergence of velocity at the grid vertex
 
1 Attachment(s)
Hello everyone
I want to calculate the divergence of velocity at the grid vertex using the value of cell center just like the attached file showing.Because the mesh file is unstructured,I don't know how to express the U(i+1,j+1)V(i+1,j+1),U(i,j+1)V(i,j+1)
U(i+1,j)V(i+1,j),U(i,j)V(i,j).

If anyone knows how to realize this,please tell me!

Thank you very much!

best regards!

xiaof

wyldckat September 1, 2013 05:51

Greetings xiaof,

Have a look into:
Best regards,
Bruno

bigphil September 2, 2013 09:05

Hi xiaof,

You could calculate the cell-centred divergence field and then interpolate this volume field to the vertices, using pointVolInterpolation (available in OpenFOAM-1.6-ext, I'm not sure which class does this in standard OpenFOAM).

Best regards,
Philip

xiaof September 2, 2013 11:12

Hi Philip
Thank you for your method.With your method,I can get the divergence at the vertices.But I think it is different what I mean.I need to use the four cell-center velocity around the vertices to get the divergence.

So if I get the vertices velocity, can I use
Code:

fvc::div()
or
fvc::grad()

to get what I want? or are there any operators about the pointFields can I use?

thank you!

xiaof

bigphil September 2, 2013 11:32

Hi xiaof,

I am not sure I understand what exactly you want to do, but I don't think the fvc/fvm operators will do exactly what you want.
The fvc/fvm operators typically deal with volume fields (cell centre) and surface fields (face centre).

You might be able to active what you want by manually calculating the value for each vertex, e.g.
Code:

const labelListList& pointCells = mesh.pointCells();
// go through all points
forAll(mesh.points(), pointi)
{
  // go through all cells around pointi
  forAll(pointCells[pointi], celli)
  {
    label cellID = pointCells[pointi][celli];

    // do some calculations here, maybe using centre co-ordinates
    // e.g.
    divU[pointi] += mesh.C()[cellID]*U[cellID];
  }
}

But you would need to be careful about including in boundary values.

Maybe you could explain a bit more about why you need to do this calculation, then we might be able to suggest the best way.

Best regards,
Philip

xiaof September 2, 2013 20:20

Hi Philip
Because we want want to test a new interpolate scheme.Although the divergence at cell center approaches to zero,the divergence at cell vertices might not.So we want to calculate the divergence of velocity at the grid vertex using the value of cell center.

Code:

divU[pointi] += mesh.C()[cellID]*U[cellID];
This code is not for the divergence, right?
With the centre co-ordinates,maybe we should calculate some weight coefficient.


If the mesh is not hexahedron,how to calculate it with general method?

Thank you!

regards!

xiaof

bigphil September 3, 2013 10:03

Quote:

Originally Posted by xiaof (Post 449454)
Hi Philip
Because we want want to test a new interpolate scheme.Although the divergence at cell center approaches to zero,the divergence at cell vertices might not.So we want to calculate the divergence of velocity at the grid vertex using the value of cell center.

Code:

divU[pointi] += mesh.C()[cellID]*U[cellID];
This code is not for the divergence, right?
With the centre co-ordinates,maybe we should calculate some weight coefficient.


If the mesh is not hexahedron,how to calculate it with general method?

Thank you!

regards!

xiaof

Your PM:
Quote:

I have some doubts there.And I have another question.Although I can know the cells around pointi,how can I know the exact cell ID of them(
left down, right down, left up, right up cells).Because to the different cell, I would take different operation,for example
Code:

0.5(Ux(right down)-Ux(left down))+0.5(Ux(right up)-Ux(right down))+0.5(Uy(left up) -Uy(left down))+0.5(Uy(right up)-Uy(right down))


Hi xiaof,

OK that sounds like an interesting interpolation scheme.

As regards this code:
Code:

divU[pointi] += mesh.C()[cellID]*U[cellID];
I was just showing you where to do your calculations, this code does not have a meaning and is just an example.

I cannot help you figure out how to do this for an unstructured grid; however, I would suggest you start by drawing some general polygons around a vertex and see if you can figure out a general method based on surrounding cell centre velocities and coordinates I suppose.
For example, OpenFOAM calculates gradients and divergences by summing up terms on each face of a cell so the method is independent of the cell shapes and number of faces.

To get the cell IDs of the cells surrounding a point is easy (OpenFOAM does the work), I will rewrite part of code from my previous post with more comments:
Code:

// pointCells gives you a list of the cell IDs of the cells around every mesh point
const labelListList& pointCells = mesh.pointCells();
// go through all points
forAll(mesh.points(), pointi)
{
  // now we go through all cells around pointi
// i.e. there are pointCells[pointi].size() cells around pointi
// and pointCells[pointi] gives you a list of the cell IDs
  forAll(pointCells[pointi], celli)
  {
// here is the ID of celli
    label cellID = pointCells[pointi][celli];
// so we can use cellID to get the velocity or coordinates below

    // do some calculations here, maybe using centre co-ordinates
    // just and example calculation - does not mean anything!
    divU[pointi] += mesh.C()[cellID]*U[cellID];
  }
}

Best regards,
Philip

xiaof September 4, 2013 04:37

1 Attachment(s)
Hi Philip
Thank you for your explain.Now I can find the all cells around the pointi.What I want to make sue further is which one is the first one ,second one...
As to the attached file,is it the leftdown cell is the first one cell.And then I can take different operation.


Thank you very much!

regards!

xiaof

bigphil September 4, 2013 10:07

Quote:

Originally Posted by xiaof (Post 449748)
Hi Philip
Thank you for your explain.Now I can find the all cells around the pointi.What I want to make sue further is which one is the first one ,second one...

You need to stop thinking in a structured mesh way and start thinking in an unstructured mesh way;

In an unstructured mesh, there is no leftUp, rightUP, etc. because there might be 3 surrounding cells or 10 surrounding cells.
So for your case, the only pertinent information you know is:
  • the number of cells surrounding a point - pointCells[pointi].size()
  • the coordinates of these surrounding cell centres - mesh.C()[cellID]
  • all other mesh connectivity, face areas, etc.
so you need to come up with a version of your method that can only uses this information without knowing about leftUp, rightUp, etc.

Philip

Z.Q. Niu December 18, 2014 07:21

Dear Philip,
I'm doing the post-processing of a vector field, I want to take an average of velocity along one direction, but I don't know how to get the velocity at the point or center of cell. Would you mind giving me some advice? Thanks!


All times are GMT -4. The time now is 06:03.