linking error when compiling CVOde in cygwin

C

capes

have functions in my cell model calling CVODE for each time step.

When I build the application I get a number of link errors:

\cardiacsimulator.o Release\ccardiaccell.o Release\ccelldata.o
Release\cgapjunction.o Release\cheart2d.o Release\integrator.o -o
D:\kp\programs\cardiacsimulator\Release\cardiacsimulator.exe
Release\integrator.o: In function `func_f':
/cygdrive/d/kp/programs/cardiacsimulator/integrator.cpp:70: multiple
definition of `_func_f'
Release\cardiacsimulator.o:/cygdrive/d/kp/programs/cardiacsimulator/integrator.cpp:70:
first defined here

What am I doing wrong? I am definitely not redefining any of the
functions!

This is the integrator file
)***************************************************************************88
#include "CDFNCell.h"

/* ----------------------------------------------------

code to call CVode
starts here

----------------------------------------------------
*/

#include <sundialstypes.h> /* definitions of types realtype and
*/
/* integertype, and the constant FALSE
*/
#include <cvode.h> /* prototypes for CVodeMalloc, CVode, and
*/
/* CVodeFree, constants OPT_SIZE, BDF,
NEWTON, */
/* SV, SUCCESS, NST,NFE,NSETUPS, NNI,
NCFN, NETF */
#include <cvdense.h> /* prototype for CVDense, constant
DENSE_NJE */
#include <nvector_serial.h> /* definitions of type N_Vector and macro
*/
/* NV_Ith_S, prototypes for N_VNew,
N_VFree */
#include <dense.h> /* definitions of type DenseMat, macro
DENSE_ELEM*/

/*
CVode specific functions

CVode is a stiff/non-stiff integrator written in C (not in
C++)
To work this code needs header files and a cvode library

*/
extern "C" {

static N_Vector cvode_y;
static void *cvode_mem;
static realtype reltol,abstol;
static N_Vector ew;
static double cvode_t;
M_Env MachEnv;

static realtype ropt[OPT_SIZE];
static long int iopt[OPT_SIZE];

}

// Call CVode
void CDFNCell::CVode_run(double h,double states[])
{
int flag=0,i;

// call CVode to solve ydot(t)=f(y,t) with y(0) given
flag = CVode(cvode_mem, start_time+h, cvode_y, &cvode_t,
NORMAL);

if (flag != SUCCESS) {
cerr<<"CVode failed, flag="<<flag<<"."<<endl;
}

// copy vector y to states which is returned to compute
for(i=0;i<statesize;i++)
states=NV_Ith_S(cvode_y,i);

states[0]=y0[0];

}

// Extra function that acts as a front to CVode
extern "C" void func_f(long N, realtype time, N_Vector y, N_Vector
ydot, void *f_data)
{
cellptr->CVode_f(N, time, y, ydot, f_data);

}

// function f(t,y) for CVode, returns derivatives of variables to CVode
void CDFNCell::CVode_f(int N, double time, N_Vector y, N_Vector ydot,
void *f_data)
{
int z;
static double states2[MAXSTATES];
bool flag=true;

// copy vector y to states2
for(z=0;z<N;z++)
states2[z]=NV_Ith_S(y,z);

// send states2 to getF which uses it to produce derivatives
calDiff(time,states2,flag);

// copy derivatives to vector ydot which is returned to CVode
for(z=0;z<N;z++) {
NV_Ith_S(ydot,z)=Diff[z];
}

}

