CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   STAR-CCM+ (https://www.cfd-online.com/Forums/star-ccm/)
-   -   User Coding - Get number of iteration (https://www.cfd-online.com/Forums/star-ccm/211012-user-coding-get-number-iteration.html)

lee_2017 November 9, 2018 05:12

User Coding - Get number of iteration
 
Dear Members,


I am working with the User Code of CCM+ v1302 and right now I am struggling to get the number of the current iteration. To keep it simple, I just copied the part of the code which belongs to the loading in of the iteration number. This code prints out a false iteration number to the terminal and furthermore does not display the number in the scalar scene of the sim file.

Does anyone of you know how the exact code has to look like to get the iteration number? Thank you!


Code:

#include "uclib.h"
#include <math.h>
#include <stdio.h>
 
void Test(CoordReal *result, CoordReal *I)

  printf("Iteration = %d\n",I);
  result = I;
}
 
void uclib()
{
  /* Register user functions here */
  ucfunc(Test, "ScalarFieldFunction", "Test User Coding");
  ucarg(Test, "Cell", "$Iteration", sizeof(CoordReal));
}


bluebase November 14, 2018 04:13

Hi Lee,

Comparing the snippet to the documentation's example: yours is missing to fill the result vector's components but instead replaces the vector result with a 1 component vector.

The argument size is explicitly needed, according to the documentation.
Try the snippet below.


Best regards,
Sebastian

Code:

#include "uclib.h"
#include <math.h>
#include <stdio.h>
 
void TestFunc(CoordReal *result, int size, CoordReal *I)

    int i;
    for (i = 0; i != size; ++i)
    {
          result[i] = I[i];
    }
}
 
void uclib()
{
  /* Register user functions here */
  ucfunc(TestFunc, "ScalarFieldFunction", "Test User Coding");
  ucarg(TestFunc, "Cell", "$Iteration", sizeof(CoordReal));
}



All times are GMT -4. The time now is 13:26.