60 #include "include/finclude/petsc.h"
61 #include "include/finclude/petscvec.h"
62 #include "include/finclude/petscmat.h"
63 #include "include/finclude/petscksp.h"
64 #include "include/finclude/petscpc.h"
70 CHARACTER(CHRLEN) :: &
71 RCSIdentString =
'$RCSfile: RFLU_ModPETScPoisson.F90,v $ $Revision: 1.5 $'
111 TYPE(t_region
),
POINTER :: pregion
119 matnullspace :: petsc_nsp
121 vec :: petsc_b,petsc_x
122 INTEGER :: petsc_col,petsc_row
124 INTEGER :: c1,c2,errorflag,
i,icg,ifg,ipatch,
j,
jbeg,
jend
127 TYPE(t_grid),
POINTER :: pgrid
128 TYPE(t_patch),
POINTER :: ppatch
134 global => pregion%global
137 'RFLU_ModPETScPoisson.F90')
139 IF ( global%myProcid == masterproc .AND. &
140 global%verbLevel > verbose_low )
THEN
141 WRITE(stdout,
'(A,1X,A)') solver_name,
'Building Poisson...'
144 pgrid => pregion%grid
150 DO i = 1,
SIZE(pgrid%poissonA,1)
151 pgrid%poissonA(
i) = 0.0_rfreal
154 DO icg = 1,pgrid%nCells
155 pgrid%poissonLast(icg) = pgrid%poissonFirst(icg) + 1
166 DO ifg = 1,pgrid%nFaces
167 c1 = pgrid%f2c(1,ifg)
168 c2 = pgrid%f2c(2,ifg)
170 term = pgrid%fn(4,ifg)/(pgrid%cofgDist(1,ifg) + pgrid%cofgDist(2,ifg))
172 IF ( c1 <= pgrid%nCells )
THEN
173 pgrid%poissonA(pgrid%poissonFirst(c1)) = &
174 pgrid%poissonA(pgrid%poissonFirst(c1)) +
term
175 pgrid%poissonA(pgrid%poissonLast(c1)) = -
term
176 pgrid%poissonLast(c1) = pgrid%poissonLast(c1) + 1
179 IF ( c2 <= pgrid%nCells )
THEN
180 pgrid%poissonA(pgrid%poissonFirst(c2)) = &
181 pgrid%poissonA(pgrid%poissonFirst(c2)) +
term
182 pgrid%poissonA(pgrid%poissonLast(c2)) = -
term
183 pgrid%poissonLast(c2) = pgrid%poissonLast(c2) + 1
200 petsc_a = pregion%poissonInfoPETSc(rflu_petsc_poisson_info_a)
202 DO icg = 1,pgrid%nCells
203 jbeg = pgrid%poissonFirst(icg)
204 jend = pgrid%poissonFirst(icg) + pgrid%poissonNNZ(icg)-1
208 petsc_col = pgrid%poissonCol(
j) - 1
211 CALL matsetvalues(petsc_a,1,petsc_row,1,petsc_col, &
212 pgrid%poissonA(
j),insert_values,errorflag)
214 global%error = errorflag
215 IF ( global%error /= err_none )
THEN
216 CALL
errorstop(global,err_petsc_output,__line__)
221 CALL matassemblybegin(petsc_a,mat_final_assembly,errorflag)
222 global%error = errorflag
223 IF ( global%error /= err_none )
THEN
224 CALL
errorstop(global,err_petsc_output,__line__)
227 CALL matassemblyend(petsc_a,mat_final_assembly,errorflag)
228 global%error = errorflag
229 IF ( global%error /= err_none )
THEN
230 CALL
errorstop(global,err_petsc_output,__line__)
237 IF ( global%myProcid == masterproc .AND. &
238 global%verbLevel > verbose_low )
THEN
239 WRITE(stdout,
'(A,1X,A)') solver_name,
'Building Poisson done.'
279 TYPE(t_region
),
POINTER :: pregion
286 vec :: petsc_b,petsc_x
288 INTEGER :: c1,c2,errorflag,icg,ifg,ipatch
290 TYPE(t_grid),
POINTER :: pgrid
291 TYPE(t_patch),
POINTER :: ppatch
297 global => pregion%global
300 'RFLU_ModPETScPoisson.F90')
302 IF ( global%myProcid == masterproc .AND. &
303 global%verbLevel > verbose_low )
THEN
304 WRITE(stdout,
'(A,1X,A)') solver_name,
'Creating Poisson...'
307 pgrid => pregion%grid
313 ALLOCATE(pgrid%poissonNNZ(pgrid%nCells),stat=errorflag)
314 global%error = errorflag
315 IF ( global%error /= err_none )
THEN
316 CALL
errorstop(global,err_allocate,__line__,
'pGrid%poissonNNZ')
319 ALLOCATE(pgrid%poissonFirst(pgrid%nCells),stat=errorflag)
320 global%error = errorflag
321 IF ( global%error /= err_none )
THEN
322 CALL
errorstop(global,err_allocate,__line__,
'pGrid%poissonFirst')
325 ALLOCATE(pgrid%poissonLast(pgrid%nCells),stat=errorflag)
326 global%error = errorflag
327 IF ( global%error /= err_none )
THEN
328 CALL
errorstop(global,err_allocate,__line__,
'pGrid%poissonLast')
335 DO icg = 1,pgrid%nCells
336 pgrid%poissonNNZ(icg) = 1
339 DO ifg = 1,pgrid%nFaces
340 c1 = pgrid%f2c(1,ifg)
341 c2 = pgrid%f2c(2,ifg)
343 IF ( c1 <= pgrid%nCells )
THEN
344 pgrid%poissonNNZ(c1) = pgrid%poissonNNZ(c1) + 1
347 IF ( c2 <= pgrid%nCells )
THEN
348 pgrid%poissonNNZ(c2) = pgrid%poissonNNZ(c2) + 1
352 pgrid%poissonFirst(1) = 1
354 DO icg = 2,pgrid%nCells
355 pgrid%poissonFirst(icg) = pgrid%poissonFirst(icg-1) &
356 + pgrid%poissonNNZ(icg-1)
359 ALLOCATE(pgrid%poissonA(
sum(pgrid%poissonNNZ)),stat=errorflag)
360 global%error = errorflag
361 IF ( global%error /= err_none )
THEN
362 CALL
errorstop(global,err_allocate,__line__,
'pGrid%poissonA')
365 ALLOCATE(pgrid%poissonCol(
sum(pgrid%poissonNNZ)),stat=errorflag)
366 global%error = errorflag
367 IF ( global%error /= err_none )
THEN
368 CALL
errorstop(global,err_allocate,__line__,
'pGrid%poissonCol')
371 DO icg = 1,pgrid%nCells
372 pgrid%poissonCol(pgrid%poissonFirst(icg)) = icg
374 pgrid%poissonLast(icg) = pgrid%poissonFirst(icg) + 1
377 DO ifg = 1,pgrid%nFaces
378 c1 = pgrid%f2c(1,ifg)
379 c2 = pgrid%f2c(2,ifg)
381 IF ( c1 <= pgrid%nCells )
THEN
382 pgrid%poissonCol(pgrid%poissonLast(c1)) = c2
383 pgrid%poissonLast(c1) = pgrid%poissonLast(c1) + 1
386 IF (c2 <= pgrid%nCells)
THEN
387 pgrid%poissonCol(pgrid%poissonLast(c2)) = c1
388 pgrid%poissonLast(c2) = pgrid%poissonLast(c2) + 1
396 CALL matcreateseqaij(petsc_comm_self,pgrid%nCells,pgrid%nCells, &
397 petsc_null_integer,pgrid%poissonNNZ,petsc_a, &
400 global%error = errorflag
401 IF ( global%error /= err_none )
THEN
402 CALL
errorstop(global,err_petsc_output,__line__)
405 CALL veccreateseqwitharray(petsc_comm_self,pgrid%nCells,petsc_null_scalar, &
408 global%error = errorflag
409 IF ( global%error /= err_none )
THEN
410 CALL
errorstop(global,err_petsc_output,__line__)
413 CALL vecduplicate(petsc_b,petsc_x,errorflag)
415 global%error = errorflag
416 IF ( global%error /= err_none )
THEN
417 CALL
errorstop(global,err_petsc_output,__line__)
420 pregion%poissonInfoPETSc(rflu_petsc_poisson_info_a) = petsc_a
421 pregion%poissonInfoPETSc(rflu_petsc_poisson_info_b) = petsc_b
422 pregion%poissonInfoPETSc(rflu_petsc_poisson_info_x) = petsc_x
428 IF ( global%myProcid == masterproc .AND. &
429 global%verbLevel > verbose_low )
THEN
430 WRITE(stdout,
'(A,1X,A)') solver_name,
'Creating Poisson done.'
471 TYPE(t_region
),
POINTER :: pregion
480 matnullspace :: petsc_nsp
489 global => pregion%global
492 'RFLU_ModPETScPoisson.F90')
494 IF ( global%myProcid == masterproc .AND. &
495 global%verbLevel > verbose_low )
THEN
496 WRITE(stdout,
'(A,1X,A)') solver_name,
'Setting solver Poisson...'
503 petsc_a = pregion%poissonInfoPETSc(rflu_petsc_poisson_info_a)
505 CALL kspcreate(petsc_comm_self,petsc_ksp,errorflag)
506 global%error = errorflag
507 IF ( global%error /= err_none )
THEN
508 CALL
errorstop(global,err_petsc_output,__line__)
511 CALL kspsetoperators(petsc_ksp,petsc_a,petsc_a,same_nonzero_pattern, &
513 global%error = errorflag
514 IF ( global%error /= err_none )
THEN
515 CALL
errorstop(global,err_petsc_output,__line__)
518 CALL kspsetfromoptions(petsc_ksp,errorflag)
519 global%error = errorflag
520 IF ( global%error /= err_none )
THEN
521 CALL
errorstop(global,err_petsc_output,__line__)
530 CALL matnullspacecreate(petsc_comm_self,petsc_true,0,0, &
534 global%error = errorflag
535 IF ( global%error /= err_none )
THEN
536 CALL
errorstop(global,err_petsc_output,__line__)
539 CALL kspsetnullspace(petsc_ksp,petsc_nsp,errorflag)
540 global%error = errorflag
541 IF ( global%error /= err_none )
THEN
542 CALL
errorstop(global,err_petsc_output,__line__)
545 CALL kspsettype(petsc_ksp,kspgmres,errorflag)
546 global%error = errorflag
547 IF ( global%error /= err_none )
THEN
548 CALL
errorstop(global,err_petsc_output,__line__)
551 CALL kspgetpc(petsc_ksp,petsc_pc,errorflag)
552 global%error = errorflag
553 IF ( global%error /= err_none )
THEN
554 CALL
errorstop(global,err_petsc_output,__line__)
557 CALL pcsettype(petsc_pc,pcilu,errorflag)
558 global%error = errorflag
559 IF ( global%error /= err_none )
THEN
560 CALL
errorstop(global,err_petsc_output,__line__)
563 pregion%poissonInfoPETSc(rflu_petsc_poisson_info_ksp) = petsc_ksp
564 pregion%poissonInfoPETSc(rflu_petsc_poisson_info_pc ) = petsc_pc
565 pregion%poissonInfoPETSc(rflu_petsc_poisson_info_nsp) = petsc_nsp
571 IF ( global%myProcid == masterproc .AND. &
572 global%verbLevel > verbose_low )
THEN
573 WRITE(stdout,
'(A,1X,A)') solver_name,
'Setting solver Poisson done.'
614 TYPE(t_region
),
POINTER :: pregion
623 vec :: petsc_b,petsc_x
625 INTEGER :: c1,c2,errorflag,ifg,ifl,ipatch
627 petscreal,
DIMENSION(:),
ALLOCATABLE ::
b,
x
629 TYPE(t_grid),
POINTER :: pgrid
630 TYPE(t_patch),
POINTER :: ppatch
632 INTEGER :: cvmixtpres
638 global => pregion%global
641 'RFLU_ModPETScPoisson.F90')
643 pgrid => pregion%grid
649 ALLOCATE(
x(pgrid%nCells),stat=errorflag)
650 global%error = errorflag
651 IF ( global%error /= err_none )
THEN
652 CALL
errorstop(global,err_allocate,__line__,
'x')
655 ALLOCATE(
b(pgrid%nCells),stat=errorflag)
656 global%error = errorflag
657 IF ( global%error /= err_none )
THEN
658 CALL
errorstop(global,err_allocate,__line__,
'b')
664 DO ifg = 1,pgrid%nFaces
665 c1 = pgrid%f2c(1,ifg)
666 c2 = pgrid%f2c(2,ifg)
674 flx = pregion%mixt%vfMixt(ifg)*pgrid%fn(4,ifg)
677 IF ( c1 <= pgrid%nCells )
THEN
681 IF ( c2 <= pgrid%nCells )
THEN
686 DO ipatch = 1,pgrid%nPatches
687 ppatch => pregion%patches(ipatch)
689 DO ifl = 1,ppatch%nBFaces
690 c1 = ppatch%bf2c(ifl)
698 flx = ppatch%vfMixt(ifl)*ppatch%fn(4,ifl) &
717 petsc_a = pregion%poissonInfoPETSc(rflu_petsc_poisson_info_a)
718 petsc_b = pregion%poissonInfoPETSc(rflu_petsc_poisson_info_b)
719 petsc_x = pregion%poissonInfoPETSc(rflu_petsc_poisson_info_x)
721 petsc_ksp = pregion%poissonInfoPETSc(rflu_petsc_poisson_info_ksp)
722 petsc_pc = pregion%poissonInfoPETSc(rflu_petsc_poisson_info_pc )
724 CALL vecplacearray(petsc_b,
b,errorflag)
725 global%error = errorflag
726 IF ( global%error /= err_none )
THEN
727 CALL
errorstop(global,err_petsc_output,__line__)
730 CALL vecplacearray(petsc_x,
x,errorflag)
731 global%error = errorflag
732 IF ( global%error /= err_none )
THEN
733 CALL
errorstop(global,err_petsc_output,__line__)
741 CALL kspsolve(petsc_ksp,petsc_b,petsc_x,errorflag)
742 global%error = errorflag
743 IF ( global%error /= err_none )
THEN
744 CALL
errorstop(global,err_petsc_output,__line__)
751 cvmixtpres =
rflu_getcvloc(global, fluid_model_incomp, cv_mixt_pres)
752 pregion%mixt%cv(cvmixtpres,1:pgrid%nCells) =
x
759 DEALLOCATE(
x,stat=errorflag)
760 global%error = errorflag
761 IF ( global%error /= err_none )
THEN
762 CALL
errorstop(global,err_deallocate,__line__,
'x')
765 DEALLOCATE(
b,stat=errorflag)
766 global%error = errorflag
767 IF ( global%error /= err_none )
THEN
768 CALL
errorstop(global,err_deallocate,__line__,
'b')
INTEGER function rflu_getcvloc(global, fluidModel, var)
Tfloat sum() const
Return the sum of all the pixel values in an image.
subroutine, public rflu_petsc_solvepressurepoisson(pRegion)
subroutine, public rflu_petsc_buildpoisson(pRegion)
subroutine, public rflu_petsc_setsolverpoisson(pRegion)
subroutine registerfunction(global, funName, fileName)
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com 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 **********************************************************************INTERFACE SUBROUTINE knode jend
subroutine errorstop(global, errorCode, errorLine, addMessage)
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com 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 **********************************************************************INTERFACE SUBROUTINE knode jbeg
subroutine deregisterfunction(global)
subroutine, public rflu_petsc_createpoisson(pRegion)