- **OpenFOAM Programming & Development**
(*http://www.cfd-online.com/Forums/openfoam-programming-development/*)

- - **How to calculate the divergence of velocity at the grid vertex**
(*http://www.cfd-online.com/Forums/openfoam-programming-development/122930-how-calculate-divergence-velocity-grid-vertex.html*)

How to calculate the divergence of velocity at the grid vertex1 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 |

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
Bruno |

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 |

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()` thank you! xiaof |

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();` 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 |

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];` 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:
Quote:
Hi xiaof, OK that sounds like an interesting interpolation scheme. As regards this code: Code:
`divU[pointi] += mesh.C()[cellID]*U[cellID];` 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` Philip |

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 |

Quote:
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.
Philip |

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 23:37. |