xref: /petsc/src/mat/impls/python/pythonmat.c (revision 486bdcd39f7bde83224b636fa8b45c9c231feb46)
1af0996ceSBarry Smith #include <petsc/private/matimpl.h>          /*I "petscmat.h" I*/
2c4aff060SBarry Smith 
3c4aff060SBarry Smith /*@C
4a5b23f4aSJose E. Roman    MatPythonSetType - Initialize a Mat object implemented in Python.
5c4aff060SBarry Smith 
6c4aff060SBarry Smith    Collective on Mat
7c4aff060SBarry Smith 
8d8d19677SJose E. Roman    Input Parameters:
9c4aff060SBarry Smith +  mat - the matrix (Mat) object.
10c4aff060SBarry Smith -  pyname - full dotted Python name [package].module[.{class|function}]
11c4aff060SBarry Smith 
12c4aff060SBarry Smith    Options Database Key:
1367b8a455SSatish Balay .  -mat_python_type <pyname> - python class
14c4aff060SBarry Smith 
15c4aff060SBarry Smith    Level: intermediate
16c4aff060SBarry Smith 
17186e87acSLisandro Dalcin .seealso: MatCreate(), MatSetType(), MATPYTHON, PetscPythonInitialize()
18c4aff060SBarry Smith @*/
197087cfbeSBarry Smith PetscErrorCode  MatPythonSetType(Mat mat,const char pyname[])
20c4aff060SBarry Smith {
21c4aff060SBarry Smith   PetscFunctionBegin;
220700a824SBarry Smith   PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
23c4aff060SBarry Smith   PetscValidCharPointer(pyname,2);
24cac4c232SBarry Smith   PetscTryMethod(mat,"MatPythonSetType_C",(Mat, const char[]),(mat,pyname));
25c4aff060SBarry Smith   PetscFunctionReturn(0);
26c4aff060SBarry Smith }
27c4aff060SBarry Smith 
28c4aff060SBarry Smith /*@C
29c4aff060SBarry Smith    MatPythonCreate - Create a Mat object implemented in Python.
30c4aff060SBarry Smith 
31c4aff060SBarry Smith    Collective on Mat
32c4aff060SBarry Smith 
33c4aff060SBarry Smith    Input Parameters:
34c4aff060SBarry Smith +  comm - MPI communicator
35c4aff060SBarry Smith .  m - number of local rows (or PETSC_DECIDE to have calculated if M is given)
36c4aff060SBarry Smith .  n - number of local columns (or PETSC_DECIDE to have calculated if N is given)
37c4aff060SBarry Smith .  M - number of global rows (or PETSC_DECIDE to have calculated if m is given)
38c4aff060SBarry Smith .  N - number of global columns (or PETSC_DECIDE to have calculated if n is given)
39c4aff060SBarry Smith -  pyname - full dotted Python name [package].module[.{class|function}]
40c4aff060SBarry Smith 
41c4aff060SBarry Smith    Output Parameter:
42c4aff060SBarry Smith .  A - the matrix
43c4aff060SBarry Smith 
44c4aff060SBarry Smith    Level: intermediate
45c4aff060SBarry Smith 
46c4aff060SBarry Smith .seealso: MATPYTHON, MatPythonSetType(), PetscPythonInitialize()
47c4aff060SBarry Smith 
48c4aff060SBarry Smith @*/
497087cfbeSBarry Smith PetscErrorCode  MatPythonCreate(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,const char pyname[],Mat *A)
50c4aff060SBarry Smith {
51c4aff060SBarry Smith   PetscFunctionBegin;
52c4aff060SBarry Smith   PetscValidCharPointer(pyname,6);
53c4aff060SBarry Smith   PetscValidPointer(A,6);
549566063dSJacob Faibussowitsch   PetscCall(MatCreate(comm,A));
559566063dSJacob Faibussowitsch   PetscCall(MatSetSizes(*A,m,n,M,N));
569566063dSJacob Faibussowitsch   PetscCall(MatSetType(*A,MATPYTHON));
579566063dSJacob Faibussowitsch   PetscCall(MatPythonSetType(*A,pyname));
58*486bdcd3SStefano Zampini   PetscCall(MatBindToCPU(*A,PETSC_FALSE));
59c4aff060SBarry Smith   PetscFunctionReturn(0);
60c4aff060SBarry Smith }
61