Commits

Matthew Emmett  committed 472624e

Add residual and evaluate_all to explicit, implicit, and imex (use generic).

  • Participants
  • Parent commits 798e862

Comments (0)

Files changed (7)

File Makefile.defaults

 # Default build settings for libpfasst.
 #
 
-FC = gfortran
+FC = mpif90
 CC = mpicc
 AR = ar rcs
 PY = python

File Makefile.rules

 build/pf_cycle.o:       build/pf_dtype.o
 build/pf_ndarray.o:     build/pf_dtype.o
 build/pf_utils.o:       build/pf_timer.o
-build/pf_explicit.o:    build/pf_timer.o
+build/pf_explicit.o:    build/pf_timer.o build/pf_utils.o
 build/pf_hooks.o:       build/pf_timer.o
 build/pf_hooks.o:       build/pf_timer.o
-build/pf_implicit.o:    build/pf_timer.o
+build/pf_implicit.o:    build/pf_timer.o build/pf_utils.o
 build/pf_mpi.o:         build/pf_timer.o
 build/pf_logger.o:      build/pf_hooks.o
-build/pf_imex.o:        build/pf_timer.o build/pf_explicit.o build/pf_implicit.o
+build/pf_imex.o:        build/pf_timer.o build/pf_explicit.o build/pf_implicit.o build/pf_utils.o
 build/pf_restrict.o:    build/pf_utils.o build/pf_timer.o build/pf_hooks.o
 build/pf_interpolate.o: build/pf_restrict.o build/pf_hooks.o
 build/pf_parallel.o:    build/pf_interpolate.o build/pf_hooks.o build/pf_cycle.o

File src/pf_dtype.f90

   type :: pf_sweeper_t
      type(c_ptr) :: sweeperctx
      integer     :: npieces
-     procedure(pf_sweep_p),      pointer, nopass :: sweep
-     procedure(pf_initialize_p), pointer, nopass :: initialize
-     procedure(pf_evaluate_p),   pointer, nopass :: evaluate
-     procedure(pf_evaluate_all_p),   pointer, nopass :: evaluate_all
-     procedure(pf_integrate_p),  pointer, nopass :: integrate
-     procedure(pf_residual_p),   pointer, nopass :: residual
-     procedure(pf_sweepdestroy_p),  pointer, nopass :: destroy
+     procedure(pf_sweep_p),        pointer, nopass :: sweep
+     procedure(pf_initialize_p),   pointer, nopass :: initialize
+     procedure(pf_evaluate_p),     pointer, nopass :: evaluate
+     procedure(pf_evaluate_all_p), pointer, nopass :: evaluate_all
+     procedure(pf_integrate_p),    pointer, nopass :: integrate
+     procedure(pf_residual_p),     pointer, nopass :: residual
+     procedure(pf_sweepdestroy_p), pointer, nopass :: destroy
   end type pf_sweeper_t
 
   type :: pf_encap_t
 
      subroutine pf_residual_p(Lev, dt)
        import pf_level_t, c_ptr, pfdp
-       type(pf_level_t),  intent(in)    :: Lev
+       type(pf_level_t),  intent(inout) :: Lev
        real(pfdp),        intent(in)    :: dt
      end subroutine pf_residual_p
 

File src/pf_explicit.f90

 
 module pf_mod_explicit
   use pf_mod_dtype
+  use pf_mod_utils
   implicit none
   integer, parameter, private :: npieces = 1
 
     sweeper%initialize => explicit_initialize
     sweeper%integrate  => explicit_integrate
     sweeper%destroy    => pf_explicit_destroy
+    sweeper%evaluate_all => pf_generic_evaluate_all
+    sweeper%residual     => pf_generic_residual
 
     sweeper%sweeperctx = c_loc(exp)
   end subroutine pf_explicit_create

File src/pf_imex.f90

 
 module pf_mod_imex
   use pf_mod_dtype
