10 fid = open(
"include/slepc/private/stimpl.h")
11 lignes = fid.readlines(); fid.close();
13 for i
in range(len(lignes)):
14 if (lignes[i].startswith(
'struct _p_ST')):
19 if (lignes[i].find(
"matsolve") >= 0):
22 if (lignes[i].startswith(
'};')):
23 lignes.insert(i,
" PetscErrorCode (*matsolve_trans)(Mat A, Vec b, Vec x);\n");
24 lignes.insert(i,
" PetscErrorCode (*matsolve)(Mat A, Vec b, Vec x);\n");
27 fid = open(
"include/slepc/private/stimpl.h",
'w')
28 fid.writelines(lignes); fid.close();
30 print(
"Unable to modify include/slepc/private/stimpl.h")
41 fid = open(
"src/sys/classes/st/interface/stsles.c")
42 lignes = fid.readlines(); fid.close();
43 test_func =
False; i = 0;
44 while (i < len(lignes)):
45 if (lignes[i].startswith(
"PetscErrorCode STMatSolve(ST st")):
46 if (lignes[i+2].find(
"matsolve") == -1):
47 lignes.insert(i+2,
" return (*st->matsolve)(st->A[0], b, x);\n");
48 lignes.insert(i+2,
" if (st->matsolve != NULL)\n");
50 if (lignes[i].startswith(
"PetscErrorCode STMatSolveTranspose(ST st")):
51 if (lignes[i+2].find(
"matsolve") == -1):
52 lignes.insert(i+2,
" return (*st->matsolve_trans)(st->A[0], b, x);\n");
53 lignes.insert(i+2,
" if (st->matsolve_trans != NULL)\n");
57 fid = open(
"src/sys/classes/st/interface/stsles.c",
'w')
58 fid.writelines(lignes); fid.close();
60 print(
"Unable to modify src/sys/classes/st/interface/stsles.c")
66 fid = open(
"src/sys/classes/st/interface/stfunc.c")
67 lignes = fid.readlines(); fid.close();
69 while (i < len(lignes)):
70 if (lignes[i].startswith(
"PetscErrorCode STCreate")):
71 j = i; test_solve =
False; pos_solve = i+4;
72 while (j < len(lignes)):
73 if (lignes[j].startswith(
'}')):
76 if (lignes[j].find(
"st->data") >= 0):
79 if (lignes[j].find(
"matsolve") >= 0):
85 lignes.insert(pos_solve,
" st->matsolve_trans = NULL;\n");
86 lignes.insert(pos_solve,
" st->matsolve = NULL;\n");
92 fid = open(
"src/sys/classes/st/interface/stfunc.c",
'w')
93 fid.writelines(lignes); fid.close();
95 print(
"Unable to modify src/sys/classes/st/interface/stfunc.c")
99 fid = open(
"src/nep/impls/nleigs/nleigs.c")
100 lignes = fid.readlines(); fid.close()
102 while (i < len(lignes)):
103 if (lignes[i].startswith(
"static PetscErrorCode NEPNLEIGSDividedDifferences_callback")):
104 j = i; pos_bv_create = -1
105 pres_ligne_rand_ctx =
False
106 while (j < len(lignes)):
107 if (lignes[j].startswith(
'}')):
110 if (lignes[j].find(
"BVGetRandomContext") >= 0):
111 pres_ligne_rand_ctx =
True
112 ligne_rand_ctx = lignes[j]
116 if (lignes[j].find(
"MatCreateVecs(D[0]") >= 0):
122 if (pos_bv_create >= 0):
123 if (lignes[pos_bv_create].find(
"BVCreate") < 0):
124 lignes.insert(pos_bv_create,
" ierr = BVCreate(PetscObjectComm((PetscObject)nep), &nep->V);CHKERRQ(ierr);\n");
125 if (pres_ligne_rand_ctx):
126 lignes.insert(pos_bv_create+1, ligne_rand_ctx)
133 while (i < len(lignes)):
134 if (lignes[i].find(
"MatCreateShell") >= 0):
135 mots = lignes[i].split(
',')
137 chaine =
"PetscObject)";
138 pos = lignes[i].find(chaine)
139 name_matrix = lignes[i][pos+len(chaine)];
140 lignes.insert(i,
"PetscInt nloc; ierr = MatGetLocalSize("+name_matrix+
",&nloc,NULL);CHKERRQ(ierr);\n");
141 lignes[i+1] = mots[0] +
", nloc, nloc";
142 for j
in range(3, len(mots)):
143 lignes[i+1] +=
"," + mots[j]
148 fid = open(
"src/nep/impls/nleigs/nleigs.c",
"w")
149 fid.writelines(lignes); fid.close();
151 print(
"Unable to modify src/nep/impls/nleigs/nleigs.c")
154 chemin = os.environ.get(
"PETSC_DIR")
156 for rep
in os.listdir(chemin +
"/include/petsc"):
160 if (
not presence_src):
161 commande_ln =
"ln -s " + chemin +
"/src " + chemin +
"/include/petsc/src"
162 os.system(commande_ln)