MFNVector MFCreateLOCANVectorWithData(const Teuchos::RCP<LMCEV>& u, MFErrorHandler err) { MFNVector cthis; #ifdef MFTIMINGS clock_t starttime; MFCalledMFCreateNVector++; starttime=clock(); #endif cthis=MFCreateNVectorBaseClass("LOCA",err); LOCANVectorData *vec_data = new LOCANVectorData(u); MFNVectorSetData(cthis,vec_data,err); MFNVectorSetDiff(cthis,MFLOCANVDiff,err); MFNVectorSetAdd(cthis,MFLOCANVAdd,err); MFNVectorSetClone(cthis,MFCloneLOCANVector,err); MFNVectorSetPrint(cthis,MFLOCANVPrint,err); MFNVectorSetFreeData(cthis,MFFreeLOCANVectorData,err); #ifdef MFTIMINGS MFTimeMFCreateNVector+=clock()-starttime; #endif return cthis; }
MFNVector MFCreateWrappedNVector(int n,double *vl, MFErrorHandler e) { static char RoutineName[]={"MFCreateWrappedNVector"}; struct MFDenseNVectorData *data; int i; MFNVector thisVector; thisVector=NULL; #ifdef MFNOCONFIDENCE if(n<1) { sprintf(MFNVectorErrorMsg,"Length of Vector %d (argument 1) is Illegal. Must be positive.",n); MFSetError(e,12,RoutineName,MFNVectorErrorMsg,__LINE__,__FILE__); return NULL; } if(vl==NULL) { sprintf(MFNVectorErrorMsg,"Pointer to data (argument 2) is Illegal. Must be non-NULL."); MFSetError(e,12,RoutineName,MFNVectorErrorMsg,__LINE__,__FILE__); return thisVector; } #endif data=(struct MFDenseNVectorData*)malloc(sizeof(struct MFDenseNVectorData)); #ifndef MFNOSAFETYNET if(data==NULL) { sprintf(MFNVectorErrorMsg,"Out of memory, trying to allocate %d bytes",sizeof(struct MFDenseNVectorData)); MFSetError(e,12,RoutineName,MFNVectorErrorMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return thisVector; } #endif data->nC=n; data->data=vl; data->wrapped=1; thisVector=MFCreateNVectorBaseClass("DENSE",e); MFNVectorSetData(thisVector,data,e); MFNVectorSetFreeData(thisVector,MFFreeDenseNVectorData,e); MFNVectorSetWriteData(thisVector,MFWriteDenseNVectorData,e); MFNVectorSetGetNC(thisVector,MFDenseNVGetNC,e); MFNVectorSetGetC(thisVector,MFDenseNVGetC,e); MFNVectorSetSetC(thisVector,MFDenseNVSetC,e); MFNVectorSetDiff(thisVector,MFDenseNVDiff,e); MFNVectorSetAdd(thisVector,MFDenseNVAdd,e); MFNVectorSetClone(thisVector,MFCloneDenseNVector,e); MFNVectorSetPrint(thisVector,MFPrintDenseNVector,e); return thisVector; }
MFNVector MFCreateNVectorWithData(int n,double *vl, MFErrorHandler e) { static char RoutineName[]={"MFCreateNVectorWithData"}; struct MFDenseNVectorData *data; int i; MFNVector thisVector; #ifdef MFNOCONFIDENCE if(n<1) { sprintf(MFNVectorErrorMsg,"Length of Vector %d (argument 1) is Illegal. Must be positive.",n); MFSetError(e,12,RoutineName,MFNVectorErrorMsg,__LINE__,__FILE__); return NULL; } #endif data=(struct MFDenseNVectorData*)malloc(sizeof(struct MFDenseNVectorData)); /*done*/ #ifndef MFNOSAFETYNET if(data==NULL) { sprintf(MFNVectorErrorMsg,"Out of memory, trying to allocate %d bytes",sizeof(struct MFDenseNVectorData)); MFSetError(e,12,RoutineName,MFNVectorErrorMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return thisVector; } #endif data->nC=n; data->data=(double*)malloc(n*sizeof(double)); #ifndef MFNOSAFETYNET if(n>0&&data->data==NULL) { sprintf(MFNVectorErrorMsg,"Out of memory, trying to allocate %d bytes",n*sizeof(double)); MFSetError(e,12,RoutineName,MFNVectorErrorMsg,__LINE__,__FILE__); return thisVector; } #endif if(n>0&&vl!=NULL) { for(i=0;i<n;i++)(data->data)[i]=vl[i]; }else if(vl==NULL) { for(i=0;i<n;i++)(data->data)[i]=0.; } data->wrapped=0; thisVector=MFCreateNVectorBaseClass("DENSE",e); MFNVectorSetData(thisVector,data,e); MFNVectorSetFreeData(thisVector,MFFreeDenseNVectorData,e); MFNVectorSetWriteData(thisVector,MFWriteDenseNVectorData,e); MFNVectorSetGetNC(thisVector,MFDenseNVGetNC,e); MFNVectorSetGetC(thisVector,MFDenseNVGetC,e); MFNVectorSetSetC(thisVector,MFDenseNVSetC,e); MFNVectorSetDiff(thisVector,MFDenseNVDiff,e); MFNVectorSetAdd(thisVector,MFDenseNVAdd,e); MFNVectorSetClone(thisVector,MFCloneDenseNVector,e); MFNVectorSetPrint(thisVector,MFPrintDenseNVector,e); return thisVector; }