## Fluids

#### How to pass “Electric Current Magnitude” to UDF for deformation calculation?

• paoching
Subscriber

I'm writing a UDF for galvanic corrosion deformation of Al and Cu block submerged in water.

The process goes like so:

1. the geometry is a 10mm*20mm*5mm electrolyte domain with one face split to 2 10mm square face representing boundary to Al and Cu electrode.

2. material is water-liquid for the entire domain with electric conductivity of 50 S/m.

3. potential boundary conditions are set to galvanic potential of Al and Cu at -0.85 V and -0.3 V respectively

4. using fluent's electric potential model, run steady state simulation

5. contour of Electric Current Magnitude is plotted as follow

6. I would then pass calculated "Electric Current Magnitude" as J to corrosion damage UDF to calculate corrosion rate in transient simulation and hook it to Dynamic mesh zone of Al electrode as mesh motion UDF

My question is how to pass the current density (or Electric Current Magnitude, a post-processing variable under potential) to UDF. I know there are micros that can pass cell or face variable like temperature and pressure to UDF like C_P(c,t) or F_T(f,t), but I can find no such macro for current density. Perhaps the potential model is still relatively new and incomplete? Is there anyway to work around that using UDM or RP variable?

Paul Lee

P.S. attached is the UDF I have so far.

• jmccasli
Ansys Employee

Hi Paul,

The current is calculated from the Ohm's law i = -(electric conductivity) * gradient (electric potential), i.e.

Fluent has macros to access the value of the electric potential in the cell c of the thread ct: C_PHI_1(c,ct). Also the ith component of its gradient is obtained with C_PHI_1_G(c,ct). So you can compute the magnitude from the components and store it in a UDS or UDM as needed.

I hope this helps!

Regards,

Jeremy

• paoching
Subscriber

Thank you Jeremy, I've tried to implement C_PHI_1_G(c,ct) in my UDF as you suggested but ran into another error. Here is the updated UDF:

/**********************************************************

node motion based on corrosion rate calculated from electric

current density compiled UDF

**********************************************************/

#include "udf.h"

#include "metric.h"

#include "mem.h"

#include "sg_udms.h"

#include "sg.h"

#include "models.h"

#include "dynamesh_tools.h"

DEFINE_GRID_MOTION(corrosion_rate,domain,dt,time,dtime)

{

face_t f;

cell_t c;

Node *v;

real y;

int n;

real F=96485.34; //Faraday's constant C/mol or A*s/mol

real MWT=26.981539; //molecular weight

int z=3; //al ion charge#

real RHO=2700000; //Al density g/m^3

real sigma=5;

real k=(-sigma*MWT/(z*F*RHO));

{

begin_c_loop (c,tf)

{

C_UDMI(c,tf,0) = k*C_PHI_1_G(c,tf)[1];

}

end_c_loop (c,tf)

}

/* set deforming flag on adjacent cell zone */

Message ("time = %f, Cr = %fn", time);

begin_f_loop(f,tf)

{

f_node_loop(f,tf,n)

{

v = F_NODE(f,tf,n);

if (NODE_POS_NEED_UPDATE (v))

{

/* indicate that node position has been update

so that it's not updated more than once */

NODE_POS_UPDATED(v);

NODE_Y(v) -= C_UDMI(c,tf,0)*dtime; //new y position

}

}

}

end_f_loop(f,tf);

}

Although I can compile and load it, I got segmentation fault error after hooking it to dynamic mesh when previewing dynamic mesh and when solving transient case. Naturally, static case runs fine if UDF is not used.

Error: received a fatal signal (Segmentation fault).

Error Object: #f

Thoughts? a google search tell me that segmentation fault is the result of trying to access a variable that is not saved. But is it referring to the UDM or the C_PHI_G? I have made sure to enable UDM in fluent, so what could be causing this error?

• DrAmine
Ansys Employee

You can only access the gradient of quantity if you are are in the DEFINE Macro eligible  for that: Example Temperature gradient can be accessed directly if you have to define a Source for the energy equation. For all other scenarios like you have, there is an official and supported way (some other ways are possible) will be via /solve/set> expert and then choose to Keep temporary solver memory from being freed? [yes]. That should work for almost all gradients.

• paoching
Subscriber

You can only access the gradient of quantity if you are are in the DEFINE Macro eligible  for that: Example Temperature gradient can be accessed directly if you have to define a Source for the energy equation.

Do you mean that C_PHI_1_G(c,tf) isn't eligible in DEFINE_GRID_MOTION? if that is so, what variable is eligible? and what DEFINE macro can access potential gradient? is there a list somewhere? note that my thread_loop_c that house the C_PHI_1_G(c,tf) is inside the DEFINE_GRID_MOTION macro.

For all other scenarios like you have, there is an official and supported way (some other ways are possible) will be via /solve/set> expert and then choose to Keep temporary solver memory from being freed? [yes]. That should work for almost all gradients.

good tips on setting to keep solver memory, I've done so without changing my UDF and get the following error when previewing zone motion:

Updating mesh to time 1.00000e-01 (step = 00001)...

Info: Maximum Cell Skewness outside reasonable limits, using 0.95 instead.

Info: Maximum Cell Skewness outside reasonable limits, using 0.95 instead.

==============================================================================

Node 999999: Process 15004: Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 1: Process 6236: Received signal SIGSEGV.

==============================================================================

MPI Application rank 0 exited before MPI_Finalize() with status -1073741819

The fl process could not be started.

Also, I could not run transient calculation as is, nothing happen when I press the calculate button. no error message is produced. A floating dialog box appear for a fraction of a second letting me know that I did press the calculate button, but nothing happens. My guess is that whatever error in dynamic mesh is preventing the solver to start properly.

• Konstantine Kourbatski
Ansys Employee

Your code is wrong, dt is the dynamic zone thread, which is a face in you case, and using it in begin_c_loop will result is SIGSEGV. You also cannot NODE_Y(v) -= C_UDMI(c,tf,0)*dtime; as C_UDMI is a cell value not available on the face. Instead, you need to retrieve the gradient value from the cell center of the adjacent cell. Macros for this are described in the UDF manual

• paoching
Subscriber

Thank you, I will attempt to fix the code as you suggested!