# How to build divergence of volume fraction gradient in UDF?

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

April 1, 2017, 13:28
How to build divergence of volume fraction gradient in UDF?
#1
New Member

Join Date: Jun 2016
Posts: 3
Rep Power: 10
Hello,
I want to calculate 'curvature' in UDF. I have attached formulation of curvature.
'F' is volume fraction.
C_VOF_G(c,t) can calculate gradient of volume fraction
NV_MAG(C_VOF_G(c,t)) can calculate magnitude of volume fraction. I can calculate gradient of volume fraction but My problem is that I can't calculate divergence of volume fraction gradient in UDF.

Attached Images
 Curvature.png (5.8 KB, 10 views)

February 11, 2021, 13:53
#2
New Member

ANOOP K UNNI
Join Date: Jun 2017
Posts: 9
Rep Power: 9
Quote:
 Originally Posted by bss Hello, I want to calculate 'curvature' in UDF. I have attached formulation of curvature. 'F' is volume fraction. C_VOF_G(c,t) can calculate gradient of volume fraction NV_MAG(C_VOF_G(c,t)) can calculate magnitude of volume fraction. I can calculate gradient of volume fraction but My problem is that I can't calculate divergence of volume fraction gradient in UDF. Thank you in advance.
Hi did you solve?

 February 12, 2021, 00:47 #3 Senior Member   Join Date: Nov 2013 Posts: 1,965 Rep Power: 26 Going from the gradient to the divergence (in standard Cartesian coordinates) is super simple... Just sum them. Maybe I don't understand the problem?

February 12, 2021, 01:14
#4
New Member

ANOOP K UNNI
Join Date: Jun 2017
Posts: 9
Rep Power: 9
Quote:
 Originally Posted by pakk Going from the gradient to the divergence (in standard Cartesian coordinates) is super simple... Just sum them. Maybe I don't understand the problem?
I have written a UDF for a multiphase (of) problem dealing with recoil pressure which has to be added as momentum source term. i have attached a figure which shows a definition of my problem and also udf. can you please check whether i have written in the right way because i am not able to run the case.
#include "udf.h"
#include "sg.h"
#include "sg_mphase.h"
#include "flow.h"
#include "mem.h"

{
cell_t c;
real DVOFNX,DVOFNY,DVOFDNZ;
domain = Get_Domain(6);

/* Fill UDS with the variable. */

{
begin_c_loop (c,t)
{
C_UDSI(c,t,0) = C_VOF(c,t);

DVOFNX = C_UDSI_G(c,t,0)[0];
DVOFNY = C_UDSI_G(c,t,0)[1];
DVOFNZ = C_UDSI_G(c,t,0)[2];

C_UDMI(c,t,0) = DVOFNX;
C_UDMI(c,t,1) = DVOFNY;
C_UDMI(c,t,2) = DVOFNZ;

}
end_c_loop (c,t)
}

{
begin_c_loop (c,t)
{
C_UDMI(c,t,3) = NV_MAG(C_UDSI_G(c,t,0));
}
end_c_loop (c,t)
}

{
Domain *domain;
cell_t c;
domain = Get_Domain(6);

/* Fill the UDM with magnitude of gradient. */

{
begin_c_loop (c,t)
{
C_UDMI(c,t,4) = C_UDMI(c,t,0)/NV_MAG(C_UDSI_G(c,t,0));
C_UDMI(c,t,5) = C_UDMI(c,t,1)/NV_MAG(C_UDSI_G(c,t,0));
C_UDMI(c,t,6) = C_UDMI(c,t,2)/NV_MAG(C_UDSI_G(c,t,0));
}
end_c_loop (c,t)
}
}
}

DEFINE_SOURCE(x_recoil,c,t,dS,eqn)
{
real x[ND_ND];
real source;
real time;
real temp;
time=RP_Get_Real("flow-time"); //Acquire time from FLUENT solver
C_CENTROID(x,c,t);
temp=C_T(c,t); //Acquire the face centroid location
if (C_T(c,t) >= 3201.)
{
source=(54715.5*exp(13.14*(temp-(3200)/temp)))*(C_UDMI(c,t,4));
C_UDMI(c,t,7) = source;
dS[eqn] = 0;
}
else
{
source = dS[eqn] = 0.;
}
return source;
}
//same for y and z
Attached Images
 deep.jpg (40.6 KB, 55 views) keyhole.jpg (129.6 KB, 49 views)

February 12, 2021, 06:31
#5
Senior Member

Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
Quote:
 Originally Posted by anoop.k.unni can you please check whether i have written in the right way because i am not able to run the case.
"not able to run the case" can mean 20 things. Please be more detailed, that makes it much easier to help you.

February 12, 2021, 07:39
#6
New Member

ANOOP K UNNI
Join Date: Jun 2017
Posts: 9
Rep Power: 9
Quote:
 Originally Posted by pakk Going from the gradient to the divergence (in standard Cartesian coordinates) is super simple... Just sum them. Maybe I don't understand the problem?
Quote:
 Originally Posted by pakk "not able to run the case" can mean 20 things. Please be more detailed, that makes it much easier to help you.
After initializing the case with adjust gradient hoking and it is showing' Received signal SIGSEGV. MPI Application rank 0 exited before MPI_Finalize()' So, I want to know whether is it because of any mistake in UDF or other (improper boundary conditions,patching issue)

February 12, 2021, 11:22
#7
Senior Member

Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
Quote:
 Originally Posted by anoop.k.unni After initializing the case with adjust gradient hoking and it is showing' Received signal SIGSEGV. MPI Application rank 0 exited before MPI_Finalize()' So, I want to know whether is it because of any mistake in UDF or other (improper boundary conditions,patching issue)
That is a good question. To find out if your error comes from the UDF or from somewhere else: run it without hooking the UDF! If you don't get an error, the problem was in your UDF.

If you do get a problem: debug! Simplify your UDF, and find out which line causes the error.

 Tags curvature, gradients, udf and programming, vof method