Skip to content
Draft

Dev #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Examples/Parareal/ERK/bm1.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
!
! Test parameters for the nonlinear Schroedinger eq
!

&PARAMS

Tfin = 13.5
nx = 1024 1024

nsteps = 1
nsteps_rk = 1 1
rk_order = 4 4

eq_type = 3
ic_type = 3

split_damp=.true.
split_rho=0.0245436926061703 ! pi/128
Lx=25.1327412287183 ! 8 pi

pfasst_nml="parareal.nml" ! Use the common input file for pfasst parameters
/
23 changes: 23 additions & 0 deletions Examples/Parareal/ERK/bm1serial.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
!
! Test parameters for the nonlinear Schroedinger eq
!

&PARAMS

Tfin = 13.5
nx = 1024

nsteps = 4096
nsteps_rk = 128
rk_order = 4

eq_type = 3
ic_type = 3

split_damp=.false.
split_rho=0.0245436926061703 ! pi/128
Lx=25.1327412287183 ! 8 pi

pfasst_nml="serial.nml" ! Use the common input file for pfasst parameters
! pfasst_nml="parareal.nml" ! Use the common input file for pfasst parameters
/
Binary file added Examples/Parareal/ERK/nls_bm1.npy
Binary file not shown.
32 changes: 32 additions & 0 deletions Examples/Parareal/ERK/serial.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
&PF_PARAMS
! These are internal pfasst variables that must be set
nlevels = 1

! These are internal pfasst variables that can be reset
niters = 1 ! default is 5 - 0 leaves predictor on coarse level

! optional variables to control termination (defaults are 0.0)
abs_res_tol = 1.d-10
rel_res_tol = 1.d-10

nnodes = 2 2

! Choices to run parareal instead of PFASST
use_rk_stepper=.true.
use_sdc_sweeper=.false.

! These flags control the output. For fastest timings, turn them off
save_residuals=.false.
save_delta_q0=.false.
save_errors=.false.

! Flag for timings. For fastest timing of only full algorithm, set to 1
save_timings = 1

! Flag for saving solutions, needed for problems with no exact solution
save_solutions = 1

! Directory name for output
outdir="serial"
/

4 changes: 2 additions & 2 deletions Examples/Parareal/ERK/src/stepper_include.f90
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end subroutine destroy

!F_EVAL: evaluates the nonlinear function f(t,y(t)) at y, t.
subroutine f_eval(this, y, t, level_index, f)
use probin, only: eq_type,splitting
use probin, only: eq_type,split_damp
! arguments
class(my_stepper_t), intent(inout) :: this
class(pf_encap_t), intent(in) :: y
Expand All @@ -90,7 +90,7 @@ subroutine f_eval(this, y, t, level_index, f)
call f_NL(this%yvec,this%fvec,this%fft_ops%opNL,this%tmp,fft)

! include damping
if (split_damping) this%fvec= this%fvec - this%fft_ops%opDamp*this%yvec
if (split_damp) this%fvec= this%fvec - this%fft_ops%opDamp*this%yvec
end subroutine f_eval

subroutine compA(this, dt, i, j, F, val)
Expand Down
1 change: 1 addition & 0 deletions Examples/Parareal/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endif
FFLAGS += -I$(LIBPFASST)/include -I$(LIBNPY)/include
LDFLAGS += -L$(LIBNPY)/libnpy_fortran_mod -lnpy


build/main_rk.o : ../src/main_rk.f90 build/probin.o build/hooks_rk.o build/level_rk.o build/stepper_$(DIM)d.o build/utils_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a
build/probin.o :../src/probin.f90 build/dim_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a
build/utils_$(DIM)d.o : ../src/utils_$(DIM)d.f90 build/probin.o
Expand Down
8 changes: 5 additions & 3 deletions Examples/Parareal/src/probin.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ module probin
real(pfdp), save :: gamma
! parameters for split damping
real(pfdp), save :: d0,d1,r0,r1
logical, save :: split_damping
logical, save :: split_damp
real(pfdp), save :: split_rho
character(len=32), save :: pfasst_nml

character(len=64), save :: output ! directory name for output
Expand All @@ -46,7 +47,7 @@ module probin
integer :: ios,iostat
namelist /params/ nx,ic_type, eq_type, nsteps,nsteps_rk,rk_order, dt, Tfin
namelist /params/ pfasst_nml, lam1,lam2,a,b,c, nu, t00, sigma, beta, gamma, splitting
namelist /params/ kfreqx,kfreqy,kfreqz,Lx,Ly,Lz,d0,d1,r0,r1,split_damping
namelist /params/ kfreqx,kfreqy,kfreqz,Lx,Ly,Lz,d0,d1,r0,r1,split_damp,split_rho

contains

