Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLU_ModPETScNewtonKrylov.F90
Go to the documentation of this file.
1 ! *********************************************************************
2 ! * Rocstar Simulation Suite *
3 ! * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4 ! * *
5 ! * Illinois Rocstar LLC *
6 ! * Champaign, IL *
7 ! * www.illinoisrocstar.com *
8 ! * sales@illinoisrocstar.com *
9 ! * *
10 ! * License: See LICENSE file in top level of distribution package or *
11 ! * http://opensource.org/licenses/NCSA *
12 ! *********************************************************************
13 ! *********************************************************************
14 ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15 ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16 ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17 ! * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18 ! * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19 ! * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20 ! * Arising FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21 ! * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22 ! *********************************************************************
23 !******************************************************************************
24 !
25 ! Purpose: Collection of routines related to Newton-Krylov schemes.
26 !
27 ! Description: None.
28 !
29 ! Notes: None.
30 !
31 ! ******************************************************************************
32 
34 
35  USE moddatatypes
36  USE modglobal, ONLY: t_global
37  USE modparameters
38  USE moderror
39  USE moddatastruct, ONLY: t_region
40  USE modgrid, ONLY: t_grid
41  USE modmixture, ONLY: t_mixt,t_mixt_input
42  USE modmpi
43 
44  IMPLICIT NONE
45 
46 #include "finclude/petsc.h"
47 #include "finclude/petscvec.h"
48 #include "finclude/petscmat.h"
49 #include "finclude/petscsnes.h"
50 
51  PRIVATE
52  PUBLIC :: rflu_petsc_createvectors, &
63 
64 
65 ! ******************************************************************************
66 ! Declarations and definitions
67 ! ******************************************************************************
68 
69  CHARACTER(CHRLEN) :: &
70  RCSIdentString = '$RCSfile: RFLU_ModPETScNewtonKrylov.F90,v $ $Revision: 1.9 $'
71 
72 ! ******************************************************************************
73 ! Routines
74 ! ******************************************************************************
75 
76  CONTAINS
77 
78 
79 
80 
81 
82 
83 ! ******************************************************************************
84 !
85 ! Purpose: Create and allocate memory for vectors needed by PETSc
86 !
87 ! Description: None.
88 !
89 ! Input:
90 ! pRegion Data for a grid region
91 !
92 ! Output:
93 ! x Solution vector (initial solution)
94 ! r Callback vector (zeros)
95 !
96 ! Notes: None.
97 !
98 ! ******************************************************************************
99 
100 SUBROUTINE rflu_petsc_createvectors(pRegion)
101 
102  USE moddatastruct, ONLY: t_region
103 
104  IMPLICIT NONE
105 
106 ! ******************************************************************************
107 ! Include PETSc headers
108 ! ******************************************************************************
109 
110 #include "finclude/petsc.h"
111 #include "finclude/petscvec.h"
112 
113 ! ******************************************************************************
114 ! Declarations and definitions
115 ! ******************************************************************************
116 
117 ! ==============================================================================
118 ! Arguments
119 ! ==============================================================================
120 
121  TYPE(t_region), POINTER :: pregion
122 
123 ! ==============================================================================
124 ! Locals
125 ! ==============================================================================
126 
127  INTEGER :: ierr, ndof
128  petscscalar :: zero = 0.0
129  TYPE(t_global),POINTER :: global
130 
131 ! ******************************************************************************
132 ! Start
133 ! ******************************************************************************
134 
135  global => pregion%global
136  CALL registerfunction(global,'RFLU_PETSC_CreateVectors',&
137  'RFLU_ModPETScNewtonKrylov.F90')
138 
139 ! ******************************************************************************
140 ! Count the number of degrees of freedom
141 ! ******************************************************************************
142 
143  ndof = (cv_mixt_ener - cv_mixt_dens + 1) * pregion%grid%nCells
144 
145 ! ******************************************************************************
146 ! Create vectors
147 ! ******************************************************************************
148 
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)
153 
154 ! ******************************************************************************
155 ! End
156 ! ******************************************************************************
157 
158  CALL deregisterfunction(global)
159 
160 END SUBROUTINE rflu_petsc_createvectors
161 
162 
163 
164 
165 ! ******************************************************************************
166 !
167 ! Purpose: Create and allocate memory for matrices and solver needed by PETSc
168 !
169 ! Description: None.
170 !
171 ! Input:
172 ! pRegion data for grid region
173 !
174 ! Output:
175 ! A the shell jacobian matrix for matrix-free operations
176 ! pA the explicitely formed preconditioning jacobian matrix
177 ! snes the PETSc SNES solver context
178 !
179 ! Notes: None.
180 !
181 ! ******************************************************************************
182 
183 SUBROUTINE rflu_petsc_createjacobian(pRegion)
184 
185  USE moddatastruct, ONLY: t_region
186 
187  IMPLICIT NONE
188 
189 ! ******************************************************************************
190 ! Include PETSc headers
191 ! ******************************************************************************
192 
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"
198 
199 ! ******************************************************************************
200 ! Declarations and definitions
201 ! ******************************************************************************
202 
203 ! ==============================================================================
204 ! Arguments
205 ! ==============================================================================
206 
207  TYPE(t_region), POINTER :: pregion
208 
209 ! ==============================================================================
210 ! Locals
211 ! ==============================================================================
212 
213  INTEGER :: ierr, ndof, gndof, maxitsnes, maxitksp
214  ksp :: ksp, subksp
215  pc :: pc, subpc
216  petscscalar :: snestol, ksptol, snestrtol
217  TYPE(t_global), POINTER :: global
218 
219  maxitsnes = 1
220  maxitksp = 10000
221  snestol = 1.0e-32 ! tight to avoid SNES thinking its converged
222  ksptol = 1.0e-3 ! loose to facilitate fast solving
223  snestrtol = 1.0e-32 ! tight to avoid SNES TR thinking its converged
224 
225 ! ******************************************************************************
226 ! Start
227 ! *****************************************************************************
228 
229  global => pregion%global
230  CALL registerfunction(global,'RFLU_PETSC_CreateJacobian',&
231  'RFLU_ModPETScNewtonKrylov.F90')
232 
233 ! ******************************************************************************
234 ! Create the Application Ordering context
235 ! ******************************************************************************
236 
237  IF ( global%nProcAlloc > 1 ) THEN
239  END IF ! global%nProcAlloc
240 
241 ! ******************************************************************************
242 ! Count the number of degrees of freedom
243 ! ******************************************************************************
244 
245  ndof = (cv_mixt_ener - cv_mixt_dens + 1) * pregion%grid%nCells
246 
247 ! ******************************************************************************
248 ! Set PETSc Trust Region Options
249 ! ******************************************************************************
250 
251  CALL petscoptionssetvalue('-snes_tr_delta0','1.e64',ierr)
252 
253 ! ******************************************************************************
254 ! Find the global number of dof
255 ! ******************************************************************************
256 
257  CALL mpi_allreduce(ndof,gndof,1,mpi_integer,mpi_sum,mpi_comm_world,ierr)
258 
259 ! ******************************************************************************
260 ! Create matrices
261 ! ******************************************************************************
262 
263 ! ==============================================================================
264 ! Create SNES solver context
265 ! ==============================================================================
266 
267  CALL snescreate(petsc_comm_world,pregion%snes,ierr)
268 
269 ! ==============================================================================
270 ! Create jacobian matrix and preconditioning matrix
271 ! ==============================================================================
272 
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)
277 
278 ! ==============================================================================
279 ! Set solver parameters
280 ! ==============================================================================
281 
282 ! ------------------------------------------------------------------------------
283 ! Nonlinear solver parameters
284 ! ------------------------------------------------------------------------------
285 
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)
291 
292 ! ------------------------------------------------------------------------------
293 ! Linear solver & preconditioner parameters
294 ! ------------------------------------------------------------------------------
295 
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)
304 
305 ! ------------------------------------------------------------------------------
306 ! ASM Sub solver & preconditioner parameters
307 ! ------------------------------------------------------------------------------
308 
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)
312 
313 ! ------------------------------------------------------------------------------
314 ! Finalize solver parameters
315 ! ------------------------------------------------------------------------------
316 
317  CALL snessetfromoptions(pregion%snes,ierr)
318 
319 ! ==============================================================================
320 ! Prefill Jacobian and Create Jacobian Coloring
321 ! ==============================================================================
322 
323  IF ( global%myProcid == 0 ) THEN
324  WRITE(*,*) 'Please wait while the Jacobian is prefilled and colored. This may take a while...'
325  END IF ! global%myProcid
326  CALL rflu_petsc_createcoloring(pregion)
327 
328 ! ******************************************************************************
329 ! End
330 ! ******************************************************************************
331 
332  CALL deregisterfunction(global)
333 
334 END SUBROUTINE rflu_petsc_createjacobian
335 
336 
337 ! ******************************************************************************
338 !
339 ! Purpose: Destroy the vectors that were created for PETSc
340 !
341 ! Description: None.
342 !
343 ! Input:
344 ! pRegion data for grid region
345 !
346 ! Output:
347 ! none
348 !
349 ! Notes: None.
350 !
351 ! ******************************************************************************
352 
353 SUBROUTINE rflu_petsc_destroyvectors(pRegion)
354 
355  USE moddatastruct, ONLY: t_region
356 
357  IMPLICIT NONE
358 
359 ! ******************************************************************************
360 ! Include PETSc headers
361 ! ******************************************************************************
362 
363 #include "finclude/petsc.h"
364 #include "finclude/petscvec.h"
365 
366 ! ******************************************************************************
367 ! Declarations and definitions
368 ! ******************************************************************************
369 
370  INTEGER :: ierr
371  TYPE(t_region), POINTER :: pregion
372  TYPE(t_global), POINTER :: global
373 
374 ! ******************************************************************************
375 ! Start
376 ! *****************************************************************************
377 
378  global => pregion%global
379  CALL registerfunction(global,'RFLU_PETSC_DestroyVectors',&
380  'RFLU_ModPETScNewtonKrylov.F90')
381 
382 ! ******************************************************************************
383 ! Destroy the vectors
384 ! ******************************************************************************
385 
386  CALL vecdestroy(pregion%x,ierr)
387  CALL vecdestroy(pregion%r,ierr)
388 
389 ! ******************************************************************************
390 ! End
391 ! ******************************************************************************
392 
393  CALL deregisterfunction(global)
394 
395 END SUBROUTINE rflu_petsc_destroyvectors
396 
397 
398 ! ******************************************************************************
399 !
400 ! Purpose: Destroy the matrices and solver contexts that were created for PETSc
401 !
402 ! Description: None.
403 !
404 ! Input:
405 ! pRegion data for grid region
406 !
407 ! Output:
408 ! none
409 !
410 ! Notes: None.
411 !
412 ! ******************************************************************************
413 
414 SUBROUTINE rflu_petsc_destroyjacobian(pRegion)
415 
416  USE moddatastruct, ONLY: t_region
417 
418  IMPLICIT NONE
419 
420 ! ******************************************************************************
421 ! Include PETSc headers
422 ! ******************************************************************************
423 
424 #include "finclude/petsc.h"
425 #include "finclude/petscmat.h"
426 #include "finclude/petscsnes.h"
427 
428 ! ******************************************************************************
429 ! Declarations and definitions
430 ! ******************************************************************************
431 
432  INTEGER :: ierr
433  TYPE(t_region), POINTER :: pregion
434  TYPE(t_global), POINTER :: global
435 
436 ! ******************************************************************************
437 ! Start
438 ! *****************************************************************************
439 
440  global => pregion%global
441  CALL registerfunction(global,'RFLU_PETSC_DestroyJacobian',&
442  'RFLU_ModPETScNewtonKrylov.F90')
443 
444 ! ******************************************************************************
445 ! Destroy the matrices and solver context
446 ! ******************************************************************************
447 
448  IF ( global%nProcAlloc == 1 ) THEN
449  CALL matfdcoloringdestroy(pregion%fdcolor,ierr)
450  END IF ! global%nProcAlloc
451  CALL matdestroy(pregion%A,ierr)
452  CALL matdestroy(pregion%preA,ierr)
453  CALL snesdestroy(pregion%snes,ierr)
454 
455 ! ******************************************************************************
456 ! Destroy the Application Ordering context
457 ! ******************************************************************************
458 
459  IF ( global%nProcAlloc > 1 ) THEN
461  END IF ! global%nProcAlloc
462 
463 ! ******************************************************************************
464 ! End
465 ! ******************************************************************************
466 
467  CALL deregisterfunction(global)
468 
469 END SUBROUTINE rflu_petsc_destroyjacobian
470 
471 
472 
473 
474 
475 
476 ! ******************************************************************************
477 !
478 ! Purpose: Explicitely forms the preconditioning Jacobian matrix for PETSc.
479 !
480 ! Description: None.
481 !
482 ! Input:
483 ! snes the PETSc SNES solver context
484 ! v the vector at which to compute the jacobian
485 ! flag PETSc flag denoting matrix structure
486 ! dummy PETSc dummy context
487 !
488 ! Output:
489 ! J matrix-free jacobian matrix (is not modified)
490 ! pJ explicitely formed preconditioning jacobian matrix
491 ! ierr PETSc error code
492 !
493 ! Notes: None.
494 !
495 ! ******************************************************************************
496 
497 SUBROUTINE rflu_petsc_formjacobian(snes,v,J,pJ,flag,pRegion,ierr)
498 
499  USE moddatastruct, ONLY: t_region
500 
501  IMPLICIT NONE
502 
503 ! ******************************************************************************
504 ! Include PETSc headers
505 ! ******************************************************************************
506 
507 #include "finclude/petsc.h"
508 #include "finclude/petscvec.h"
509 #include "finclude/petscmat.h"
510 #include "finclude/petscsnes.h"
511 
512 ! ******************************************************************************
513 ! Declarations and definitions
514 ! ******************************************************************************
515 
516  snes :: snes
517  mat :: j, pj
518  vec :: v
519  INTEGER :: ierr, order
520  matstructure :: flag
521  TYPE(t_region),POINTER :: pregion
522  TYPE(t_global), POINTER :: global
523  REAL(kind=8) :: val
524  INTEGER :: icg, ieq, neq, row
525 ! DEBUG
526  INTEGER :: n, i, k, low, high, nz, gnz
527  petscoffset xx_i
528  petscscalar xx_v(1)
529 ! END DEBUG
530 
531 ! ******************************************************************************
532 ! Start
533 ! ******************************************************************************
534 
535  global => pregion%global
536  CALL registerfunction(global,'RFLU_PETSC_FormJacobian',&
537  'RFLU_ModPETScNewtonKrylov.F90')
538 
539 ! ******************************************************************************
540 ! Compute the preconditioning Jacobian matrix
541 ! ******************************************************************************
542 
543  flag = different_nonzero_pattern
544  CALL snesdefaultcomputejacobiancolor(snes,v,j,pj,flag, &
545  pregion%fdcolor,ierr)
546 
547 ! DEBUG
548 !
549 ! IF ( global%currentIter == 2 ) THEN
550 ! print*,'writing jacobian to file...'
551 ! if(global%myProcid == 0) then
552 ! OPEN(unit=123,file='jacobian_computational_0.m')
553 ! else
554 ! OPEN(unit=123,file='jacobian_computational_1.m')
555 ! endif
556 ! CALL VecGetSize(v,n,ierr)
557 ! CALL VecGetOwnershipRange(pRegion%x,low,high,ierr)
558 ! DO i = low, high-1
559 ! DO k = 1, n
560 ! CALL MatGetValues(pJ,1,i,1,k-1,val,ierr)
561 ! if(val /= 0.0) then
562 ! write(123,*) 'A(',i+1,',',k,') = ',val,';'
563 ! endif
564 ! ENDDO
565 ! ENDDO
566 ! close(123)
567 ! print*,'done writing jacobian to file'
568 !! CALL VecView(v,PETSC_VIEWER_STDOUT_WORLD,ierr)
569 ! stop
570 ! END IF
571 !
572 ! IF ( global%myProcid == 0 ) THEN
573 ! DO i = 1, 5
574 ! DO k = 1, 5
575 ! CALL MatGetValues(pJ,1,i-1,1,k-1,val,ierr)
576 ! print*,'JAC',i,k,val
577 ! END DO
578 ! END DO
579 ! END IF
580 ! STOP
581 !
582 ! END DEBUG
583 
584 ! ******************************************************************************
585 ! End
586 ! ******************************************************************************
587 
588  CALL deregisterfunction(global)
589 
590 END SUBROUTINE rflu_petsc_formjacobian
591 
592 
593 
594 
595 ! ******************************************************************************
596 !
597 ! Purpose: Returns the residual of the nonlinear equations to PETSc.
598 !
599 ! Description: None.
600 !
601 ! Input:
602 ! x vector at which to compute the residual
603 ! dummy PETSc dummy input argument
604 !
605 ! Output:
606 ! f residual vector
607 ! ierr PETSc error code
608 !
609 ! Notes: None.
610 !
611 ! ******************************************************************************
612 
613 SUBROUTINE rflu_petsc_formresidual(snes,x,f,pRegion,ierr)
614 
615  USE rflu_modresidual
616  USE rflu_modmpi
617 
618  USE moddatastruct, ONLY: t_region
619 
622 
623  IMPLICIT NONE
624 
625 ! ******************************************************************************
626 ! Include PETSc headers
627 ! ******************************************************************************
628 
629 #include "finclude/petsc.h"
630 #include "finclude/petscvec.h"
631 #include "finclude/petscmat.h"
632 #include "finclude/petscsnes.h"
633 
634 ! ******************************************************************************
635 ! Definitions and declarations
636 ! ******************************************************************************
637 
638  snes snes
639  vec x, f
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
645  TYPE(t_global), POINTER :: global
646 
647 ! ******************************************************************************
648 ! Start
649 ! ******************************************************************************
650 
651  global => pregion%global
652  CALL registerfunction(global,'RFLU_PETSC_FormResidual',&
653  'RFLU_ModPETScNewtonKrylov.F90')
654 
655 ! ******************************************************************************
656 ! Get the vectors
657 ! ******************************************************************************
658 
659  CALL vecgetarray(x,xx_v,xx_i,ierr)
660  CALL vecgetarray(f,ff_v,ff_i,ierr)
661 
662 ! ******************************************************************************
663 ! Backup the original values for cv and dv
664 ! ******************************************************************************
665 
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')
670  END IF ! global%errorFlag
671 
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')
676  END IF ! global%errorFlag
677 
678  cv(:,:) = pregion%mixt%cv(:,:)
679  dv(:,:) = pregion%mixt%dv(:,:)
680 
681 ! ******************************************************************************
682 ! Compute copy the given vector into cv and check for validity
683 ! ******************************************************************************
684 
685  counter = 0
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)
690  END DO ! ieq
691  END DO ! icg
692 
693 ! ******************************************************************************
694 ! Communicate virtual cell values & compute dependent variables
695 ! ******************************************************************************
696 
697  CALL rflu_mpi_isendwrapper(pregion)
698 ! CALL RFLU_MPI_CopyWrapper(regions)
699  CALL rflu_setdependentvars(pregion,1,pregion%grid%nCells)
700  CALL rflu_mpi_recvwrapper(pregion)
701  CALL rflu_mpi_clearrequestwrapper(pregion)
702  CALL rflu_setdependentvars(pregion,pregion%grid%nCells+1,pregion%grid%nCellsTot)
703  CALL rflu_checkpositivity(pregion)
704 
705 ! ******************************************************************************
706 ! Compute the residual
707 ! ******************************************************************************
708 
709  CALL rflu_res_computeresidual(pregion)
710 
711 ! ******************************************************************************
712 ! Copy the residual array into the PETSc vector
713 ! ******************************************************************************
714 
715  counter = 0
716 
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) &
724  ) / global%dtImposed
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)) &
727  + temp
728  ELSE
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))
731  END IF ! global%flowType
732  END DO ! ieq
733  END DO ! icg
734 
735 ! ******************************************************************************
736 ! Restore original values for cv and dv
737 ! ******************************************************************************
738 
739  pregion%mixt%cv(:,:) = cv(:,:)
740  pregion%mixt%dv(:,:) = dv(:,:)
741 
742  DEALLOCATE(cv,stat=errorflag)
743  global%error = errorflag
744  IF ( global%error /= err_none ) THEN
745  CALL errorstop(global,err_deallocate,__line__,'cv')
746  END IF !global%error
747 
748  DEALLOCATE(dv,stat=errorflag)
749  global%error = errorflag
750  IF ( global%error /= err_none ) THEN
751  CALL errorstop(global,err_deallocate,__line__,'dv')
752  END IF !global%error
753 
754 ! ******************************************************************************
755 ! Put the vectors back together
756 ! ******************************************************************************
757 
758  CALL vecrestorearray(x,xx_v,xx_i,ierr)
759  CALL vecrestorearray(f,ff_v,ff_i,ierr)
760 
761 ! ******************************************************************************
762 ! End
763 ! ******************************************************************************
764 
765  CALL deregisterfunction(global)
766 
767 END SUBROUTINE rflu_petsc_formresidual
768 
769 
770 
771 
772 
773 
774 
775 
776 ! ******************************************************************************
777 !
778 ! Purpose: Returns the residual of the nonlinear equations to PETSc with first
779 ! order spacial accuracy.
780 !
781 ! Description: None.
782 !
783 ! Input:
784 ! x vector at which to compute the residual
785 ! dummy PETSc dummy input argument
786 !
787 ! Output:
788 ! f residual vector
789 ! ierr PETSc error code
790 !
791 ! Notes: None.
792 !
793 ! ******************************************************************************
794 
795 SUBROUTINE rflu_petsc_formresidualfirstorder(snes,x,f,pRegion,ierr)
796 
797  USE moddatastruct, ONLY: t_region
798 
799  IMPLICIT NONE
800 
801 ! ******************************************************************************
802 ! Include PETSc headers
803 ! ******************************************************************************
804 
805 #include "finclude/petsc.h"
806 #include "finclude/petscvec.h"
807 #include "finclude/petscmat.h"
808 #include "finclude/petscsnes.h"
809 
810 ! ******************************************************************************
811 ! Definitions and declarations
812 ! ******************************************************************************
813 
814  snes snes
815  vec x, f
816  TYPE(t_region),POINTER :: pregion
817  TYPE(t_global), POINTER :: global
818  INTEGER :: ierr, oldspaceorder
819 
820 ! ******************************************************************************
821 ! Start
822 ! ******************************************************************************
823 
824  global => pregion%global
825  CALL registerfunction(global,'RFLU_PETSC_FormResidualFirstOrder',&
826  'RFLU_ModPETScNewtonKrylov.F90')
827 
828 ! ==============================================================================
829 ! Set the spacial order of accuracy to first order
830 ! ==============================================================================
831 
832  oldspaceorder = pregion%mixtInput%spaceOrder
833  pregion%mixtInput%spaceOrder = 1
834 
835 ! ==============================================================================
836 ! Get the residual
837 ! ==============================================================================
838 
839  CALL rflu_petsc_formresidual(snes,x,f,pregion,ierr)
840 
841 ! ==============================================================================
842 ! Set the spacial order of accuracy to what it was to start with
843 ! ==============================================================================
844 
845  pregion%mixtInput%spaceOrder = oldspaceorder
846 
847 ! ******************************************************************************
848 ! End
849 ! ******************************************************************************
850 
851  CALL deregisterfunction(global)
852 
854 
855 
856 
857 
858 
859 
860 
861 ! ******************************************************************************
862 !
863 ! Purpose: Creates the Jacobian matrix coloring contexts needed by PETSc, and
864 ! preallocates and prefills the Jacobian matrix.
865 !
866 ! Description: None.
867 !
868 ! Input:
869 ! pRegion data for grid region
870 !
871 ! Output:
872 ! none
873 !
874 ! Notes: None.
875 !
876 ! ******************************************************************************
877 
878 SUBROUTINE rflu_petsc_createcoloring(pRegion)
879 
880  USE rflu_modcoloring
881 
882  USE moddatastruct, ONLY: t_region
885 
886  IMPLICIT NONE
887 
888 ! ******************************************************************************
889 ! Include PETSc headers
890 ! ******************************************************************************
891 
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"
897 
898 ! ******************************************************************************
899 ! Declarations and definitions
900 ! ******************************************************************************
901 
902  TYPE(t_region), POINTER :: pregion
903  TYPE(t_global), POINTER :: global
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
907  petscscalar :: val
908  iscoloring :: iscolor
909  INTEGER,ALLOCATABLE,DIMENSION(:) :: rows, cols
910  petscscalar,ALLOCATABLE,DIMENSION(:,:) :: vals
911 
912 ! ******************************************************************************
913 ! Start
914 ! ******************************************************************************
915 
916  global => pregion%global
917  CALL registerfunction(global,'RFLU_PETSC_CreateColoring',&
918  'RFLU_ModPETScNewtonKrylov.F90')
919 
920 ! ==============================================================================
921 ! Create the Connectivity Array
922 ! ==============================================================================
923 
924  rssizemax = 1000
925 
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')
930  END IF ! global%errorFlag
931 
932 ! ==============================================================================
933 ! Preallocate the Jacobian Matrix
934 ! ==============================================================================
935 
936 ! ------------------------------------------------------------------------------
937 ! Get misc dimensions
938 ! ------------------------------------------------------------------------------
939 
940  neq = cv_mixt_ener - cv_mixt_dens + 1
941  CALL vecgetsize(pregion%x,gndof,ierr)
942  CALL vecgetlocalsize(pregion%x,ndof,ierr)
943 
944 ! ------------------------------------------------------------------------------
945 ! Allocate preallocation variables
946 ! ------------------------------------------------------------------------------
947 
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')
952  END IF ! global%errorFlag
953 
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')
958  END IF ! global%errorFlag
959 
960 ! ------------------------------------------------------------------------------
961 ! Calculate number of nonzeros in each row in the Jacobian. NOTE must be careful
962 ! with Fortran and C-style numbering - nnzon uses Fortran numbering...
963 ! ------------------------------------------------------------------------------
964 
965  nnzon(:) = neq
966  nnzoff(:) = 0
967 
968  DO c1 = 1, pregion%grid%nCells
969 ! TEMPORARY
970 ! IF ( pRegion%mixtInput%spaceOrder == DISCR_ORDER_1 ) THEN
971  CALL rflu_getresidualsupport1(pregion,c1,rs,rssizemax,rssize)
972 ! ELSE
973 ! CALL RFLU_GetResidualSupport2(pRegion,c1,rs,rsSizeMax,rsSize)
974 ! END IF ! pRegion%mixtInput%spaceOrder
975 ! END TEMPORARY
976 
977  DO irs = 1, rssize
978  c2 = rs(irs)
979 
980  DO ieq = cv_mixt_dens, cv_mixt_ener
981  j = neq*(c1-1) + ieq
982  nnzon(j) = nnzon(j) + neq
983 
984  IF ( c2 <= pregion%grid%nCells ) THEN
985  j = neq*(c2-1) + ieq
986  nnzon(j) = nnzon(j) + neq
987  ELSE
988  j = neq*(c1-1) + ieq
989  nnzoff(j) = nnzoff(j) + neq
990  END IF ! c2
991  END DO ! ieq
992  END DO ! irs
993  END DO ! c1
994 
995 ! ------------------------------------------------------------------------------
996 ! Preallocate the matrix
997 ! ------------------------------------------------------------------------------
998 
999  IF ( global%nProcAlloc == 1 ) THEN
1000  CALL matseqaijsetpreallocation(pregion%preA,0,nnzon,ierr)
1001  ELSE
1002  CALL matmpiaijsetpreallocation(pregion%preA,0,nnzon,0,nnzoff,ierr)
1003  END IF ! global%nProcAlloc
1004 
1005 ! ------------------------------------------------------------------------------
1006 ! Deallocate preallocation variables
1007 ! ------------------------------------------------------------------------------
1008 
1009  DEALLOCATE(nnzon,stat=errorflag)
1010  global%error = errorflag
1011  IF ( global%error /= err_none ) THEN
1012  CALL errorstop(global,err_deallocate,__line__,'nnzon')
1013  END IF !global%error
1014 
1015  DEALLOCATE(nnzoff,stat=errorflag)
1016  global%error = errorflag
1017  IF ( global%error /= err_none ) THEN
1018  CALL errorstop(global,err_deallocate,__line__,'nnzoff')
1019  END IF !global%error
1020 
1021 ! ==============================================================================
1022 ! Pre-Fill the Jacobian Matrix
1023 ! ==============================================================================
1024 
1025 ! ------------------------------------------------------------------------------
1026 ! Allocate pre-fill variables
1027 ! ------------------------------------------------------------------------------
1028 
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')
1033  END IF ! global%errorFlag
1034 
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')
1039  END IF ! global%errorFlag
1040 
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')
1045  END IF ! global%errorFlag
1046 
1047 ! ------------------------------------------------------------------------------
1048 ! Create the array of nonzero values
1049 ! ------------------------------------------------------------------------------
1050 
1051  DO i = 1, neq
1052  DO j = 1, neq
1053  vals(i,j) = 1.0
1054  END DO ! j
1055  END DO ! i
1056 
1057 ! ------------------------------------------------------------------------------
1058 ! Set nonzeros in off-diagonal blocks
1059 ! ------------------------------------------------------------------------------
1060 
1061  DO c1 = 1, pregion%grid%nCells
1062 ! TEMPORARY
1063 ! IF ( pRegion%mixtInput%spaceOrder == DISCR_ORDER_1 ) THEN
1064  CALL rflu_getresidualsupport1(pregion,c1,rs,rssizemax,rssize)
1065 ! ELSE
1066 ! CALL RFLU_GetResidualSupport2(pRegion,c1,rs,rsSizeMax,rsSize)
1067 ! END IF ! pRegion%mixtInput%spaceOrder
1068 ! END TEMPORARY
1069  DO irs = 1, rssize
1070  c2 = rs(irs)
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
1075  ELSE
1076  rows(ieq) = neq*(pregion%grid%pc2sc(c1)-1) + ieq - 1
1077  cols(ieq) = neq*(pregion%grid%pc2sc(c2)-1) + ieq - 1
1078  END IF ! global%nProcAlloc
1079  END DO ! ieq
1080  IF ( global%nProcAlloc > 1 ) THEN
1081  CALL aoapplicationtopetsc(pregion%ao,neq,rows,ierr)
1082  CALL aoapplicationtopetsc(pregion%ao,neq,cols,ierr)
1083  END IF ! global%nProcAlloc
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)
1087  END IF ! c2
1088  END DO ! irs
1089  END DO ! ifg
1090 
1091 ! ------------------------------------------------------------------------------
1092 ! Set nonzeros in on-diagonal blocks
1093 ! ------------------------------------------------------------------------------
1094 
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
1099  ELSE
1100  rows(ieq) = neq*(pregion%grid%pc2sc(icg)-1) + ieq - 1
1101  END IF ! global%nProcAlloc
1102  END DO ! ieq
1103  IF ( global%nProcAlloc > 1 ) THEN
1104  CALL aoapplicationtopetsc(pregion%ao,neq,rows,ierr)
1105  END IF ! global%nProcAlloc
1106  CALL matsetvalues(pregion%preA,neq,rows,neq,rows,vals,insert_values,ierr)
1107  END DO ! icg
1108 
1109 ! ------------------------------------------------------------------------------
1110 ! Deallocate pre-fill variables
1111 ! ------------------------------------------------------------------------------
1112 
1113  DEALLOCATE(vals,stat=errorflag)
1114  global%error = errorflag
1115  IF ( global%error /= err_none ) THEN
1116  CALL errorstop(global,err_deallocate,__line__,'vals')
1117  END IF !global%error
1118 
1119  DEALLOCATE(rows,stat=errorflag)
1120  global%error = errorflag
1121  IF ( global%error /= err_none ) THEN
1122  CALL errorstop(global,err_deallocate,__line__,'rows')
1123  END IF !global%error
1124 
1125  DEALLOCATE(cols,stat=errorflag)
1126  global%error = errorflag
1127  IF ( global%error /= err_none ) THEN
1128  CALL errorstop(global,err_deallocate,__line__,'cols')
1129  END IF !global%error
1130 
1131 ! ------------------------------------------------------------------------------
1132 ! Assemble the matrix
1133 ! ------------------------------------------------------------------------------
1134 
1135  CALL matassemblybegin(pregion%preA,mat_final_assembly,ierr)
1136  CALL matassemblyend(pregion%preA,mat_final_assembly,ierr)
1137 
1138 ! DEBUG
1139 ! print*,'writing jacobian to file...'
1140 ! if(global%myProcid == 0) then
1141 ! OPEN(unit=123,file='jacobian_computational_0.m')
1142 ! else
1143 ! OPEN(unit=123,file='jacobian_computational_1.m')
1144 ! endif
1145 ! CALL VecGetSize(pRegion%x,gndof,ierr)
1146 ! CALL VecGetOwnershipRange(pRegion%x,low,high,ierr)
1147 ! DO i = low, high-1
1148 ! DO k = 1, gndof
1149 ! CALL MatGetValues(pRegion%preA,1,i,1,k-1,val,ierr)
1150 ! if(val /= 0.0) then
1151 ! write(123,*) 'A(',i+1,',',k,') = ',val,';'
1152 ! endif
1153 ! ENDDO
1154 ! ENDDO
1155 ! close(123)
1156 ! print*,'done writing jacobian to file'
1157 ! stop
1158 ! END DEBUG
1159 
1160 ! ==============================================================================
1161 ! Create Coloring for Jacobian Evaluation
1162 ! ==============================================================================
1163 
1164 ! ------------------------------------------------------------------------------
1165 ! Allocate coloring variables
1166 ! ------------------------------------------------------------------------------
1167 
1168  CALL rflu_col_createcoloring(pregion)
1169 
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')
1174  END IF ! global%errorFlag
1175 
1176 ! ------------------------------------------------------------------------------
1177 ! Read the cell coloring from the .col files
1178 ! ------------------------------------------------------------------------------
1179 
1180  CALL rflu_col_readcoloring(pregion)
1181 
1182 ! ------------------------------------------------------------------------------
1183 ! Compute the DOF coloring
1184 ! ------------------------------------------------------------------------------
1185 
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
1189  END DO ! ieq
1190  END DO ! icg
1191 
1192 ! ------------------------------------------------------------------------------
1193 ! Give PETSc the coloring
1194 ! ------------------------------------------------------------------------------
1195 
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)
1200 
1201 ! ------------------------------------------------------------------------------
1202 ! Deallocate the coloring variables
1203 ! ------------------------------------------------------------------------------
1204 
1205  CALL rflu_col_destroycoloring(pregion)
1206 
1207  DEALLOCATE(colors,stat=errorflag)
1208  global%error = errorflag
1209  IF ( global%error /= err_none ) THEN
1210  CALL errorstop(global,err_deallocate,__line__,'colors')
1211  END IF !global%error
1212 
1213 ! ==============================================================================
1214 ! Destroy the Connectivity Array
1215 ! ==============================================================================
1216 
1217  DEALLOCATE(rs,stat=errorflag)
1218  global%error = errorflag
1219  IF ( global%error /= err_none ) THEN
1220  CALL errorstop(global,err_deallocate,__line__,'rs')
1221  END IF !global%error
1222 
1223 ! ******************************************************************************
1224 ! End
1225 ! ******************************************************************************
1226 
1227  CALL deregisterfunction(global)
1228 
1229 END SUBROUTINE rflu_petsc_createcoloring
1230 
1231 
1232 
1233 
1234 ! ******************************************************************************
1235 !
1236 ! Purpose: Creates the PETSc Application Ordering context to map Rocflu global
1237 ! dof indices to PETSc global dof indices.
1238 !
1239 ! Description: None.
1240 !
1241 ! Input:
1242 ! pRegion data for grid region
1243 !
1244 ! Output:
1245 ! none
1246 !
1247 ! Notes: None.
1248 !
1249 ! ******************************************************************************
1250 
1252 
1253  USE moddatastruct, ONLY: t_region
1254 
1255  IMPLICIT NONE
1256 
1257 ! ******************************************************************************
1258 ! Include PETSc headers
1259 ! ******************************************************************************
1260 
1261 #include "finclude/petsc.h"
1262 #include "finclude/petscvec.h"
1263 #include "finclude/petscao.h"
1264 
1265 ! ******************************************************************************
1266 ! Declarations and definitions
1267 ! ******************************************************************************
1268 
1269  TYPE(t_region), POINTER :: pregion
1270  TYPE(t_global), POINTER :: global
1271  INTEGER,ALLOCATABLE,DIMENSION(:) :: numpetsc, numapp
1272  INTEGER :: icg, ieq, neq, ipetsc, iapp, low, counter, ierr, errorflag
1273 
1274 ! ******************************************************************************
1275 ! Start
1276 ! ******************************************************************************
1277 
1278  global => pregion%global
1279  CALL registerfunction(global,'RFLU_PETSC_CreateApplicationOrdering',&
1280  'RFLU_ModPETScNewtonKrylov.F90')
1281 
1282 ! ==============================================================================
1283 ! Allocate the numbering arrays
1284 ! ==============================================================================
1285 
1286  neq = cv_mixt_ener - cv_mixt_dens + 1
1287 
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')
1292  END IF ! global%errorFlag
1293 
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')
1298  END IF ! global%errorFlag
1299 
1300 ! ==============================================================================
1301 ! Fill the application and PETSc numbering arrays
1302 ! ==============================================================================
1303 
1304  CALL vecgetownershiprange(pregion%x,low,petsc_null_integer,ierr)
1305  ipetsc = low - 1
1306  counter = 0
1307  DO icg = 1, pregion%grid%nCells
1308  DO ieq = cv_mixt_dens, cv_mixt_ener
1309  ipetsc = ipetsc + 1
1310  counter = counter + 1
1311  iapp = neq*(pregion%grid%pc2sc(icg) - 1) + ieq - 1
1312  numapp(counter) = iapp
1313  numpetsc(counter) = ipetsc
1314  END DO ! ieq
1315  END DO ! icg
1316 
1317 ! ==============================================================================
1318 ! Create the Application Ordering context
1319 ! ==============================================================================
1320 
1321  CALL aocreatebasic(petsc_comm_world, neq*pregion%grid%nCells, &
1322  numapp, numpetsc, pregion%ao, ierr)
1323 
1324 ! ==============================================================================
1325 ! Deallocate the numbering arrays
1326 ! ==============================================================================
1327 
1328  DEALLOCATE(numpetsc,stat=errorflag)
1329  global%error = errorflag
1330  IF ( global%error /= err_none ) THEN
1331  CALL errorstop(global,err_deallocate,__line__,'numpetsc')
1332  END IF !global%error
1333 
1334  DEALLOCATE(numapp,stat=errorflag)
1335  global%error = errorflag
1336  IF ( global%error /= err_none ) THEN
1337  CALL errorstop(global,err_deallocate,__line__,'numapp')
1338  END IF !global%error
1339 
1340 ! ******************************************************************************
1341 ! End
1342 ! ******************************************************************************
1343 
1344  CALL deregisterfunction(global)
1345 
1347 
1348 
1349 
1350 
1351 
1352 ! ******************************************************************************
1353 !
1354 ! Purpose: Destroys the PETSc Application Ordering context
1355 !
1356 ! Description: None.
1357 !
1358 ! Input:
1359 ! pRegion data for grid region
1360 !
1361 ! Output:
1362 ! none
1363 !
1364 ! Notes: None.
1365 !
1366 ! ******************************************************************************
1367 
1369 
1370  USE moddatastruct, ONLY: t_region
1371 
1372  IMPLICIT NONE
1373 
1374 ! ******************************************************************************
1375 ! Include PETSc headers
1376 ! ******************************************************************************
1377 
1378 #include "finclude/petsc.h"
1379 #include "finclude/petscao.h"
1380 
1381 ! ******************************************************************************
1382 ! Declarations and definitions
1383 ! ******************************************************************************
1384 
1385  TYPE(t_region), POINTER :: pregion
1386  TYPE(t_global), POINTER :: global
1387  INTEGER :: ierr
1388 
1389 ! ******************************************************************************
1390 ! Start
1391 ! ******************************************************************************
1392 
1393  global => pregion%global
1394  CALL registerfunction(global,'RFLU_PETSC_DestroyApplicationOrdering',&
1395  'RFLU_ModPETScNewtonKrylov.F90')
1396 
1397 ! ==============================================================================
1398 ! Destroy the Application Ordering context
1399 ! ==============================================================================
1400 
1401  CALL aodestroy(pregion%ao,ierr)
1402 
1403 ! ******************************************************************************
1404 ! End
1405 ! ******************************************************************************
1406 
1407  CALL deregisterfunction(global)
1408 
1410 
1411 
1412 
1413 
1414 
1415 
1416 ! ******************************************************************************
1417 !
1418 ! Purpose: Provides the dt scaling factor for implicit runs
1419 !
1420 ! Description: None.
1421 !
1422 ! Input:
1423 ! pRegion data for grid region
1424 !
1425 ! Output:
1426 ! none
1427 !
1428 ! Notes: None.
1429 !
1430 ! ******************************************************************************
1431 
1432 SUBROUTINE rflu_petsc_getdtscale(global,dtscale)
1433 
1434  USE moddatastruct, ONLY: t_region
1435 
1436  IMPLICIT NONE
1437 
1438 ! ******************************************************************************
1439 ! Declarations and definitions
1440 ! ******************************************************************************
1441 
1442  TYPE(t_global), POINTER :: global
1443  REAL(RFREAL) :: dtscale
1444 
1445 ! ******************************************************************************
1446 ! Start
1447 ! ******************************************************************************
1448 
1449  CALL registerfunction(global,'RFLU_PETSC_GetDtScale',&
1450  'RFLU_ModPETScNewtonKrylov.F90')
1451 
1452 ! ==============================================================================
1453 ! Compute the dt scaling
1454 ! ==============================================================================
1455 
1456  dtscale = 1.1 ** global%currentIter
1457 
1458 ! ******************************************************************************
1459 ! End
1460 ! ******************************************************************************
1461 
1462  CALL deregisterfunction(global)
1463 
1464 END SUBROUTINE rflu_petsc_getdtscale
1465 
1466 
1467 
1468 
1469 
1470 
1471 ! ******************************************************************************
1472 ! END
1473 ! ******************************************************************************
1474 
1475 END MODULE rflu_modpetscnewtonkrylov
1476 
1477 
1478 
1479 
1480 
1481 
1482 
1483 
1484 
1485 
1486 
1487 
1488 
1489 
1490 
1491 
1492 
void zero()
Sets all entries to zero (more efficient than assignement).
subroutine rs(nm, n, a, w, matz, z, fv1, fv2, ierr)
j indices k indices k
Definition: Indexing.h:6
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)
Definition: ModError.F90:449
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
Definition: roccomf90.h:20
subroutine, public rflu_petsc_destroyjacobian(pRegion)
subroutine, public rflu_petsc_destroyapplicationordering(pRegion)
subroutine, public rflu_mpi_recvwrapper(pRegion)
blockLoc i
Definition: read.cpp:79
subroutine, public rflu_petsc_getdtscale(global, dtscale)
void int int REAL * x
Definition: read.cpp:74
const NT & n
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)
j indices j
Definition: Indexing.h:6
subroutine, public rflu_petsc_createapplicationordering(pRegion)
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine rflu_checkpositivity(pRegion)
subroutine deregisterfunction(global)
Definition: ModError.F90:469
subroutine, public rflu_col_readcoloring(pRegion)