CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   SIGSEGV error when running UDF (https://www.cfd-online.com/Forums/fluent-udf/231941-sigsegv-error-when-running-udf.html)

tricha122 November 24, 2020 07:25

SIGSEGV error when running UDF
 
Hi,

I'm trying to calculate the heat transfer coefficient at the interface between my solid and fluid mesh (simple pipe, CHT)

The following code seems to fail every time with a SIGSEGV error. In fact, it wont even print out my messages within begin_f_loop. The output i get is "Begin F loop" (as i message out), and then the SIGSEGV error. I originally thought this was due to trying to loop along some solid faces, so i put a little if statement to omit any threads other than the one i am interested in.

I am totally lost. any help would be greatly appreciated.

Thanks!

Code:


#include "udf.h"
#include "sg.h"
#include "mem.h"


DEFINE_ON_DEMAND(on_demand_calc)
{

  /* Initialize face data */
  real kt, dTx, dTy, dTxRG, dTyRG, dTr, dTrRG;


        /* Initialize heat Transfer Coefficient*/
        real whtc, whtcRG;

  /* Initialize Temp, Q */

  real TWall, TBulk, QWall, QWallRG, TWadj;

  Domain *d; /* declare domain pointer since it is not passed as an argument to the DEFINE macro */
  Thread *t, *t0;
  cell_t c0;
  face_t f;

  d = Get_Domain(1);
  /* Loop over all boundary zones in the domain */
  thread_loop_f(t,d)
  {
          Message ("Cell Thread %d \n", t);
      Message (THREAD_NAME(t));
      if (strcmp(THREAD_NAME(t),"pipe_fluid")!=0)
      {
        Message ("skipping thread \n");
        continue;
        /* break; */
      }
          /* function that returns TRUE if Thread *t is a boundary face thread */
          if (BOUNDARY_FACE_THREAD_P(t)) /* (WALL_THREAD_P(t))*/
      {
            Message ("Begin F loop \n");
            /* Loop over all faces */
            begin_f_loop(f,t)
            {
              if (f==0)
              {
                  Message ("Beginning face loop \n");
              }
              /* c0 and t0 identify the adjacent cell */
              c0 = F_C0(f, t);
              t0 = THREAD_T0(t);

                              /* Properties */
                              kt = C_K_L(c0,t0);
              Message ("kt = %g \n",kt);

              /* Cell Gradients */
              dTx = C_T_G(c0,t0)[0]; /* returns the x-component of the cell temperature gradient vector */
              dTy = C_T_G(c0,t0)[1]; /* returns the x-component of the cell temperature gradient vector */

              Message ("dTx = %g \n",dTx);
              Message ("dTy = %g \n",dTy);

              dTxRG = C_T_RG(c0,t0)[0]; /* returns the x-component of the cell temperature gradient vector */
              dTyRG = C_T_RG(c0,t0)[1]; /* returns the x-component of the cell temperature gradient vector */

              Message ("dTxRG = %g \n",dTxRG);
              Message ("dTyRG = %g \n",dTyRG);

              dTr = pow(pow(dTx,2)+pow(dTy,2),0.5);
              dTrRG = pow(pow(dTxRG,2)+pow(dTyRG,2),0.5);

              Message ("dTr = %g \n", dTr);
              Message ("dTrRG = %g \n",dTrRG);

              QWall = -kt*dTr;
              QWallRG = -kt*dTrRG;

              Message ("Qwall = %g \n", QWall);
              Message ("QwallRG = %g \n",QWallRG);


                              /* Retrieve bulk temperature & Wall Adjacent Temperature */
                              TBulk = RP_Get_Real("ref/temperature");
              TWadj = F_T(f,t);

              Message ("TBulk = %g \n",TBulk);
              Message ("TWadj = %g \n",TWadj);


              /* Calculate heat transfer coefficient */

              whtc = QWall/(TWadj-TBulk);
              whtcRG = QWallRG/(TWadj/TBulk);

              /* TWall = QWall/(-kt*dTr) + TWadj */

              Message ("Store data \n");

              C_UDMI(c0,t0,0) = whtc;
              F_UDMI(f,t,0) = whtc;

              C_UDMI(c0,t0,1) = QWall;
              F_UDMI(f,t,1) = QWall;

              C_UDMI(c0,t0,2) = QWallRG;
              F_UDMI(f,t,2) = QWallRG;

              C_UDMI(c0,t0,3) = TBulk;
              F_UDMI(f,t,3) = TBulk;

              C_UDMI(c0,t0,4) = TWadj;
              F_UDMI(f,t,4) = TWadj;

              C_UDMI(c0,t0,5) = whtcRG;
              F_UDMI(f,t,5) = whtcRG;


                      }
            end_f_loop(f,t)
      }
  }
}


Cell Thread 89742640
pipe_solid-non-overlappingskipping thread
Cell Thread 89581616
pipe_fluid-non-overlappingskipping thread
Cell Thread 89420592
pipe_interface-wall1-1-1skipping thread
Cell Thread 89903664
pipe_interface-wall1-1-1-shadowskipping thread
Cell Thread 86909472
interior-fluidskipping thread
Cell Thread 87070496
inletskipping thread
Cell Thread 87231520
outletskipping thread
Cell Thread 87392544
pipe_fluidBegin F loop
Cell Thread 88369344
interior-solidskipping thread
Cell Thread 88518224
wall-solidskipping thread
Cell Thread 88667104
pipe_solidskipping thread
Cell Thread 88828128
htfx_bcskipping thread

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

Node 0: Process 381551: Received signal SIGSEGV.

================================================== ============================
The fluent process could not be started.

pakk November 24, 2020 13:18

Do you get the same if you replace

kt = C_K_L(c0,t0);

By

kt = 0.0;

?

tricha122 November 26, 2020 10:27

Quote:

Originally Posted by pakk (Post 788723)
Do you get the same if you replace

kt = C_K_L(c0,t0);

By

kt = 0.0;

?

Thanks for looking into this!

Turns out the problem was as follows:

1) I was retrieving gradient data (C_T_G) and that is only stored if you request it
2) I was storing calculations to UDMI_F() on an interface… you can only store face values to walls and boundaries….


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