Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16226


Ignore:
Timestamp:
10/10/18 11:49:47 (6 years ago)
Author:
gkronber
Message:

#2925: added vector access methods

Location:
branches/2925_AutoDiffForDynamicalModels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2925_AutoDiffForDynamicalModels/AutoDiffForDynamicalModelsTest/TestCvodes.cs

    r16225 r16226  
    3333      int numberOfEquations = 1;
    3434      var y = Problem.N_VNew_Serial(numberOfEquations);
    35       Problem.N_VConst_Serial(100.0, y);
     35      // y must be initialized before calling CVodeInit
     36      // Problem.N_VConst_Serial(100.0, y);
     37      Problem.NV_Set_Ith_S(y, 0, 100.0);
    3638
    3739      var cvode_mem = Problem.CVodeCreate(Problem.MultistepMethod.CV_ADAMS, Problem.NonlinearSolverIteration.CV_FUNCTIONAL);
     
    8587      IntPtr user_data) {
    8688
    87       Problem.N_VScale(-0.1, y, ydot);
     89      Problem.NV_Set_Ith_S(ydot, 0, -0.1 * Problem.NV_Get_Ith_S(y, 0));
    8890      return 0;
    8991      ;
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs

    r16225 r16226  
    258258    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
    259259    public static extern int CVodeSStolerances(
    260       IntPtr cvode_mem, 
    261       double reltol, 
     260      IntPtr cvode_mem,
     261      double reltol,
    262262      double abstol
    263263      );
     
    272272    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetJacFn", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
    273273    public static extern int CVDlsSetJacFn(
    274       IntPtr cvode_mem, 
     274      IntPtr cvode_mem,
    275275      CVDlsJacFunc jacFunc
    276276      );
     
    309309    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolSetup", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
    310310    public static extern int SUNLinSolSetup(
    311       IntPtr linearSolver, 
     311      IntPtr linearSolver,
    312312      IntPtr A // SUNMatrix
    313313      );
     
    340340    public static extern void N_VConst_Serial(double c, IntPtr vec);
    341341
    342    
     342
    343343    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VL1Norm_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
    344344    public static extern double N_VL1Norm_Serial(IntPtr vec);
     
    356356    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
    357357    public unsafe static extern double* N_VGetArrayPointer_Serial(IntPtr vec);
     358
     359    /*
     360#define NV_CONTENT_S(v)  ( (N_VectorContent_Serial)(v->content) )
     361
     362#define NV_LENGTH_S(v)   ( NV_CONTENT_S(v)->length )
     363
     364#define NV_OWN_DATA_S(v) ( NV_CONTENT_S(v)->own_data )
     365
     366#define NV_DATA_S(v)     ( NV_CONTENT_S(v)->data )
     367
     368#define NV_Ith_S(v,i)    ( NV_DATA_S(v)[i] )
     369*/
     370// methods for macros
     371    public unsafe static int* NV_CONTENT_S(IntPtr v) {
     372      int* content = (int*)*(int*)v.ToPointer();
     373      return content;
     374    }
     375
     376    public unsafe static long NV_LENGTH_S(IntPtr v) {
     377      long length = *NV_CONTENT_S(v);
     378      return length;
     379    }
     380    public unsafe static bool NV_OWN_DATA_S(IntPtr v) {
     381      var content = NV_CONTENT_S(v);
     382      int own_data = *(content + 2);
     383      return own_data > 0;
     384    }
     385    public unsafe static double* NV_DATA_S(IntPtr v) {
     386      var content = NV_CONTENT_S(v);
     387      double* data = (double*)*(content + 3);
     388      return data;
     389    }
     390    public unsafe static double NV_Get_Ith_S(IntPtr v, long i) {
     391      return NV_DATA_S(v)[i];
     392    }
     393    public unsafe static void NV_Set_Ith_S(IntPtr v, long i, double val) {
     394      NV_DATA_S(v)[i] = val;
     395    }
    358396    #endregion
    359397
Note: See TracChangeset for help on using the changeset viewer.