Date: 2022-03-04T17:37:20+00:00

Actual source code: gcreatev.c

      2: #include <petscvec.h>
      3: #include <petsc/private/petscimpl.h>

      5: #include <engine.h>   /* MATLAB include file */
      6: #include <mex.h>      /* MATLAB include file */

      8: PETSC_EXTERN PetscErrorCode  VecMatlabEnginePut_Default(PetscObject obj,void *mengine)
      9: {
     10:   PetscErrorCode    ierr;
     11:   PetscInt          n;
     12:   Vec               vec = (Vec)obj;
     13:   const PetscScalar *array;
     14:   mxArray           *mat;

     17:   VecGetArrayRead(vec,&array);
     18:   VecGetLocalSize(vec,&n);
     19: #if !defined(PETSC_USE_COMPLEX)
     20:   mat  = mxCreateDoubleMatrix(n,1,mxREAL);
     21: #else
     22:   mat  = mxCreateDoubleMatrix(n,1,mxCOMPLEX);
     23: #endif
     24:   PetscArraycpy(mxGetPr(mat),array,n);
     25:   PetscObjectName(obj);
     26:   engPutVariable((Engine*)mengine,obj->name,mat);

     28:   VecRestoreArrayRead(vec,&array);
     29:   return(0);
     30: }

     32: PETSC_EXTERN PetscErrorCode  VecMatlabEngineGet_Default(PetscObject obj,void *mengine)
     33: {
     35:   PetscInt       n;
     36:   Vec            vec = (Vec)obj;
     37:   PetscScalar    *array;
     38:   mxArray        *mat;

     41:   VecGetArray(vec,&array);
     42:   VecGetLocalSize(vec,&n);
     43:   mat  = engGetVariable((Engine*)mengine,obj->name);
     44:   if (!mat) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unable to get object %s from matlab",obj->name);
     45:   PetscArraycpy(array,mxGetPr(mat),n);
     46:   VecRestoreArray(vec,&array);
     47:   return(0);
     48: }