Fluids

Fluids

Difference in GUI based surface intergral and UDF based formula.

    • atulsingh92
      Subscriber

      Hello,

      I have a UDF that tries to calculate area weighted average of Pressure at the surface, as follows.

      float Print_dynPressure(Domain *domain, int id)
      {
           cell_t c;
          Thread *t;
          face_t f;
          t = Lookup_Thread(domain, id);
      
          begin_f_loop(f,t)
          {
              uc = F_U(f,t);
              vc = F_V(f,t);
              wc = F_W(f,t);
              temp = F_T(f,t);
              stat_p = F_P(f,t);
              dens = F_R(f,t);
              Flux = F_FLUX(f,t);
      
              F_AREA(area,f,t);
              Amag = NV_MAG(area);
              total_area += Amag;
      
              vmag = sqrt(pow(uc,2) + pow(vc,2) + pow(wc,2));
              vavg = Flux / (dens * Amag) ; //in a single cell
              dyn_p = 0.5*dens*pow(vavg,2);
              total_p = stat_p + dyn_p;
      
              p_sum += total_p * Amag;
      
          }
          end_f_loop(f,t)
          float pa_glob = PRF_GRSUM1(p_sum);
          float area_avg_p_f = pa_glob/total_area ; // for area averaged pressure i.e sigma p|A|/A
          return area_avg_p_f;
      }
      


      The results obtained from above method called ad DEFINE_ON_DEMAND, with the resutls obtained from Area weighted average of Total pressure from gui are as follows,

    • Keyur Kanade
      Ansys Employee
      Why do you want to replicate it in UDF it already exists in Fluent as standard function? nWe will not debug UDF. Others on forum can pitch in. nYou can see how area weighted is calculated in Fluent at following link. nPlease go through help manual for more details nRegards,nKeyurnHow to access Ansys Online Help DocumentnHow to show full resolution imagenGuidelines on the Student CommunitynHow to use Google to search within Ansys Student Communityn
    • atulsingh92
      Subscriber
      I guess the question is not to debug the udf, but rather to ask, if I have missed out on any formula that calculates the surface integral?nI already have the link that you provided in my equation, (see second last line within comments), so I am already summing the total pressure, multiplying with an area, summing this product, and dividing with total area.nOr perhaps a way to narrow down the source of this difference would also be helpful.n
    • YasserSelima
      Subscriber
      First, whatever you calculate using report definition is accessible to your UDF ... I don't have access to the manual now to get you the macro, but search for it in the manual. You can just get the value and report it in your files.nSecond, I suspect that you did a very common mistake ... Did you set p_sum = 0 before starting the loop every time ? I can't answer because I can't see the rest of the codenThird, make sure that you selected total pressure in the report definition, so you compare total pressure to total pressurenn
    • YasserSelima
      Subscriber
      Look for Get_Report_Definition_Values to access the values calculated in your report definitio
    • atulsingh92
      Subscriber
      As always, many thanks Yasser, nyes p_sum=0.0 was defined.nAnd yes, I knew about the Get_report_definition_values, however, the idea was to simply read/tally/ from surface-integrals instead, becuase choosing 4 surfaces, lets say, for a report definition gives a cumulative pressure at all the 4 surfaces, while doing the same on surface integral gives individual values at each surface.nThis means, there should be 4 such reports for 4 different surfaces, and this will quickly become cumbersome, if there are many surfaces, (inlet/outlets of tubes of heat exchangers).n
    • YasserSelima
      Subscriber
      This would still be faster than recalculating the values ... And if you create the report definition for all 4 surfaces and checked the box per zone, the function will return the 4 values separately ... nAnyway, your function seems right but has two minor corrections which will not make much difference .. but let's trynnAdd this before calculating the average pressurentotal_area = PRF_GRSUM1(total_area);nand correct this, use the magnitude instead of vavgndyn_p = 0.5*dens*pow(vmag,2);nn
    • atulsingh92
      Subscriber
      yes, it doesn't make much difference!nAnd could I request Fluent team to correct example 3.8.3 of Fluent manual on Get_Report_Definition_Values. Using this udf as it is, gives the following error.nPlease note, the udf has been used as it is given exactly in 3.8.3, Steady state example, as my requirement was the same.nc(9) is at int rv = Get....nc(10) is at the very next if condition.n..\..\src\get_report.c(9): error C2099: initializer is not a constant n..\..\src\get_report.c(10): error C2059: syntax error: 'if'n..\..\src\get_report.c(29): error C2059: syntax error: 'else'nnhere is the code.n#include udf.hnint nrOfvalues=0;nreal *values;nint *ids;nint index;nint counter;nint rv ;n nrv = Get_Report_Definition_Values(area-avg-tot-pressure, 0, &nrOfvalues, NULL, NULL,NULL);  / 0 if successful, 1 if fails!nnMessage(Report definition evaluated at iteration has %d values, rv);nnif (rv==0 && nrOfvalues)n{nn    Message(Report definition evaluated at iteration has %d values, nrOfvalues);n    /*Memory is allocated for values and ids.*/n    values = (real*) malloc(sizeof(real)* nrOfvalues);n    ids = (int*) malloc(sizeof(int)* nrOfvalues);n    /* Second call to get data. The number of values is null, but the lastn    * three are not.*/n    rv = Get_Report_Definition_Values(area-avg-tot-pressure, 0, NULL, values, ids, &index);n    Message(Values correspond to iteration index:%d, index);n    for ( counter = 0; counter < nrOfvalues; counter++ )n        {n            Message(report definition values: %d, %f, ids[counter], values[counter]);n        }n        /*Memory is freed.*/n    free(values);n    free(ids);nnelsen{n    /*The command can be unsuccessful if the report definition does not existn    or if it has not been evaluated yet.*/n    if (rv == 1)n    {n    Message(report definition: %s does not exist, area-avg-tot-pressure);n    }n    else if ( nrOfvalues == 0 )n    {n    Message(report definition: %s not evaluated at iteration level, area-avg-tot-pressure);n    }nn
    • YasserSelima
      Subscriber
      Add it inside a Define function ... do not leave it like this ..nn#include udf.hnnDEFINE_ON_DEMAND(get_report)n{ nint nrOfvalues=0;nreal *values;nint *ids;nint index;nint counter;nint rv ;nn Add the code heren
Viewing 8 reply threads
  • You must be logged in to reply to this topic.