AmesimKnowledge

solvers-numerics

How to handle discontinuities in a utility function

The case of a utility function coded in C or Fortran is similar to the case of a submodel. The main difference is the access to the “flag” integer argument. This integer is automatically added to the argument list of a submodel as indicated in the section Implementation in a submodel. However, utility functions do not always have this integer as argument, simply because they can be called by other functions that do not require it.

For that reason, a specific function getofg has been created. The role of this global function consists in returning the value of the discontinuity flag wherever in the code. It can be used similarly to the flag integer, as on the following example of sampler function.

Copy

/* preprocessor define used to clarify the code. */
#define TNEXT   c[0]
#define XSAMPLE c[1]

extern void samplerfunction_(double *y, double *x, double *period,
                             double *t, double *c[2])
{
   /* Discontinuity restart. */

   if (getofg_() == 0) 
   {
      if (*t >= TNEXT) /* Restarting just after TNEXT. 
                          update of TNEXT and XSAMPLE is
                          needed. */
      {
         TNEXT = TNEXT + *period;
         XSAMPLE = *x;
      }
   }

   *y = XSAMPLE;

   /* Indicate to the solver the time of the next sample. */
   distim_(&TNEXT);
}

}

For more information on the getofg function, please refer to the HTML documentation of Simcenter Amesim libraries.

Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.TB121_Discontinuity_Handling/xid1849194 · retrieved 2026-07-17