CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Interpolation within a cell

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 9, 2020, 07:34
Default Interpolation within a cell
  #1
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
Hello,
i have written an UDF to interpolate flow-values at a desired poisition inside the domain.

First, the UDF searches for the cell in which the specified point is located. Then the value at the specified point is interpolated using the gradient and the distance to the cell center.
Exampe for u-velocity yomponent:

Code:
NV_VV(dy, =, coords_VOLUME[point], -, point_list_VOLUME[point].centroid);

NV_V(grady, =, C_U_RG(c,t));
y0 = C_U(c,t);
y = y0 + NV_DOT(grady, dy);
Although this procedure works, the accuracy achieved is not satisfactory (i calculate the q-criterion based on the interpolated velocities and get really wiggly isosurfaces compared to the fluent output). I have already tested various gradient settings (Green-Gauss / Least Squares - Different limiter Types and cell2cell / cell2face), without success.


Now I'm wondering if there is a built in marco for the interpolation purpose or if there is an UDF example of a more sophisticated approach (interpolation based on the nearest neighbours/trilinear interpolation?)



Many thanks in advance!
Mohinder Suresh is offline   Reply With Quote

Old   April 9, 2020, 09:51
Default Interpolation
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
For zeroth order interpolation, you just need to report the values at the centers of the cells containing the points. In my view, you should report difference and the values at the cell centers and then check if the variation is significant enough to justify all this effort.

How is an iso-surface connected to your UDF?
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 9, 2020, 13:03
Default
  #3
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
When I generate an iso surface of the q-criterion based on the interpolated values of u, v, w (UDF) and compare it to the isosurface based on the original grid data in a .dat file, it is not as smooth as it should be.
Mohinder Suresh is offline   Reply With Quote

Old   April 9, 2020, 13:04
Default
  #4
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
I think that the interpolation method using the gradient is not accurate enough and I'm wondering if there is an in built macro for interpolation, which is more accurate?
Mohinder Suresh is offline   Reply With Quote

Old   April 9, 2020, 13:10
Default Udm
  #5
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
I suppose you are saving values in a UDM and then using the UDM for creating iso-surface.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 9, 2020, 13:13
Default
  #6
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
I'm saving the interpolated values of u, v, w to a file at every nth time step and generate the isosurface in tecplot.
Mohinder Suresh is offline   Reply With Quote

Old   April 9, 2020, 13:45
Default Isosurface
  #7
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
I am not sure how it is done in Tecplot, however, from the very fundamental concepts, it should be similar to what is being done in Fluent or any other tool. Iso-surface generation usually does interpolation to find points that have same value within a certain tolerance. You use interpolation to find values at certain points and then those are being used to generate iso-surface causing re-interpolation. If you want to generation iso-surface, I'd suggest using original data instead of interpolated one.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 9, 2020, 14:13
Default
  #8
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
Yes of course it would be better to use the original data, as interpolation allways brings some errors but when you have over 100m cells its not possible to save volume data at high sampling frequencies ... =|
Mohinder Suresh is offline   Reply With Quote

Old   April 9, 2020, 14:24
Default Big Mesh
  #9
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
In that case, I suppose zeroth order might give you better results. Even better could be to report the coordinates of the cell centers and their values corresponding to the points you use. Then, use the reported cell centers and cell center based data in Tecplot.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 10, 2020, 02:01
Default
  #10
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
Hi vinerm,
Thanks for your reply. I also tried 0th order interpolation and this gives worse results than the gradient based interpolation as you can see in the attached pictures...I'm wondering which method fluent uses when you define a monitor point via the GUI and if this method is available through a UDF macro ....
Attached Images
File Type: jpg interpolation.jpg (47.0 KB, 16 views)
Mohinder Suresh is offline   Reply With Quote

Old   April 10, 2020, 03:08
Default Iso-surface
  #11
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Is the image on the left based on 0th order?

What if you directly generate iso-surface within Fluent? You may not have data at all times but for whichever time you have it available, it will be good to compare against that.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 10, 2020, 03:41
Default
  #12
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
Hi vinerm,
yes left is the contour of 0th order.

I compared isosurfaces of q-criterion between fluent (original grid) and tecplot (interpolated data) and the fluent isosurface is much smoother. I really think that this is caused by the gradient interpolation.
Mohinder Suresh is offline   Reply With Quote

Old   April 10, 2020, 03:43
Default
  #13
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
in CFX I have used the inbuilt interpolation for the same purpose and it gave me perfectly smooth isosurfaces...
Mohinder Suresh is offline   Reply With Quote

Old   April 10, 2020, 04:13
Default Interpolation
  #14
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
For interpolation, I don't think Fluent uses first-order interpolation. It is most likely second order and centered. There is one way of using in-built interpolation. But you should try it with a small number of points first. What you need to do is create particles at the same locations where you have points. This can done using FILE injection. Each particle has its primary phase data structure attached to it. To determine particle Re number, Fluent uses interpolation to determine fluid velocity at the particle locations. Each particle's continuous phase member is defined by structure cphase. So, to access x-velocity at the location of the particle, you can do the following

cphase_state_t *cp;
real xvelatp;
cp = p->cphase;
xvetatp = cp->V[0];
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 10, 2020, 04:18
Default
  #15
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
Hi vinerm,
thanks for this work around. I will give it a try tomorrow and will report if it gives better results!
Greets
Mohinder Suresh is offline   Reply With Quote

Old   April 10, 2020, 12:36
Default
  #16
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
Okay, I just wanted to implement your suggestion but I'm stuck at the injection part.
As I have a loop over all the points where I want to get the velocity components, is it possible to only inject one particle inside this loop at the desired point?

Greets
Mohinder Suresh is offline   Reply With Quote

Old   April 10, 2020, 12:49
Default Injection
  #17
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
You can setup a file injection where your monitor points can be used as coordinates of particles. So, you would not require a loop.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 11, 2020, 03:50
Default
  #18
Member
 
Mohinder Suresh
Join Date: Dec 2014
Posts: 32
Rep Power: 11
Mohinder Suresh is on a distinguished road
Good morning,
I think fluent uses the same gradient based interpolation for the particle velocities as described in solution #2061258

Quote:
Continuous phase velocities are interpolated to particle locations for evaluating interactions such as particledrag.For example, the term (𝑢𝑢𝑝) uses the interpolated continuous phase velocity 𝑢 at theparticle location (𝑥𝑝,𝑦𝑝,𝑧𝑝) using cell center values of fluid velocity and its gradients.

Nevertheless, I could find the reason for the wiggles in the q-criterion. It was caused by the central scheme momentum discretiszation. The CDS wiggles where only observable in the gradient fields and corrupted the interpolation procedure. With bounded CDS the wiggles are gone.



Now I have one final question: Do you think it is better to use the reconstruction gradients for the interpolation? The difference compared to the regular gradients is only marginal.


Greets








Mohinder Suresh is offline   Reply With Quote

Old   April 11, 2020, 09:00
Default Gradient
  #19
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
That's good that the wiggles are gone with bounded scheme.

Reconstruction and Gradients should be very close. For a deeply converged solution, both should be same within machine precision. With weak convergence, reconstruction gradients are better though non-conservative.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Reply


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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 18:57
Journal file error magicalmarshmallow FLUENT 3 April 4, 2014 12:25
[General] 2 datas on one plot Akuji ParaView 46 December 1, 2013 14:06
FvMatrix coefficients shrina OpenFOAM Running, Solving & CFD 10 October 3, 2013 14:38
Extracting cell centre values WITHOUT interpolation dalaron OpenFOAM Post-Processing 1 August 18, 2013 00:39


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