Example #1
0
void vfield(int *n, double *t, double *x, double *f,
	    double *rpar, int *ipar) {

  FillCurrentExtInputValues(gIData, *t);

  vfieldfunc(*n, (unsigned) gIData->paramDim, *t, x,
	     rpar, f, (unsigned) gIData->extraSpaceSize, gIData->gExtraSpace,
	     (unsigned) gIData->nExtInputs, gIData->gCurrentExtInputVals);
}
Example #2
0
PyObject* JacobianP(double t, double *x, double *p) {
  PyObject *OutObj = NULL;
  PyObject *JacPOut = NULL;

  double *jactual = NULL, **jtemp = NULL;
  int i, n, m;

  _init_numpy();

  if( (gIData == NULL) || (gIData->isInitBasic == 0) 
      || (gIData->hasJacP == 0) || (gIData->paramDim == 0) ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  else if( (gIData->nExtInputs > 0) && (gIData->isInitExtInputs == 0) ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  else {
    OutObj = PyTuple_New(1);
    assert(OutObj);

    n = gIData->phaseDim;
    m = gIData->paramDim;
    jactual = (double *)PyMem_Malloc(n*m*sizeof(double));
    assert(jactual);
    jtemp = (double **)PyMem_Malloc(n*sizeof(double *));
    assert(jtemp);
    for( i = 0; i < n; i++ ) {
      jtemp[i] = jactual + m * i;
    }
    
    if( gIData->nExtInputs > 0 ) {
      FillCurrentExtInputValues( gIData, t );
    }

    /* Assume jacobianParam is returned in column-major format */
    jacobianParam(gIData->phaseDim, gIData->paramDim, t, x, p, jtemp, 
		  gIData->extraSpaceSize, gIData->gExtraSpace, 
		  gIData->nExtInputs, gIData->gCurrentExtInputVals);

    PyMem_Free(jtemp);

    npy_intp dims[2] = {gIData->paramDim, gIData->phaseDim};
    JacPOut = PyArray_SimpleNewFromData(2, dims, NPY_DOUBLE, jactual);
    if(JacPOut) {
        PyArray_UpdateFlags((PyArrayObject *)JacPOut, NPY_ARRAY_CARRAY | NPY_ARRAY_OWNDATA);
        PyTuple_SetItem(OutObj, 0, PyArray_Transpose((PyArrayObject *)JacPOut, NULL));
        return OutObj;
    } else {
        PyMem_Free(jactual);
        Py_INCREF(Py_None);
        return Py_None;
    }
  }
}
Example #3
0
PyObject* MassMatrix(double t, double *x, double *p) {
  PyObject *OutObj = NULL;
  PyObject *MassOut = NULL;

  double *mmactual = NULL, **mmtemp = NULL;
  int i, j, n;

  import_array();
  
  if( (gIData == NULL) || (gIData->isInitBasic == 0) || (gIData->hasMass == 0) ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  else if( (gIData->nExtInputs > 0) && (gIData->isInitExtInputs == 0) ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  else {
    OutObj = PyTuple_New(1);
    assert(OutObj);
    n = gIData->phaseDim;
    mmactual = (double *)PyMem_Malloc(n*n*sizeof(double));
    assert(mmactual);
    mmtemp = (double **)PyMem_Malloc(n*sizeof(double *));
    assert(mmtemp);
    for( i = 0; i < n; i++ ) {
      mmtemp[i] = mmactual + n * i;
    }
    
    if( gIData->nExtInputs > 0 ) {
      FillCurrentExtInputValues( gIData, t );
    }

    /* Assume massMatrix is returned in column-major format */
    massMatrix(gIData->phaseDim, gIData->paramDim, t, x, p, mmtemp, 
	       gIData->extraSpaceSize, gIData->gExtraSpace, 
	       gIData->nExtInputs, gIData->gCurrentExtInputVals);

    PyMem_Free(mmtemp);

    npy_intp dims[2] = {gIData->phaseDim, gIData->phaseDim};
    MassOut = PyArray_SimpleNewFromData(2, dims, NPY_DOUBLE, mmactual);
    if(MassOut) {
        PyArray_UpdateFlags((PyArrayObject *)MassOut, NPY_ARRAY_CARRAY | NPY_ARRAY_OWNDATA);
        PyTuple_SetItem(OutObj, 0, PyArray_Transpose((PyArrayObject *)MassOut, NULL));
        return OutObj;
    } else {
        PyMem_Free(mmactual);
        Py_INCREF(Py_None);
        return Py_None;
    }
  }
}
Example #4
0
/* Phase space dim n, pointer to mass array write location am,
   int mass matrix lower bandwidth lmas,
   double real-valued parameters rpar
   int int-valued parameters ipar */
void vfieldmas(int *n, double *am, int *lmas, double *rpar, int *ipar, double *t, double *x) {
  double **f = NULL;

  setMassPtrs(gIData, am);
  f = gIData->gMassPtrs;

  FillCurrentExtInputValues(gIData, *t);

  massMatrix(*n, (unsigned) gIData->paramDim, *t, x, rpar, f,
	     (unsigned) gIData->extraSpaceSize, gIData->gExtraSpace,
	     (unsigned) gIData->nExtInputs, gIData->gCurrentExtInputVals);
}
Example #5
0
void vfieldjac(int *n, double *t, double *x, double *df, int *ldf,
	       double *rpar, int *ipar) {
  double **f = NULL;

  setJacPtrs(gIData, df);
  f = gIData->gJacPtrs;

  FillCurrentExtInputValues(gIData, *t);

  jacobian(*n, (unsigned) gIData->paramDim, *t, x, rpar, f,
	   (unsigned) gIData->extraSpaceSize, gIData->gExtraSpace,
	   (unsigned) gIData->nExtInputs, gIData->gCurrentExtInputVals);
}
Example #6
0
PyObject* AuxFunc(double t, double *x, double *p) {
  PyObject *OutObj = NULL;
  PyObject *AuxOut = NULL;
  
  double *ftemp = NULL;
  int i; 

  import_array();

  if( (gIData == NULL) || (gIData->isInitBasic == 0) || (gIData->nAuxVars == 0) ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  else if( (gIData->nExtInputs > 0) && (gIData->isInitExtInputs == 0) ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  else {
    OutObj = PyTuple_New(1);
    assert(OutObj);

    ftemp = (double *)PyMem_Malloc((gIData->nAuxVars)*sizeof(double));
    assert(ftemp);

    if( gIData->nExtInputs > 0 ) {
      FillCurrentExtInputValues( gIData, t );
    }

    auxvars(gIData->phaseDim, gIData->phaseDim, t, x, p, ftemp, 
	    gIData->extraSpaceSize, gIData->gExtraSpace, 
	    gIData->nExtInputs, gIData->gCurrentExtInputVals);

    npy_intp dims[1] = {gIData->nAuxVars};
    AuxOut = PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE, ftemp);
    if(AuxOut) {
        PyArray_UpdateFlags((PyArrayObject *)AuxOut, NPY_ARRAY_CARRAY | NPY_ARRAY_OWNDATA);
        PyTuple_SetItem(OutObj, 0, AuxOut);
        return OutObj;
    }
    else {
        PyMem_Free(ftemp);
        Py_INCREF(Py_None);
        return Py_None;
    }
    return OutObj;
  }
}
/* Performs calculation of auxilliary variables after integration, event finding
   are complete. This is the only place where memory is allocated outside of
   an "Init" function. */
void AuxVarCalc( IData *GS ) {
  int i;
  
  assert(GS);

  if( (GS->nAuxVars > 0) && (GS->pointsIdx > 0 ) ) {
    
    /* Allocate space for aux variable calculations if this is the first
       time we have done aux calculations */
    if( GS->gAuxPoints == NULL ) {
      GS->gAuxPoints = (double **)PyMem_Malloc(GS->pointsIdx*sizeof(double *));
      assert(GS->gAuxPoints);
      
      for( i = 0; i < GS->pointsIdx; i++ ) {
	GS->gAuxPoints[i] = (double *)PyMem_Malloc(GS->nAuxVars*sizeof(double));
	assert(GS->gAuxPoints[i]);
      }
    }
    /* Otherwise, realloc space for the additional pointers, PyMem_Malloc
       space for the new aux points */
    else {
      double **temp = NULL;
      temp = (double **)PyMem_Realloc(GS->gAuxPoints,GS->pointsIdx*sizeof(double *));
      assert(temp);
      GS->gAuxPoints = temp;
      for( i = GS->auxIdx; i < GS->pointsIdx; i++ ) {
	GS->gAuxPoints[i] = (double *)PyMem_Malloc(GS->nAuxVars*sizeof(double));
	assert(GS->gAuxPoints[i]);
      }
    }
    
   /* Perform calculation on each integrated point */
    for( i = GS->auxIdx; i < GS->pointsIdx; i++ ) {
      if( GS->nExtInputs > 0 ) {
	FillCurrentExtInputValues(GS, GS->gTimeV[i]);
      }
      auxvars((unsigned) GS->phaseDim, (unsigned) GS->paramDim, GS->gTimeV[i], 
	      GS->gPoints[i], GS->gParams, GS->gAuxPoints[i], 
	      (unsigned) GS->extraSpaceSize, GS->gExtraSpace, 
	      (unsigned) GS->nExtInputs, GS->gCurrentExtInputVals);
    }
    
    GS->auxIdx = GS->pointsIdx;    
  }
}
Example #8
0
PyObject* Vfield(double t, double *x, double *p) {
  PyObject *OutObj = NULL;
  PyObject *PointsOut = NULL;
  
  double *ftemp = NULL;

  _init_numpy();

  if( (gIData == NULL) || (gIData->isInitBasic == 0) ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  else if( (gIData->nExtInputs > 0) && (gIData->isInitExtInputs == 0) ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  else {
    OutObj = PyTuple_New(1);
    assert(OutObj);

    ftemp = (double *)PyMem_Malloc((gIData->phaseDim)*sizeof(double));
    assert(ftemp);

    if( gIData->nExtInputs > 0 ) {
      FillCurrentExtInputValues( gIData, t );
    }

    vfieldfunc(gIData->phaseDim, gIData->paramDim, t, x, p, ftemp, 
	       gIData->extraSpaceSize, gIData->gExtraSpace, 
	       gIData->nExtInputs, gIData->gCurrentExtInputVals);
    
    npy_intp dims[1] = {gIData->phaseDim};
    PointsOut = PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE, ftemp);
    if(!PointsOut) {
        PyMem_Free(ftemp);
        Py_INCREF(Py_None);
        return Py_None;
    }
    PyArray_UpdateFlags((PyArrayObject *)PointsOut, NPY_ARRAY_CARRAY | NPY_ARRAY_OWNDATA);
    PyTuple_SetItem(OutObj, 0, PointsOut);
    return OutObj;
  }
}