// Initializes CVode
void CDFNCell::CVodeInit(double states[],double timenow)
{
int i;

MachEnv = M_EnvInit_Serial((int)statesize);
if (MachEnv == NULL) {
cerr<<"Trouble with MachEnv in CVODE"<<endl;
exit(-3);
}

// Allocate memory for solution vector y(t)
cvode_y = N_VNew((int)statesize, MachEnv);
// Allocate memory for solution vector ew(t)
ew = N_VNew((int)statesize, MachEnv);

// rel tolerance of 10^-5 might be a good idea
reltol = tolerance_relative;
abstol = tolerance_absolute;

// initialize vector cvode_y with states
for(i=0;i<statesize;i++)
NV_Ith_S(cvode_y,i)=states;

// use default values for options
for(i=0;i<OPT_SIZE;i++) {
ropt=0.0;
iopt=0;
}
// except for these
ropt[HMAX]=step_max; // Largest step size
ropt[HMIN]=step_min; // Smallest step size
iopt[MXSTEP]=100000; // max internal step number for cvode

// scale tolerance based on maximum value of state
for(i=0;i<statesize;i++) {
NV_Ith_S(ew,i)=abstol/errweight;
}

/* CVodeMalloc sets up initial settings for CVode. See
CVODE
documentation.
Integration method is BDF(Backward Differential
Formula)
Other choice would be ADAMS but it is not as stable as
BDF */
#if 0
// This method of calling CVODE does not pass error
weights
cvode_mem = CVodeMalloc(statesize, func_f, timenow, cvode_y,
BDF,
NEWTON, SS, &reltol, &abstol,
NULL, NULL, TRUE, iopt, ropt, MachEnv);

//#else
// We wish to pass errorweight to CVODE
//cvode_mem = CVodeMalloc(statesize, func_f, timenow, cvode_y,
BDF,
NEWTON,
// SV, &reltol,
ew, NULL, NULL, TRUE, iopt, ropt, MachEnv);
#endif

if (cvode_mem == NULL) {
cerr<<"CVodeMalloc failed."<<endl;
exit(1);
}

/* CVDense is needed by Newton algorithm for solving linear
system
The second NULL tells the solver to compute an approximation
of the
Jacobian. */
CVDense(cvode_mem, NULL, NULL);

}

void CDFNCell::CVodeExit(void)
{
N_VFree(cvode_y);
CVodeFree(cvode_mem);
M_EnvFree_Serial(MachEnv);

}

***********************************************************************
THis is the class definition:

#define CDFNCELL_H
#include <math.h>
#include <iostream>
#include "ccardiaccell.h"
#include <cvode.h> /* prototypes for CVodeMalloc, CVode, and
CVodeFree, */
/* constants OPT_SIZE, BDF, NEWTON, SV, SUCCESS,
*/
/* NST, NFE, NSETUPS, NNI, NCFN, NETF
*/
#include <cvdense.h> /* prototype for CVDense, constant DENSE_NJE
*/
#include <nvector.h> /* definitions of type N_Vector and macro N_VIth,
*/
#include <nvector_serial.h> /* definitions of type N_Vector and macro
N_VIth, */
/* prototypes for N_VNew, N_VFree
*/
#include <dense.h> /* definitions of type DenseMat, macro DENSE_ELEM
*/
#include <vector>

using namespace std;
const int MAXSTATES = 16;

//Noble Cell Constants
class CDFNCell : public CCardiacCell {
private:
//double iteration;
double I_DFN;
//Membranne Potential
double Vm;
//stim current
double IStim;

void copy(const CDFNCell &);

void setDifferential();
void setState();

public:
CDFNCell();
~CDFNCell();
void initialize();
void simulate(double Iext);
void calDiff(double,double[],bool);
void returnParameterList(vector<string>&);
void returnParamaterValues(const vector<string>&
requestedParameters, vector<double>&);
inline double returnVolt(){return (Vm);};
inline double returnNa_i(){return (Na_i);};
inline double returnCa_i(){return (Ca_i);}; //repeat
function for m n
h
inline double returnK_i(){return (K_i);};
inline double returnK_o(){return (K_c);};

//CVOde functions
void CVode_f(int N, double time, N_Vector y, N_Vector ydot,
void
*f_data);
void CVodeInit(double[],double);
void CVodeExit(void);
void CVode_run(double h,double states[]);

int statesize;
bool success;
double start_time;
bool notdone;
double tr_error,errtmp;
double errweight[15];
double tolerance_relative,tolerance_absolute; // tolerances for
integrators
double tstep;
double step_min,step_max; // minimum and maximum step sizes for
integrators

//constants

int stateFlag; // Is state.txt written out
int currentFlag; // Is current.txt written out
int statederivsFlag; // Is Deriv.txt written out
int stimulusFlag; // Is stimulus used or not
double y0[15];
double States[MAXSTATES];
double Diff[MAXSTATES];

};

extern CDFNCell *cellptr;

#endif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top