46 #include "finclude/petsc.h"
47 #include "finclude/petscvec.h"
48 #include "finclude/petscmat.h"
49 #include "finclude/petscsnes.h"
69 CHARACTER(CHRLEN) :: &
70 RCSIdentString =
'$RCSfile: RFLU_ModPETScNewtonKrylov.F90,v $ $Revision: 1.9 $'
110 #include "finclude/petsc.h"
111 #include "finclude/petscvec.h"
121 TYPE(t_region
),
POINTER :: pregion
127 INTEGER :: ierr, ndof
128 petscscalar ::
zero = 0.0
135 global => pregion%global
137 'RFLU_ModPETScNewtonKrylov.F90')
143 ndof = (cv_mixt_ener - cv_mixt_dens + 1) * pregion%grid%nCells
149 CALL veccreatempiwitharray(petsc_comm_world,ndof,petsc_decide, &
150 pregion%mixt%cv,pregion%x,ierr)
151 CALL vecduplicate(pregion%x,pregion%r,ierr)
152 CALL vecset(pregion%r,
zero,ierr)
193 #include "finclude/petsc.h"
194 #include "finclude/petscmat.h"
195 #include "finclude/petscksp.h"
196 #include "finclude/petscpc.h"
197 #include "finclude/petscsnes.h"
207 TYPE(t_region
),
POINTER :: pregion
213 INTEGER :: ierr, ndof, gndof, maxitsnes, maxitksp
216 petscscalar :: snestol, ksptol, snestrtol
229 global => pregion%global
231 'RFLU_ModPETScNewtonKrylov.F90')
237 IF ( global%nProcAlloc > 1 )
THEN
245 ndof = (cv_mixt_ener - cv_mixt_dens + 1) * pregion%grid%nCells
251 CALL petscoptionssetvalue(
'-snes_tr_delta0',
'1.e64',ierr)
257 CALL mpi_allreduce(ndof,gndof,1,mpi_integer,mpi_sum,mpi_comm_world,ierr)
267 CALL snescreate(petsc_comm_world,pregion%snes,ierr)
273 CALL matcreatesnesmf(pregion%snes,pregion%x,pregion%A,ierr)
274 CALL matcreate(petsc_comm_world,pregion%preA,ierr)
275 CALL matsetsizes(pregion%preA,ndof,ndof,gndof,gndof,ierr)
276 CALL matsetfromoptions(pregion%preA,ierr)
286 CALL snessettype(pregion%snes,snestr,ierr)
287 CALL snessettolerances(pregion%snes,snestol,petsc_default_double_precision, &
288 petsc_default_double_precision,maxitsnes,petsc_default_integer,ierr)
289 CALL snessettrustregiontolerance(pregion%snes,snestrtol,ierr)
290 CALL snesgetksp(pregion%snes,ksp,ierr)
296 CALL kspsettype(ksp,kspgmres,ierr)
297 CALL kspgetpc(ksp,pc,ierr)
298 CALL pcsettype(pc,pcasm,ierr)
299 CALL kspsettolerances(ksp,ksptol,petsc_default_double_precision, &
300 petsc_default_double_precision,maxitksp,ierr)
301 CALL kspsetinitialguessnonzero(ksp,petsc_true,ierr)
302 CALL kspgmressetrestart(ksp,30,ierr)
303 CALL kspgmressetpreallocatevectors(ksp,ierr)
309 CALL petscoptionssetvalue(
'-sub_pc_type',
'ilu',ierr)
310 CALL petscoptionssetvalue(
'-sub_pc_ilu_levels',
'1',ierr)
311 CALL petscoptionssetvalue(
'-sub_ksp_type',
'preonly',ierr)
317 CALL snessetfromoptions(pregion%snes,ierr)
323 IF ( global%myProcid == 0 )
THEN
324 WRITE(*,*)
'Please wait while the Jacobian is prefilled and colored. This may take a while...'
363 #include "finclude/petsc.h"
364 #include "finclude/petscvec.h"
371 TYPE(t_region
),
POINTER :: pregion
378 global => pregion%global
380 'RFLU_ModPETScNewtonKrylov.F90')
386 CALL vecdestroy(pregion%x,ierr)
387 CALL vecdestroy(pregion%r,ierr)
424 #include "finclude/petsc.h"
425 #include "finclude/petscmat.h"
426 #include "finclude/petscsnes.h"
433 TYPE(t_region
),
POINTER :: pregion
440 global => pregion%global
442 'RFLU_ModPETScNewtonKrylov.F90')
448 IF ( global%nProcAlloc == 1 )
THEN
449 CALL matfdcoloringdestroy(pregion%fdcolor,ierr)
451 CALL matdestroy(pregion%A,ierr)
452 CALL matdestroy(pregion%preA,ierr)
453 CALL snesdestroy(pregion%snes,ierr)
459 IF ( global%nProcAlloc > 1 )
THEN
507 #include "finclude/petsc.h"
508 #include "finclude/petscvec.h"
509 #include "finclude/petscmat.h"
510 #include "finclude/petscsnes.h"
519 INTEGER :: ierr,
order
521 TYPE(t_region
),
POINTER :: pregion
524 INTEGER :: icg, ieq, neq, row
526 INTEGER ::
n,
i,
k, low, high, nz, gnz
535 global => pregion%global
537 'RFLU_ModPETScNewtonKrylov.F90')
543 flag = different_nonzero_pattern
544 CALL snesdefaultcomputejacobiancolor(snes,
v,
j,pj,flag, &
545 pregion%fdcolor,ierr)
629 #include "finclude/petsc.h"
630 #include "finclude/petscvec.h"
631 #include "finclude/petscmat.h"
632 #include "finclude/petscsnes.h"
640 INTEGER ierr, counter, icg, ieq, errorflag
641 petscoffset xx_i, ff_i
642 petscscalar xx_v(1),ff_v(1),temp
643 REAL(KIND=8),
ALLOCATABLE,
DIMENSION(:,:) :: cv, dv
644 TYPE(t_region
),
POINTER :: pregion
651 global => pregion%global
653 'RFLU_ModPETScNewtonKrylov.F90')
659 CALL vecgetarray(
x,xx_v,xx_i,ierr)
660 CALL vecgetarray(f,ff_v,ff_i,ierr)
666 ALLOCATE(cv(cv_mixt_dens:cv_mixt_ener,1:pregion%grid%nCellsTot),stat=errorflag)
667 global%error = errorflag
668 IF ( global%error /= err_none )
THEN
669 CALL
errorstop(global,err_allocate,__line__,
'cv')
672 ALLOCATE(dv(dv_mixt_pres:dv_mixt_soun,1:pregion%grid%nCellsTot),stat=errorflag)
673 global%error = errorflag
674 IF ( global%error /= err_none )
THEN
675 CALL
errorstop(global,err_allocate,__line__,
'dv')
678 cv(:,:) = pregion%mixt%cv(:,:)
679 dv(:,:) = pregion%mixt%dv(:,:)
686 DO icg = 1, pregion%grid%nCells
687 DO ieq = cv_mixt_dens, cv_mixt_ener
688 counter = counter + 1
689 pregion%mixt%cv(ieq,icg) = xx_v(xx_i+counter)
717 DO icg = 1,pregion%grid%nCells
718 DO ieq = cv_mixt_dens,cv_mixt_ener
719 counter = counter + 1
720 IF ( global%flowType == flow_unsteady )
THEN
721 temp = ( 1.5_rfreal*pregion%mixt%cv(ieq,icg) * pregion%grid%vol(icg) &
722 - 2.0_rfreal*pregion%mixt%cvOld1(ieq,icg) * pregion%gridOld%vol(icg) &
723 + 0.5_rfreal*pregion%mixt%cvOld2(ieq,icg) * pregion%gridOld2%vol(icg) &
725 ff_v(ff_i+counter) = pregion%mixt%rhs(ieq,icg) &
726 + pregion%grid%vol(icg)/pregion%dt(icg)*(pregion%mixt%cv(ieq,icg)-cv(ieq,icg)) &
729 ff_v(ff_i+counter) = pregion%mixt%rhs(ieq,icg) &
730 + pregion%grid%vol(icg)/pregion%dt(icg)*(pregion%mixt%cv(ieq,icg)-cv(ieq,icg))
739 pregion%mixt%cv(:,:) = cv(:,:)
740 pregion%mixt%dv(:,:) = dv(:,:)
742 DEALLOCATE(cv,stat=errorflag)
743 global%error = errorflag
744 IF ( global%error /= err_none )
THEN
745 CALL
errorstop(global,err_deallocate,__line__,
'cv')
748 DEALLOCATE(dv,stat=errorflag)
749 global%error = errorflag
750 IF ( global%error /= err_none )
THEN
751 CALL
errorstop(global,err_deallocate,__line__,
'dv')
758 CALL vecrestorearray(
x,xx_v,xx_i,ierr)
759 CALL vecrestorearray(f,ff_v,ff_i,ierr)
805 #include "finclude/petsc.h"
806 #include "finclude/petscvec.h"
807 #include "finclude/petscmat.h"
808 #include "finclude/petscsnes.h"
816 TYPE(t_region
),
POINTER :: pregion
818 INTEGER :: ierr, oldspaceorder
824 global => pregion%global
826 'RFLU_ModPETScNewtonKrylov.F90')
832 oldspaceorder = pregion%mixtInput%spaceOrder
833 pregion%mixtInput%spaceOrder = 1
845 pregion%mixtInput%spaceOrder = oldspaceorder
892 #include "finclude/petsc.h"
893 #include "finclude/petscmat.h"
894 #include "finclude/petscsnes.h"
895 #include "finclude/petscis.h"
896 #include "finclude/petscao.h"
902 TYPE(t_region
),
POINTER :: pregion
904 INTEGER ::
i,
j,
k, ifg, icg, ieq, irs, c1, c2, ierr, gndof, ndof, dof,
color, neq
905 INTEGER :: low, high, coloroffset, errorflag, rssizemax, rssize
906 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: nnzon, nnzoff, colors, pcolors,
rs
908 iscoloring :: iscolor
909 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: rows, cols
910 petscscalar,
ALLOCATABLE,
DIMENSION(:,:) :: vals
916 global => pregion%global
918 'RFLU_ModPETScNewtonKrylov.F90')
926 ALLOCATE(
rs(1:rssizemax),stat=errorflag)
927 global%error = errorflag
928 IF ( global%error /= err_none )
THEN
929 CALL
errorstop(global,err_allocate,__line__,
'rs')
940 neq = cv_mixt_ener - cv_mixt_dens + 1
941 CALL vecgetsize(pregion%x,gndof,ierr)
942 CALL vecgetlocalsize(pregion%x,ndof,ierr)
948 ALLOCATE(nnzon(1:ndof),stat=errorflag)
949 global%error = errorflag
950 IF ( global%error /= err_none )
THEN
951 CALL
errorstop(global,err_allocate,__line__,
'nnzon')
954 ALLOCATE(nnzoff(1:ndof),stat=errorflag)
955 global%error = errorflag
956 IF ( global%error /= err_none )
THEN
957 CALL
errorstop(global,err_allocate,__line__,
'nnzoff')
968 DO c1 = 1, pregion%grid%nCells
980 DO ieq = cv_mixt_dens, cv_mixt_ener
982 nnzon(
j) = nnzon(
j) + neq
984 IF ( c2 <= pregion%grid%nCells )
THEN
986 nnzon(
j) = nnzon(
j) + neq
989 nnzoff(
j) = nnzoff(
j) + neq
999 IF ( global%nProcAlloc == 1 )
THEN
1000 CALL matseqaijsetpreallocation(pregion%preA,0,nnzon,ierr)
1002 CALL matmpiaijsetpreallocation(pregion%preA,0,nnzon,0,nnzoff,ierr)
1009 DEALLOCATE(nnzon,stat=errorflag)
1010 global%error = errorflag
1011 IF ( global%error /= err_none )
THEN
1012 CALL
errorstop(global,err_deallocate,__line__,
'nnzon')
1015 DEALLOCATE(nnzoff,stat=errorflag)
1016 global%error = errorflag
1017 IF ( global%error /= err_none )
THEN
1018 CALL
errorstop(global,err_deallocate,__line__,
'nnzoff')
1029 ALLOCATE(vals(1:neq,1:neq),stat=errorflag)
1030 global%error = errorflag
1031 IF ( global%error /= err_none )
THEN
1032 CALL
errorstop(global,err_allocate,__line__,
'vals')
1035 ALLOCATE(rows(1:neq),stat=errorflag)
1036 global%error = errorflag
1037 IF ( global%error /= err_none )
THEN
1038 CALL
errorstop(global,err_allocate,__line__,
'rows')
1041 ALLOCATE(cols(1:neq),stat=errorflag)
1042 global%error = errorflag
1043 IF ( global%error /= err_none )
THEN
1044 CALL
errorstop(global,err_allocate,__line__,
'cols')
1061 DO c1 = 1, pregion%grid%nCells
1071 DO ieq = cv_mixt_dens, cv_mixt_ener
1072 IF ( global%nProcAlloc == 1 )
THEN
1073 rows(ieq) = neq*(c1-1) + ieq - 1
1074 cols(ieq) = neq*(c2-1) + ieq - 1
1076 rows(ieq) = neq*(pregion%grid%pc2sc(c1)-1) + ieq - 1
1077 cols(ieq) = neq*(pregion%grid%pc2sc(c2)-1) + ieq - 1
1080 IF ( global%nProcAlloc > 1 )
THEN
1081 CALL aoapplicationtopetsc(pregion%ao,neq,rows,ierr)
1082 CALL aoapplicationtopetsc(pregion%ao,neq,cols,ierr)
1084 CALL matsetvalues(pregion%preA,neq,rows,neq,cols,vals,insert_values,ierr)
1085 IF ( c2 <= pregion%grid%nCells )
THEN
1086 CALL matsetvalues(pregion%preA,neq,cols,neq,rows,vals,insert_values,ierr)
1095 DO icg = 1, pregion%grid%nCells
1096 DO ieq = cv_mixt_dens, cv_mixt_ener
1097 IF ( global%nProcAlloc == 1 )
THEN
1098 rows(ieq) = neq*(icg-1) + ieq - 1
1100 rows(ieq) = neq*(pregion%grid%pc2sc(icg)-1) + ieq - 1
1103 IF ( global%nProcAlloc > 1 )
THEN
1104 CALL aoapplicationtopetsc(pregion%ao,neq,rows,ierr)
1106 CALL matsetvalues(pregion%preA,neq,rows,neq,rows,vals,insert_values,ierr)
1113 DEALLOCATE(vals,stat=errorflag)
1114 global%error = errorflag
1115 IF ( global%error /= err_none )
THEN
1116 CALL
errorstop(global,err_deallocate,__line__,
'vals')
1119 DEALLOCATE(rows,stat=errorflag)
1120 global%error = errorflag
1121 IF ( global%error /= err_none )
THEN
1122 CALL
errorstop(global,err_deallocate,__line__,
'rows')
1125 DEALLOCATE(cols,stat=errorflag)
1126 global%error = errorflag
1127 IF ( global%error /= err_none )
THEN
1128 CALL
errorstop(global,err_deallocate,__line__,
'cols')
1135 CALL matassemblybegin(pregion%preA,mat_final_assembly,ierr)
1136 CALL matassemblyend(pregion%preA,mat_final_assembly,ierr)
1170 ALLOCATE(colors(1:ndof),stat=errorflag)
1171 global%error = errorflag
1172 IF ( global%error /= err_none )
THEN
1173 CALL
errorstop(global,err_allocate,__line__,
'colors')
1186 DO icg = 1, pregion%grid%nCells
1187 DO ieq = cv_mixt_dens, cv_mixt_ener
1188 colors(neq * (icg-1) + ieq) = neq * (pregion%grid%col(icg) - 1) + ieq - 1
1196 CALL iscoloringcreate(petsc_comm_world,ndof,colors,iscolor,ierr)
1197 CALL matfdcoloringcreate(pregion%preA,iscolor,pregion%fdcolor,ierr)
1198 CALL matfdcoloringsetfromoptions(pregion%fdcolor,ierr)
1199 CALL iscoloringdestroy(iscolor,ierr)
1207 DEALLOCATE(colors,stat=errorflag)
1208 global%error = errorflag
1209 IF ( global%error /= err_none )
THEN
1210 CALL
errorstop(global,err_deallocate,__line__,
'colors')
1217 DEALLOCATE(
rs,stat=errorflag)
1218 global%error = errorflag
1219 IF ( global%error /= err_none )
THEN
1220 CALL
errorstop(global,err_deallocate,__line__,
'rs')
1261 #include "finclude/petsc.h"
1262 #include "finclude/petscvec.h"
1263 #include "finclude/petscao.h"
1269 TYPE(t_region
),
POINTER :: pregion
1271 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: numpetsc, numapp
1272 INTEGER :: icg, ieq, neq, ipetsc, iapp, low, counter, ierr, errorflag
1278 global => pregion%global
1280 'RFLU_ModPETScNewtonKrylov.F90')
1286 neq = cv_mixt_ener - cv_mixt_dens + 1
1288 ALLOCATE(numpetsc(1:neq*pregion%grid%nCells),stat=errorflag)
1289 global%error = errorflag
1290 IF ( global%error /= err_none )
THEN
1291 CALL
errorstop(global,err_allocate,__line__,
'numpetsc')
1294 ALLOCATE(numapp(1:neq*pregion%grid%nCells),stat=errorflag)
1295 global%error = errorflag
1296 IF ( global%error /= err_none )
THEN
1297 CALL
errorstop(global,err_allocate,__line__,
'numapp')
1304 CALL vecgetownershiprange(pregion%x,low,petsc_null_integer,ierr)
1307 DO icg = 1, pregion%grid%nCells
1308 DO ieq = cv_mixt_dens, cv_mixt_ener
1310 counter = counter + 1
1311 iapp = neq*(pregion%grid%pc2sc(icg) - 1) + ieq - 1
1312 numapp(counter) = iapp
1313 numpetsc(counter) = ipetsc
1321 CALL aocreatebasic(petsc_comm_world, neq*pregion%grid%nCells, &
1322 numapp, numpetsc, pregion%ao, ierr)
1328 DEALLOCATE(numpetsc,stat=errorflag)
1329 global%error = errorflag
1330 IF ( global%error /= err_none )
THEN
1331 CALL
errorstop(global,err_deallocate,__line__,
'numpetsc')
1334 DEALLOCATE(numapp,stat=errorflag)
1335 global%error = errorflag
1336 IF ( global%error /= err_none )
THEN
1337 CALL
errorstop(global,err_deallocate,__line__,
'numapp')
1378 #include "finclude/petsc.h"
1379 #include "finclude/petscao.h"
1385 TYPE(t_region
),
POINTER :: pregion
1393 global => pregion%global
1395 'RFLU_ModPETScNewtonKrylov.F90')
1401 CALL aodestroy(pregion%ao,ierr)
1443 REAL(RFREAL) :: dtscale
1450 'RFLU_ModPETScNewtonKrylov.F90')
1456 dtscale = 1.1 ** global%currentIter
void zero()
Sets all entries to zero (more efficient than assignement).
subroutine rs(nm, n, a, w, matz, z, fv1, fv2, ierr)
subroutine, public rflu_petsc_formresidual(snes, x, f, pRegion, ierr)
subroutine, public rflu_res_computeresidual(pRegion)
subroutine rflu_setdependentvars(pRegion, icgBeg, icgEnd)
subroutine, public rflu_mpi_isendwrapper(pRegion)
Size order() const
Degree of the element. 1 for linear and 2 for quadratic.
subroutine, public rflu_petsc_destroyvectors(pRegion)
subroutine registerfunction(global, funName, fileName)
subroutine, public rflu_col_createcoloring(pRegion)
subroutine, public rflu_getresidualsupport1(pRegion, icg, rs, rsSizeMax, rsSize)
subroutine, public rflu_petsc_createvectors(pRegion)
subroutine, public rflu_mpi_clearrequestwrapper(pRegion)
subroutine, public rflu_petsc_createcoloring(pRegion)
int color() const
The color of the parent window (BLUE or GREEN).
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
subroutine, public rflu_petsc_destroyjacobian(pRegion)
subroutine, public rflu_petsc_destroyapplicationordering(pRegion)
subroutine, public rflu_mpi_recvwrapper(pRegion)
subroutine, public rflu_petsc_getdtscale(global, dtscale)
subroutine, public rflu_col_destroycoloring(pRegion)
subroutine, public rflu_getresidualsupport2(pRegion, icg, rs, rsSizeMax, rsSize)
subroutine, public rflu_petsc_formresidualfirstorder(snes, x, f, pRegion, ierr)
subroutine, public rflu_petsc_formjacobian(snes, v, J, pJ, flag, pRegion, ierr)
subroutine, public rflu_petsc_createjacobian(pRegion)
subroutine, public rflu_petsc_createapplicationordering(pRegion)
subroutine errorstop(global, errorCode, errorLine, addMessage)
subroutine rflu_checkpositivity(pRegion)
subroutine deregisterfunction(global)
subroutine, public rflu_col_readcoloring(pRegion)