Sundials CVODE: y vector values "lost"/corrupted

View: New views
2 Messages — Rating Filter:   Alert me  

Sundials CVODE: y vector values "lost"/corrupted

by Carol Woodward :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Date: Sun, 11 Oct 2009 18:02:05 -0700 (PDT)
From: bowens1 <bowens1@...>
To: sundials-users@...
Subject: [sundials-users] Sundials CVODE: y vector values "lost"/corrupted
  after first call to RHSfunction
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Nabble-From: bowens1@...


Hello,

I am currently implementing CVODE into an in-house FEA code written in C++
that makes thorough use of object oriented programming. Within a particular
method of a class I am trying to implement CVODE. I have made my RHS
function a static function outside the class as I have seen done in the
examples. I am having some problem in that at the second call to the
RHSfunction the values passed in under "N_vector y" seem clearly incorrect.
For example my IVP for  the problem is [0.79 0 0] and the second call to RHS
function has the y vector as [-5.0784477968231915e+057
-5.0784477968231915e+057 -5.0784477968231915e+057]. It seems as though the y
vector is being corrupted some where in the main CVODE function.


To test out sundials I wrote a smaller matlab code that is not nearly as
robust as the C++ implementation. The matlab implementation worked with
great success. I am using the same settings in both C++ and matlab
implementations. Also the two implementations are giving identical output
during the first call to the RHS function, the  C++ code gives erroneous
results after this.

If needed here is my RHS function:

DiffusionModel is a class and user_data points to an object of this class
that I later assign to dmod. The method "solve_for_qdot()" solves for qdot
and assigns it to some data object "udot" local to the DiffusionModel class.
//==============================================================
static int RHSfunction(realtype t, N_Vector y, N_Vector ydot, void
*user_data)
{
        DiffusionModel* dmod;
        dmod =(DiffusionModel*)user_data;

        double *qdot;
        double *q;
        q = NV_DATA_S(y);
        dmod->solve_for_qdot(t,q);

        qdot = dmod->udot;
        ydot = N_VMake_Serial(dmod->totalNumDof,qdot);

        int flag=0;
        return flag;
}
//==============================================================

I greatly appreciate any help in this matter, and I'll be glad to provide
anymore details as needed.

Thanks,
Brian

--
View this message in context:
http://*www.*nabble.com/Sundials-CVODE%3A-y-vector-values-%22lost%22-corrupted-after-first-call-to-RHSfunction-tp25849334p25849334.html
Sent from the Sundials - Users mailing list archive at Nabble.com.


Parent Message unknown Re: Sundials CVODE: y vector values "lost"/corrupted

by Slaven :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Brian:

Some C++ compilers have problems with handling pointers to static member
functions. I was dealing with a similar problem a while ago, so I'll try to
dig out a reference for you.

My solution was to define RHS function as an extern "C". That way your RHS
won't be member function of DiffusionModel, but standalone C function. The
rest of your code should remain more or less the same. This worked for me.

Cheers,
Slaven

 >
 >
 > Hello,
 >
 > I am currently implementing CVODE into an in-house FEA code written in C++
 > that makes thorough use of object oriented programming. Within a particular
 > method of a class I am trying to implement CVODE. I have made my RHS
 > function a static function outside the class as I have seen done in the
 > examples. I am having some problem in that at the second call to the
 > RHSfunction the values passed in under "N_vector y" seem clearly incorrect.
 > For example my IVP for  the problem is [0.79 0 0] and the second call to
 > RHS function has the y vector as [-5.0784477968231915e+057
 > -5.0784477968231915e+057 -5.0784477968231915e+057]. It seems as though the
 > y vector is being corrupted some where in the main CVODE function.
 >
 >
 > To test out sundials I wrote a smaller matlab code that is not nearly as
 > robust as the C++ implementation. The matlab implementation worked with
 > great success. I am using the same settings in both C++ and matlab
 > implementations. Also the two implementations are giving identical output
 > during the first call to the RHS function, the  C++ code gives erroneous
 > results after this.
 >
 > If needed here is my RHS function:
 >
 > DiffusionModel is a class and user_data points to an object of this class
 > that I later assign to dmod. The method "solve_for_qdot()" solves for qdot
 > and assigns it to some data object "udot" local to the DiffusionModel
 > class. //==============================================================
 > static int RHSfunction(realtype t, N_Vector y, N_Vector ydot, void
 > *user_data)
 > {
 >       DiffusionModel* dmod;
 >       dmod =(DiffusionModel*)user_data;
 >
 >       double *qdot;
 >       double *q;
 >       q = NV_DATA_S(y);
 >       dmod->solve_for_qdot(t,q);
 >
 >       qdot = dmod->udot;
 >       ydot = N_VMake_Serial(dmod->totalNumDof,qdot);
 >
 >       int flag=0;
 >       return flag;
 > }
 > //==============================================================
 >
 > I greatly appreciate any help in this matter, and I'll be glad to provide
 > anymore details as needed.
 >
 > Thanks,
 > Brian

----------------------------------------------------------------------------------------------------------------
Center for Applied Scientific Computing
Lawrence Livermore National Laboratory
P.O. Box 808, L-561
Livermore, CA  94551

(925) 424-6013  (Office)            cswoodward@...
(925) 423-2993  (Fax)               http://people.llnl.gov/woodward6