Date: 2022-03-31T04:46: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:   PetscInt          n;
     11:   Vec               vec = (Vec)obj;
     12:   const PetscScalar *array;
     13:   mxArray           *mat;

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

     26:   VecRestoreArrayRead(vec,&array);
     27:   return 0;
     28: }

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

     37:   VecGetArray(vec,&array);
     38:   VecGetLocalSize(vec,&n);
     39:   mat = engGetVariable((Engine*)mengine,obj->name);
     41:   PetscArraycpy(array,mxGetPr(mat),n);
     42:   VecRestoreArray(vec,&array);
     43:   return 0;
     44: }