# How to calculate the divergence of velocity at the grid vertex

 Register Blogs Members List Search Today's Posts Mark Forums Read

September 1, 2013, 01:10
How to calculate the divergence of velocity at the grid vertex
#1
New Member

JM
Join Date: Jul 2013
Posts: 7
Rep Power: 4
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
Attached Images
 QQ??20130901130610.png (8.6 KB, 27 views)

 September 1, 2013, 05:51 #2 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 8,318 Blog Entries: 34 Rep Power: 84 Greetings xiaof, Have a look into: The Programmer's Guide: http://foam.sourceforge.net/docs/Gui...mmersGuide.pdf And this utility that demonstrates how reconstruct and interpolate work in OpenFOAM: https://github.com/wyldckat/reconstr...rpolate-fields Best regards, Bruno __________________ OpenFOAM: Frequently Asked Questions | Useful links for building and using Forum: How to ask for help | Posting code and output with [CODE] My to-do list and when I'll be able to come to the forum: http://wyldckat.github.io And please: Read this before sending private messages to me

 September 2, 2013, 09:05 #3 Senior Member     Philip Cardiff Join Date: Mar 2009 Location: Dublin,Ireland Posts: 568 Rep Power: 19 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

 September 2, 2013, 11:12 #4 New Member   JM Join Date: Jul 2013 Posts: 7 Rep Power: 4 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

 September 2, 2013, 11:32 #5 Senior Member     Philip Cardiff Join Date: Mar 2009 Location: Dublin,Ireland Posts: 568 Rep Power: 19 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

 September 2, 2013, 20:20 #6 New Member   JM Join Date: Jul 2013 Posts: 7 Rep Power: 4 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

September 3, 2013, 10:03
#7
Senior Member

Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 568
Rep Power: 19
Quote:
 Originally Posted by xiaof 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
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

September 4, 2013, 04:37
#8
New Member

JM
Join Date: Jul 2013
Posts: 7
Rep Power: 4
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
Attached Images
 1.jpg (13.3 KB, 6 views)

September 4, 2013, 10:07
#9
Senior Member

Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 568
Rep Power: 19
Quote:
 Originally Posted by xiaof 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

 December 18, 2014, 08:21 #10 Member   Niu Join Date: Apr 2014 Posts: 42 Rep Power: 3 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!

 Tags divergence of velocity

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post alfaruk CFX 8 December 3, 2013 17:51 hanklord Main CFD Forum 0 July 12, 2013 03:25 wanghaojie Fluent UDF and Scheme Programming 0 March 23, 2012 11:21 Abhi Main CFD Forum 12 July 8, 2002 09:11 Chuck Leakeas Main CFD Forum 2 May 26, 2000 11:18

All times are GMT -4. The time now is 01:04.