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/)
-   -   udf not working properly (https://www.cfd-online.com/Forums/fluent-udf/233761-udf-not-working-properly.html)

Ravi palla February 10, 2021 09:00

udf not working properly
 
i have a domain for which i need to find co-ordinates of maximum stream function at all flow time values. for this i wrote a code as follows. but it worked fine for on time piston travel of my domain but for off time (i.e., after the end of piston movement the flow continues) the udf is giving same output values for all the flow time intervals. i have been working on this for a month can any one please tell me where i was wrong. the code is as follows


Code:

#include "udf.h"
#include "metric.h"
#include "mem.h"
#include <math.h>

#define ID 12 /* Zone ID (in boundary condition panel) on which node data is to be obtained */

char *what = "stream-function"; /* field variable name for which data is to be extracted */
char *what1 = "q-criterion"; /* field variable name for which data is to be extracted */
char *what2= "vorticity-mag"; /* field variable name for which data is to be extracted */

DEFINE_ON_DEMAND(on_demand_calc_stream_fun_node)
{
Domain *d; /* declare domain pointer since it is not passed as an argument to the DEFINE macro */
FILE *fp;
real tem,tmax=0.;
real x, y,x1,y1;
real z[ND_ND];
int n;
real flow_time=CURRENT_TIME;
Thread *t;
cell_t c;
Node *v;

d = Get_Domain(1); /* Get the domain using ANSYS Fluent utility */
t=Lookup_Thread(d,ID);

Node_Function_Values(d, what);

  /* Initalize all node marks on the thread == 0 */
  begin_c_loop(c, t)
  {
    c_node_loop(c, t, n)
        {
      v=C_NODE(c,t,n);
      NODE_MARK(v) = 0;
    }
  }
  end_c_loop(c, t);
/* Loop over the nodes and get the data */
  begin_c_loop(c, t)
  {
    c_node_loop(c, t, n)
        {
      v = C_NODE(c,t,n);

      x = NODE_X(v);
      y = NODE_Y(v);
         
      if(NODE_MARK(v) == 0) /* if not already visited */
          {
                C_CENTROID(z,c,t);
               
              if ((z[0]<=0.17967881) && (z[1]<=0.042617384))
          {
        tem=NODE_VALUE(v);
                if (tem > tmax)
                {                       
                tmax = tem;
                x1=x;   
                y1=y;               
                }       
          }               
        NODE_MARK(v) = 1;         
          }
    }
  }
  end_c_loop(f, t);
  fp = fopen("c_1_stream_fun_max_node.dat","a");
  fprintf(fp,"stream_fun_max_node = %g\t x= %g\t y= %g\t flow_time = %g\n",tmax,x1,y1,flow_time);
  fclose(fp); 
}


jscsgh June 19, 2022 09:24

field variable name
 
Hiya, just saw your post, not sure if you have figured the issue out. My case is that I am modelling a multi phase simulation and I would like to export the temperature value of some certain nodes. I noticed that you defined three field variables (what, what1, and what2). How do you obtain the name of your field variables. Many thanks.


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