Expand Down Expand Up @@ -87,7 +88,8 @@ subroutine probin_init(pf_fname)
Ly = two_pi
Lz = two_pi
! Default damping parameters are 0
split_damping=.true.
split_damp=.true.
split_rho=two_pi/256.0_pfdp
d0=0.0_pfdp
d1=0.0_pfdp
r0=0.0_pfdp
Expand Down
23 changes: 16 additions & 7 deletions Examples/Parareal/src/utils_1d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ subroutine f_NL(yvec,fvec,opNL,tmp,fft)
case DEFAULT
call pf_stop(__FILE__,__LINE__,'Bad case in SELECT',eq_type)
end select

end subroutine f_NL

end module pf_mod_zutils
Expand All @@ -275,7 +276,7 @@ module pf_mod_fftops
contains

subroutine fftops_init(this,fft,nx)
use probin, only: d0,d1,r0,r1
use probin, only: d0,d1,r0,r1,split_damp,split_rho
class(pf_fft_ops_t), intent(inout) :: this
type(pf_fft_t), pointer, intent(in) :: fft
integer, intent(in) :: nx
Expand All @@ -289,8 +290,6 @@ subroutine fftops_init(this,fft,nx)
if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat)
allocate(this%opNL(nx),STAT=istat)
if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat)
allocate(this%opDamp(nx),STAT=istat)
if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat)

call fft%make_deriv(this%ddx) ! First derivative
call fft%make_lap(this%lap) ! Second derivative
Expand All @@ -299,19 +298,29 @@ subroutine fftops_init(this,fft,nx)
call set_ops(this%opL,this%opNL,this%ddx,this%lap)

! Create damping op
this%opDamp= d0*this%ddx**r0 + d1*abs(this%ddx)**r1
! add damping to linear operator
this%opL=this%opL+this%opDamp
if (split_damp) then
allocate(this%opDamp(nx),STAT=istat)
if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat)
! this%opDamp= d0*this%ddx**r0 + d1*abs(this%ddx)**r1
this%opDamp= abs(this%ddx)**2/tan(two_pi/4.0_pfdp + split_rho)

! add damping to linear operator
this%opL=this%opL+this%opDamp
end if
deallocate(this%lap)
deallocate(this%ddx)
end subroutine fftops_init

subroutine fftops_destroy(this)
use probin, only: split_damp
class(pf_fft_ops_t), intent(inout) :: this

deallocate(this%opL)
deallocate(this%opNL)
deallocate(this%opDamp)
if (split_damp) then
deallocate(this%opDamp)
end if

end subroutine fftops_destroy

!> Routine to return out put the solution to numpy (dimension dependent)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ USE_PETSC ?= FALSE
USE_HYPRE ?= FALSE
USE_SUNDIALS ?= FALSE
USE_AMREX ?= FALSE
USE_FFT ?= FALSE
USE_FFT ?= TRUE


# File for compiler options
Expand Down
6 changes: 4 additions & 2 deletions Makefile.examples/Makefile.local
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ AR=ar rcs

FFLAGS = -Ibuild -Jinclude -cpp -ffree-line-length-none
# Use this flag on newer compilers with stricter bounds checking
#FFLAGS = -fallow-argument-mismatch
# FFLAGS_EXTRA is used for F77 in building dfftpack
#FFLAGS += -fallow-argument-mismatch
#FFLAGS_EXTRA += fallow-argument-mismatch

ifeq ($(DEBUG),TRUE)
FFLAGS += -fcheck=all -fbacktrace -g -ffpe-trap=invalid,zero,overflow -fbounds-check -fimplicit-none -ffree-line-length-none
else
FFLAGS += -O3
endif
endif
27 changes: 27 additions & 0 deletions Makefile.examples/Makefile.local.cori
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Set some compiler flags

AR = ar rcs
ifeq ($(PE_ENV),INTEL)
#FC = mpiifort
#CC = mpiiCC
FC = ftn
LD = ftn -static
CC = cc
FFLAGS = -Ibuild -module include -cpp -static
ifeq ($(DEBUG),TRUE)
FFLAGS += -g -O0
endif
endif

ifeq ($(PE_ENV),CRAY)
#FC = mpiifort
#CC = mpiiCC
FC = ftn
LD = ftn
CC = cc
FFLAGS = -Ibuild -Jinclude
LDLAGS = -Ibuild -Jinclude
ifeq ($(DEBUG),TRUE)
FFLAGS += -g
endif
endif
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ Approximation Scheme in Space and Time (PFASST) algorithm. It is
written in Fortran (mostly F90, with some F03), but can be interfaced
with C and C++ fairly easily.

