Notices
Results 1 to 1 of 1

Thread: Spring simulation with Sundial IDA

  1. #1 Spring simulation with Sundial IDA 
    New Member
    Join Date
    Apr 2011
    Posts
    1
    Hi,
    I currently trying to simulate a simple spring to compare two
    solver/simulation.
    We have a complex biological simulation working with IDA and C++ code,
    but we want to move to an other physical simulator. Since there is
    some difference with the two simulator, we want to compare them with a simple spring.

    The code is in C++ and we use Sundial IDA DAE solver (it's the solver used in the reference simulation)
    It is a perfect spring with no damping:
    d^2x/dt^2 = k/m*x
    Where k is the stiffness (10)
    and m the mass (1)
    I use yy = [x]

    My residual function currently look like this :

    Code:
    /* Residual function, see sundial ida doc */
    int res_func(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr,
          void *data)
    {
       // Import data from vectors
       realtype *yval,
                *ypval,
                *rval;
       realtype x,
                v,
                Fspring,
                Fdamping ;
    
       yval = NV_DATA_S(yy); 
       ypval = NV_DATA_S(yp); 
       rval = NV_DATA_S(rr);
    
       x = yval[0] ;
       v = ypval[0] ;
       Fspring = STIFFNESS * x ;
       Fdamping = DAMPING * v;
    
       rval[0] = Fspring - Fdamping - ypval[0] ;
    
       return(0);
    }
    Since it is almost new to me to work with spring (last time was close to
    a decade ago...) I may have forget something.
    Thanks for all possible help.

    -- Mayeu


    Reply With Quote  
     

  2.  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •