Save data in memory

Unknown
edited August 2022 in Community Q&A

Hi experts,

I wanted to know if there's some kind of UDF routine to temporarily store some kind of user-specific data in memory in udfHd opaque handle. For example, I call a UDF, then UDF performs some calculations and store the result temporarily in memory (may be udfHd opaque handle). Is this possible in acuSolve?

Thanks!

Best Answer

  • acupro
    acupro
    Altair Employee
    edited August 2022 Answer ✓

    I want to store a data in udfHd so that when the UDF is closed, memory still has that value so that the next time another new UDF is called, it can be extracted same as the data in udfHd (opaque handle). I am planning to hook multiple UDFs in my code. This is different case and not related to my another question.

    Thanks.

    You can define multiple user functions in a single C file - compiling that single file will create the various user functions.  I am told that if you specify a static variable (for example - static Integer myData1) before the first function definition that Integer variable myData1 can be used, set, modified by any of the functions.  I think the header may be something like the following - but I need to verify that.  (Then myData1 would be available to any defined functions later in that file.)

    #include "acusim.h"
    #include "udf.h"

    static Integer myData1 ;

    UDF_PROTOTYPE( usrHSMult ) ; /* function prototype */

Answers

  • acupro
    acupro
    Altair Employee
    edited August 2022

    Is the solution on the other question - using a static variable - needed here as well?

    What do you need to do with that memory - outside of the particular UDF?  Does something else need to access it?

     

  • Unknown
    edited August 2022

    Is the solution on the other question - using a static variable - needed here as well?

    What do you need to do with that memory - outside of the particular UDF?  Does something else need to access it?

     

    I want to store a data in udfHd so that when the UDF is closed, memory still has that value so that the next time another new UDF is called, it can be extracted same as the data in udfHd (opaque handle). I am planning to hook multiple UDFs in my code. This is different case and not related to my another question.

    Thanks.

  • acupro
    acupro
    Altair Employee
    edited August 2022 Answer ✓

    I want to store a data in udfHd so that when the UDF is closed, memory still has that value so that the next time another new UDF is called, it can be extracted same as the data in udfHd (opaque handle). I am planning to hook multiple UDFs in my code. This is different case and not related to my another question.

    Thanks.

    You can define multiple user functions in a single C file - compiling that single file will create the various user functions.  I am told that if you specify a static variable (for example - static Integer myData1) before the first function definition that Integer variable myData1 can be used, set, modified by any of the functions.  I think the header may be something like the following - but I need to verify that.  (Then myData1 would be available to any defined functions later in that file.)

    #include "acusim.h"
    #include "udf.h"

    static Integer myData1 ;

    UDF_PROTOTYPE( usrHSMult ) ; /* function prototype */

  • Unknown
    edited August 2022

    You can define multiple user functions in a single C file - compiling that single file will create the various user functions.  I am told that if you specify a static variable (for example - static Integer myData1) before the first function definition that Integer variable myData1 can be used, set, modified by any of the functions.  I think the header may be something like the following - but I need to verify that.  (Then myData1 would be available to any defined functions later in that file.)

    #include "acusim.h"
    #include "udf.h"

    static Integer myData1 ;

    UDF_PROTOTYPE( usrHSMult ) ; /* function prototype */

    I have not tried but this has raised another question. It means that if I want to use density model, gravity model, conductivity model, etc. then all can be done in a single C file but just name them different functions, right?

  • acupro
    acupro
    Altair Employee
    edited August 2022

    I have not tried but this has raised another question. It means that if I want to use density model, gravity model, conductivity model, etc. then all can be done in a single C file but just name them different functions, right?

    Yes - that is correct.  You would have multiple functions within a single C file - each starting with UDF_PROTOTYPE