8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
12 #include "../../../shared/Numerics/Verbosity.h"
13 #include "../../../shared/MemOps/MemOps.h"
14 #include "../../../shared/Exceptions/exceptions.h"
15 #include "../../../shared/io/Comm/IssmComm.h"
16 #include "../../../shared/Enum/Enum.h"
17 #include "../../../shared/io/Print/Print.h"
23 Vec uf0_vector = NULL;
26 if(uf0) uf0_vector = uf0->
vector;
27 if(df) df_vector = df->
vector;
41 int local_m,local_n,global_m,global_n;
48 bool fromlocalsize =
true;
49 #if _PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)
61 #if _PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)
65 if(
VerboseSolver())PetscOptionsView(PETSC_VIEWER_STDOUT_WORLD);
67 if(
VerboseSolver())PetscOptionsView(NULL,PETSC_VIEWER_STDOUT_WORLD);
73 MatGetSize(Kff,&global_m,&global_n);
_assert_(global_m==global_n);
81 PetscOptionsGetString(PETSC_NULL,
"-ksp_type",ksp_type,49,&flg);
83 PetscOptionsGetString(NULL,PETSC_NULL,
"-ksp_type",ksp_type,49,&flg);
85 if (strcmp(ksp_type,
"preonly")==0)uf0=NULL;
90 VecDuplicate(uf0,&uf); VecCopy(uf0,uf);
102 _error_(
"requested MUMPS solver, which was not compiled into ISSM!\n");
108 #if (_PETSC_MAJOR_==3) && (_PETSC_MINOR_>=5)
109 KSPSetOperators(ksp,Kff,Kff);
111 KSPSetOperators(ksp,Kff,Kff,DIFFERENT_NONZERO_PATTERN);
113 KSPSetFromOptions(ksp);
118 #if (_PETSC_MAJOR_==3) && (_PETSC_MINOR_>=9)
119 PCFactorSetMatSolverType(pc,MATSOLVERMUMPS);
121 PCFactorSetMatSolverPackage(pc,MATSOLVERMUMPS);
128 if(!df)
_error_(
"need doftypes for FS solver!\n");
134 PCFieldSplitSetIS(pc,isv);
135 PCFieldSplitSetIS(pc,isp);
137 PCFieldSplitSetIS(pc,PETSC_NULL,isv);
138 PCFieldSplitSetIS(pc,PETSC_NULL,isp);
148 KSPSetInitialGuessNonzero(ksp,PETSC_TRUE);
157 KSPGetIterationNumber(ksp,&iteration_number);
158 if (iteration_number<0)
_error_(
"Solver diverged at iteration number: " << -iteration_number);
178 int* pressure_indices=NULL;
179 int* velocity_indices=NULL;
182 int pressure_count=0;
183 int velocity_count=0;
188 VecGetOwnershipRange(df,&start,&end);
189 VecGetLocalSize(df,&df_local_size);
190 VecGetArray(df,&df_local);
194 for(
int i=0;i<df_local_size;i++){
200 if(pressure_num)pressure_indices=xNew<int>(pressure_num);
201 if(velocity_num)velocity_indices=xNew<int>(velocity_num);
205 for(
int i=0;i<df_local_size;i++){
207 pressure_indices[pressure_count]=start+i;
211 velocity_indices[velocity_count]=start+i;
215 VecRestoreArray(df,&df_local);
218 #if _PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)
222 ISCreateGeneral(
IssmComm::GetComm(),pressure_num,pressure_indices,PETSC_COPY_VALUES,&isp);
223 ISCreateGeneral(
IssmComm::GetComm(),velocity_num,velocity_indices,PETSC_COPY_VALUES,&isv);
228 xDelete<int>(pressure_indices);
229 xDelete<int>(velocity_indices);