## References
- Matthew Emmett, Michael Minion: Toward an efficient parallel in time method for partial differential equations, Commun. Appl. Math. Comput. Sci. 7(1), 105-132, 2012. [http://dx.doi.org/10.2140/camcos.2012.7.105](http://dx.doi.org/10.2140/camcos.2012.7.105)
- Matthew Emmett, Michael Minion: Efficient Implementation of a Multi-Level Parallel in Time Algorithm. In: Erhel, J., Gander, M., Halpern, L., Pichot, G., Sassi, T., Widlund, O. (eds) Domain Decomposition Methods in Science and Engineering XXI. Lecture Notes in Computational Science and Engineering, vol 98. Springer, Cham, 2014. [https://doi.org/10.1007/978-3-319-05789-7_33](https://doi.org/10.1007/978-3-319-05789-7_33)

## Documentation
We are currently writing better documentation, examples, and a tutorial, at [https://libpfasst.github.io/LibPFASST](https://libpfasst.github.io/LibPFASST).
The documentation can be edited on the gh-pages branch of this repo.

## Requirements
- a Fortran compiler, for some external libraries like FFTW C/C++ compiler
- an MPI library
- makedepf90 for generating dependencies
- python 3.12 for the test (including numpy, matplotlib, pandas, scipy, tqdm, pytest)

## Quickstart
- compile the library, see [https://libpfasst.github.io/LibPFASST/docs/build/html/compiling.html](https://libpfasst.github.io/LibPFASST/docs/build/html/compiling.html)
- look through the tutorials, see [https://libpfasst.github.io/LibPFASST/docs/build/html/tutorial.html](https://libpfasst.github.io/LibPFASST/docs/build/html/tutorial.html)

## License

Libpfasst Copyright (c) 2018, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy) and Sebastian Goetschel. All rights reserved.

Expand All @@ -23,9 +42,7 @@ You are under no obligation whatsoever to provide any bug fixes, patches, or upg



# Documentation
We are currently writing better documentation, examples, and a tutorial, at https://libpfasst.github.io/LibPFASST.
The documentation can be edited on the gh-pages branch of this repo.




Expand Down
10 changes: 5 additions & 5 deletions pf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import io
import convergence
import speedup
import pfasst
import nwc
import pf.io
import pf.convergence
import pf.speedup
import pf.pfasst
import pf.nwc
17 changes: 9 additions & 8 deletions pf/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from itertools import product

import numpy as np
import pylab
#import pylab
import matplotlib.pyplot as plt
import pf.io


Expand Down Expand Up @@ -57,7 +58,7 @@ def errors(reference, approximate, **kwargs):
err = abs(ref - app).max()
errors[step, aiter, alev] = err
except:
print 'WARNING: size mismatch:', step, aiter, alev
print('WARNING: size mismatch:', step, aiter, alev)

return errors, steps, iters, levels

Expand All @@ -84,19 +85,19 @@ def plot(errs, steps, iters, levels, **kwargs):
# if not isinstance(ax, list):
# ax = [ ax ]

pylab.figure()
plt.figure()

for l, level in enumerate(levels):
for i, iter in enumerate(iters):

x = steps
y = [ errs[step,iter,level] for step in steps ]

pylab.subplot(1, len(levels), l+1)
plt.subplot(1, len(levels), l+1)

pylab.semilogy(x, y, **kwargs)
pylab.title('level %d' % level)
pylab.xlabel('step/processor')
pylab.ylabel('max abs. error')
plt.semilogy(x, y, **kwargs)
plt.title('level %d' % level)
plt.xlabel('step/processor')
plt.ylabel('max abs. error')

# return fig, ax
8 changes: 4 additions & 4 deletions pf/nwc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os import getcwd, chdir, makedirs, devnull
from subprocess import call
from scipy.io import FortranFile
from pfasst import PFASST
from pf.pfasst import PFASST
import numpy as np

class NWC(PFASST):
Expand All @@ -11,7 +11,7 @@ def __init__(self, home, params=None, **kwargs):
if params is None:
params = Params()
PFASST.__init__(self, home, params, **kwargs)
print 'Setting up NWC'
print('Setting up NWC')
self.nwc = self.home + '/nwc.sh'
self.cwd = getcwd() + '/'
self.nwc_base_string = 'echo\nscratch_dir ./scratch\npermanent_dir ./perm\n\n'\
Expand All @@ -33,7 +33,7 @@ def __init__(self, home, params=None, **kwargs):
except:
raise Exception('unsuccessful NWC run, check input!')
else:
print 'exact dirs already exist'
print('exact dirs already exist')

self.xtrans, self.ytrans = self._parse_transforms()
self.initial = self._get_nwc_dmat('initial_condition')
Expand Down Expand Up @@ -68,7 +68,7 @@ def _create_nwc_inp(self):
def _run_nwc(self):
FNULL = open(devnull, 'w')
chdir(self.p.exact_dir)
print '---- running nwc ----'
print('---- running nwc ----')
call([self.nwc, 'nw'], stdout=FNULL)
chdir(self.cwd)
FNULL.close()
Expand Down
Loading