+  use pf_mod_utils
   use pf_mod_explicit, only: pf_f1eval_p
   use pf_mod_implicit, only: pf_f2eval_p, pf_f2comp_p
   implicit none
      procedure(pf_f2eval_p), pointer, nopass :: f2eval
      procedure(pf_f2comp_p), pointer, nopass :: f2comp
 
-     !  Matrices
-     real(pfdp), ALLOCATABLE :: SdiffE(:,:)
-     real(pfdp), ALLOCATABLE :: SdiffI(:,:)
-
+     real(pfdp), allocatable :: SdiffE(:,:)
+     real(pfdp), allocatable :: SdiffI(:,:)
   end type pf_imex_t
 
 contains
     imex%f2comp => f2comp
 
     sweeper%npieces = npieces
-    sweeper%sweep      => imex_sweep
-    sweeper%evaluate   => imex_evaluate
-    sweeper%initialize => imex_initialize
-    sweeper%integrate  => imex_integrate
-    sweeper%destroy    => pf_imex_destroy
+    sweeper%sweep        => imex_sweep
+    sweeper%evaluate     => imex_evaluate
+    sweeper%initialize   => imex_initialize
+    sweeper%integrate    => imex_integrate
+    sweeper%destroy      => pf_imex_destroy
+    sweeper%evaluate_all => pf_generic_evaluate_all
+    sweeper%residual     => pf_generic_residual
 
     sweeper%sweeperctx = c_loc(imex)
   end subroutine pf_imex_create

File src/pf_implicit.f90

 
 module pf_mod_implicit
   use pf_mod_dtype
+  use pf_mod_utils
   implicit none
   integer, parameter, private :: npieces = 1
 
     sweeper%evaluate   => implicit_evaluate
     sweeper%initialize => implicit_initialize
     sweeper%integrate  => implicit_integrate
+    sweeper%evaluate_all => pf_generic_evaluate_all
+    sweeper%residual     => pf_generic_residual
 
     sweeper%sweeperctx = c_loc(imp)
   end subroutine pf_implicit_create

File src/pf_utils.f90

     end do
   end subroutine pf_apply_mat
 
+  !
+  ! Generic residual
+  !
+  subroutine pf_generic_residual(Lev, dt)
+    type(pf_level_t),  intent(inout) :: Lev
+    real(pfdp),        intent(in)    :: dt
+
+    integer :: m, n
+
+    call Lev%sweeper%integrate(Lev, Lev%Q, Lev%F, dt, Lev%I)
+    do m = 2, Lev%nnodes-1
+       call Lev%encap%axpy(Lev%I(m), 1.0_pfdp, Lev%I(m-1))
+    end do
+
+    ! add tau (which is 'node to node')
+    if (associated(Lev%tau)) then
+       do m = 1, Lev%nnodes-1
+          do n = 1, m
+             call Lev%encap%axpy(Lev%I(m), 1.0_pfdp, Lev%tau(n))
+          end do
+       end do
+    end if
+
+    ! subtract out Q
+    do m = 1, Lev%nnodes-1
+       call Lev%encap%copy(Lev%R(m), Lev%Q(1))
+       call Lev%encap%axpy(Lev%R(m),  1.0_pfdp, Lev%I(m))
+       call Lev%encap%axpy(Lev%R(m), -1.0_pfdp, Lev%Q(m+1))
+    end do
+
+  end subroutine pf_generic_residual
+
+  !
+  ! Generic evaluate all
+  !
+  subroutine pf_generic_evaluate_all(Lev, t)
+    type(pf_level_t),  intent(inout) :: Lev
+    real(pfdp),        intent(in)    :: t(:)
+
+    integer :: m
+    do m = 1, Lev%nnodes
+       call Lev%sweeper%evaluate(Lev, t(m), m)
+    end do
+  end subroutine pf_generic_evaluate_all
+
 end module pf_mod_utils