├── .circleci └── config.yml ├── .depend ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── Dockerfile ├── Examples ├── Hypre │ ├── .depend │ ├── Makefile │ ├── probin.nml │ └── src │ │ ├── comm.f90 │ │ ├── encap.f90 │ │ ├── hooks.f90 │ │ ├── hypre_fortran.cpp │ │ ├── hypre_fortran.hpp │ │ ├── hypre_solver.cpp │ │ ├── hypre_solver.hpp │ │ ├── hypre_struct.cpp │ │ ├── hypre_struct.hpp │ │ ├── hypre_vector.cpp │ │ ├── hypre_vector.hpp │ │ ├── level.f90 │ │ ├── main.cpp │ │ ├── main.f90 │ │ ├── main_solver.cpp │ │ ├── main_test_encap.f90 │ │ ├── main_vector.cpp │ │ ├── pfasst_hypre.f90 │ │ ├── probin.f90 │ │ ├── stepper.f90 │ │ └── sweeper.f90 ├── MGRIT │ ├── EX1_Dahlquist_mgrit │ │ ├── .depend │ │ ├── Makefile │ │ ├── probin.nml │ │ └── src │ │ │ ├── hooks.f90 │ │ │ ├── level.f90 │ │ │ ├── main.f90 │ │ │ ├── probin.f90 │ │ │ ├── stepper.f90 │ │ │ └── sweeper.f90 │ └── EX3_adv_diff_mgrit │ │ ├── .depend │ │ ├── Makefile │ │ ├── probin.nml │ │ └── src │ │ ├── hooks.f90 │ │ ├── level.f90 │ │ ├── main.f90 │ │ ├── probin.f90 │ │ ├── stepper.f90 │ │ └── sweeper.f90 └── Parareal │ ├── ERK │ ├── Makefile │ ├── ad.nml │ ├── burg.nml │ ├── dahlquist.nml │ ├── kdv.nml │ ├── kdv_serial.nml │ ├── ks.nml │ ├── nls.nml │ ├── parareal.nml │ └── src │ │ ├── stepper_1d.f90 │ │ ├── stepper_2d.f90 │ │ ├── stepper_3d.f90 │ │ └── stepper_include.f90 │ ├── Make.package │ └── src │ ├── dim_1d.f90 │ ├── dim_2d.f90 │ ├── dim_3d.f90 │ ├── hooks_rk.f90 │ ├── level.f90 │ ├── level_rk.f90 │ ├── main_rk.f90 │ ├── phi_mod.f90 │ ├── probin.f90 │ ├── utils_1d.f90 │ ├── utils_2d.f90 │ └── utils_3d.f90 ├── LICENSE ├── Makefile ├── Makefile.defaults ├── Makefile.examples ├── Makefile.AMReX ├── Makefile.FFT ├── Makefile.PETSc ├── Makefile.hypre ├── Makefile.local └── Makefile.local.gnu ├── Makefile.external ├── Makefile.local ├── Makefile.rules ├── README.md ├── Tutorials ├── EX1_Dahlquist │ ├── .depend │ ├── Makefile │ ├── README │ ├── multi_level.nml │ ├── pipeline.nml │ ├── probin.nml │ ├── sdc.nml │ └── src │ │ ├── level.f90 │ │ ├── main.f90 │ │ ├── probin.f90 │ │ └── sweeper.f90 ├── EX2_Dahlquist │ ├── .depend │ ├── Makefile │ ├── README │ ├── multi_level.nml │ ├── pipeline.nml │ ├── probin.nml │ ├── sdc.nml │ └── src │ │ ├── encap.f90 │ │ ├── hooks.f90 │ │ ├── level.f90 │ │ ├── main.f90 │ │ ├── probin.f90 │ │ └── sweeper.f90 ├── EX3_adv_diff │ ├── .depend │ ├── Makefile │ ├── multi_level.nml │ ├── pipeline.nml │ ├── probin.nml │ ├── sdc.nml │ └── src │ │ ├── hooks.f90 │ │ ├── level.f90 │ │ ├── main.f90 │ │ ├── probin.f90 │ │ └── sweeper.f90 ├── EX4_Boussinesq │ ├── .depend │ ├── Makefile │ ├── out │ ├── src │ │ ├── hooks.f90 │ │ ├── level.f90 │ │ ├── main.f90 │ │ ├── probin.f90 │ │ ├── split │ │ └── sweeper.f90 │ └── tg.nml └── EX5_KS_control │ ├── Makefile │ ├── doc │ ├── figures │ │ ├── ctrlKS_T1_nstep100_nx1024_u0_075uexact_diff_final.png │ │ ├── ctrlKS_T1_nstep100_nx1024_u0_075uexact_progress.png │ │ ├── gradientKS_T1_nstep100_nx1024_u0_075uexact_progress.pdf │ │ ├── gradientsKS_T1_nstep100_nx1024_u0_075uexact_progress.png │ │ ├── objKS_T1_nstep100_nx1024_u0_075uexact_progress.pdf │ │ ├── solKS_T1_nstep100_nx1024_optit60.png │ │ ├── solKS_T1_nstep100_nx1024_yd.png │ │ └── solKS_T60_nstep600_nx1024.png │ ├── notes.pdf │ ├── notes.tex │ └── references.bib │ ├── imex.nml │ ├── plot.py │ └── src │ ├── hooks.f90 │ ├── level.f90 │ ├── main.f90 │ ├── pf_optimization_1d.f90 │ ├── probin.f90 │ └── sweeper.f90 ├── mk ├── GPackage.mak ├── makefile.gcc47.defs ├── makefile.juqueen.defs ├── makefile.orga.defs └── makefile.spruce.defs ├── pf ├── __init__.py ├── convergence.py ├── io.py ├── nwc.py ├── pfasst.py ├── setup.py └── speedup.py ├── pp ├── README ├── iter_per_step.py ├── parareal_run.py ├── pfasst_run.py ├── stats_per_step.py └── time_per_proc.py ├── src ├── README ├── dfftpack.f ├── pf_amisdc_sweeper.f90 ├── pf_amisdc_sweeperQ.f90 ├── pf_amrex_encap.f90 ├── pf_comm.f90 ├── pf_dtype.f90 ├── pf_erkstepper.f90 ├── pf_exp_sweeper.f90 ├── pf_fexp_sweeper.f90 ├── pf_fft.f90 ├── pf_fftpack.f90 ├── pf_fftw.f90 ├── pf_ham_sys_encap.f90 ├── pf_hooks.f90 ├── pf_imexQ_oc_sweeper.f90 ├── pf_imexR_sweeper.f90 ├── pf_imex_sweeper.f90 ├── pf_imk_sweeper.f90 ├── pf_interpolate.f90 ├── pf_magpicard_sweeper.f90 ├── pf_mgrit.f90 ├── pf_misdcQ_oc_sweeper.f90 ├── pf_misdcQ_sweeper.f90 ├── pf_misdc_sweeper.f90 ├── pf_mpi.f90 ├── pf_ndarray_encap.f90 ├── pf_ndarray_oc_encap.f90 ├── pf_ndsysarray_encap.f90 ├── pf_parallel.f90 ├── pf_parallel_oc.f90 ├── pf_parareal.f90 ├── pf_petscVec_encap.f90 ├── pf_pfasst.f90 ├── pf_quadrature.f90 ├── pf_restrict.f90 ├── pf_results.f90 ├── pf_rkstepper.f90 ├── pf_solutions.f90 ├── pf_stop.f90 ├── pf_sundials_vec.f90 ├── pf_timer.f90 ├── pf_utils.f90 ├── pf_verlet_sweeper.f90 ├── pf_zndarray_encap.f90 ├── pf_zndsysarray_encap.f90 └── pfasst.f90 └── test ├── EXP_adv_diff_fft └── 1d │ ├── .depend │ ├── Makefile │ ├── multi_level.nml │ ├── pipeline.nml │ ├── probin.nml │ ├── sdc.nml │ └── src │ ├── hooks.f90 │ ├── level.f90 │ ├── main.f90 │ ├── phi_mod.f90 │ ├── probin.f90 │ └── sweeper.f90 ├── Ndarray ├── IMEX_sweeper │ ├── .depend │ ├── Makefile │ ├── src │ │ ├── .#sweeper_3d.f90 │ │ ├── sweeper_1d.f90 │ │ ├── sweeper_2d.f90 │ │ ├── sweeper_3d.f90 │ │ └── sweeper_include.f90 │ ├── test_1d.nml │ ├── test_2d.nml │ └── test_3d.nml ├── Make.package └── src │ ├── dim_1d.f90 │ ├── dim_2d.f90 │ ├── dim_3d.f90 │ ├── hooks.f90 │ ├── hooks_rk.f90 │ ├── level.f90 │ ├── level_rk.f90 │ ├── main.f90 │ ├── main_rk.f90 │ ├── phi_mod.f90 │ ├── probin.f90 │ ├── utils_1d.f90 │ ├── utils_2d.f90 │ └── utils_3d.f90 ├── imk ├── .depend ├── Makefile ├── facke.nml ├── facke_multi.nml ├── probin.nml ├── simple.ipynb ├── src │ ├── factory.f90 │ ├── hooks.f90 │ ├── level.f90 │ ├── main.f90 │ ├── matrix_exponential.f90 │ ├── probin.f90 │ ├── sweeper.f90 │ └── utils.f90 ├── testbed.ipynb └── toda.nml ├── magpicard ├── .depend ├── Makefile ├── facke.nml ├── final_solution ├── movie.py ├── pareto.py ├── plotchain.m ├── probin.nml ├── run1.sh ├── src │ ├── hooks.f90 │ ├── main.f90 │ ├── matrix_exponential.f90 │ ├── probin.f90 │ ├── sweeper.f90 │ └── utils.f90 ├── testbed.ipynb └── toda.nml ├── nagumo ├── .depend ├── Makefile ├── pfasst.nml ├── probin.nml └── src │ ├── feval.f90 │ ├── hooks.f90 │ ├── level.f90 │ ├── main_split.f90 │ ├── numpy.c │ ├── pf_optimization.f90 │ ├── probin.f90 │ └── solutions.f90 ├── run_tests.sh ├── test_EXP.py ├── test_encaps.sh ├── test_imk.py ├── test_mag_toda.py ├── test_magpicard.old ├── test_nagumo.py └── zNdarray ├── ERK_stepper ├── .depend ├── Makefile ├── src │ ├── stepper_1d.f90 │ ├── stepper_2d.f90 │ ├── stepper_3d.f90 │ └── stepper_include.f90 ├── test_1d.nml ├── test_2d.nml └── test_3d.nml ├── EXP_sweeper ├── Makefile ├── src │ ├── sweeper_1d.f90 │ ├── sweeper_2d.f90 │ ├── sweeper_3d.f90 │ └── sweeper_include.f90 ├── test_1d.nml ├── test_2d.nml └── test_3d.nml ├── IMEX_sweeper ├── .depend ├── Makefile ├── nls_sisdc_step.png ├── nls_sisdc_time.png ├── src │ ├── sweeper_1d.f90 │ ├── sweeper_2d.f90 │ ├── sweeper_3d.f90 │ └── sweeper_include.f90 ├── test_1d.nml ├── test_2d.nml └── test_3d.nml ├── Make.package ├── RK_stepper ├── Makefile ├── out ├── src │ ├── stepper_1d.f90 │ ├── stepper_2d.f90 │ ├── stepper_3d.f90 │ └── stepper_include.f90 ├── test_1d.nml ├── test_2d.nml └── test_3d.nml ├── nls.nml └── src ├── dim_1d.f90 ├── dim_2d.f90 ├── dim_3d.f90 ├── hooks.f90 ├── hooks_rk.f90 ├── level.f90 ├── level_rk.f90 ├── main.f90 ├── main_rk.f90 ├── phi_mod.f90 ├── probin.f90 ├── utils_1d.f90 ├── utils_2d.f90 ├── utils_3d.f90 └── visc_burg.f90 /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report bugs for us to improve the code 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug / Actual behavior** 11 | A clear and concise description of what the bug is (what behavior did you observe). 12 | 13 | **Expected behavior** 14 | A clear and concise description of what you expected to happen. 15 | 16 | **Minimal code example** 17 | If possible, provide a code snippet to reproduce the bug. 18 | 19 | **Screenshots** 20 | If applicable, add screenshots to help explain your problem. 21 | 22 | **System** 23 | - OS including version number [e.g., Ubuntu 22.04.5, MacOS 13.6.9] 24 | - Compiler including version number [e.g., gcc version 12.3.0], ideally the output of, e.g., gfortran -v 25 | - MPI library [e.g., MPICH 4.1.2] 26 | - if applicable, any other third-party libraries used 27 | 28 | **Additional context** 29 | Add any other context about the problem here. 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#* 3 | 4 | fftw* 5 | hdf5* 6 | gcc* 7 | xz* 8 | 9 | *.exe 10 | *.defs 11 | fort.* 12 | *.out 13 | 14 | *.pyc 15 | *.pkl 16 | *.npy 17 | 18 | lib/ 19 | build/ 20 | include/ 21 | staging/ 22 | src/pf_version.f90 23 | /.project 24 | 25 | test/*/build 26 | test/*/include 27 | test/*/output 28 | test/output 29 | latex 30 | html 31 | *.dat 32 | final_solution 33 | *.gif 34 | .pytest_cache 35 | /TAGS 36 | *.ipynb_checkpoints 37 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # In order to update the image that gets used in the CircleCI testing do: 2 | # 1. Create a new hub.docker.com account to push the newly built docker image to 3 | # e.g. a libpfasst dockerhub account 4 | # 2. `docker build -t libpfasst/libpfasst:latest .` 5 | # this will create a new image on your compute 6 | # 3. `docker login` 7 | # using the credentials from the newly created account 8 | # 4. `docker push libpfasst/libpfasst` 9 | # this will put the image in the docker hub account so it can be pulled 10 | # Finally, go and update the docker image used in the .circleci/config.yml file 11 | 12 | FROM ubuntu:18.04 13 | ENV TZ=US/Pacific 14 | RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone 15 | RUN apt-get -y update && \ 16 | apt-get -y install \ 17 | make \ 18 | wget \ 19 | unzip \ 20 | gfortran \ 21 | mpich \ 22 | libmpich-dev \ 23 | libopenblas-dev \ 24 | liblapack-dev 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Examples/Hypre/.depend: -------------------------------------------------------------------------------- 1 | ./build/main.o : src/main.f90 ./build/encap.o ./build/probin.o ./build/hooks.o ./build/level.o ./build/sweeper.o ./build/stepper.o 2 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o ./build/encap.o 3 | ./build/stepper.o : src/stepper.f90 ./build/sweeper.o ./build/probin.o ./build/encap.o 4 | ./build/level.o : src/level.f90 ./build/encap.o 5 | ./build/hooks.o : src/hooks.f90 ./build/sweeper.o ./build/encap.o 6 | ./build/encap.o : src/encap.f90 7 | ./build/probin.o : src/probin.f90 8 | -------------------------------------------------------------------------------- /Examples/Hypre/Makefile: -------------------------------------------------------------------------------- 1 | #################### 2 | # User-set variables 3 | #################### 4 | # Hypre include directory 5 | export HYPRE_DIR=./hypre/src/hypre 6 | # C++ compiler (user must set this) 7 | CPP_COMPILE = g++ -O3 -g 8 | # LibPFASST directory 9 | LIBPFASST ?= ../.. 10 | 11 | CPP_SRC_DIR=src/ 12 | export USE_HYPRE=TRUE 13 | 14 | CPP_FILES = \ 15 | $(CPP_SRC_DIR)hypre_struct.cpp \ 16 | $(CPP_SRC_DIR)hypre_vector.cpp \ 17 | $(CPP_SRC_DIR)hypre_solver.cpp \ 18 | $(CPP_SRC_DIR)hypre_fortran.cpp 19 | 20 | CPP_INCLUDE = \ 21 | -I$(HYPRE_DIR)/include \ 22 | -I./hypre/src/struct_ls 23 | 24 | BUILDDIR = build 25 | 26 | EXE = main.exe 27 | 28 | # Must use Makefile.defaults included in this repo 29 | include $(LIBPFASST)/Makefile.defaults 30 | 31 | FSRC = src/comm.f90 src/level.f90 src/sweeper.f90 src/stepper.f90 src/hooks.f90 src/probin.f90 src/encap.f90 src/pfasst_hypre.f90 src/main.f90 32 | CSRC = src/hypre_struct.cpp src/hypre_vector.cpp src/hypre_solver.cpp src/hypre_fortran.cpp 33 | 34 | OBJ = $(subst src, build,$(FSRC:.f90=.o)) 35 | OBJ += $(subst src, build,$(CSRC:.cpp=.o)) 36 | 37 | FFLAGS += -I$(LIBPFASST)/include -g 38 | 39 | all: hypre_cpp $(EXE) 40 | 41 | hypre_cpp: 42 | mkdir -p build 43 | $(CPP_COMPILE) -c $(CPP_FILES) $(CPP_INCLUDE) 44 | mv $(subst src, .,$(CPP_FILES:.cpp=.o)) build/ 45 | 46 | VPATHS = src 47 | 48 | include $(LIBPFASST)/Makefile.rules 49 | 50 | include .depend 51 | main.exe : $(LIBPFASST)/lib/libpfasst.a 52 | -------------------------------------------------------------------------------- /Examples/Hypre/probin.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level imex 3 | ! 4 | 5 | ! These are internal pfasst variables that must be set 6 | &PF_PARAMS 7 | nlevels = 2 ! must be set 8 | 9 | niters = 20 ! default is 5 10 | nnodes = 2 3 11 | 12 | nsweeps_pred= 1 1 13 | nsweeps= 1 1 1 14 | 15 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 16 | qtype = 1 17 | 18 | ! optional variables to control termination (defaults are 0.0) 19 | abs_res_tol = 0 20 | rel_res_tol = 0 21 | 22 | ! Variable which determine how the predictor runs (default is .false. and .true.) 23 | pipeline_pred = .true. 24 | PFASST_pred = .true. 25 | 26 | ! Variable to tell if Vcycling will be done. Here PFASST vcycles 27 | Vcycle=.TRUE. 28 | 29 | save_timings = 2 30 | / 31 | 32 | ! Now define the local variables you need 33 | &PARAMS 34 | 35 | T0 = 0.0 36 | Tfin = 1 37 | nsteps = 2 38 | num_grid_points = 128 39 | nspace = 1 40 | ntime = 1 41 | init_cond = 50.0 42 | space_dim = 2 43 | max_space_v_cycles = 50 44 | 45 | mgrit_n_init = 4 46 | mgrit_refine_factor = 2 47 | 48 | solver_type = 1 49 | 50 | nsteps_rk = 1 1 51 | 52 | imex_stat=1 53 | ark_stat=1 54 | 55 | rk_order=4 56 | 57 | FAS_flag = .false. 58 | FCF_flag = .false. 59 | 60 | / 61 | -------------------------------------------------------------------------------- /Examples/Hypre/src/comm.f90: -------------------------------------------------------------------------------- 1 | module pf_space_comm 2 | use pf_mod_mpi 3 | use pfasst 4 | implicit none 5 | contains 6 | 7 | subroutine create_simple_communicators(nspace, ntime, space_comm, time_comm, space_color, time_color, space_dim) 8 | integer, intent(out) :: space_comm, time_comm 9 | integer, intent(out) :: space_color, time_color 10 | integer, intent(in) :: nspace, ntime 11 | integer, intent(in) :: space_dim 12 | 13 | integer :: nproc, rank, error 14 | real(pfdp) :: nspace_real 15 | 16 | ! check size 17 | call mpi_comm_size(MPI_COMM_WORLD, nproc, error) 18 | call mpi_comm_rank(MPI_COMM_WORLD, rank, error) 19 | 20 | if (nproc .ne. (nspace * ntime)) then 21 | print '(a)', 'ERROR: create_simple_communicators: processor number mismatch.' 22 | print '(a,i4,a,i4)', ' Expecting ', & 23 | nspace * ntime, ' MPI processors but received ', & 24 | nproc 25 | stop 26 | end if 27 | 28 | ! for now, nspace must be a perfect square 29 | if (space_dim .eq. 2) then 30 | nspace_real = sqrt(real(nspace)) 31 | if (nspace_real .ne. nint(nspace_real)) then 32 | print'(a)', 'ERROR: create_simple_communicators: nspace must be perfect square.' 33 | stop 34 | end if 35 | end if 36 | 37 | if (ntime == 1) then 38 | time_color = rank 39 | space_color = 0 40 | space_comm = MPI_COMM_WORLD 41 | time_comm = MPI_COMM_SELF 42 | else if (nspace == 1) then 43 | time_color = 0 44 | space_color = rank 45 | space_comm = MPI_COMM_SELF 46 | time_comm = MPI_COMM_WORLD 47 | else 48 | ! split by color 49 | !space_color = mod(rank, nspace) 50 | !call mpi_comm_split(MPI_COMM_WORLD, space_color, rank, space_comm, error) 51 | 52 | !time_color = rank / nspace 53 | !call mpi_comm_split(MPI_COMM_WORLD, time_color, rank, time_comm, error) 54 | 55 | space_color = rank / nspace 56 | call mpi_comm_split(MPI_COMM_WORLD, space_color, rank, space_comm, error) 57 | 58 | time_color = mod(rank, nspace) 59 | call mpi_comm_split(MPI_COMM_WORLD, time_color, rank, time_comm, error) 60 | end if 61 | 62 | end subroutine create_simple_communicators 63 | 64 | end module pf_space_comm 65 | -------------------------------------------------------------------------------- /Examples/Hypre/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use encap 7 | use pf_my_sweeper 8 | use probin 9 | implicit none 10 | 11 | interface 12 | function HypreMaxErr(x, t, init_cond) result(max_err) bind(c, name="HypreMaxErr") 13 | use iso_c_binding 14 | type(c_ptr), value :: x 15 | real(c_double), value :: t 16 | real(c_double), value :: init_cond 17 | real(c_double) :: max_err 18 | end function 19 | end interface 20 | contains 21 | 22 | !> Output the error and residual in the solution 23 | subroutine echo_error(pf, level_index) 24 | type(pf_pfasst_t), intent(inout) :: pf 25 | integer, intent(in) :: level_index 26 | 27 | real(pfdp) :: yexact 28 | real(pfdp) :: maxerr, error 29 | real(pfdp) :: residual 30 | class(hypre_vector_encap), pointer :: y_end 31 | integer :: nproc, rank, ierr 32 | 33 | !> Get the solution at the end of this step 34 | y_end => cast_as_hypre_vector(pf%levels(level_index)%qend) 35 | 36 | !> compute error 37 | error = HypreMaxErr(y_end%c_hypre_vector_ptr, Tfin, init_cond) 38 | residual = pf%levels(level_index)%residual 39 | 40 | if (solver_type .eq. 1) then 41 | pf%results%residuals(level_index,1,pf%state%iter+1,1) = residual 42 | pf%results%errors(level_index,1,pf%state%iter+1,1) = error 43 | else 44 | pf%results%residuals(level_index,pf%state%pfblock,pf%state%iter+1,pf%state%sweep) = residual 45 | pf%results%errors(level_index,pf%state%pfblock,pf%state%iter+1,pf%state%sweep) = error 46 | end if 47 | 48 | !call mpi_comm_rank(pf%comm%comm, rank, ierr) 49 | !call mpi_comm_size(pf%comm%comm, nproc, ierr) 50 | 51 | 52 | if ((pf%rank == pf%comm%nproc-1) .and. (level_index == pf%nlevels) .and. (pf%state%iter .gt. 0) & 53 | .and. ((pf%state%step .eq. pf%state%nsteps-1) .or. (solver_type .eq. 1) .or. (solver_type .eq. 2))) then 54 | print '("error: rank: ", i4.4," step: ",i4.4," iter: ",i4.3," level: ",i2.2," error: ",es14.7," res: ",es18.10e4)', & 55 | pf%rank,pf%state%step+1, pf%state%iter,level_index, error, residual 56 | call flush(6) 57 | end if 58 | end subroutine echo_error 59 | 60 | 61 | end module hooks 62 | -------------------------------------------------------------------------------- /Examples/Hypre/src/hypre_fortran.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HYPRE_FORTRAN_HPP 2 | #define HYPRE_FORTRAN_HPP 3 | 4 | #include "hypre_vector.hpp" 5 | #include "hypre_solver.hpp" 6 | #include 7 | 8 | /* 9 | * Prototypes for C++ functions that are called from Fortran 10 | */ 11 | 12 | extern "C" 13 | { 14 | int PfasstToHypreLevelIndex(int pfasst_level_index, int num_levels); 15 | int HypreSolverGetNumRowsLevel(HypreSolver *hypre_solver, int pfasst_level_index); 16 | void HypreVectorCreate(HypreVector **hypre_vector, 17 | int num_grid_points, 18 | int comm_color, 19 | int space_dim, 20 | int nrows, 21 | int ilower0, 22 | int ilower1, 23 | int iupper0, 24 | int iupper1); 25 | void HypreVectorDestroy(HypreVector *hypre_vector); 26 | void HypreVectorSetVal(HypreVector *hypre_vector, double val); 27 | void HypreVectorSetSinInitCond(HypreVector *hypre_vector); 28 | void HypreVectorCopy(HypreVector *dest, HypreVector *src); 29 | double *HypreVectorPack(HypreVector *hypre_vector); 30 | void HypreVectorUnpack(HypreVector *hypre_vector, double *z); 31 | double HypreVectorNorm(HypreVector *hypre_vector); 32 | void HypreVectorAxpy(HypreVector *y, double a, HypreVector *x); 33 | void HypreVectorPrint(HypreVector *hypre_vector); 34 | void HypreSolverInit(HypreSolver **hypre_solver, 35 | int pfasst_level_index, 36 | int num_grid_points, 37 | int comm_color, 38 | int space_dim, 39 | int max_iter, 40 | int max_levels, 41 | int spacial_coarsen_flag); 42 | void HypreImplicitSolverInit(HypreSolver **hypre_solver, 43 | int pfasst_level_index, 44 | int num_grid_points, 45 | int comm_color, 46 | int space_dim, 47 | int max_iter, 48 | int max_levels, 49 | double dtq); 50 | void HypreSolverDestroy(HypreSolver *hypre_solver, int pfasst_level_index); 51 | void HypreSolverFEval(HypreSolver *hypre_solver, HypreVector *y, double t, int pfasst_level_index, HypreVector *f, int piece); 52 | void HypreSolverFComp(HypreSolver *hypre_solver, HypreVector *y, double t, double dtq, HypreVector *rhs, int pfasst_level_index, HypreVector *f, int piece); 53 | double HypreMaxErr(HypreVector *hypre_vector, double t, double init_cond); 54 | void HypreRestrict(HypreVector *y_f, HypreVector *y_c, int f_level, int c_level); 55 | void HypreProlong(HypreVector *y_f, HypreVector *y_c, int f_level, int c_level); 56 | int HypreSolverGetExtentLevel(HypreSolver *hypre_solver, int pfasst_level_index, int i); 57 | void HypreSolverSetLevelData(HypreSolver **y, HypreSolver *x, int pfasst_level_index); 58 | int HypreSolverGetNumLevels(HypreSolver *hypre_solver); 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Examples/Hypre/src/hypre_solver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HYPRE_SOLVER_HPP 2 | #define HYPRE_SOLVER_HPP 3 | 4 | #include "hypre_struct.hpp" 5 | #include "smg.h" 6 | #include "pfmg.h" 7 | 8 | #define SOLVER_PFMG 0 9 | #define SOLVER_PFMG_CG 1 10 | #define SOLVER_JACOBI 2 11 | #define SOLVER_JACOBI_CG 3 12 | 13 | #define RELAX_JACOBI 0 14 | #define RELAX_WEIGHTED_JACOBI 1 15 | #define RELAX_RBGS 2 16 | #define RELAX_RBGS_NONSYMMETRIC 3 17 | 18 | using namespace std; 19 | 20 | class HypreSolver: public HypreStruct { 21 | protected: 22 | ; 23 | 24 | public: 25 | HYPRE_StructMatrix A_exp = NULL; 26 | HYPRE_StructMatrix A_imp = NULL; 27 | HYPRE_StructVector b = NULL; 28 | HYPRE_StructVector x = NULL; 29 | HYPRE_StructSolver solver_imp = NULL; 30 | HYPRE_StructSolver precond_imp = NULL; 31 | 32 | hypre_PFMGData *pfmg_data; 33 | HYPRE_StructSolver pfmg_level_data; 34 | HYPRE_StructMatrix *A_exp_lev; 35 | HYPRE_StructMatrix *A_imp_lev; 36 | hypre_StructMatrix **RT_lev; 37 | hypre_StructMatrix **P_lev; 38 | hypre_StructVector **x_lev; 39 | hypre_StructVector **b_lev; 40 | void **restrict_data_lev; 41 | void **interp_data_lev; 42 | int *nrows_lev; 43 | int **ilower_lev; 44 | int **iupper_lev; 45 | 46 | int num_levels; 47 | int n_pre, n_post; 48 | int smg_print_level, pcg_print_level; 49 | double tol; 50 | int max_iter; 51 | double jacobi_weight; 52 | int relax_type; 53 | int solver_type; 54 | int max_levels; 55 | int setup_done = 0; 56 | //int setup_spacial_solver_in_FComp_flag = 0; 57 | 58 | HypreSolver(MPI_Comm in_comm = MPI_COMM_WORLD, int dim = 2, int max_iter = 100, int max_levels = 0, int num_grid_points = 32); 59 | ~HypreSolver(void); 60 | 61 | int GetNumRowsLevel(int level_index); 62 | int GetNumLevels(void); 63 | void SetupStructSolver(HYPRE_StructMatrix *A, HYPRE_StructSolver *solver, HYPRE_StructSolver *precond); 64 | void CleanupStructSolver(HYPRE_StructSolver *solver, HYPRE_StructSolver *precond); 65 | void SetupStructPFMGSolver(HYPRE_StructSolver *pfmg_solver); 66 | void SetupSpacialCoarsen(void); 67 | void SetupMatrix(HYPRE_StructMatrix *A, 68 | int num_grid_points, 69 | int level_index, 70 | int spacial_coarsen_flag, 71 | int implicit_flag, 72 | double dtq); 73 | double* UpdateImplicitMatrix(HYPRE_StructMatrix *A, double dtq); 74 | HYPRE_StructVector SetupVector(void); 75 | void FEval(double *y, double t, int level_index, double **f); 76 | void FComp(double **y, double t, double dtq, double *rhs, int level_index, double **f); 77 | void Restrict(HYPRE_StructVector y_f, HYPRE_StructVector y_c, int f_level, int c_level); 78 | void Prolong(HYPRE_StructVector y_f, HYPRE_StructVector y_c, int f_level, int c_level); 79 | void Cleanup(void); 80 | }; 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /Examples/Hypre/src/hypre_struct.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HYPRE_STRUCT_HPP 2 | #define HYPRE_STRUCT_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "_hypre_struct_mv.h" 10 | #include "_hypre_struct_ls.h" 11 | #include "HYPRE_struct_mv.h" 12 | #include "HYPRE_struct_ls.h" 13 | #include 14 | 15 | using namespace std; 16 | 17 | class HypreStruct { 18 | protected: 19 | ; 20 | 21 | public: 22 | /* TODO: make protected */ 23 | HYPRE_StructGrid grid; 24 | HYPRE_StructStencil stencil; 25 | int offsets_1D[5][2] = {{0,0}, {-1,0}, {1,0}, {0,0}, {0,0}}; 26 | int offsets_2D[5][2] = {{0,0}, {-1,0}, {1,0}, {0,-1}, {0,1}}; 27 | 28 | double Lx, Ly; 29 | double h, h2; 30 | int n, N; 31 | int pi, pj; 32 | int **p_map; 33 | int nentries, bc_nentries; 34 | int nnz, nrows; 35 | int bc_nnz, bc_nrows; 36 | int *ilower, *iupper, bc_ilower[2], bc_iupper[2]; 37 | int *stencil_indices, bc_stencil_indices[1]; 38 | double *coords_x, *coords_y; 39 | double *exact_sol; 40 | MPI_Comm comm; 41 | int myid, num_procs; 42 | int dim; 43 | /* end TODO */ 44 | 45 | 46 | HypreStruct() { 47 | ; 48 | } 49 | ~HypreStruct() { 50 | ; 51 | } 52 | 53 | void SetComm(MPI_Comm target_comm); 54 | void SetDim(int in_dim); 55 | int GetNumRows(void); 56 | void SetInitCond(double val); 57 | void InitGrid(int num_grid_points, int in_nrows = -1, int *extents = NULL); 58 | double *HeatEquTrueSol(double t, int P, int Q, double init_cond); 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Examples/Hypre/src/hypre_vector.cpp: -------------------------------------------------------------------------------- 1 | #include "hypre_vector.hpp" 2 | 3 | HypreVector::HypreVector(int num_grid_points, double value, MPI_Comm in_comm, int in_dim, int in_nrows, int *extents) 4 | { 5 | SetComm(in_comm); 6 | SetDim(in_dim); 7 | InitGrid(num_grid_points, in_nrows, extents); 8 | //printf("%d %d %d %d %d\n", nrows, ilower[0], ilower[1], iupper[0], iupper[1]); 9 | 10 | double *values = (double *)calloc(nrows, sizeof(double)); 11 | 12 | HYPRE_StructVectorCreate(comm, grid, &v); 13 | HYPRE_StructVectorInitialize(v); 14 | 15 | for (int i = 0; i < nrows; i++){ 16 | values[i] = value; 17 | } 18 | HYPRE_StructVectorSetBoxValues(v, ilower, iupper, values); 19 | 20 | HYPRE_StructVectorAssemble(v); 21 | } 22 | 23 | HypreVector::~HypreVector(void) 24 | { 25 | HYPRE_StructVectorDestroy(v); 26 | } 27 | 28 | HYPRE_StructVector HypreVector::GetVector(void) 29 | { 30 | return v; 31 | } 32 | 33 | double *HypreVector::GetBoxValues(void) 34 | { 35 | double *values = (double *)calloc(nrows, sizeof(double)); 36 | HYPRE_StructVectorGetBoxValues(v, ilower, iupper, values); 37 | return values; 38 | } 39 | 40 | void HypreVector::SetBoxValues(double *values) 41 | { 42 | HYPRE_StructVectorSetBoxValues(v, ilower, iupper, values); 43 | } 44 | 45 | void HypreVector::SetVal(double val) 46 | { 47 | HYPRE_StructVectorSetConstantValues(v, val); 48 | } 49 | 50 | void HypreVector::SetSinInitCond(void) 51 | { 52 | double *values = (double *)calloc(nrows, sizeof(double)); 53 | double kfreq = 1.0; 54 | double omega_x = kfreq * M_PI / Lx; 55 | double omega_y = kfreq * M_PI / Ly; 56 | 57 | 58 | for (int k = 0; k < nrows; k++){ 59 | values[k] = sin(omega_x * coords_x[k]) * sin(omega_y * coords_y[k]); 60 | } 61 | 62 | HYPRE_StructVectorSetBoxValues(v, ilower, iupper, values); 63 | } 64 | 65 | void HypreVector::Axpy(double alpha, HypreVector *x) 66 | { 67 | hypre_StructAxpy(alpha, x->GetVector(), v); 68 | } 69 | 70 | double HypreVector::Norm(void) 71 | { 72 | return sqrt(hypre_StructInnerProd(v, v)); 73 | } 74 | 75 | void HypreVector::Print(void) 76 | { 77 | double *values = GetBoxValues(); 78 | if (myid == 0) printf("\n"); 79 | for (int p = 0; p < num_procs; p++){ 80 | if (p == myid){ 81 | for (int i = 0; i < nrows; i++){ 82 | //printf("%d %e %e %.16f\n", myid, coords_x[i], coords_y[i], values[i]); 83 | printf("%.16f\n", values[i]); 84 | } 85 | } 86 | MPI_Barrier(comm); 87 | } 88 | if (myid == 0) printf("\n"); 89 | // HYPRE_StructVectorPrint("hypre_vector_data.txt", v, 1); 90 | } 91 | -------------------------------------------------------------------------------- /Examples/Hypre/src/hypre_vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HYPRE_VECTOR_HPP 2 | #define HYPRE_VECTOR_HPP 3 | 4 | #include "hypre_struct.hpp" 5 | 6 | using namespace std; 7 | 8 | class HypreVector: public HypreStruct { 9 | protected: 10 | HYPRE_StructVector v; 11 | public: 12 | HypreVector(int num_grid_points = 10, double value = 0.0, MPI_Comm in_comm = MPI_COMM_WORLD, int in_dim = 2, int in_nrows = -1, int *extents = NULL); 13 | ~HypreVector(void); 14 | 15 | HYPRE_StructVector GetVector(void); 16 | double *GetBoxValues(void); 17 | void SetBoxValues(double *values); 18 | void SetVal(double val); 19 | void SetSinInitCond(void); 20 | double Norm(void); 21 | void Axpy(double alpha, HypreVector *x); 22 | void Print(void); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Examples/Hypre/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "hypre_solver.hpp" 2 | #include 3 | 4 | int main(void) 5 | { 6 | HypreSolver *hypre_solver; 7 | int level_index = 0; 8 | int num_grid_points = 3; 9 | 10 | MPI_Init(NULL, NULL); 11 | 12 | hypre_solver = new HypreSolver; 13 | 14 | hypre_solver->SetComm(MPI_COMM_WORLD); 15 | hypre_solver->SetupMatrix(level_index, num_grid_points); 16 | 17 | int n = hypre_solver->GetNumRows(); 18 | int piece = 2; 19 | double t = 1.0, dtq = .1; 20 | double *y = (double *)malloc(n * sizeof(double)); 21 | double *f = (double *)malloc(n * sizeof(double)); 22 | double *rhs = (double *)malloc(n * sizeof(double)); 23 | for (int i = 0; i < n; i++){ 24 | rhs[i] = 1.0; 25 | } 26 | hypre_solver->FComp(&y, t, dtq, rhs, level_index, &f, piece); 27 | 28 | hypre_solver->FEval(rhs, t, level_index, &f, piece); 29 | 30 | hypre_solver->Cleanup(); 31 | 32 | delete hypre_solver; 33 | 34 | free(y); 35 | free(f); 36 | free(rhs); 37 | MPI_Finalize(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Examples/Hypre/src/main_solver.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "hypre_solver.hpp" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | int num_procs, rank; 7 | MPI_Init(NULL, NULL); 8 | MPI_Comm_size(MPI_COMM_WORLD, &num_procs); 9 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); 10 | 11 | HypreSolver *hypre_solver; 12 | int level_index = 0; 13 | int n = 4; 14 | int num_grid_points; 15 | 16 | int arg_index = 0; 17 | 18 | while (arg_index < argc){ 19 | if (strcmp(argv[arg_index], "-n") == 0){ 20 | arg_index++; 21 | n = atoi(argv[arg_index]); 22 | } 23 | arg_index++; 24 | } 25 | 26 | num_grid_points = n / (int)sqrt((double)num_procs); 27 | 28 | hypre_solver = new HypreSolver(MPI_COMM_WORLD, 2, 50, 15); 29 | hypre_solver->SetupMatrix(num_grid_points, level_index, 0); 30 | 31 | int num_rows = hypre_solver->GetNumRows(); 32 | double t = 1.0, dtq = .1; 33 | double *y = (double *)malloc(num_rows * sizeof(double)); 34 | double *f = (double *)malloc(num_rows * sizeof(double)); 35 | double *rhs = (double *)malloc(num_rows * sizeof(double)); 36 | for (int i = 0; i < num_rows; i++){ 37 | rhs[i] = rank*num_rows + i; 38 | } 39 | //hypre_solver->FComp(&y, t, dtq, rhs, level_index, &f); 40 | 41 | hypre_solver->FEval(rhs, t, level_index, &f); 42 | MPI_Finalize(); 43 | return 0; 44 | 45 | hypre_solver->Cleanup(); 46 | 47 | //for (int i = 0; i < num_rows; i++) printf("%f\n", f[i]); 48 | 49 | delete hypre_solver; 50 | 51 | free(y); 52 | free(f); 53 | free(rhs); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Examples/Hypre/src/main_vector.cpp: -------------------------------------------------------------------------------- 1 | #include "hypre_vector.hpp" 2 | #include "hypre_encap.hpp" 3 | 4 | int main(void) 5 | { 6 | HypreVector *x, *y; 7 | int num_grid_points = 3; 8 | 9 | MPI_Init(NULL, NULL); 10 | 11 | double a = 2.8; 12 | x = new HypreVector(num_grid_points, 0.0, MPI_COMM_WORLD); 13 | y = new HypreVector(num_grid_points, 0.0, MPI_COMM_WORLD); 14 | 15 | x->SetVal(1.0); 16 | y->SetVal(2.0); 17 | y->Axpy(a, x); 18 | 19 | delete x; 20 | delete y; 21 | 22 | HypreVectorCreate(&x, num_grid_points, MPI_COMM_WORLD); 23 | HypreVectorCreate(&y, num_grid_points, MPI_COMM_WORLD); 24 | 25 | HypreVectorSetVal(x, 1.0); 26 | HypreVectorSetVal(y, 2.0); 27 | 28 | HypreVectorAxpy(y, a, x); 29 | 30 | printf("\n%f %f\n", HypreVectorNorm(x), HypreVectorNorm(y)); 31 | 32 | HypreVectorPrint(y); 33 | HypreVectorCopy(x, y); 34 | HypreVectorPrint(y); 35 | double *values = (double *)malloc(y->GetNumRows() * sizeof(double)); 36 | for (int i = 0; i < y->GetNumRows(); i++){ 37 | values[i] = a; 38 | } 39 | HypreVectorUnpack(y, values); 40 | HypreVectorPrint(y); 41 | 42 | HypreVectorSetVal(y, 3.0); 43 | double *z = HypreVectorPack(y); 44 | printf("\n"); 45 | for (int i = 0; i < y->GetNumRows(); i++){ 46 | printf("%f\n", z[i]); 47 | } 48 | 49 | HypreVectorDestroy(x); 50 | HypreVectorDestroy(y); 51 | 52 | MPI_Finalize(); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX1_Dahlquist_mgrit/.depend: -------------------------------------------------------------------------------- 1 | ./build/main.o : src/main.f90 ./build/probin.o ./build/level.o ./build/stepper.o ./build/hooks.o ./build/sweeper.o 2 | ./build/level.o : src/level.f90 3 | ./build/stepper.o : src/stepper.f90 ./build/probin.o 4 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o 5 | ./build/probin.o : src/probin.f90 6 | ./build/hooks.o : src/hooks.f90 ./build/probin.o 7 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX1_Dahlquist_mgrit/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Dahlyquist example. 3 | # 4 | 5 | LIBPFASST ?= ../.. 6 | BUILDDIR = build 7 | 8 | EXE = main.exe 9 | 10 | include $(LIBPFASST)/Makefile.defaults 11 | 12 | FSRC = src/hooks.f90 src/stepper.f90 src/main.f90 src/level.f90 src/probin.f90 src/sweeper.f90 13 | 14 | OBJ = $(subst src, build,$(FSRC:.f90=.o)) 15 | 16 | FFLAGS += -I$(LIBPFASST)/include 17 | 18 | all: $(EXE) 19 | 20 | VPATHS = src 21 | 22 | include $(LIBPFASST)/Makefile.rules 23 | 24 | # 25 | # dependencies 26 | # 27 | include .depend 28 | main.exe : $(LIBPFASST)/lib/libpfasst.a 29 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX1_Dahlquist_mgrit/probin.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level imex 3 | ! 4 | 5 | ! These are internal pfasst variables that must be set 6 | &PF_PARAMS 7 | nlevels = 3 ! must be set 8 | 9 | niters = 5 ! default is 5 10 | 11 | qtype = 1 12 | nnodes = 2 3 5 13 | 14 | nsweeps_pred= 1 1 1 15 | nsweeps= 1 1 1 16 | 17 | ! optional variables to control termination (defaults are 0.0) 18 | abs_res_tol = 1.d-12 19 | rel_res_tol = 1.d-12 20 | 21 | ! Variable to tell if Vcycling will be done. Here PFASST vcycles 22 | Vcycle=.TRUE. 23 | 24 | save_residuals=.true. 25 | save_delta_q0=.true. 26 | 27 | / 28 | 29 | ! Now define the local variables you need 30 | &PARAMS 31 | 32 | nsteps = 16 33 | Tfin = .1 34 | 35 | lam1=1.0 36 | lam2=-2.0 37 | 38 | mgrit_n_coarse = 16 39 | mgrit_refine_factor = 8 40 | 41 | use_mgrit = .true. 42 | 43 | imex_stat=2 44 | ark_stat=2 45 | / 46 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX1_Dahlquist_mgrit/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pfasst 7 | use pf_mod_ndarray 8 | implicit none 9 | contains 10 | 11 | !> Output the error and residual in the solution 12 | subroutine echo_error(pf, level_index) 13 | type(pf_pfasst_t), intent(inout) :: pf 14 | integer, intent(in) :: level_index 15 | 16 | real(pfdp) :: y_exact 17 | real(pfdp) :: maxerr 18 | real(pfdp) :: residual 19 | real(pfdp) :: t 20 | real(pfdp), pointer :: y_end(:) 21 | 22 | !> Get the solution at the end of this step 23 | y_end => get_array1d(cast_as_ndarray(pf%levels(level_index)%qend)) 24 | 25 | !> compute the exact solution 26 | t = pf%state%t0+pf%state%dt 27 | call exact(t, y_exact) 28 | !> compute error 29 | maxerr = abs(y_end(1) - y_exact) 30 | residual = pf%levels(level_index)%residual 31 | 32 | !print '("error: step: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," res: ",es18.10e4)', & 33 | ! pf%state%step+1, pf%state%iter,level_index, maxerr,residual 34 | print '("error: time: ", f8.4," step: ",i8.1," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," resid: ",es14.7," deltaq0: ",es14.7)', & 35 | t,pf%state%step+1, pf%rank, pf%state%iter,level_index,maxerr,pf%levels(level_index)%residual,pf%levels(level_index)%max_delta_q0 36 | call flush(6) 37 | 38 | call pf_set_error(pf,level_index,maxerr) 39 | 40 | end subroutine echo_error 41 | 42 | subroutine exact(t, yex) 43 | use probin, only: lam1,lam2 44 | real(pfdp), intent(in) :: t 45 | real(pfdp), intent(out) :: yex 46 | 47 | yex = exp((lam1 + lam2) * t) 48 | end subroutine exact 49 | 50 | end module hooks 51 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX1_Dahlquist_mgrit/src/level.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | ! 5 | !> Level specification for Dahlquist example. 6 | !> u_t = lam1*u + lam2*u 7 | module pf_my_level 8 | use pf_mod_ndarray 9 | 10 | !> extend the generic level type by defining transfer operators 11 | type, extends(pf_user_level_t) :: my_level_t 12 | contains 13 | procedure :: restrict 14 | procedure :: interpolate 15 | end type my_level_t 16 | 17 | contains 18 | 19 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 20 | !> These are the transfer functions that must be provided for the level 21 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 22 | !> Interpolate from coarse level to fine 23 | subroutine interpolate(this, f_lev, c_lev, f_vec, c_vec, t, flags) 24 | class(my_level_t), intent(inout) :: this 25 | class(pf_level_t), intent(inout) :: f_lev, c_lev ! fine and coarse levels 26 | class(pf_encap_t), intent(inout) :: f_vec, c_vec ! fine and coarse vectors 27 | real(pfdp), intent(in ) :: t 28 | integer, intent(in), optional :: flags 29 | 30 | 31 | !> Here we use the identity map 32 | call f_vec%copy(c_vec) 33 | 34 | end subroutine interpolate 35 | 36 | !> Restrict from fine level to coarse 37 | subroutine restrict(this, f_lev, c_lev, f_vec, c_vec, t, flags) 38 | class(my_level_t), intent(inout) :: this 39 | class(pf_level_t), intent(inout) :: f_lev, c_lev ! fine and coarse levels 40 | class(pf_encap_t), intent(inout) :: f_vec, c_vec ! fine and coarse vectors 41 | real(pfdp), intent(in ) :: t !< time of solution 42 | integer, intent(in), optional :: flags 43 | 44 | !> Here we use the identity map 45 | call c_vec%copy(f_vec) 46 | end subroutine restrict 47 | 48 | 49 | end module pf_my_level 50 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX1_Dahlquist_mgrit/src/stepper.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | ! 5 | !> Sweeper and RHS specification for Dahlquist example. 6 | !> u_t = lam1*u + lam2*u 7 | module pf_my_stepper 8 | use pf_mod_ndarray 9 | use pf_mod_rkstepper 10 | 11 | !> extend the imex stepper type with stuff we need to compute rhs 12 | type, extends(pf_ark_stepper_t) :: my_stepper_t 13 | 14 | contains 15 | 16 | procedure :: f_eval ! Computes the explicit rhs terms 17 | procedure :: f_comp ! Does implicit solves 18 | 19 | end type my_stepper_t 20 | 21 | contains 22 | 23 | 24 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 25 | ! These routines must be provided for the stepper 26 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 27 | ! Evaluate the explicit function at y, t. 28 | subroutine f_eval(this, y, t, level_index, f, piece) 29 | use probin, only: lam1, lam2 30 | class(my_stepper_t), intent(inout) :: this 31 | class(pf_encap_t), intent(in ) :: y 32 | class(pf_encap_t), intent(inout) :: f 33 | real(pfdp), intent(in ) :: t 34 | integer, intent(in ) :: level_index 35 | integer, intent(in ) :: piece 36 | 37 | real(pfdp), pointer :: yvec(:), fvec(:) 38 | 39 | !> Grab the arrays from the encapsulation 40 | yvec => get_array1d(y) 41 | fvec => get_array1d(f) 42 | 43 | ! Compute the function values 44 | select case (piece) 45 | case (1) ! Explicit piece 46 | fvec = lam1*yvec 47 | case (2) ! Implicit piece 48 | fvec = lam2*yvec 49 | case DEFAULT 50 | print *,'Bad case for piece in f_eval ', piece 51 | call exit(0) 52 | end select 53 | 54 | end subroutine f_eval 55 | 56 | !> Solve for y and return f2 also. 57 | subroutine f_comp(this, y, t, dtq, rhs, level_index, f,piece) 58 | use probin, only: lam1, lam2 59 | class(my_stepper_t), intent(inout) :: this 60 | class(pf_encap_t), intent(inout) :: y 61 | real(pfdp), intent(in ) :: t 62 | real(pfdp), intent(in ) :: dtq 63 | class(pf_encap_t), intent(in ) :: rhs 64 | integer, intent(in ) :: level_index 65 | class(pf_encap_t), intent(inout) :: f 66 | integer, intent(in ) :: piece 67 | 68 | real(pfdp), pointer :: yvec(:), rhsvec(:), fvec(:) 69 | 70 | if (piece == 2) then 71 | !> Grab the arrays from the encapsulation 72 | yvec => get_array1d(y) 73 | rhsvec => get_array1d(rhs) 74 | fvec => get_array1d(f) 75 | 76 | ! Do the solve 77 | yvec = rhsvec/(1.0_pfdp - dtq*lam2) 78 | 79 | ! The function is easy to derive (equivalent to lam2*yvec) 80 | fvec = (yvec - rhsvec) / dtq 81 | else 82 | print *,'Bad piece in f_comp ',piece 83 | call exit(0) 84 | end if 85 | end subroutine f_comp 86 | 87 | end module pf_my_stepper 88 | 89 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX1_Dahlquist_mgrit/src/sweeper.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | ! 5 | !> Sweeper and RHS specification for Dahlquist example. 6 | !> u_t = lam1*u + lam2*u 7 | module pf_my_sweeper 8 | use pf_mod_ndarray 9 | use pf_mod_imex_sweeper 10 | 11 | !> extend the imex sweeper type with stuff we need to compute rhs 12 | type, extends(pf_imex_sweeper_t) :: my_sweeper_t 13 | 14 | contains 15 | 16 | procedure :: f_eval ! Computes the explicit rhs terms 17 | procedure :: f_comp ! Does implicit solves 18 | 19 | end type my_sweeper_t 20 | 21 | contains 22 | 23 | 24 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 25 | ! These routines must be provided for the sweeper 26 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 27 | ! Evaluate the explicit function at y, t. 28 | subroutine f_eval(this, y, t, level_index, f, piece) 29 | use probin, only: lam1, lam2 30 | class(my_sweeper_t), intent(inout) :: this 31 | class(pf_encap_t), intent(in ) :: y 32 | class(pf_encap_t), intent(inout) :: f 33 | real(pfdp), intent(in ) :: t 34 | integer, intent(in ) :: level_index 35 | integer, intent(in ) :: piece 36 | 37 | real(pfdp), pointer :: yvec(:), fvec(:) 38 | 39 | !> Grab the arrays from the encapsulation 40 | yvec => get_array1d(y) 41 | fvec => get_array1d(f) 42 | 43 | ! Compute the function values 44 | select case (piece) 45 | case (1) ! Explicit piece 46 | fvec = lam1*yvec 47 | case (2) ! Implicit piece 48 | fvec = lam2*yvec 49 | case DEFAULT 50 | print *,'Bad case for piece in f_eval ', piece 51 | call exit(0) 52 | end select 53 | 54 | end subroutine f_eval 55 | 56 | !> Solve for y and return f2 also. 57 | subroutine f_comp(this, y, t, dtq, rhs, level_index, f,piece) 58 | use probin, only: lam1, lam2 59 | class(my_sweeper_t), intent(inout) :: this 60 | class(pf_encap_t), intent(inout) :: y 61 | real(pfdp), intent(in ) :: t 62 | real(pfdp), intent(in ) :: dtq 63 | class(pf_encap_t), intent(in ) :: rhs 64 | integer, intent(in ) :: level_index 65 | class(pf_encap_t), intent(inout) :: f 66 | integer, intent(in ) :: piece 67 | 68 | real(pfdp), pointer :: yvec(:), rhsvec(:), fvec(:) 69 | 70 | if (piece == 2) then 71 | !> Grab the arrays from the encapsulation 72 | yvec => get_array1d(y) 73 | rhsvec => get_array1d(rhs) 74 | fvec => get_array1d(f) 75 | 76 | ! Do the solve 77 | yvec = rhsvec/(1.0_pfdp - dtq*lam2) 78 | 79 | ! The function is easy to derive (equivalent to lam2*yvec) 80 | fvec = (yvec - rhsvec) / dtq 81 | else 82 | print *,'Bad piece in f_comp ',piece 83 | call exit(0) 84 | end if 85 | end subroutine f_comp 86 | 87 | end module pf_my_sweeper 88 | 89 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX3_adv_diff_mgrit/.depend: -------------------------------------------------------------------------------- 1 | ./build/main.o : src/main.f90 ./build/probin.o ./build/hooks.o ./build/level.o ./build/sweeper.o 2 | ./build/level.o : src/level.f90 ./build/sweeper.o 3 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o 4 | ./build/hooks.o : src/hooks.f90 ./build/sweeper.o 5 | ./build/probin.o : src/probin.f90 6 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX3_adv_diff_mgrit/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for advection diffusion example 3 | # 4 | 5 | LIBPFASST ?= ../.. 6 | BUILDDIR = build 7 | 8 | EXE = main.exe 9 | include $(LIBPFASST)/Makefile.defaults 10 | 11 | FSRC = src/probin.f90 src/stepper.f90 src/main.f90 src/level.f90 src/hooks.f90 src/sweeper.f90 12 | 13 | OBJ = $(subst src, build,$(FSRC:.f90=.o)) 14 | 15 | FFLAGS += -I$(LIBPFASST)/include 16 | 17 | all: $(EXE) 18 | 19 | VPATHS = src 20 | 21 | 22 | include $(LIBPFASST)/Makefile.rules 23 | 24 | # 25 | # dependencies 26 | # 27 | include .depend 28 | main.exe : $(LIBPFASST)/lib/libpfasst.a 29 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX3_adv_diff_mgrit/probin.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a single level example 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 4 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | nnodes = 2 3 5 16 | 17 | use_proper_nodes=.false. 18 | nsweeps_pred = 1 1 1 19 | nsweeps = 1 1 1 20 | 21 | ! optional variables to control termination (defaults are 0.0) 22 | abs_res_tol = 1.d-9 23 | rel_res_tol = 1.d-12 24 | 25 | Vcycle=.TRUE. 26 | 27 | save_residuals=.true. 28 | save_delta_q0=.true. 29 | 30 | pipeline_pred = .false. 31 | PFASST_pred = .true. 32 | 33 | 34 | / 35 | 36 | ! Now define the local variables you need 37 | &PARAMS 38 | 39 | nx = 128 256 512 1024 40 | nu = 1.0 41 | v=0.0 42 | Lx=1 43 | kfreq = 4 44 | 45 | Tfin = .1 46 | nsteps = 6 47 | 48 | mgrit_n_coarse = 1 49 | mgrit_refine_factor = 2 50 | 51 | use_mgrit = .true. 52 | 53 | imex_stat=2 54 | ark_stat=2 55 | 56 | rk_order=2 57 | 58 | / 59 | -------------------------------------------------------------------------------- /Examples/MGRIT/EX3_adv_diff_mgrit/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pfasst 7 | use pf_mod_ndarray 8 | implicit none 9 | contains 10 | 11 | !> Output the error and residual in the solution 12 | subroutine echo_error(pf, level_index) 13 | use my_sweeper, only: exact 14 | type(pf_pfasst_t), intent(inout) :: pf 15 | integer, intent(in) :: level_index 16 | 17 | real(pfdp) :: yexact(pf%levels(level_index)%lev_shape(1)) 18 | real(pfdp), pointer :: y_end(:) 19 | real(pfdp) :: maxerr 20 | real(pfdp) :: residual 21 | real(pfdp) :: t 22 | 23 | !> compute the error at last end point 24 | y_end => get_array1d(pf%levels(level_index)%qend) 25 | call exact(pf%state%t0+pf%state%dt, yexact) 26 | maxerr = maxval(abs(y_end-yexact)) 27 | residual=pf%levels(level_index)%residual 28 | t = pf%state%t0+pf%state%dt 29 | 30 | !print '("error: step: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," res: ",es14.7)', & 31 | ! pf%state%step+1, pf%state%iter,level_index, maxerr,residual 32 | 33 | if (level_index .eq. pf%nlevels) then 34 | print '("error: time: ", f8.4," step: ",i8.1," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," resid: ",es14.7," deltaq0: ",es14.7)', & 35 | t,pf%state%step+1, pf%rank, pf%state%iter,level_index,maxerr,pf%levels(level_index)%residual,pf%levels(level_index)%max_delta_q0 36 | end if 37 | 38 | call pf_set_error(pf,level_index,maxerr) 39 | 40 | end subroutine echo_error 41 | end module hooks 42 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Exponential RK examples 3 | # 4 | 5 | LIBPFASST ?= ../../../../LibPFASST 6 | LIBNPY ?= $(LIBPFASST)/libnpy 7 | DO_EXP=TRUE 8 | DO_RK=TRUE 9 | 10 | DIM=1 11 | EXE = main.$(DIM)d.exe 12 | all: $(EXE) 13 | BUILDDIR = build 14 | 15 | include $(LIBPFASST)/Makefile.defaults 16 | FSRC = src/stepper_$(DIM)d.f90 17 | 18 | include ../Make.package 19 | OBJ = $(subst src, build,$(FSRC:.f90=.o) $(CSRC:.c=.o)) 20 | 21 | 22 | all: $(EXE) 23 | 24 | VPATHS = src:../src 25 | 26 | 27 | include $(LIBPFASST)/Makefile.rules 28 | 29 | 30 | # dependencies 31 | # 32 | 33 | main.exe : $(LIBPFASST)/lib/libpfasst.a 34 | build/stepper_$(DIM)d.o : src/stepper_$(DIM)d.f90 build/phi_mod.o build/probin.o build/utils_$(DIM)d.o src/stepper_include.f90 35 | 36 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/ad.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for scalar advection diffusion in DIM=1,2,3 3 | ! u_t + V.grad(u) = nu lap(u) 4 | ! 5 | &PARAMS 6 | 7 | Tfin = 6.28318530717958647692528676655900576839433879875021 8 | nx = 128 128 9 | nu = 0.01 10 | a = 1.0 11 | b = 1.0 12 | c = 1.0 13 | 14 | 15 | nsteps = 64 ! Number of "parareal" steps 16 | nsteps_rk = 1 16 ! Number of steps in coarse and fine propagators 17 | rk_order = 4 4 ! Order of coarse and fine propagators 18 | 19 | eq_type = 1 ! 1 specifies advection-diffusion 20 | ic_type = 0 ! 0 is Guassian 1 is sin 21 | 22 | ! controls splitting (1 treats u_xx implicit and u_x explicitly, 2 treats u_xx and u_x exponentially) 23 | splitting = 1 24 | 25 | pfasst_nml="parareal.nml" ! Use the common input file for pfasst parameters 26 | / 27 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/burg.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a Burgers Eq. in DIM=1,2,3 3 | ! 4 | &PARAMS 5 | 6 | Tfin = 0.2 7 | nx = 128 128 8 | nu = 0.0 9 | 10 | nsteps = 128 11 | nsteps_rk = 1 10 12 | rk_order = 4 4 13 | 14 | eq_type = 2 15 | 16 | pfasst_nml="parareal.nml" ! Use the common input file for pfasst parameters 17 | / 18 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/dahlquist.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D Dahlquist Eq y'=lam1*y + lam2*y 3 | ! 4 | &PARAMS 5 | 6 | Tfin = 1.0 7 | nx = 1 1 8 | lam1 = 1600.0 ! the exponential part 9 | lam2 = 1.0 10 | 11 | 12 | nsteps = 32 13 | nsteps_rk = 1 32 14 | rk_order = 4 4 15 | 16 | eq_type = 0 17 | 18 | splitting=1 19 | 20 | pfasst_nml="parareal.nml" ! Use the common input file for pfasst parameters 21 | / 22 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/kdv.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for KdV equation 3 | ! 4 | &PARAMS 5 | 6 | Tfin = 1.0 7 | nx = 384 384 8 | beta=8.0 9 | 10 | nsteps=32 11 | nsteps_rk = 32 64 12 | rk_order = 4 4 13 | 14 | eq_type = 4 15 | ic_type = 1 16 | 17 | pfasst_nml="parareal.nml" ! Use the common input file for pfasst parameters 18 | / 19 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/kdv_serial.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 1 8 | ! These are internal pfasst variables that can be reset 9 | niters = 50 ! default is 5 10 | 11 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 12 | qtype = 1 13 | 14 | ! optional variables to control termination (defaults are 0.0) 15 | abs_res_tol = 1.d-11 16 | rel_res_tol = 1.d-11 17 | 18 | nnodes = 1 19 | 20 | save_residuals=.true. 21 | use_rk_stepper=.true. 22 | use_sdc_sweeper=.false. 23 | outdir="kdv" 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 384 31 | beta=8.0 32 | nsteps=1 33 | nsteps_rk = 1 34 | rk_order = 4 35 | 36 | Tfin = 1.0 37 | eq_type = 4 38 | ic_type = 1 39 | 40 | 41 | / 42 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/ks.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a K-S 3 | ! 4 | &PARAMS 5 | 6 | Tfin = 40.0 7 | nx = 512 512 8 | 9 | nsteps = 32 10 | nsteps_rk = 16 16 11 | rk_order = 4 4 12 | 13 | Lx=1.00530964914873d2 14 | eq_type = 5 15 | ic_type = 1 16 | 17 | pfasst_nml="parareal.nml" ! Use the common input file for pfasst parameters 18 | 19 | / 20 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/nls.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for the nonlinear Schroedinger eq 3 | ! 4 | 5 | &PARAMS 6 | 7 | Tfin = 10.0 8 | nx = 1024 1024 9 | 10 | nsteps = 16000 11 | nsteps_rk = 1 8 12 | rk_order = 3 4 13 | 14 | eq_type = 3 15 | ic_type = 1 16 | 17 | 18 | pfasst_nml="parareal.nml" ! Use the common input file for pfasst parameters 19 | / 20 | -------------------------------------------------------------------------------- /Examples/Parareal/ERK/parareal.nml: -------------------------------------------------------------------------------- 1 | &PF_PARAMS 2 | ! These are internal pfasst variables that must be set 3 | nlevels = 2 4 | 5 | ! These are internal pfasst variables that can be reset 6 | niters = 100 ! default is 5 - 0 leaves predictor on coarse level 7 | 8 | ! optional variables to control termination (defaults are 0.0) 9 | abs_res_tol = 1.d-10 10 | rel_res_tol = 1.d-10 11 | 12 | nnodes = 2 2 13 | 14 | ! Choices to run parareal instead of PFASST 15 | use_rk_stepper=.true. 16 | use_sdc_sweeper=.false. 17 | 18 | ! These flags control the output. For fastest timings, turn them off 19 | save_residuals=.true. 20 | save_delta_q0=.true. 21 | save_errors=.true. 22 | 23 | ! Flag for timings. For fastest timing of only full algorithm, set to 1 24 | save_timings = 2 25 | 26 | ! Flag for saving solutions, needed for problems with no exact solution 27 | save_solutions = 1 28 | 29 | ! Directory name for output 30 | outdir="parareal" 31 | / 32 | 33 | -------------------------------------------------------------------------------- /Examples/Parareal/Make.package: -------------------------------------------------------------------------------- 1 | LIBNPY ?= $(LIBPFASST)/libnpy 2 | # Include the standard 3 | FSRC += src/probin.f90 src/utils_$(DIM)d.f90 src/dim_$(DIM)d.f90 src/main_rk.f90 src/hooks_rk.f90 src/level_rk.f90 4 | 5 | ifeq ($(DO_EXP),TRUE) 6 | FSRC += src/phi_mod.f90 7 | endif 8 | 9 | FFLAGS += -I$(LIBPFASST)/include -I$(LIBNPY)/include 10 | LDFLAGS += -L$(LIBNPY)/libnpy_fortran_mod -lnpy 11 | 12 | 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 13 | build/probin.o :../src/probin.f90 build/dim_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 14 | build/utils_$(DIM)d.o : ../src/utils_$(DIM)d.f90 build/probin.o 15 | build/dim_$(DIM)d.o : ../src/dim_$(DIM)d.f90 16 | build/level_rk.o : ../src/level_rk.f90 build/stepper_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 17 | build/hooks_rk.o : ../src/hooks_rk.f90 build/stepper_$(DIM)d.o build/utils_$(DIM)d.o 18 | build/phi_mod.o : ../src/phi_mod.f90 19 | 20 | -------------------------------------------------------------------------------- /Examples/Parareal/src/dim_1d.f90: -------------------------------------------------------------------------------- 1 | !> Compiler dependent module to set spatial dimension 2 | module pf_mod_dim 3 | 4 | implicit none 5 | contains 6 | function echo_dim() result(N) 7 | integer :: N 8 | N=1 9 | end function echo_dim 10 | 11 | end module pf_mod_dim 12 | -------------------------------------------------------------------------------- /Examples/Parareal/src/dim_2d.f90: -------------------------------------------------------------------------------- 1 | !> Compiler dependent module to set spatial dimension 2 | module pf_mod_dim 3 | 4 | implicit none 5 | contains 6 | function echo_dim() result(N) 7 | integer :: N 8 | N=2 9 | end function echo_dim 10 | 11 | end module pf_mod_dim 12 | -------------------------------------------------------------------------------- /Examples/Parareal/src/dim_3d.f90: -------------------------------------------------------------------------------- 1 | !> Compiler dependent module to set spatial dimension 2 | module pf_mod_dim 3 | 4 | implicit none 5 | contains 6 | function echo_dim() result(N) 7 | integer :: N 8 | N=3 9 | end function echo_dim 10 | 11 | end module pf_mod_dim 12 | -------------------------------------------------------------------------------- /Examples/Parareal/src/hooks_rk.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pfasst 7 | use pf_mod_zndarray 8 | use pf_mod_zutils 9 | implicit none 10 | contains 11 | 12 | !> Output the error and residual in the solution 13 | subroutine echo_error(pf, level_index) 14 | use probin, only: grid_size 15 | use pf_my_stepper, only: my_stepper_t, as_my_stepper 16 | type(pf_pfasst_t), intent(inout) :: pf 17 | integer, intent(in) :: level_index 18 | 19 | class(my_stepper_t), pointer :: stepper 20 | real(pfdp) :: maxerr,t 21 | type(pf_zndarray_t) :: y_ex !< the initial condition 22 | 23 | call zndarray_build(y_ex, pf%levels(level_index)%lev_shape) 24 | stepper => as_my_stepper(pf%levels(level_index)%ulevel%stepper) 25 | 26 | 27 | !> compute the exact solution 28 | t=pf%state%t0+pf%state%dt 29 | call exact(stepper%fft_tool,t, y_ex) 30 | 31 | !> compute error 32 | call y_ex%axpy(-1.0d0,pf%levels(level_index)%qend) 33 | 34 | !> compute error 35 | maxerr = y_ex%norm() 36 | print '("error: time: ", f8.4," step: ",i8.1," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," resid: ",es14.7," deltaq0: ",es14.7)', & 37 | t,pf%state%step+1, pf%rank, pf%state%iter,level_index,maxerr,pf%levels(level_index)%residual,pf%levels(level_index)%max_delta_q0 38 | 39 | call flush(6) 40 | 41 | call zndarray_destroy(y_ex) 42 | 43 | end subroutine echo_error 44 | 45 | subroutine set_error(pf, level_index) 46 | use probin, only: grid_size 47 | use pf_my_stepper, only: my_stepper_t, as_my_stepper 48 | type(pf_pfasst_t), intent(inout) :: pf 49 | integer, intent(in) :: level_index 50 | 51 | class(my_stepper_t), pointer :: stepper 52 | real(pfdp) :: maxerr,t 53 | type(pf_zndarray_t) :: y_ex !< the initial condition 54 | 55 | call zndarray_build(y_ex, pf%levels(level_index)%lev_shape) 56 | stepper => as_my_stepper(pf%levels(level_index)%ulevel%stepper) 57 | 58 | !> compute the exact solution 59 | t=pf%state%t0+pf%state%dt 60 | call exact(stepper%fft_tool,t, y_ex) 61 | 62 | !> compute error 63 | call y_ex%axpy(-1.0d0,pf%levels(level_index)%qend) 64 | 65 | !> compute error 66 | maxerr = y_ex%norm() 67 | 68 | call zndarray_destroy(y_ex) 69 | 70 | call pf_set_error(pf,level_index,maxerr) 71 | end subroutine set_error 72 | end module hooks 73 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | 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. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory, U.S. Dept. of Energy, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | 14 | You are under no obligation whatsoever to provide any bug fixes, patches, or upgrades to the features, functionality or performance of the source code ("Enhancements") to anyone; however, if you choose to make your Enhancements available either publicly, or directly to Lawrence Berkeley National Laboratory, without imposing a separate written license agreement for such Enhancements, then you hereby grant the following license: a non-exclusive, royalty-free perpetual license to install, use, modify, prepare derivative works, incorporate into other computer software, distribute, and sublicense such enhancements or derivative works thereof, in binary and source code form. 15 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for builds the static LibPFASST library libpfasst.a 3 | # 4 | 5 | LIBPFASST ?= $(PWD) 6 | BUILDDIR = build 7 | include $(LIBPFASST)/Makefile.defaults 8 | 9 | # 10 | # libpfasst 11 | # 12 | build/libpfasst.a: $(OBJ) 13 | @mkdir -p lib 14 | $(AR) lib/libpfasst.a $(OBJ) 15 | 16 | include $(LIBPFASST)/Makefile.rules 17 | include $(LIBPFASST)/Makefile.external 18 | 19 | .PHONY: clean depend 20 | 21 | -------------------------------------------------------------------------------- /Makefile.defaults: -------------------------------------------------------------------------------- 1 | # 2 | # Default build settings for libpfasst. 3 | # 4 | 5 | 6 | # Set some variables to determine what is included in the build 7 | # The "?=" checks to see if they have been defined so that applications 8 | # that need the FFT can specify it automatically in the local Makefile 9 | DEBUG ?= FALSE 10 | MKVERBOSE ?= FALSE 11 | USE_PETSC ?= FALSE 12 | USE_HYPRE ?= FALSE 13 | USE_SUNDIALS ?= FALSE 14 | USE_AMREX ?= FALSE 15 | USE_FFT ?= FALSE 16 | 17 | 18 | # File for compiler options 19 | include $(LIBPFASST)/Makefile.local 20 | 21 | 22 | VPATHS = $(LIBPFASST)/src 23 | LDFLAGS += -L$(LIBPFASST)/lib -lpfasst 24 | 25 | # Source files 26 | FSRC = src/pfasst.f90 \ 27 | src/pf_comm.f90 \ 28 | src/pf_dtype.f90 \ 29 | src/pf_fft.f90 \ 30 | src/pf_hooks.f90 \ 31 | src/pf_interpolate.f90 \ 32 | src/pf_mgrit.f90 \ 33 | src/pf_parallel.f90 \ 34 | src/pf_parareal.f90 \ 35 | src/pf_parallel_oc.f90 \ 36 | src/pf_pfasst.f90 \ 37 | src/pf_quadrature.f90 \ 38 | src/pf_restrict.f90 \ 39 | src/pf_results.f90 \ 40 | src/pf_rkstepper.f90 \ 41 | src/pf_erkstepper.f90 \ 42 | src/pf_solutions.f90 \ 43 | src/pf_stop.f90 \ 44 | src/pf_timer.f90 \ 45 | src/pf_utils.f90 \ 46 | src/pf_ham_sys_encap.f90 \ 47 | src/pf_ndarray_encap.f90 \ 48 | src/pf_ndarray_oc_encap.f90 \ 49 | src/pf_ndsysarray_encap.f90 \ 50 | src/pf_zndsysarray_encap.f90 \ 51 | src/pf_zndarray_encap.f90 \ 52 | src/pf_exp_sweeper.f90 \ 53 | src/pf_fexp_sweeper.f90 \ 54 | src/pf_imex_sweeper.f90 \ 55 | src/pf_imexR_sweeper.f90 \ 56 | src/pf_imexQ_oc_sweeper.f90 \ 57 | src/pf_imk_sweeper.f90 \ 58 | src/pf_magpicard_sweeper.f90 \ 59 | src/pf_misdcQ_sweeper.f90 \ 60 | src/pf_misdcQ_oc_sweeper.f90 \ 61 | src/pf_verlet_sweeper.f90 \ 62 | src/pf_fexp_sweeper.f90 \ 63 | # src/pf_amisdc.f90 pf_amisdcQ.f90 \ 64 | 65 | # AMReX options 66 | ifeq ($(USE_AMREX),TRUE) 67 | include $(LIBPFASST)/Makefile.AMReX 68 | endif 69 | 70 | # FFT options 71 | ifeq ($(USE_FFT),TRUE) 72 | include $(LIBPFASST)/Makefile.FFT 73 | endif 74 | 75 | # PETSc options 76 | ifeq ($(USE_PETSC),TRUE) 77 | include $(LIBPFASST)/Makefile.PETSc 78 | endif 79 | 80 | # SUNDIALS options 81 | ifeq ($(USE_SUNDIALS),TRUE) 82 | include $(LIBPFASST)/Makefile.SUNDIALS 83 | endif 84 | 85 | ifeq ($(USE_HYPRE),TRUE) 86 | include $(LIBPFASST)/Makefile.hypre 87 | endif 88 | 89 | ifdef NOMPI 90 | FFLAGS += -DNOMPI 91 | else 92 | FSRC += src/pf_mpi.f90 93 | endif 94 | 95 | ifdef OMP 96 | FFLAGS += -fopenmp 97 | endif 98 | 99 | OBJ = $(subst src, build,$(FSRC:.f90=.o) $(CSRC:.c=.o)) 100 | ifeq ($(USE_FFT),TRUE) 101 | OBJ += $(subst src,build,$(F77SRC:.f=.o)) 102 | endif 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Makefile.examples/Makefile.AMReX: -------------------------------------------------------------------------------- 1 | # Example Makefile to use AMReX with LibPFASST 2 | # You can download and get install instructions at 3 | # https://github.com/AMReX-Codes/amrex 4 | # 5 | 6 | AMREX_HOME=$(LIBPFASST)/../amrex 7 | AMREX_LIBRARY_HOME= $(AMREX_HOME)/tmp_install_dir 8 | 9 | FSRC += src/pf_amrex_encap.f90 10 | 11 | LIBDIR := $(AMREX_LIBRARY_HOME)/lib 12 | INCDIR := $(AMREX_LIBRARY_HOME)/include 13 | 14 | COMPILE_CPP_FLAGS ?= $(shell awk '/Cflags:/ {$$1=$$2=""; print $$0}' $(LIBDIR)/pkgconfig/amrex.pc) 15 | COMPILE_LIB_FLAGS ?= $(shell awk '/Libs:/ {$$1=$$2=""; print $$0}' $(LIBDIR)/pkgconfig/amrex.pc) 16 | 17 | FFLAGS += -I$(INCDIR) $(COMPILE_CPP_FLAGS) 18 | LDFLAGS += -L$(LIBDIR) $(COMPILE_LIB_FLAGS) -lamrex -lpthread -lstdc++ 19 | -------------------------------------------------------------------------------- /Makefile.examples/Makefile.FFT: -------------------------------------------------------------------------------- 1 | # LibPFASST has a convenient set of FFT wrappers 2 | # To use FFTW, it must be installed. This can be done with 3 | # "make fftw3" from the LibPFASST base directory and it will 4 | # installed in the directory fftw3/ Or one can point FFTW below 5 | # to the proper local installation 6 | # 7 | # The second option is to use the F77 implementation in src/pf_fftpack.f90 8 | # This might cause compiler errors and/or warnings with some compilers 9 | # due to it's "classic" style 10 | 11 | # Add the interface to the FFT 12 | FSRC += src/pf_fft.f90 13 | 14 | # Decide if FFTW will be used (can be over ridden by defining beforehand) 15 | USE_FFTW?=FALSE 16 | 17 | ifeq ($(USE_FFTW),FALSE) 18 | FSRC += src/pf_fftpack.f90 19 | F77SRC = src/dfftpack.o 20 | else 21 | FSRC += src/pf_fftw.f90 22 | FFTWLIB=$(LIBPFASST)/fftw3 23 | FFLAGS += -I$(FFTWLIB)/include 24 | LDFLAGS += -L$(FFTWLIB)/lib -lfftw3 25 | endif 26 | -------------------------------------------------------------------------------- /Makefile.examples/Makefile.PETSc: -------------------------------------------------------------------------------- 1 | # Before using PETSc, one must set the environment variables 2 | # PETSC_DIR and PETSC_ARCH 3 | # These are displayed at the end of the petsc configuration step 4 | 5 | # Include the petscVec encapsulation 6 | FSRC+= src/pf_petscVec_encap.f90 7 | 8 | FFLAGS += -I$(PETSC_DIR)/include -I$(PETSC_DIR)/$(PETSC_ARCH)/include -I$(PETSC_DIR)/include/petsc/finclude 9 | LDFLAGS += -L$(PETSC_DIR)/$(PETSC_ARCH)/lib -lpetsc 10 | 11 | -------------------------------------------------------------------------------- /Makefile.examples/Makefile.hypre: -------------------------------------------------------------------------------- 1 | # Flags for linking to hypre 2 | # In this example hypre is installed in the same directory as LibPFASST 3 | 4 | HYPRE_DIR = $(LIBPFASST)/../hypre/src 5 | 6 | # The location of include and libHYPRE.a can vary 7 | FFLAGS += -I$(HYPRE_DIR)/hypre/include 8 | LDFLAGS += -lstdc++ $(HYPRE_DIR)/hypre/lib/libHYPRE.a 9 | -------------------------------------------------------------------------------- /Makefile.examples/Makefile.local: -------------------------------------------------------------------------------- 1 | # Flags for compilers and linkers on local machine 2 | # This example is from GNU compilers on Linux 3 | FC = mpifort 4 | CC = mpicc 5 | LD = $(FC) 6 | AR=ar rcs 7 | 8 | FFLAGS = -Ibuild -Jinclude -cpp -ffree-line-length-none 9 | # Use this flag on newer compilers with stricter bounds checking 10 | #FFLAGS = -fallow-argument-mismatch 11 | 12 | ifeq ($(DEBUG),TRUE) 13 | FFLAGS += -fcheck=all -fbacktrace -g -ffpe-trap=invalid,zero,overflow -fbounds-check -fimplicit-none -ffree-line-length-none 14 | else 15 | FFLAGS += -O3 16 | endif -------------------------------------------------------------------------------- /Makefile.examples/Makefile.local.gnu: -------------------------------------------------------------------------------- 1 | # Flags for compilers and linkers on local machine 2 | # This example is from GNU compilers on Linux 3 | FC = mpifort 4 | CC = mpicc 5 | LD = $(FC) 6 | AR=ar rcs 7 | 8 | FFLAGS = -Ibuild -Jinclude -cpp -ffree-line-length-none 9 | # Use this flag on newer compilers with stricter bounds checking 10 | #FFLAGS = -fallow-argument-mismatch 11 | 12 | ifeq ($(DEBUG),TRUE) 13 | FFLAGS += -fcheck=all -fbacktrace -g -ffpe-trap=invalid,zero,overflow -fbounds-check -fimplicit-none -ffree-line-length-none 14 | else 15 | FFLAGS += -O3 16 | endif -------------------------------------------------------------------------------- /Makefile.external: -------------------------------------------------------------------------------- 1 | # 2 | # fftw3 3 | # 4 | FFTW3 = fftw-3.3.8 5 | FFTW3_CONFIG = --enable-openmp --enable-threads --enable-sse2 # --enable-shared --enable-long-double 6 | 7 | fftw3: $(FFTW3).tar.gz 8 | rm -rf $(FFTW3) 9 | tar xzf $(FFTW3).tar.gz 10 | cd $(FFTW3) && ./configure --prefix=$(PWD)/fftw3 $(FFTW3_CONFIG) 11 | cd $(FFTW3) && make install 12 | 13 | $(FFTW3).tar.gz: 14 | wget http://fftw.org/$(FFTW3).tar.gz 15 | 16 | 17 | # 18 | # Libnpy, a library for writing numpy arrays from f90 19 | # 20 | libnpy: 21 | wget https://github.com/libpfasst/libnpy/archive/refs/heads/master.zip 22 | unzip master.zip 23 | \rm -rf libnpy 24 | mv libnpy-master libnpy 25 | cd libnpy && cp archs/arch.inc.gcc arch.inc && make INSTALL_FLAVOR=fortran_mod 26 | 27 | #libnpy: 28 | # git clone https://github.com/kovalp/libnpy.git 29 | # cd libnpy && cp archs/arch.inc.gcc arch.inc && make INSTALL_FLAVOR=fortran_mod 30 | 31 | 32 | # Quick and dirty way to install hypre 33 | hypre: 34 | git clone https://github.com/hypre-space/hypre.git 35 | cd hypre/src && make distclean && ./configure --disable-fortran && make -j 36 | 37 | 38 | -------------------------------------------------------------------------------- /Makefile.local: -------------------------------------------------------------------------------- 1 | # Flags for compilers and linkers on local machine 2 | # This example is from GNU compilers on Linux 3 | FC = mpifort 4 | CC = mpicc 5 | LD = $(FC) 6 | AR=ar rcs 7 | 8 | FFLAGS = -Ibuild -Jinclude -cpp -ffree-line-length-none 9 | # Use this flag on newer compilers with stricter bounds checking 10 | #FFLAGS = -fallow-argument-mismatch 11 | 12 | ifeq ($(DEBUG),TRUE) 13 | FFLAGS += -fcheck=all -fbacktrace -g -ffpe-trap=invalid,zero,overflow -fbounds-check -fimplicit-none -ffree-line-length-none 14 | else 15 | FFLAGS += -O3 16 | endif -------------------------------------------------------------------------------- /Makefile.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile rules for compiling examples. 3 | # 4 | 5 | vpath %.f90 $(VPATHS) 6 | vpath %.c $(VPATHS) 7 | vpath %.f $(VPATHS) 8 | 9 | $(EXE): $(OBJ) 10 | ifeq ($(MKVERBOSE),TRUE) 11 | $(FC) $(FFLAGS) $(FFLAGS_EXTRA) $^ $(OUTPUT_OPTION) $(LDFLAGS) 12 | else 13 | @echo "Linking..." 14 | @$(FC) $(FFLAGS) $(FFLAGS_EXTRA) $^ $(OUTPUT_OPTION) $(LDFLAGS) 15 | endif 16 | 17 | build/%.o build/%.mod: %.f90 18 | @mkdir -p build 19 | @mkdir -p include 20 | 21 | ifeq ($(MKVERBOSE),TRUE) 22 | $(FC) $(FFLAGS) $(FFLAGS_EXTRA) -c $< $(OUTPUT_OPTION) 23 | else 24 | @echo "Building $<..." 25 | @$(FC) $(FFLAGS) $(FFLAGS_EXTRA) -c $< $(OUTPUT_OPTION) 26 | endif 27 | 28 | build/%.o: %.c 29 | @mkdir -p build 30 | @mkdir -p include 31 | 32 | ifeq ($(MKVERBOSE),TRUE) 33 | $(CC) $(CFLAGS) -c $< $(OUTPUT_OPTION) 34 | else 35 | @echo "Building $<..." 36 | @$(CC) $(CFLAGS) -c $< $(OUTPUT_OPTION) 37 | endif 38 | 39 | build/%.o: %.f 40 | @mkdir -p build 41 | @mkdir -p include 42 | ifeq ($(MKVERBOSE),TRUE) 43 | $(FC) $(FFLAGS_EXTRA) -c -w $< $(OUTPUT_OPTION) 44 | else 45 | @echo "Building $<..." 46 | @$(FC) $(FFLAGS_EXTRA) -c -w $< $(OUTPUT_OPTION) 47 | endif 48 | 49 | .PHONY: clean depend 50 | 51 | clean: 52 | \rm -f *.exe 53 | \rm -rf build 54 | \rm -f fort.* *.slog2 *.edf *.trc gmon.out 55 | \rm -rf include 56 | \rm -f lib/*.a 57 | 58 | 59 | # We can use this to build a new dependency file. If makedepf90 is installed type "make depend" 60 | depend $(PWD)/.depend: 61 | makedepf90 -b ./build $(FSRC) > .depend 62 | 63 | 64 | include $(LIBPFASST)/.depend 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # LibPFASST 3 | 4 | LibPFASST is a lightweight implementation of the Parallel Full 5 | Approximation Scheme in Space and Time (PFASST) algorithm. It is 6 | written in Fortran (mostly F90, with some F03), but can be interfaced 7 | with C and C++ fairly easily. 8 | 9 | 10 | 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. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 13 | 14 | (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 15 | 16 | (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 17 | 18 | (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory, U.S. Dept. of Energy, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | 22 | You are under no obligation whatsoever to provide any bug fixes, patches, or upgrades to the features, functionality or performance of the source code ("Enhancements") to anyone; however, if you choose to make your Enhancements available either publicly, or directly to Lawrence Berkeley National Laboratory, without imposing a separate written license agreement for such Enhancements, then you hereby grant the following license: a non-exclusive, royalty-free perpetual license to install, use, modify, prepare derivative works, incorporate into other computer software, distribute, and sublicense such enhancements or derivative works thereof, in binary and source code form. 23 | 24 | 25 | 26 | # Documentation 27 | We are currently writing better documentation, examples, and a tutorial, at https://libpfasst.github.io/LibPFASST. 28 | The documentation can be edited on the gh-pages branch of this repo. 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/.depend: -------------------------------------------------------------------------------- 1 | ./build/main.o : src/main.f90 ./build/probin.o ./build/level.o ./build/sweeper.o 2 | ./build/level.o : src/level.f90 3 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o 4 | ./build/probin.o : src/probin.f90 5 | -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Dahlyquist example. 3 | # 4 | 5 | LIBPFASST ?= ../.. 6 | BUILDDIR = build 7 | 8 | EXE = main.exe 9 | 10 | include $(LIBPFASST)/Makefile.defaults 11 | 12 | FSRC = src/main.f90 src/level.f90 src/sweeper.f90 src/probin.f90 13 | 14 | OBJ = $(subst src, build,$(FSRC:.f90=.o)) 15 | 16 | FFLAGS += -I$(LIBPFASST)/include 17 | 18 | all: $(EXE) 19 | 20 | VPATHS = src 21 | 22 | include $(LIBPFASST)/Makefile.rules 23 | 24 | # 25 | # dependencies 26 | # 27 | include .depend 28 | main.exe : $(LIBPFASST)/lib/libpfasst.a 29 | -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/README: -------------------------------------------------------------------------------- 1 | Example program calling libpfasst to solve the Dahlquist problem 2 | 3 | y' = lam1*y+lam2*y 4 | y(0)=1 5 | 6 | This version uses the ndarray encapsulation. -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/multi_level.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level imex 3 | ! 4 | &PF_PARAMS 5 | ! Internal pfasst variable that must be set 6 | nlevels = 3 ! must be set 7 | 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | nnodes = 2 3 5 11 | 12 | ! optional variables to control termination (defaults are 0.0) 13 | abs_res_tol = 1.d-13 14 | rel_res_tol = 1.d-13 15 | 16 | / 17 | 18 | ! Now define the local variables you need 19 | &PARAMS 20 | 21 | Tfin = 2.0 22 | nsteps = 8 23 | 24 | lam1=1.0 25 | lam2=-0.1 26 | 27 | / 28 | -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/pipeline.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level pipeline IMEX 3 | ! 4 | 5 | ! These are internal pfasst variables that must be set 6 | &PF_PARAMS 7 | ! Internal pfasst variable that must be set 8 | nlevels = 3 ! must be set 9 | 10 | ! These are internal pfasst variables that can be reset 11 | nnodes = 2 3 5 12 | 13 | niters = 10 ! default is 5 14 | 15 | nsweeps_pred=3 1 1 ! SDC sweeps per level in predictor phase 16 | nsweeps= 3 1 1 ! SDC sweeps per level 17 | 18 | ! optional variables to control termination (defaults are 0.0) 19 | abs_res_tol = 0.d-13 20 | rel_res_tol = 0.d-13 21 | 22 | ! Variable which determine how the predictor runs (default is .false. and .true.) 23 | pipeline_pred = .true. 24 | PFASST_pred = .true. 25 | 26 | ! Variable to tell if Vcycling will be done. Here we do pipelining 27 | Vcycle=.false. 28 | 29 | / 30 | 31 | ! Now define the local variables you need 32 | &PARAMS 33 | 34 | Tfin = 1.0 35 | nsteps = 32 36 | 37 | lam1=1.0 38 | lam2=-2.0 39 | 40 | / 41 | -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/probin.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level imex 3 | ! 4 | 5 | ! These are internal pfasst variables that must be set 6 | &PF_PARAMS 7 | nlevels = 3 ! must be set 8 | 9 | niters = 25 ! default is 5 10 | nnodes = 2 3 5 11 | 12 | nsweeps_pred= 1 1 13 | nsweeps= 1 1 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-14 17 | rel_res_tol = 1.d-14 18 | 19 | ! Variable to tell if Vcycling will be done. Here PFASST vcycles 20 | Vcycle=.TRUE. 21 | / 22 | 23 | ! Now define the local variables you need 24 | &PARAMS 25 | 26 | Tfin = 1.0 27 | nsteps = 32 28 | 29 | lam1=1.0 30 | lam2=-2.0 31 | 32 | / 33 | -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/sdc.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters to run the Dahlquist example with just SDC 3 | ! 4 | ! If run in serial, this will be SDC 5 | ! If run in parallel, this will be pipelined SDC 6 | 7 | &PF_PARAMS 8 | ! Internal pfasst variable that must be set 9 | nlevels = 1 10 | 11 | ! These are internal pfasst variables that can be reset 12 | nnodes = 5 ! Number of quadrature nodes (default is 3) 13 | 14 | niters = 10 ! Max PFASST iterations default is 5 15 | 16 | ! optional variables to control termination (defaults are 0.0) 17 | abs_res_tol = 1.d-13 18 | rel_res_tol = 1.d-13 19 | 20 | ! Variable to tell if Vcycling will be done. Here there is only one level 21 | Vcycle=.false. 22 | / 23 | 24 | ! Now define the local variables you need 25 | &PARAMS 26 | 27 | Tfin = 1.0 28 | nsteps = 32 29 | 30 | lam1=1.0 31 | lam2=-2.0 32 | 33 | / 34 | -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/src/level.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | ! 5 | !> Level specification for Dahlquist example. 6 | !> u_t = lam1*u + lam2*u 7 | module pf_my_level 8 | use pf_mod_ndarray 9 | 10 | !> extend the generic level type by defining transfer operators 11 | type, extends(pf_user_level_t) :: my_level_t 12 | contains 13 | procedure :: restrict 14 | procedure :: interpolate 15 | end type my_level_t 16 | 17 | contains 18 | 19 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 20 | !> These are the transfer functions that must be provided for the level 21 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 22 | !> Interpolate from coarse level to fine 23 | subroutine interpolate(this, f_lev, c_lev, f_vec, c_vec, t, flags) 24 | class(my_level_t), intent(inout) :: this 25 | class(pf_level_t), intent(inout) :: f_lev, c_lev ! fine and coarse levels 26 | class(pf_encap_t), intent(inout) :: f_vec, c_vec ! fine and coarse vectors 27 | real(pfdp), intent(in ) :: t 28 | integer, intent(in), optional :: flags 29 | 30 | 31 | !> Here we use the identity map 32 | call f_vec%copy(c_vec) 33 | 34 | end subroutine interpolate 35 | 36 | !> Restrict from fine level to coarse 37 | subroutine restrict(this, f_lev, c_lev, f_vec, c_vec, t, flags) 38 | class(my_level_t), intent(inout) :: this 39 | class(pf_level_t), intent(inout) :: f_lev, c_lev ! fine and coarse levels 40 | class(pf_encap_t), intent(inout) :: f_vec, c_vec ! fine and coarse vectors 41 | real(pfdp), intent(in ) :: t !< time of solution 42 | integer, intent(in), optional :: flags 43 | 44 | !> Here we use the identity map 45 | call c_vec%copy(f_vec) 46 | end subroutine restrict 47 | 48 | 49 | end module pf_my_level 50 | -------------------------------------------------------------------------------- /Tutorials/EX1_Dahlquist/src/sweeper.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | ! 5 | !> Sweeper and RHS specification for Dahlquist example. 6 | !> u_t = lam1*u + lam2*u 7 | module pf_my_sweeper 8 | use pf_mod_ndarray 9 | use pf_mod_imex_sweeper 10 | 11 | !> extend the imex sweeper type with stuff we need to compute rhs 12 | type, extends(pf_imex_sweeper_t) :: my_sweeper_t 13 | 14 | contains 15 | 16 | procedure :: f_eval ! Computes the explicit rhs terms 17 | procedure :: f_comp ! Does implicit solves 18 | 19 | end type my_sweeper_t 20 | 21 | contains 22 | 23 | 24 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 25 | ! These routines must be provided for the sweeper 26 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 27 | ! Evaluate the explicit function at y, t. 28 | subroutine f_eval(this, y, t, level_index, f, piece) 29 | use probin, only: lam1, lam2 30 | class(my_sweeper_t), intent(inout) :: this 31 | class(pf_encap_t), intent(in ) :: y 32 | class(pf_encap_t), intent(inout) :: f 33 | real(pfdp), intent(in ) :: t 34 | integer, intent(in ) :: level_index 35 | integer, intent(in ) :: piece 36 | 37 | real(pfdp), pointer :: yvec(:), fvec(:) 38 | 39 | !> Grab the arrays from the encapsulation 40 | yvec => get_array1d(y) 41 | fvec => get_array1d(f) 42 | 43 | ! Compute the function values 44 | select case (piece) 45 | case (1) ! Explicit piece 46 | fvec = lam1*yvec 47 | case (2) ! Implicit piece 48 | fvec = lam2*yvec 49 | case DEFAULT 50 | print *,'Bad case for piece in f_eval ', piece 51 | call exit(0) 52 | end select 53 | 54 | end subroutine f_eval 55 | 56 | !> Solve for y and return f2 also. 57 | subroutine f_comp(this, y, t, dtq, rhs, level_index, f,piece) 58 | use probin, only: lam1, lam2 59 | class(my_sweeper_t), intent(inout) :: this 60 | class(pf_encap_t), intent(inout) :: y 61 | real(pfdp), intent(in ) :: t 62 | real(pfdp), intent(in ) :: dtq 63 | class(pf_encap_t), intent(in ) :: rhs 64 | integer, intent(in ) :: level_index 65 | class(pf_encap_t), intent(inout) :: f 66 | integer, intent(in ) :: piece 67 | 68 | real(pfdp), pointer :: yvec(:), rhsvec(:), fvec(:) 69 | 70 | if (piece == 2) then 71 | !> Grab the arrays from the encapsulation 72 | yvec => get_array1d(y) 73 | rhsvec => get_array1d(rhs) 74 | fvec => get_array1d(f) 75 | 76 | ! Do the solve 77 | yvec = rhsvec/(1.0_pfdp - dtq*lam2) 78 | 79 | ! The function is easy to derive (equivalent to lam2*yvec) 80 | fvec = (yvec - rhsvec) / dtq 81 | else 82 | print *,'Bad piece in f_comp ',piece 83 | call exit(0) 84 | end if 85 | end subroutine f_comp 86 | 87 | end module pf_my_sweeper 88 | 89 | -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/.depend: -------------------------------------------------------------------------------- 1 | ./build/main.o : src/main.f90 ./build/encap.o ./build/probin.o ./build/hooks.o ./build/level.o ./build/sweeper.o 2 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o ./build/encap.o 3 | ./build/level.o : src/level.f90 ./build/encap.o 4 | ./build/hooks.o : src/hooks.f90 ./build/sweeper.o ./build/encap.o 5 | ./build/encap.o : src/encap.f90 6 | ./build/probin.o : src/probin.f90 7 | -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Dahlquist example. 3 | # 4 | 5 | LIBPFASST ?= ../.. 6 | BUILDDIR = build 7 | 8 | EXE = main.exe 9 | 10 | include $(LIBPFASST)/Makefile.defaults 11 | 12 | FSRC = src/main.f90 src/sweeper.f90 src/level.f90 src/hooks.f90 src/encap.f90 src/probin.f90 13 | 14 | OBJ = $(subst src, build,$(FSRC:.f90=.o)) 15 | 16 | FFLAGS += -I$(LIBPFASST)/include 17 | 18 | all: $(EXE) 19 | 20 | VPATHS = src 21 | 22 | include $(LIBPFASST)/Makefile.rules 23 | 24 | # 25 | # dependencies 26 | # 27 | include .depend 28 | main.exe : $(LIBPFASST)/lib/libpfasst.a 29 | -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/README: -------------------------------------------------------------------------------- 1 | Example program calling libpfasst to solve the Dahlquist problem 2 | 3 | y' = lam1*y+lam2*y 4 | y(0)=1 5 | 6 | This version creates a local encapsulation. -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/multi_level.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level imex 3 | ! 4 | &PF_PARAMS 5 | ! Internal pfasst variable that must be set 6 | nlevels = 3 ! must be set 7 | 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | nnodes = 2 3 5 11 | 12 | 13 | ! optional variables to control termination (defaults are 0.0) 14 | abs_res_tol = 1.d-13 15 | rel_res_tol = 1.d-13 16 | 17 | / 18 | 19 | ! Now define the local variables you need 20 | &PARAMS 21 | 22 | Tfin = 2.0 23 | nsteps = 8 24 | 25 | lam1=1.0 26 | lam2=-0.1 27 | 28 | / 29 | -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/pipeline.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level pipeline IMEX 3 | ! 4 | 5 | &PF_PARAMS 6 | ! Internal pfasst variable that must be set 7 | nlevels = 3 ! must be set 8 | 9 | niters = 10 ! default is 5 10 | nnodes = 3 3 5 11 | 12 | nsweeps_pred=3 1 1 13 | nsweeps= 3 1 1 14 | 15 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 16 | qtype = 1 17 | 18 | ! optional variables to control termination (defaults are 0.0) 19 | abs_res_tol = 0.d-14 20 | rel_res_tol = 0.d-14 21 | 22 | ! Variable which determine how the predictor runs (default is .false. and .true.) 23 | pipeline_pred = .true. 24 | PFASST_pred = .true. 25 | 26 | ! Variable to tell if Vcycling will be done. Here we do pipelining 27 | Vcycle=.false. 28 | / 29 | 30 | ! Now define the local variables you need 31 | &PARAMS 32 | 33 | Tfin = 1.0 34 | nsteps = 32 35 | 36 | lam1=1.0 37 | lam2=-2.0 38 | 39 | / 40 | -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/probin.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level imex 3 | ! 4 | &PF_PARAMS 5 | ! These are internal pfasst variables that must be set 6 | nlevels = 3 ! must be set 7 | 8 | niters = 10 ! default is 5 9 | nnodes = 2 3 5 10 | 11 | nsweeps_pred= 1 1 12 | nsweeps= 1 1 1 13 | 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-14 17 | rel_res_tol = 1.d-14 18 | 19 | / 20 | 21 | ! Now define the local variables you need 22 | &PARAMS 23 | 24 | Tfin = 1.0 25 | nsteps = 32 26 | 27 | lam1=1.0 28 | lam2=-2.0 29 | 30 | / 31 | -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/sdc.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters to run Dahlquist example with just SDC 3 | ! 4 | ! If run in serial, this will be SDC 5 | ! If run in parallel, this will be pipelined SDC 6 | 7 | &PF_PARAMS 8 | ! These are internal pfasst variables that must be set 9 | nlevels = 1 10 | 11 | nnodes = 5 ! Number of quadrature nodes (default is 3) 12 | 13 | ! These are internal pfasst variables that can be reset 14 | niters = 32 ! default is 5 15 | 16 | ! optional variables to control termination (defaults are 0.0) 17 | abs_res_tol = 1.d-13 18 | rel_res_tol = 1.d-13 19 | 20 | ! Variable to tell if Vcycling will be done. Here we do pipelining 21 | Vcycle=.false. 22 | / 23 | 24 | ! Now define the local variables you need 25 | &PARAMS 26 | 27 | Tfin = 1.0 28 | nsteps = 32 29 | 30 | lam1=1.0 31 | lam2=-2.0 32 | 33 | / 34 | -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use encap 7 | use pf_my_sweeper 8 | implicit none 9 | contains 10 | 11 | !> Output the error and residual in the solution 12 | subroutine echo_error(pf, level_index) 13 | use pf_my_sweeper, only: exact 14 | type(pf_pfasst_t), intent(inout) :: pf 15 | integer, intent(in) :: level_index 16 | 17 | class(scalar_encap), pointer :: y_end 18 | real(pfdp) :: yexact 19 | real(pfdp) :: maxerr 20 | real(pfdp) :: time,resid 21 | integer :: step,rank,iter 22 | time=pf%state%t0+pf%state%dt 23 | step=pf%state%step+1 24 | rank=pf%rank 25 | iter=pf%state%iter 26 | 27 | !> Get the solution at the end of this step 28 | y_end => cast_as_scalar(pf%levels(level_index)%qend) 29 | 30 | !> compute the exact solution 31 | call exact(time, yexact) 32 | !> compute error 33 | maxerr = abs(y_end%y-yexact) 34 | resid=pf%levels(level_index)%residual 35 | 36 | print '("time: ", f10.4," step: ", i7.7," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," res: ",es14.7)', & 37 | time, step, rank, iter,level_index, maxerr,resid 38 | call flush(6) 39 | end subroutine echo_error 40 | 41 | 42 | end module hooks 43 | -------------------------------------------------------------------------------- /Tutorials/EX2_Dahlquist/src/level.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> Level specification for Dahlquist example. 5 | !> u_t = lam1*u + lam2*u 6 | module pf_my_level 7 | use encap 8 | use pf_mod_imex_sweeper 9 | 10 | !> extend the generic level type by defining transfer operators 11 | type, extends(pf_user_level_t) :: my_level_t 12 | contains 13 | procedure :: restrict 14 | procedure :: interpolate 15 | end type my_level_t 16 | 17 | contains 18 | 19 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 20 | !> These are the transfer functions that must be provided for the level 21 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 22 | !> Interpolate from coarse level to fine 23 | subroutine interpolate(this, f_lev, c_lev, f_vec, c_vec, t, flags) 24 | class(my_level_t), intent(inout) :: this 25 | real(pfdp), intent(in ) :: t 26 | class(pf_level_t), intent(inout) :: f_lev, c_lev ! fine and coarse levels 27 | class(pf_encap_t), intent(inout) :: f_vec, c_vec ! fine and coarse vectors 28 | integer, intent(in), optional :: flags 29 | 30 | class(scalar_encap), pointer :: y_f, y_c 31 | 32 | !> Cast the abstract encap as my data type 33 | y_f => cast_as_scalar(f_vec) 34 | y_c => cast_as_scalar(c_vec) 35 | 36 | !> Here we use the identity map 37 | y_f%y=y_c%y 38 | end subroutine interpolate 39 | 40 | !> Restrict from fine level to coarse 41 | subroutine restrict(this, f_lev, c_lev, f_vec, c_vec, t, flags) 42 | class(my_level_t), intent(inout) :: this 43 | class(pf_level_t), intent(inout) :: f_lev, c_lev ! fine and coarse levels 44 | class(pf_encap_t), intent(inout) :: f_vec, c_vec ! fine and coarse vectors 45 | real(pfdp), intent(in ) :: t !< time of solution 46 | integer, intent(in), optional :: flags 47 | 48 | class(scalar_encap), pointer :: y_f, y_c 49 | 50 | !> Cast the abstract encap as my data type 51 | y_f => cast_as_scalar(f_vec) 52 | y_c => cast_as_scalar(c_vec) 53 | 54 | !> Here we use the identity map 55 | y_c%y = y_f%y 56 | end subroutine restrict 57 | 58 | end module pf_my_level 59 | 60 | -------------------------------------------------------------------------------- /Tutorials/EX3_adv_diff/.depend: -------------------------------------------------------------------------------- 1 | ./build/main.o : src/main.f90 ./build/probin.o ./build/hooks.o ./build/level.o ./build/sweeper.o 2 | ./build/level.o : src/level.f90 ./build/sweeper.o 3 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o 4 | ./build/hooks.o : src/hooks.f90 ./build/sweeper.o 5 | ./build/probin.o : src/probin.f90 6 | -------------------------------------------------------------------------------- /Tutorials/EX3_adv_diff/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for advection diffusion example 3 | # 4 | 5 | LIBPFASST ?= ../.. 6 | BUILDDIR = build 7 | 8 | EXE = main.exe 9 | USE_FFT=TRUE 10 | include $(LIBPFASST)/Makefile.defaults 11 | 12 | FSRC = src/main.f90 src/level.f90 src/sweeper.f90 src/hooks.f90 src/probin.f90 13 | 14 | OBJ = $(subst src, build,$(FSRC:.f90=.o)) 15 | 16 | FFLAGS += -I$(LIBPFASST)/include 17 | 18 | all: $(EXE) 19 | 20 | VPATHS = src 21 | 22 | include $(LIBPFASST)/Makefile.rules 23 | 24 | # 25 | # dependencies 26 | # 27 | include .depend 28 | main.exe : $(LIBPFASST)/lib/libpfasst.a 29 | -------------------------------------------------------------------------------- /Tutorials/EX3_adv_diff/multi_level.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level imex 3 | ! 4 | 5 | ! These are internal pfasst variables that must be set 6 | &PF_PARAMS 7 | nlevels = 2 ! must be set 8 | 9 | niters = 15 ! default is 5 10 | nnodes = 3 5 11 | 12 | use_proper_nodes=.false. 13 | nsweeps_pred= 1 1 1 14 | nsweeps= 1 1 1 15 | 16 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 17 | qtype = 1 18 | 19 | ! optional variables to control termination (defaults are 0.0) 20 | abs_res_tol = 1.d-12 21 | rel_res_tol = 1.d-12 22 | 23 | 24 | ! Variable which determine how the predictor runs (default is .false. and .true.) 25 | pipeline_pred = .false. 26 | PFASST_pred = .true. 27 | 28 | ! Variable to tell if Vcycling will be done. Here PFASST vcycles 29 | Vcycle=.TRUE. 30 | 31 | outdir="ad" 32 | / 33 | 34 | ! Now define the local variables you need 35 | &PARAMS 36 | 37 | nx = 128 256 38 | nu = 0.1 39 | v=0.9 40 | Lx=1.0 41 | Tfin = 0.25 42 | nsteps = 16 43 | kfreq = 4 44 | imex_stat=2 45 | 46 | / 47 | -------------------------------------------------------------------------------- /Tutorials/EX3_adv_diff/pipeline.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level pipeline IMEX 3 | ! 4 | 5 | ! These are internal pfasst variables that must be set 6 | &PF_PARAMS 7 | nlevels = 3 ! must be set 8 | 9 | niters = 10 ! default is 5 10 | nnodes = 3 3 5 11 | 12 | nsweeps_pred=3 1 1 13 | nsweeps= 3 1 1 14 | 15 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 16 | qtype = 1 17 | 18 | ! optional variables to control termination (defaults are 0.0) 19 | abs_res_tol = 0.d-14 20 | rel_res_tol = 0.d-14 21 | 22 | ! Variable which determine how the predictor runs (default is .false. and .true.) 23 | pipeline_pred = .true. 24 | PFASST_pred = .true. 25 | 26 | ! Variable to tell if Vcycling will be done. Here we do pipelining 27 | Vcycle=.false. 28 | 29 | / 30 | 31 | ! Now define the local variables you need 32 | &PARAMS 33 | 34 | nx = 64 128 256 35 | nu = 0.02 36 | v=1.0 37 | 38 | Tfin = 0.9 39 | nsteps = 32 40 | 41 | imex_stat=2 42 | 43 | / 44 | -------------------------------------------------------------------------------- /Tutorials/EX3_adv_diff/probin.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a single level example 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 1 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 8 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 5 20 | 21 | nsweeps_pred= 1 22 | nsweeps= 1 23 | / 24 | 25 | ! Now define the local variables you need 26 | &PARAMS 27 | 28 | nx = 64 29 | nu = 0.02 30 | v=1.0 31 | 32 | Tfin = 1.0 33 | nsteps = 64 34 | 35 | imex_stat=2 36 | 37 | / 38 | -------------------------------------------------------------------------------- /Tutorials/EX3_adv_diff/sdc.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters to run advection diffusion example with just SDC 3 | ! 4 | ! If run in serial, this will be SDC 5 | ! If run in parallel, this will be pipelined SDC 6 | 7 | &PF_PARAMS 8 | ! These are internal pfasst variables that must be set 9 | nlevels = 1 10 | nnodes = 15 11 | 12 | nsweeps_pred= 1 13 | nsweeps= 1 14 | 15 | ! These are internal pfasst variables that can be reset 16 | niters = 9 ! default is 5 17 | 18 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 19 | qtype = 1 20 | 21 | ! optional variables to control termination (defaults are 0.0) 22 | abs_res_tol = 1.d-13 23 | rel_res_tol = 1.d-13 24 | 25 | ! Variable which determine how the predictor runs (default is .false. and .true.) 26 | Pipeline_pred = .true. 27 | PFASST_pred = .true. 28 | 29 | 30 | ! Variable to tell if Vcycling will be done. Here we do pipelining 31 | Vcycle=.false. 32 | / 33 | 34 | ! Now define the local variables you need 35 | &PARAMS 36 | 37 | 38 | nx = 64 39 | 40 | Tfin = 0.9 41 | nsteps = 16 42 | 43 | nu=0.02 44 | v=1.0 45 | 46 | imex_stat=2 47 | / 48 | -------------------------------------------------------------------------------- /Tutorials/EX3_adv_diff/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pfasst 7 | use pf_mod_ndarray 8 | implicit none 9 | contains 10 | 11 | !> Output the error and residual in the solution 12 | subroutine echo_error(pf, level_index) 13 | use my_sweeper, only: exact 14 | type(pf_pfasst_t), intent(inout) :: pf 15 | integer, intent(in) :: level_index 16 | 17 | real(pfdp) :: yexact(pf%levels(level_index)%lev_shape(1)) 18 | real(pfdp), pointer :: y_end(:) 19 | real(pfdp) :: maxerr 20 | real(pfdp) :: time,resid 21 | integer :: step,rank,iter 22 | time=pf%state%t0+pf%state%dt 23 | step=pf%state%step+1 24 | rank=pf%rank 25 | iter=pf%state%iter 26 | resid=pf%levels(level_index)%residual 27 | 28 | !> compute the error at last end point 29 | y_end => get_array1d(pf%levels(level_index)%qend) 30 | call exact(pf%state%t0+pf%state%dt, yexact) 31 | maxerr = maxval(abs(y_end-yexact)) 32 | 33 | print '("time: ", f10.4," step: ", i7.7," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," res: ",es14.7)', & 34 | time, step, rank, iter,level_index, maxerr,resid 35 | 36 | call pf_set_error(pf,level_index,maxerr) 37 | 38 | end subroutine echo_error 39 | end module hooks 40 | -------------------------------------------------------------------------------- /Tutorials/EX4_Boussinesq/.depend: -------------------------------------------------------------------------------- 1 | ./build/main.o : src/main.f90 ./build/probin.o ./build/hooks.o ./build/level.o ./build/sweeper.o 2 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o 3 | ./build/level.o : src/level.f90 ./build/sweeper.o 4 | ./build/hooks.o : src/hooks.f90 ./build/sweeper.o 5 | ./build/probin.o : src/probin.f90 6 | -------------------------------------------------------------------------------- /Tutorials/EX4_Boussinesq/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for 2D Boussinesq Example 3 | # 4 | 5 | LIBPFASST ?= ../../ 6 | LIBNPY ?= $(LIBPFASST)/libnpy 7 | 8 | EXE = main.exe 9 | BUILDDIR = build 10 | 11 | USE_FFT=TRUE 12 | include $(LIBPFASST)/Makefile.defaults 13 | 14 | FSRC = src/main.f90 src/sweeper.f90 src/level.f90 src/hooks.f90 src/probin.f90 15 | 16 | OBJ = $(subst src, build,$(FSRC:.f90=.o)) 17 | 18 | FFLAGS += -I$(LIBPFASST)/include -I$(LIBNPY)/include 19 | LDFLAGS += -L$(LIBNPY)/libnpy_fortran_mod -lnpy 20 | 21 | all: $(EXE) 22 | 23 | VPATHS = src 24 | 25 | 26 | include $(LIBPFASST)/Makefile.rules 27 | 28 | 29 | # dependencies 30 | # 31 | include $(PWD)/.depend 32 | main.exe : $(LIBPFASST)/lib/libpfasst.a 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Tutorials/EX4_Boussinesq/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pfasst 7 | use pf_mod_zndsysarray 8 | implicit none 9 | contains 10 | 11 | !> Output the error and residual in the solution 12 | subroutine echo_error(pf, level_index) 13 | use pf_my_sweeper, only: exact,my_sweeper_t, as_my_sweeper 14 | type(pf_pfasst_t), intent(inout) :: pf 15 | integer, intent(in) :: level_index 16 | 17 | class(my_sweeper_t), pointer :: sweeper 18 | complex(pfdp), pointer :: omega_end(:,:),rho_end(:,:) 19 | complex(pfdp), pointer :: omega_ex(:,:), rho_ex(:,:) 20 | real(pfdp) :: maxerr_om,maxerr_rho,t,t0 21 | 22 | 23 | sweeper => as_my_sweeper(pf%levels(level_index)%ulevel%sweeper) 24 | 25 | ! Get the solution at the end of time step 26 | omega_end => get_array2d(pf%levels(level_index)%qend,1) 27 | rho_end => get_array2d(pf%levels(level_index)%qend,2) 28 | 29 | ! Use sweeper temp space for exact solutions 30 | omega_ex => sweeper%tmp 31 | rho_ex => sweeper%tmphat 32 | rho_ex => sweeper%u 33 | 34 | !> compute the exact solution 35 | t=pf%state%t0+pf%state%dt 36 | t0=pf%state%t0 37 | call sweeper%exact(t, omega_ex,rho_ex) 38 | 39 | !> compute error 40 | maxerr_om = maxval(abs(omega_end-omega_ex)) 41 | maxerr_rho = maxval(abs(rho_end-rho_ex)) 42 | 43 | print '("time: ", f8.4," step: ",i3.3," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error_om: ",es14.7," error_rho: ",es14.7," resid: ",es14.7)', & 44 | t,pf%state%step+1, pf%rank, pf%state%iter,level_index,maxerr_om,maxerr_rho,pf%levels(level_index)%residual 45 | 46 | 47 | call pf_set_error(pf,level_index,maxerr_om) 48 | 49 | 50 | end subroutine echo_error 51 | 52 | end module hooks 53 | -------------------------------------------------------------------------------- /Tutorials/EX4_Boussinesq/src/split: -------------------------------------------------------------------------------- 1 | this%tmphat=this%ddx*omega ! omega_x in spectral space 2 | call fft%ifft(this%tmphat,this%tmp) ! omega_x in real space 3 | if (splitting .eq. 1) then 4 | this%tmp = -(this%u+v0(1))*this%tmp ! -(u+v0(1)).omega_x in real space 5 | else 6 | this%tmp = -(this%u)*this%tmp ! -u.omega_x in real space 7 | end if 8 | 9 | call fft%fft(this%tmp,f_omega) ! -(u+v0(1)).omega_x in spectral space 10 | 11 | this%tmphat=this%ddy*omega ! omega_y in spectral space 12 | call fft%ifft(this%tmphat,this%tmp) ! omega_y in spectral 13 | if (splitting .eq. 1) then 14 | this%tmp = (this%v+v0(2))*this%tmp ! -(v+v0(2)).omega_y in real space 15 | else 16 | this%tmp = (this%v)*this%tmp ! -v.omega_y in real space 17 | end if 18 | 19 | call fft%fft(this%tmp,this%tmphat) ! v.omega_y in spectral space 20 | f_omega=f_omega-this%tmphat ! f = -u.omega_x-v.omega_y 21 | 22 | f_omega=f_omega-grav*this%ddy*rho ! f = -u.omega_x-v.omega_y-g*rho_y 23 | 24 | this%tmphat=this%ddx*rho ! rho_x in spectral space 25 | call fft%ifft(this%tmphat,this%tmp) ! rho_x in real space 26 | if (splitting .eq. 1) then 27 | this%tmp = (this%u+v0(1))*this%tmp ! u.rho_x in real space 28 | else 29 | this%tmp = (this%u)*this%tmp ! u.rho_x in real space 30 | end if 31 | 32 | call fft%fft(this%tmp,this%tmphat) ! u.rho_x in spectral space 33 | f_rho= -this%tmphat ! f = -u.rho_x 34 | 35 | this%tmphat=this%ddy*rho ! rho_y in spectral space 36 | call fft%ifft(this%tmphat,this%tmp) ! rho_y in real space 37 | if (splitting .eq. 1) then 38 | this%tmp = (this%v+v0(2))*this%tmp ! v.rho_y in real space 39 | else 40 | this%tmp = (this%v)*this%tmp ! v.rho_y in real space 41 | end if 42 | 43 | call fft%fft(this%tmp,this%tmphat) ! v.rho_y in spectral space 44 | f_rho = f_rho - this%tmphat ! f = -u.rho_x-v.rho_y 45 | else ! Implicit 46 | if (splitting .eq. 1) then 47 | f_omega = nu*this%lap*omega ! f = nu*Lap*omega 48 | f_rho = kappa*this%lap*rho ! f = kappa*Lap*rho 49 | else 50 | f_omega = (nu*this%lap-v0(1)*this%ddx-v0(2)*this%ddy)*omega ! f = nu*Lap*omega 51 | f_rho = (kappa*this%lap-v0(1)*this%ddx-v0(2)*this%ddy)*rho ! f = kappa*Lap*rho 52 | end if 53 | 54 | -------------------------------------------------------------------------------- /Tutorials/EX4_Boussinesq/tg.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 1 22 | nsweeps= 1 23 | save_residuals=.true. 24 | save_errors=.true. 25 | 26 | / 27 | 28 | ! Now define the local variables you need 29 | &PARAMS 30 | 31 | nx = 32 64 64 32 | nu = 0.01 33 | kappa = 0.01 34 | Lx=1.0 1.0 35 | grav=0.0 36 | v0= 1.0 1.0 37 | Tfin = 0.5 38 | nsteps = 16 39 | ic_type = 2 40 | splitting = 2 41 | 42 | 43 | / 44 | -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for optimal control with K-S equation 3 | # 4 | 5 | LIBPFASST ?= ../../../LibPFASST 6 | #FFTW3 ?= $(LIBPFASST)/fftw3 7 | LIBNPY ?= $(LIBPFASST)/libnpy 8 | 9 | EXE = main.exe 10 | 11 | USE_FFT=TRUE 12 | include $(LIBPFASST)/Makefile.defaults 13 | 14 | BUILDDIR = build 15 | 16 | #USEFFTW=TRUE 17 | #NOFFTW=FALSE 18 | 19 | DEBUG=FALSE 20 | 21 | VPATHS = src 22 | FSRC = src/probin.f90 src/sweeper.f90 src/hooks.f90 src/pf_optimization_1d.f90 src/level.f90 src/main.f90 23 | 24 | OBJ = $(subst src, build, $(FSRC:.f90=.o)) 25 | 26 | FFLAGS += -I$(LIBPFASST)/include -I$(LIBNPY)/include 27 | # -g -fcheck=all,bounds -fbacktrace 28 | #-I$(FFTW3)/include 29 | LDFLAGS += -L$(LIBPFASST)/lib -lpfasst -L$(LIBNPY)/libnpy_fortran_mod -lnpy 30 | #-lblas -llapack 31 | #LDFLAGS += -L$(FFTW3)/lib -L$(FFTW3)/lib64 -lfftw3 32 | 33 | 34 | all: $(EXE) 35 | 36 | include $(LIBPFASST)/Makefile.rules 37 | 38 | main.exe : $(LIBPFASST)/lib/libpfasst.a 39 | # 40 | # dependencies 41 | # 42 | 43 | build/feval.o: build/probin.o 44 | build/pf_optimization_1d.o: build/sweeper.o build/probin.o 45 | build/main.o: build/feval.o build/level.o build/hooks.o build/probin.o $(LIBPFASST)/lib/libpfasst.a 46 | -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/figures/ctrlKS_T1_nstep100_nx1024_u0_075uexact_diff_final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/figures/ctrlKS_T1_nstep100_nx1024_u0_075uexact_diff_final.png -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/figures/ctrlKS_T1_nstep100_nx1024_u0_075uexact_progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/figures/ctrlKS_T1_nstep100_nx1024_u0_075uexact_progress.png -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/figures/gradientKS_T1_nstep100_nx1024_u0_075uexact_progress.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/figures/gradientKS_T1_nstep100_nx1024_u0_075uexact_progress.pdf -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/figures/gradientsKS_T1_nstep100_nx1024_u0_075uexact_progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/figures/gradientsKS_T1_nstep100_nx1024_u0_075uexact_progress.png -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/figures/objKS_T1_nstep100_nx1024_u0_075uexact_progress.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/figures/objKS_T1_nstep100_nx1024_u0_075uexact_progress.pdf -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/figures/solKS_T1_nstep100_nx1024_optit60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/figures/solKS_T1_nstep100_nx1024_optit60.png -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/figures/solKS_T1_nstep100_nx1024_yd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/figures/solKS_T1_nstep100_nx1024_yd.png -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/figures/solKS_T60_nstep600_nx1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/figures/solKS_T60_nstep600_nx1024.png -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/Tutorials/EX5_KS_control/doc/notes.pdf -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/doc/references.bib: -------------------------------------------------------------------------------- 1 | @BOOK{HinzeEtAl2009, 2 | title = {Optimization with {PDE} constraints}, 3 | publisher = {Springer}, 4 | year = {2009}, 5 | author = {Hinze, Michael and Pinnau, Rene and Ulbrich, Michael and Ulbrich, 6 | Stefan}, 7 | address = {Berlin} 8 | } 9 | 10 | @BOOK{NocedalWright2006, 11 | title = {Numerical Optimization}, 12 | publisher = {Springer}, 13 | year = {2006}, 14 | author = {Nocedal, Jorge and Wright, Stephen J.}, 15 | address = {New York} 16 | } 17 | 18 | @BOOK{HinzeEtAl2009, 19 | title = {Optimization with {PDE} constraints}, 20 | publisher = {Springer}, 21 | year = {2009}, 22 | author = {Hinze, Michael and Pinnau, Rene and Ulbrich, Michael and Ulbrich, 23 | Stefan}, 24 | address = {Berlin} 25 | } 26 | 27 | @BOOK{Troeltzsch2010, 28 | title = {Optimal Control of Partial Differential Equations: Theory, Methods and Applications}, 29 | publisher = {AMS}, 30 | year = {2010}, 31 | author = {Tr\"{o}ltzsch, Fredi}, 32 | } 33 | 34 | @article{KassamTrefethen2005, 35 | title={Fourth-order time-stepping for stiff PDEs}, 36 | author={Kassam, Aly-Khan and Trefethen, Lloyd N}, 37 | journal={SIAM J. Sci. Comput.}, 38 | volume={26}, 39 | number={4}, 40 | pages={1214--1233}, 41 | year={2005}, 42 | publisher={SIAM} 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/imex.nml: -------------------------------------------------------------------------------- 1 | &PF_PARAMS 2 | ! These are internal pfasst variables that must be set 3 | nlevels = 2 4 | 5 | ! These are internal pfasst variables that can be reset 6 | niters = 150 ! default is 5 7 | 8 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 9 | qtype = 1 10 | 11 | 12 | ! optional variables to control termination (defaults are 0.0) 13 | abs_res_tol = 1e-10 14 | rel_res_tol = 1e-10 15 | 16 | ! Variable which determine how the predictor runs (default is .false. and .true.) 17 | PFASST_pred = .true. 18 | pipeline_pred = .false. 19 | 20 | 21 | / 22 | 23 | &PARAMS 24 | poutmod = 1 25 | 26 | ndim = 1 27 | 28 | nsteps = 100 29 | 30 | nvars = 512 1024 31 | nnodes = 3 5 32 | 33 | 34 | Finterp = F 35 | 36 | Lx = 100.5309649 ! 32pi 37 | Tfin = 1.0 38 | 39 | alpha = 1e-6 40 | max_opt_iter = 10 41 | tol_grad = 1e-4 42 | 43 | tol_obj = 1e-6 44 | max_step_size = 1.0 45 | 46 | do_imex = 1 47 | warmstart = 0 48 | logfile = "check" 49 | 50 | pfasst_nml = "imex.nml" 51 | fbase = "pfasst_V" 52 | 53 | output = " " 54 | / 55 | -------------------------------------------------------------------------------- /Tutorials/EX5_KS_control/plot.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | from mpl_toolkits import mplot3d 4 | from matplotlib import cm 5 | 6 | nnodes = 5; 7 | nvars = 1024; 8 | nsteps = 100; 9 | 10 | path = './npy/' 11 | 12 | dat = np.zeros([nnodes*nsteps,nvars]); 13 | 14 | x = np.linspace(0,32*np.pi,nvars) 15 | 16 | #plt.figure() 17 | #dat = np.zeros([nvars]) 18 | #fn = path+'uexact.npy' 19 | #dat = np.load(fn) 20 | #plt.plot(x,dat) 21 | 22 | plt.figure() 23 | 24 | dat = np.zeros([nsteps+1,nvars]); 25 | counter = 0 26 | for step in range(0,nsteps+1): 27 | # for m in range(1,nnodes+1): 28 | #fn=path+'ys'+str(step).zfill(4)+'m' + str(m).zfill(2) + '.npy' 29 | fn=path+'ys'+str(step).zfill(4) + '.npy' 30 | dat[counter,:] = np.load(fn); 31 | counter = counter + 1 32 | 33 | plt.imshow(dat,extent=[0,101,0,60],aspect='auto',origin='lower',interpolation='none') 34 | plt.colorbar() 35 | plt.xlabel('x') 36 | plt.ylabel('t') 37 | plt.title('state') 38 | 39 | plt.figure() 40 | dat = np.zeros([nsteps*nnodes,nvars]); 41 | counter = 0 42 | for step in range(1,nsteps+1): 43 | for m in range(1,nnodes+1): 44 | fn=path+'ytargets'+str(step).zfill(4)+'m' + str(m).zfill(2) + '.npy' 45 | #fn=path+'ys'+str(step).zfill(4) + '.npy' 46 | dat[counter,:] = np.load(fn); 47 | counter = counter + 1 48 | plt.imshow(dat,extent=[0,101,0,60],aspect='auto',origin='lower',interpolation='none') 49 | plt.colorbar() 50 | plt.xlabel('x') 51 | plt.ylabel('t') 52 | plt.title('target state') 53 | 54 | 55 | #plt.figure() 56 | #plt.plot(dat[:,15]) 57 | #plt.title('state at node 15') 58 | 59 | #plt.figure() 60 | #plt.plot(dat[:,16]) 61 | #plt.title('state at node 16') 62 | 63 | #plt.figure() 64 | #plt.plot(dat[:,-1]) 65 | #plt.title('state at node 1024') 66 | 67 | plt.figure() 68 | #plt.plot(dat[-1,:]) 69 | 70 | datuex = np.zeros([nvars]) 71 | fn = path+'uexact.npy' 72 | datuex = np.load(fn) 73 | plt.plot(datuex, label='exact') 74 | 75 | 76 | #plt.figure() 77 | datu = np.zeros([nvars]) 78 | fn = path+'uk0001.npy' 79 | datu = np.load(fn) 80 | plt.plot(datu, label='initial') 81 | 82 | 83 | #plt.figure() 84 | datu = np.zeros([nvars]) 85 | fn = path+'ufinal.npy' 86 | datu = np.load(fn) 87 | plt.plot(datu, label='final') 88 | plt.legend(loc='upper right') 89 | plt.title('controls') 90 | 91 | plt.figure() 92 | plt.plot(datu-datuex) 93 | plt.title('diff computed - exact control') 94 | 95 | 96 | plt.figure() 97 | fn = path+'gradientk0001.npy' 98 | datu = np.load(fn) 99 | #plt.plot(datu,label='it 1') 100 | fn = path+'gradientk0005.npy' 101 | datu = np.load(fn) 102 | plt.plot(datu,label='it 5') 103 | fn = path+'gradientk0020.npy' 104 | datu = np.load(fn) 105 | plt.plot(datu,label='it 20') 106 | fn = path+'gradientk0060.npy' 107 | datu = np.load(fn) 108 | plt.plot(datu,label='it 60') 109 | plt.legend(loc='upper left') 110 | plt.title('gradients') 111 | 112 | 113 | plt.title('gradients') 114 | 115 | 116 | plt.show() 117 | -------------------------------------------------------------------------------- /mk/GPackage.mak: -------------------------------------------------------------------------------- 1 | f90sources += pfasst.f90 2 | f90sources += pf_cycle.f90 3 | f90sources += pf_dtype.f90 4 | f90sources += pf_explicit.f90 5 | f90sources += pf_fake.f90 6 | f90sources += pf_fakecomm.f90 7 | f90sources += pf_hooks.f90 8 | f90sources += pf_imex.f90 9 | f90sources += pf_implicit.f90 10 | f90sources += pf_interpolate.f90 11 | f90sources += pf_logger.f90 12 | f90sources += pf_mpi.f90 13 | f90sources += pf_options.f90 14 | f90sources += pf_parallel.f90 15 | f90sources += pf_pfasst.f90 16 | f90sources += pf_pthreads.f90 17 | f90sources += pf_quadrature.f90 18 | f90sources += pf_restrict.f90 19 | f90sources += pf_timer.f90 20 | f90sources += pf_utils.f90 21 | f90sources += sdc_poly.f90 22 | f90sources += sdc_quadrature.f90 23 | 24 | csources += pf_cpthreads.c 25 | -------------------------------------------------------------------------------- /mk/makefile.gcc47.defs: -------------------------------------------------------------------------------- 1 | # 2 | # Build settings for auto-installed gcc47. 3 | # 4 | 5 | export OMPI_FC = $(LIBPFASST)/gcc-4.7/bin/gfortran 6 | export MPICH_F90 = $(LIBPFASST)/gcc-4.7/bin/gfortran 7 | 8 | FC = mpif90 9 | CC = $(LIBPFASST)/gcc-4.7/bin/gcc 10 | AR = ar rcs 11 | 12 | FFLAGS = -Ibuild -Jbuild -Wall -cpp -g -Wno-unused-dummy-argument 13 | LDFLAGS = -g -static 14 | -------------------------------------------------------------------------------- /mk/makefile.juqueen.defs: -------------------------------------------------------------------------------- 1 | # 2 | # JUQUEEN build settings for libpfasst. 3 | # 4 | 5 | # need: module load gcc 6 | 7 | FC = mpigfortran 8 | CC = mpigcc 9 | 10 | -------------------------------------------------------------------------------- /mk/makefile.orga.defs: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile definitions for orga 3 | # 4 | 5 | export TAU_MAKEFILE=/home/memmett/src/tau-2.22.2/x86_64/lib/Makefile.tau-mpi-openmp 6 | export MPICH_F90=/home/memmett/gcc-4.7/bin/gfortran 7 | 8 | FFLAGS += -Wall -g -Wno-unused-dummy-argument -cpp -fbacktrace 9 | CFLAGS += -Wall -g 10 | 11 | # FC = tau_f90.sh -tau_options=-optTauSelectFile=tau.txt 12 | # CC = tau_cc.sh 13 | 14 | # FC = tau_f90.sh -tau_options=-optTauSelectFile=tau.txt 15 | # CC = tau_cc.sh 16 | 17 | 18 | NOSE = /home/memmett/anaconda/bin/nosetests 19 | -------------------------------------------------------------------------------- /mk/makefile.spruce.defs: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile definitions for spruce 3 | # 4 | 5 | FFLAGS += -Wall -g -pg -Wno-unused-dummy-argument 6 | -------------------------------------------------------------------------------- /pf/__init__.py: -------------------------------------------------------------------------------- 1 | import io 2 | import convergence 3 | import speedup 4 | import pfasst 5 | import nwc 6 | -------------------------------------------------------------------------------- /pf/io.py: -------------------------------------------------------------------------------- 1 | import glob 2 | import re 3 | import os 4 | from collections import namedtuple 5 | 6 | Timing = namedtuple('Timing', [ 7 | 'timer', 'rank', 'step', 'level', 'iter', 'delta', 'start', 'end' 8 | ]) 9 | 10 | Solution = namedtuple('Solution', ['step', 'iter', 'level', 'fname']) 11 | 12 | timers_of_interest = ['exp', 'feval', 'omega'] 13 | 14 | 15 | def read_timings(fname): 16 | 17 | prog = re.compile( 18 | "timer:(.*), rank:(.*), step:(.*), level:(.*), iter:(.*), cycle:(.*), " 19 | + "time .rate(.*)Hz.:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)") 20 | 21 | with open(fname, 'r') as f: 22 | output = f.read() 23 | 24 | timings = [] 25 | for line in output.split('\n'): 26 | match = prog.search(line) 27 | if match: 28 | timer = str(match.group(1)).strip() 29 | rate = float(match.group(7)) 30 | 31 | if timer not in timers_of_interest: 32 | continue 33 | 34 | rank, step, iteration = map(int, match.group(2, 3, 5)) 35 | try: 36 | level = map(int, match.group(4)) 37 | except ValueError: 38 | pass # currently unable to print level correctly in exe 39 | level = 0 40 | 41 | delta, start, end = map(lambda x: float(x) / rate, 42 | match.group(8, 9, 10)) 43 | 44 | timing = Timing(timer, rank, step + 1, level, iteration, delta, 45 | start, end) 46 | timings.append(timing) 47 | 48 | return timings 49 | 50 | 51 | def read_all_timings(dname): 52 | 53 | timings = [] 54 | for fname in glob.glob(dname + "/fort.*"): 55 | timings.extend(read_timings(fname)) 56 | return timings 57 | 58 | 59 | def read_avail(dname): 60 | """Read output directory *dname* and return list of available 61 | solutions. 62 | 63 | Note that this does not read the solutions. 64 | """ 65 | 66 | prog = re.compile('(s(\d+)i(\d+)l(\d+)).npy') 67 | 68 | solutions = [] 69 | for fname in os.listdir(dname): 70 | m = prog.search(fname) 71 | if m: 72 | step, iteration, level = map(int, m.groups()[1:]) 73 | solutions.append( 74 | Solution(step, iteration, level, 75 | os.path.join(dname, m.group(0)))) 76 | 77 | return solutions 78 | 79 | 80 | def read_final(dname): 81 | """Read output directory *dname* and return list of final solutions. 82 | 83 | Note that this does not read the solutions. 84 | """ 85 | 86 | avail = read_avail(dname) 87 | 88 | solutions = [] 89 | for step in set([x.step for x in avail]): 90 | tmp = [x for x in avail if x.step == step] 91 | max_iter = max([x.iter for x in tmp]) 92 | max_level = max([x.level for x in tmp]) 93 | 94 | solutions.extend( 95 | [x for x in tmp if x.iter == max_iter and x.level == max_level]) 96 | 97 | return sorted(solutions) 98 | -------------------------------------------------------------------------------- /pf/setup.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | import sys 4 | import os 5 | 6 | pythonpath = os.path.append('../pf') 7 | 8 | if pythonpath not in sys.path: 9 | sys.path.append(pythonpath) 10 | -------------------------------------------------------------------------------- /pp/README: -------------------------------------------------------------------------------- 1 | This is a directory of Python postprocessing scripts for pfasst and parareal runs -------------------------------------------------------------------------------- /pp/iter_per_step.py: -------------------------------------------------------------------------------- 1 | # This holds all the iteration per step of a pfasst or parareal run 2 | class Stats_per_step: 3 | Nsteps=1 # Total number of steps 4 | Niters=1 # Max iters from run 5 | Nblocks=1 6 | iters_per_step=[] 7 | resid_per_step=[] 8 | delq0_per_step=[] 9 | def __init__(self, param_dict,Nsteps): 10 | import numpy as np 11 | import json 12 | self.Nsteps = 1 13 | self.Nproc=1 14 | self.Nlev = param_dict['nlevels'] 15 | self.Niters = param_dict['niters'] 16 | self.Nproc = param_dict['nproc'] 17 | 18 | self.iters_per_step=np.zeros([self.Nsteps]) 19 | self.resid_per_step=np.zeros([self.Nsteps,self.Niters]) 20 | self.delq0_per_step=np.zeros([self.Nsteps,self.Niters]) 21 | Nblocks=int(self.Nsteps/self.Nproc) 22 | for kProcs in range(self.Nproc): 23 | iname='dat/'+param_dict['outdir']+'/residuals/Proc_'+str(kProcs).zfill(3)+'/Lev_'+str(self.Nlev).zfill(1)+'_iter.dat' 24 | rname='dat/'+param_dict['outdir']+'/residuals/Proc_'+str(kProcs).zfill(3)+'/Lev_'+str(self.Nlev).zfill(1)+'.dat' 25 | qname='dat/'+param_dict['outdir']+'/delta_q0/Proc_'+str(kProcs).zfill(3)+'/Lev_'+str(self.Nlev).zfill(1)+'.dat' 26 | k0=0 27 | 28 | iterarray=np.loadtxt(iname) 29 | resarray=np.loadtxt(rname) 30 | delqarray=np.loadtxt(qname) 31 | for ks in range(Nblocks): 32 | thisStep=int(ks*self.Nproc+kProcs+1) # same as int(resarray[ks,0]) 33 | if (Nblocks == 1): 34 | thisNiter=int(iterarray[2]) 35 | thisResid=resarray[k0:k0+thisNiter-1,4] 36 | thisDelq=resarray[k0:k0+thisNiter-1,4] 37 | else: 38 | thisNiter=int(iterarray[ks,2]) 39 | thisResid=resarray[k0:k0+thisNiter-1,4] 40 | thisDelq=resarray[k0:k0+thisNiter-1,4] 41 | k0=k0+int(thisNiter) 42 | self.iters_per_step[thisStep-1]=thisNiter 43 | self.resid_per_step[thisStep-1,0:int(thisNiter)-1]=thisResid 44 | self.delq0_per_step[thisStep-1,0:int(thisNiter)-1]=thisDelq 45 | 46 | 47 | -------------------------------------------------------------------------------- /pp/parareal_run.py: -------------------------------------------------------------------------------- 1 | # This is the class to do a parareal run and get all the statistics 2 | # If Nlev=1, than this is just a serial stepper, so there will be no residuals or delta_q0 jumps, and the number of iters should be zero Niters=0 3 | class Parareal_run: 4 | def __init__(self, Nprocs,Nsteps,Name,nmlfile): 5 | import numpy as np 6 | self.Nprocs=Nprocs 7 | self.Nsteps=Nsteps 8 | self.basename = Name 9 | self.nmlfile=nmlfile 10 | 11 | # stuff that will be set from outside 12 | self.Dim=1 13 | self.Nlevs=2 14 | self.rk_order=4 15 | self.Niters=1 16 | self.Nstep_rk_coarse=1 17 | self.Nstep_rk_fine=32 18 | self.alpha=1 19 | # Place to tack on command line options 20 | self.vstr=" " 21 | self.cmdopt=" " 22 | # internal stuff 23 | self.param_dict={} 24 | 25 | def do_run(self,execute): 26 | import os 27 | import numpy as np 28 | import json 29 | from time_per_proc import Time_per_proc as timings 30 | from stats_per_step import Stats_per_step as stats 31 | from errors_per_step import Errors_per_step as errors 32 | 33 | exe='mpirun -n '+str(self.Nprocs)+ ' ./main.'+str(self.Dim)+'d.exe ' 34 | 35 | # Build output directory 36 | self.outdir=self.basename+'P'+'{:04d}'.format(self.Nprocs) 37 | outstr='\\\"'+self.basename+'\\\"' 38 | 39 | # Build command line options 40 | self.vstr=self.nmlfile 41 | self.vstr+=' outdir='+outstr 42 | self.vstr+=' Nsteps='+str(self.Nsteps) 43 | 44 | 45 | # add on external command line options 46 | myCmd =exe+self.vstr +self.cmdopt+' > out' 47 | if (execute): 48 | print(myCmd) 49 | os.system(myCmd) # Run the code 50 | 51 | # Now get some stats from the run 52 | datdir='dat/'+self.outdir+'/' # Base output directory 53 | 54 | # Get the run parameters in dictionary form 55 | with open(datdir+'pfasst_params.json', 'r') as f: 56 | self.param_dict = json.load(f) 57 | 58 | # Load the timer module 59 | if (self.param_dict['save_timings'] > 0): 60 | self.run_times=timings(self.param_dict) 61 | 62 | # Load the run stats, there are no residuals nor delta_q0 for one level 63 | if (self.Nlevs > 1): 64 | self.iter_stats=stats(self.param_dict) 65 | 66 | 67 | -------------------------------------------------------------------------------- /pp/pfasst_run.py: -------------------------------------------------------------------------------- 1 | # This runs a single instane of PFASST and then loads all the output stats and timers 2 | class PFASST_run: 3 | method="PFASST" 4 | def __init__(self, Nprocs,Nsteps,Name,nmlfile): 5 | import numpy as np 6 | self.Nsteps=Nsteps # Number of steps 7 | self.Nprocs=Nprocs # Number of processors 8 | self.basename = Name # Base output name for run 9 | self.nmlfile=nmlfile # Input file to read 10 | self.outdir="foo" # Will be padded with number of processors 11 | self.Nlevs=1 12 | self.Niters=1 13 | self.Dim=1 14 | self.param_dict={} 15 | self.cmdopt=" " 16 | 17 | def do_run(self,do_run): 18 | import os 19 | import numpy as np 20 | import json 21 | from pp.time_per_proc import Time_per_proc as timings 22 | from pp.stats_per_step import Stats_per_step as stats 23 | 24 | # exe='mpirun -n '+str(self.Nprocs)+ ' ./main.'+str(self.Dim)+'d.exe ' 25 | exe='mpirun -n '+str(self.Nprocs)+ ' ./main.exe ' 26 | 27 | 28 | # Build output directory 29 | self.outdir=self.basename+'P'+'{:04d}'.format(self.Nprocs) 30 | outstr='\\\"'+self.basename+'\\\"' 31 | 32 | # Build command line options 33 | vstr=self.nmlfile 34 | vstr=vstr+' outdir='+outstr 35 | vstr=vstr+' Nsteps='+str(self.Nsteps) 36 | 37 | # add on external command line options 38 | myCmd =exe+vstr +self.cmdopt+' > out' 39 | if(do_run): 40 | print(myCmd) 41 | os.system(myCmd) # Run the code 42 | 43 | # Set up output directories 44 | datdir='dat/'+self.outdir+'/' # Base output directory 45 | procdir='/Proc_'+str(self.Nprocs-1).zfill(3)+'/' 46 | 47 | # Load the dictionary of parameters 48 | with open(datdir+'pfasst_params.json', 'r') as f: 49 | self.param_dict = json.load(f) 50 | 51 | # Load the timer module 52 | if (self.param_dict['save_timings'] > 0): 53 | self.run_times=timings(self.param_dict) 54 | 55 | # Load the stats module 56 | self.iter_stats=stats(self.param_dict) 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/README: -------------------------------------------------------------------------------- 1 | Conventions 2 | =========== 3 | 4 | Naming 5 | ------ 6 | 7 | * All PFASST related derived type names should begin with 'pf_' and 8 | end with '_t'. 9 | 10 | * All PFASST related module names should begin with 'pf_mod_'. 11 | 12 | 13 | Modules 14 | ------- 15 | 16 | Do not use module/global variables - use derived types as containers 17 | instead. 18 | -------------------------------------------------------------------------------- /src/pf_stop.f90: -------------------------------------------------------------------------------- 1 | !! File holding the module to exit gracefully and informatively 2 | ! 3 | ! This file is part of LIBPFASST. 4 | ! 5 | !> Module to exit gracefully and informatively 6 | module pf_mod_stop 7 | contains 8 | subroutine pf_stop(pf_file,Nline,msg, val, rank) 9 | character(len=*), intent(in) :: pf_file 10 | integer, intent(in):: Nline 11 | character(len=*), intent(in) :: msg 12 | integer, intent(in), optional :: val 13 | integer, intent(in), optional :: rank 14 | 15 | print *,'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' 16 | if (present(rank)) print *,'Rank = ',rank 17 | print *,'Stopping in File: ', pf_file 18 | print *,'Line number: ', Nline 19 | print *,msg 20 | if (present(val)) print *,' = ',val 21 | print *,'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' 22 | call EXIT(-1) 23 | end subroutine pf_stop 24 | end module pf_mod_stop 25 | -------------------------------------------------------------------------------- /src/pfasst.f90: -------------------------------------------------------------------------------- 1 | !! Some convenient use statements 2 | ! 3 | ! This file is part of LIBPFASST. 4 | ! 5 | !> Module containing a collection of "use" statements to simplify 6 | !! including the common main modules in writing applications that use libpfasst 7 | module pfasst 8 | use pf_mod_dtype 9 | use pf_mod_hooks 10 | use pf_mod_parallel 11 | use pf_mod_pfasst 12 | use pf_mod_utils 13 | use pf_mod_stop 14 | #ifndef NOMPI 15 | use pf_mod_comm_mpi 16 | #endif 17 | 18 | end module pfasst 19 | 20 | -------------------------------------------------------------------------------- /test/EXP_adv_diff_fft/1d/.depend: -------------------------------------------------------------------------------- 1 | ./build/main.o : src/main.f90 ./build/probin.o ./build/hooks.o ./build/level.o ./build/sweeper.o 2 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o ./build/phi_mod.o 3 | ./build/level.o : src/level.f90 ./build/sweeper.o ./build/phi_mod.o 4 | ./build/hooks.o : src/hooks.f90 ./build/sweeper.o 5 | ./build/probin.o : src/probin.f90 6 | ./build/phi_mod.o : src/phi_mod.f90 7 | -------------------------------------------------------------------------------- /test/EXP_adv_diff_fft/1d/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for mpi-advection example. 3 | # 4 | 5 | LIBPFASST ?= ../../.. 6 | 7 | EXE = main.exe 8 | BUILDDIR = build 9 | 10 | include $(LIBPFASST)/Makefile.defaults 11 | FSRC = main.f90 sweeper.f90 level.f90 hooks.f90 probin.f90 phi_mod.f90 12 | 13 | OBJ = $(addprefix $(BUILDDIR)/,$(FSRC:.f90=.o)) 14 | 15 | FFLAGS += -I$(LIBPFASST)/include 16 | 17 | all: $(EXE) 18 | 19 | VPATHS = src 20 | 21 | 22 | include $(LIBPFASST)/Makefile.rules 23 | 24 | 25 | # dependencies 26 | # 27 | include $(PWD)/.depend 28 | main.exe : $(LIBPFASST)/lib/libpfasst.a 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/EXP_adv_diff_fft/1d/multi_level.nml: -------------------------------------------------------------------------------- 1 | 2 | ! 3 | ! Test parameters for multi-level imex 4 | ! 5 | 6 | ! These are internal pfasst variables that must be set 7 | &PF_PARAMS 8 | nlevels = 3 ! must be set 9 | 10 | niters = 8 ! default is 5 11 | nnodes = 2 3 5 12 | 13 | nsweeps_pred= 1 1 1 14 | nsweeps= 1 1 1 15 | 16 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 17 | qtype = 1 18 | 19 | ! optional variables to control termination (defaults are 0.0) 20 | abs_res_tol = 1.d-12 21 | rel_res_tol = 1.d-12 22 | 23 | ! Variable which determine how the predictor runs (default is .false. and .true.) 24 | pipeline_pred = .false. 25 | PFASST_pred = .true. 26 | 27 | ! Variable to tell if Vcycling will be done. Here PFASST vcycles 28 | Vcycle=.TRUE. 29 | 30 | save_residuals=.false. 31 | 32 | / 33 | 34 | ! Now define the local variables you need 35 | &PARAMS 36 | 37 | nx = 16 32 64 38 | nu = 0.02 39 | v=1.0 40 | 41 | Tfin = 1.0 42 | nsteps = 32 43 | 44 | nprob = 1 45 | 46 | ! controls splitting (1 treats u_xx exponentially and u_x implicitly, 2 treats u_xx and u_x exponentially) 47 | splitting = 1 48 | 49 | / 50 | -------------------------------------------------------------------------------- /test/EXP_adv_diff_fft/1d/pipeline.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for multi-level pipeline IMEX 3 | ! 4 | 5 | ! These are internal pfasst variables that must be set 6 | &PF_PARAMS 7 | nlevels = 3 ! must be set 8 | 9 | niters = 10 ! default is 5 10 | nnodes = 3 3 5 11 | 12 | nsweeps_pred=3 1 1 13 | nsweeps= 3 1 1 14 | 15 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 16 | qtype = 1 17 | 18 | ! optional variables to control termination (defaults are 0.0) 19 | abs_res_tol = 0.d-14 20 | rel_res_tol = 0.d-14 21 | 22 | ! Variable which determine how the predictor runs (default is .false. and .true.) 23 | pipeline_pred = .true. 24 | PFASST_pred = .true. 25 | 26 | ! Variable to tell if Vcycling will be done. Here we do pipelining 27 | Vcycle=.false. 28 | 29 | / 30 | 31 | ! Now define the local variables you need 32 | &PARAMS 33 | 34 | nx = 16 32 64 35 | nu = 0.02 36 | v=1.0 37 | 38 | Tfin = 0.9 39 | nsteps = 32 40 | 41 | imex_stat=2 42 | 43 | / 44 | -------------------------------------------------------------------------------- /test/EXP_adv_diff_fft/1d/probin.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a single level example 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 1 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 10 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 5 20 | 21 | nsweeps_pred= 1 22 | nsweeps= 1 23 | / 24 | 25 | ! Now define the local variables you need 26 | &PARAMS 27 | 28 | nx = 128 29 | nu = 0.02 30 | v=1.0 31 | 32 | Tfin = 1.0 33 | nsteps = 32 34 | nprob = 1 35 | 36 | ! controls splitting (1 treats u_xx exponentially and u_x implicitly, 2 treats u_xx and u_x exponentially) 37 | splitting = 1 38 | 39 | / 40 | -------------------------------------------------------------------------------- /test/EXP_adv_diff_fft/1d/sdc.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a single level example 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 1 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 10 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 5 20 | 21 | nsweeps_pred= 1 22 | nsweeps= 1 23 | save_residuals=.false. 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 32 31 | nu = 0.02 32 | v=1.0 33 | 34 | Tfin = 1.0 35 | nsteps = 32 36 | nprob = 1 37 | 38 | ! controls splitting (1 treats u_xx exponentially and u_x implicitly, 2 treats u_xx and u_x exponentially) 39 | splitting = 1 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/EXP_adv_diff_fft/1d/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pf_mod_dtype 7 | use pf_mod_ndarray 8 | implicit none 9 | contains 10 | 11 | !> Output the error and residual in the solution 12 | subroutine echo_error(pf, level_index) 13 | use pf_my_sweeper, only: exact 14 | type(pf_pfasst_t), intent(inout) :: pf 15 | integer, intent(in) :: level_index 16 | 17 | real(pfdp) :: yexact(pf%levels(level_index)%mpibuflen) 18 | real(pfdp), pointer :: y_end(:) 19 | real(pfdp) :: maxerr,err0 20 | 21 | y_end => get_array1d(pf%levels(level_index)%qend) 22 | 23 | !> compute the exact solution 24 | call exact(pf%state%t0+pf%state%dt, yexact) 25 | !> compute error 26 | maxerr = maxval(abs(y_end-yexact)) 27 | 28 | y_end => get_array1d(pf%levels(level_index)%q0) 29 | 30 | !> compute the exact solution 31 | call exact(pf%state%t0, yexact) 32 | !> compute error 33 | err0 = maxval(abs(y_end-yexact)) 34 | 35 | print '("error: step: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7,es14.7," res: ",es14.7)', & 36 | pf%state%step+1, pf%state%iter,level_index, maxerr,err0,pf%levels(level_index)%residual 37 | call flush(6) 38 | end subroutine echo_error 39 | 40 | end module hooks 41 | -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/.depend: -------------------------------------------------------------------------------- 1 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o 2 | ./build/main.o : src/main.f90 ./build/utils_1d.o ./build/probin.o ./build/hooks.o ./build/level.o ./build/sweeper.o 3 | ./build/probin.o : src/probin.f90 4 | ./build/hooks.o : src/hooks.f90 ./build/sweeper.o ./build/probin.o ./build/utils_1d.o 5 | ./build/utils_1d.o : src/utils_1d.f90 ./build/probin.o ./build/sweeper.o 6 | ./build/level.o : src/level.f90 ./build/sweeper.o 7 | -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for mpi-advection example. 3 | # 4 | DIM=1 5 | LIBPFASST = ../../.. 6 | 7 | EXE = main.$(DIM)d.exe 8 | all: $(EXE) 9 | BUILDDIR = build 10 | 11 | include $(LIBPFASST)/Makefile.defaults 12 | 13 | FSRC = src/sweeper_$(DIM)d.f90 14 | include ../Make.package 15 | OBJ = $(subst src, build,$(FSRC:.f90=.o) $(CSRC:.c=.o)) 16 | 17 | 18 | FFLAGS += -I$(LIBPFASST)/include 19 | 20 | 21 | VPATHS = src:../src 22 | 23 | 24 | include $(LIBPFASST)/Makefile.rules 25 | 26 | 27 | 28 | 29 | # dependencies 30 | # 31 | 32 | main.exe : $(LIBPFASST)/lib/libpfasst.a $(OBJ) 33 | build/sweeper_$(DIM)d.o : src/sweeper_$(DIM)d.f90 ./build/probin.o ./build/utils_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a src/sweeper_include.f90 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/src/.#sweeper_3d.f90: -------------------------------------------------------------------------------- 1 | mlminion@mlminion-ThinkPad-T480s.18845:1581475822 -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/src/sweeper_1d.f90: -------------------------------------------------------------------------------- 1 | ! MODULE: pf_my_sweeper_ad 2 | ! IMEX Sweeper for 1-D examples 3 | module pf_my_sweeper 4 | use pf_mod_dtype 5 | use pf_mod_ndarray 6 | use pf_mod_imex_sweeper 7 | use pf_mod_fftpackage 8 | use pf_mod_solutions 9 | use pf_mod_rutils 10 | use pf_mod_fftops 11 | implicit none 12 | 13 | !> extend the IMEX sweeper 14 | type, extends(pf_imex_sweeper_t) :: my_sweeper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | real(pfdp), allocatable :: tmp(:) ! temp space for feval 20 | 21 | real(pfdp), pointer :: p_tmp(:) ! Useful pointer 22 | 23 | ! Useful for making f_eval and f_comp generic 24 | class(pf_ndarray_t), pointer :: f_encap,rhs_encap,y_encap 25 | real(pfdp), pointer :: yvec(:), rhsvec(:), fvec(:) 26 | 27 | contains 28 | procedure :: f_eval ! Computes the advection and diffusion terms 29 | procedure :: f_comp ! Computes the advection and diffusion terms 30 | procedure :: initialize 31 | procedure :: initialize_tmp 32 | procedure :: destroy 33 | end type my_sweeper_t 34 | 35 | contains 36 | !> Routine to initialize tmp array for local storage 37 | subroutine initialize_tmp(this) 38 | class(my_sweeper_t), intent(inout) :: this 39 | 40 | integer :: istat 41 | allocate(this%tmp(this%nx),STAT=istat) 42 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 43 | end subroutine initialize_tmp 44 | 45 | 46 | ! The rest of the stuff is dimension independent 47 | include 'sweeper_include.f90' 48 | 49 | end module pf_my_sweeper 50 | 51 | 52 | -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/src/sweeper_2d.f90: -------------------------------------------------------------------------------- 1 | ! MODULE: pf_my_sweeper 2 | ! IMEX Sweeper for 2-D example in spectral space: 3 | module pf_my_sweeper 4 | use pf_mod_dtype 5 | use pf_mod_ndarray 6 | use pf_mod_imex_sweeper 7 | use pf_mod_fftpackage 8 | use pf_mod_solutions 9 | use pf_mod_rutils 10 | use pf_mod_fftops 11 | implicit none 12 | 13 | !> extend the IMEX sweeper 14 | type, extends(pf_imex_sweeper_t) :: my_sweeper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | real(pfdp), allocatable :: tmp(:,:) ! temp space for feval 20 | 21 | real(pfdp), pointer :: p_tmp(:,:) ! Useful pointer 22 | 23 | ! Useful for making f_eval and f_comp generic 24 | class(pf_ndarray_t), pointer :: f_encap,rhs_encap,y_encap 25 | real(pfdp), pointer :: yvec(:,:), rhsvec(:,:), fvec(:,:) 26 | 27 | contains 28 | procedure :: f_eval ! Computes the advection and diffusion terms 29 | procedure :: f_comp ! Computes the advection and diffusion terms 30 | procedure :: initialize 31 | procedure :: initialize_tmp 32 | procedure :: destroy 33 | end type my_sweeper_t 34 | 35 | contains 36 | !> Routine to initialize tmp array for local storage 37 | subroutine initialize_tmp(this) 38 | class(my_sweeper_t), intent(inout) :: this 39 | 40 | integer :: istat 41 | allocate(this%tmp(this%nx,this%nx),STAT=istat) 42 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 43 | end subroutine initialize_tmp 44 | 45 | 46 | ! The rest of the stuff is dimension independent 47 | include 'sweeper_include.f90' 48 | 49 | 50 | 51 | end module pf_my_sweeper 52 | 53 | 54 | -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/src/sweeper_3d.f90: -------------------------------------------------------------------------------- 1 | ! MODULE: pf_my_sweeper 2 | ! IMEX Sweeper for 3-D example in real space: 3 | module pf_my_sweeper 4 | use pf_mod_dtype 5 | use pf_mod_ndarray 6 | use pf_mod_imex_sweeper 7 | use pf_mod_fftpackage 8 | use pf_mod_solutions 9 | use pf_mod_rutils 10 | use pf_mod_fftops 11 | implicit none 12 | 13 | !> extend the IMEX sweeper 14 | type, extends(pf_imex_sweeper_t) :: my_sweeper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | real(pfdp), allocatable :: tmp(:,:,:) ! temp space for feval 20 | 21 | real(pfdp), pointer :: p_tmp(:,:,:) ! Useful pointer 22 | 23 | ! Useful for making f_eval and f_comp generic 24 | class(pf_ndarray_t), pointer :: f_encap,rhs_encap,y_encap 25 | real(pfdp), pointer :: yvec(:,:,:), rhsvec(:,:,:), fvec(:,:,:) 26 | 27 | contains 28 | 29 | procedure :: f_eval ! Computes the advection and diffusion terms 30 | procedure :: f_comp ! Computes the advection and diffusion terms 31 | procedure :: initialize 32 | procedure :: initialize_tmp 33 | procedure :: destroy 34 | end type my_sweeper_t 35 | 36 | contains 37 | 38 | !> Routine to initialize tmp array for local storage 39 | subroutine initialize_tmp(this) 40 | class(my_sweeper_t), intent(inout) :: this 41 | 42 | integer :: istat 43 | allocate(this%tmp(this%nx,this%nx,this%nx),STAT=istat) 44 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 45 | end subroutine initialize_tmp 46 | 47 | 48 | ! The rest of the stuff is dimension independent 49 | include 'sweeper_include.f90' 50 | 51 | 52 | 53 | end module pf_my_sweeper 54 | 55 | 56 | -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/test_1d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 2 22 | nsweeps= 1 23 | 24 | save_errors=TRUE 25 | 26 | / 27 | 28 | ! Now define the local variables you need 29 | &PARAMS 30 | 31 | nx = 16 32 32 | nu = 0.01 33 | a = 1.0 34 | b = -1.0 35 | c = -0.5 36 | 37 | Lx=6.28318530717958647692528676655900576839433879875021 38 | 39 | Tfin = 0.25 40 | nsteps = 8 41 | eq_type = 1 42 | ic_type = 1 43 | 44 | ! controls splitting (1 treats u_xx implicit and u_x expliciity, 2 treats u_xx and u_x exponentially) 45 | splitting = 1 46 | 47 | / 48 | -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/test_2d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D burgers 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 10 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 20 | 21 | nsweeps_pred= 1 22 | nsweeps= 1 23 | save_residuals=.false. 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 32 64 31 | nu = 0.0 32 | 33 | Tfin = 0.125 34 | nsteps = 16 35 | eq_type = 2 36 | ic_type = 1 37 | 38 | ! controls splitting (1 treats u_xx exponentially and u_x implicitly, 2 treats u_xx and u_x exponentially) 39 | splitting = 1 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/Ndarray/IMEX_sweeper/test_3d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 2 22 | nsweeps= 1 23 | 24 | save_errors=TRUE 25 | 26 | / 27 | 28 | ! Now define the local variables you need 29 | &PARAMS 30 | 31 | nx = 16 32 32 | nu = 0.01 33 | a = 1.0 34 | b = -1.0 35 | c = -0.5 36 | 37 | Lx=6.28318530717958647692528676655900576839433879875021 38 | 39 | Tfin = 0.25 40 | nsteps = 8 41 | eq_type = 1 42 | ic_type = 1 43 | 44 | ! controls splitting (1 treats u_xx implicit and u_x expliciity, 2 treats u_xx and u_x exponentially) 45 | splitting = 1 46 | 47 | / 48 | -------------------------------------------------------------------------------- /test/Ndarray/Make.package: -------------------------------------------------------------------------------- 1 | # Include the standard 2 | FSRC += src/probin.f90 src/utils_$(DIM)d.f90 src/dim_$(DIM)d.f90 3 | 4 | # Choose the main and level to include 5 | ifeq ($(DO_RK),TRUE) 6 | FSRC += src/main_rk.f90 src/hooks_rk.f90 src/level_rk.f90 7 | else 8 | FSRC += src/main.f90 src/hooks.f90 src/level.f90 9 | endif 10 | ifeq ($(DO_EXP),TRUE) 11 | FSRC += src/phi_mod.f90 12 | endif 13 | 14 | build/main.o : ../src/main.f90 build/probin.o build/hooks.o build/level.o build/sweeper_$(DIM)d.o build/utils_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 15 | 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 16 | build/probin.o :../src/probin.f90 build/dim_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 17 | build/hooks.o : ../src/hooks.f90 build/sweeper_$(DIM)d.o build/probin.o build/utils_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 18 | build/level.o : ../src/level.f90 build/sweeper_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 19 | build/utils_$(DIM)d.o : ../src/utils_$(DIM)d.f90 build/probin.o 20 | #build/fftopps_$(DIM)d.o : ../src/fftops_$(DIM)d.f90 build/probin.o 21 | build/dim_$(DIM)d.o : ../src/dim_$(DIM)d.f90 22 | build/phi_mod.o : ../src/phi_mod.f90 23 | build/level_rk.o : ../src/level_rk.f90 build/stepper_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 24 | build/hooks_rk.o : ../src/hooks_rk.f90 build/stepper_$(DIM)d.o build/utils_$(DIM)d.o 25 | 26 | -------------------------------------------------------------------------------- /test/Ndarray/src/dim_1d.f90: -------------------------------------------------------------------------------- 1 | module pf_mod_dim 2 | 3 | implicit none 4 | contains 5 | function echo_dim() result(N) 6 | integer :: N 7 | N=1 8 | end function echo_dim 9 | 10 | end module pf_mod_dim 11 | 12 | -------------------------------------------------------------------------------- /test/Ndarray/src/dim_2d.f90: -------------------------------------------------------------------------------- 1 | module pf_mod_dim 2 | 3 | implicit none 4 | contains 5 | function echo_dim() result(N) 6 | integer :: N 7 | N=2 8 | end function echo_dim 9 | 10 | end module pf_mod_dim 11 | -------------------------------------------------------------------------------- /test/Ndarray/src/dim_3d.f90: -------------------------------------------------------------------------------- 1 | module pf_mod_dim 2 | 3 | implicit none 4 | contains 5 | function echo_dim() result(N) 6 | integer :: N 7 | N=3 8 | end function echo_dim 9 | 10 | end module pf_mod_dim 11 | -------------------------------------------------------------------------------- /test/Ndarray/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pf_mod_dtype 7 | use pf_mod_ndarray 8 | use pf_mod_rutils 9 | implicit none 10 | contains 11 | 12 | !> Output the error and residual in the solution 13 | subroutine echo_error(pf, level_index) 14 | use probin, only: grid_size 15 | use pf_my_sweeper, only: my_sweeper_t, as_my_sweeper 16 | type(pf_pfasst_t), intent(inout) :: pf 17 | integer, intent(in) :: level_index 18 | 19 | class(my_sweeper_t), pointer :: sweeper 20 | real(pfdp) :: maxerr,t 21 | type(pf_ndarray_t) :: y_ex !< the initial condition 22 | 23 | call ndarray_build(y_ex, pf%levels(level_index)%lev_shape) 24 | sweeper => as_my_sweeper(pf%levels(level_index)%ulevel%sweeper) 25 | 26 | 27 | !> compute the exact solution 28 | t=pf%state%t0+pf%state%dt 29 | call exact(sweeper%fft_tool,t, y_ex) 30 | 31 | !> compute error 32 | call y_ex%axpy(-1.0d0,pf%levels(level_index)%qend) 33 | 34 | !> compute error 35 | maxerr = y_ex%norm() 36 | print '("error: time: ", f8.4," step: ",i3.3," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," resid: ",es14.7," deltaq0: ",es14.7)', & 37 | t,pf%state%step+1, pf%rank, pf%state%iter,level_index,maxerr,pf%levels(level_index)%residual,pf%levels(level_index)%max_delta_q0 38 | 39 | 40 | call flush(6) 41 | 42 | call ndarray_destroy(y_ex) 43 | 44 | 45 | call pf_set_error(pf,level_index,maxerr) 46 | end subroutine echo_error 47 | 48 | end module hooks 49 | -------------------------------------------------------------------------------- /test/Ndarray/src/hooks_rk.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pf_mod_dtype 7 | use pf_mod_ndarray 8 | use pf_mod_rutils 9 | implicit none 10 | contains 11 | 12 | !> Output the error and residual in the solution 13 | subroutine echo_error(pf, level_index) 14 | use probin, only: grid_size 15 | use pf_my_stepper, only: my_stepper_t, as_my_stepper 16 | type(pf_pfasst_t), intent(inout) :: pf 17 | integer, intent(in) :: level_index 18 | 19 | class(my_stepper_t), pointer :: stepper 20 | real(pfdp) :: maxerr,t 21 | type(pf_ndarray_t) :: y_ex !< the initial condition 22 | 23 | call ndarray_build(y_ex, pf%levels(level_index)%lev_shape) 24 | stepper => as_my_stepper(pf%levels(level_index)%ulevel%stepper) 25 | 26 | 27 | !> compute the exact solution 28 | t=pf%state%t0+pf%state%dt 29 | call exact(stepper%fft_tool,t, y_ex) 30 | 31 | !> compute error 32 | call y_ex%axpy(-1.0d0,pf%levels(level_index)%qend) 33 | 34 | !> compute error 35 | maxerr = y_ex%norm() 36 | print '("error: time: ", f8.4," step: ",i3.3," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," resid: ",es14.7," deltaq0: ",es14.7)', & 37 | t,pf%state%step+1, pf%rank, pf%state%iter,level_index,maxerr,pf%levels(level_index)%residual,pf%levels(level_index)%max_delta_q0 38 | 39 | 40 | call flush(6) 41 | 42 | call ndarray_destroy(y_ex) 43 | 44 | 45 | 46 | end subroutine echo_error 47 | 48 | end module hooks 49 | -------------------------------------------------------------------------------- /test/imk/.depend: -------------------------------------------------------------------------------- 1 | ./build/probin.o : src/probin.f90 2 | ./build/factory.o : src/factory.f90 3 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o ./build/utils.o ./build/factory.o 4 | ./build/level.o : src/level.f90 ./build/utils.o ./build/factory.o 5 | ./build/main.o : src/main.f90 ./build/utils.o ./build/hooks.o ./build/level.o ./build/sweeper.o ./build/factory.o ./build/probin.o 6 | ./build/hooks.o : src/hooks.f90 ./build/probin.o ./build/sweeper.o ./build/factory.o 7 | ./build/utils.o : src/utils.f90 ./build/factory.o ./build/probin.o 8 | -------------------------------------------------------------------------------- /test/imk/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for pfasst-nwchem example. 2 | LIBPFASST = ../.. 3 | BUILDDIR = build 4 | 5 | EXE = main.exe 6 | 7 | include $(LIBPFASST)/Makefile.defaults 8 | 9 | FSRC = probin.f90 factory.f90 sweeper.f90 level.f90 main.f90 hooks.f90 utils.f90 10 | 11 | OBJ = $(addprefix $(BUILDDIR)/,$(FSRC:.f90=.o)) 12 | 13 | FFLAGS += -I$(LIBPFASST)/include 14 | LDFLAGS += -lopenblas -llapack 15 | 16 | all: $(EXE) 17 | 18 | VPATHS = src 19 | 20 | include $(LIBPFASST)/Makefile.rules 21 | 22 | 23 | include $(PWD)/.depend 24 | main.exe : $(LIBPFASST)/lib/libpfasst.a 25 | -------------------------------------------------------------------------------- /test/imk/facke.nml: -------------------------------------------------------------------------------- 1 | &pf_params 2 | nlevels = 2 3 | niters = 20 4 | nnodes = 3 5 5 | nsweeps_pred =1 1 6 | nsweeps = 1 1 7 | qtype = 1 8 | abs_res_tol = 1e-13 9 | rel_res_tol = 0e-13 10 | pipeline_pred = .true. 11 | pfasst_pred = .true. 12 | vcycle = .true. 13 | / 14 | 15 | ¶ms 16 | Nprob=2 17 | nterms=2 12 18 | fbase = "./output" 19 | tfin = 0.05 20 | nsteps = 32 21 | exptol = 1.d-15 22 | nparticles = 20 23 | save_solutions = .true. 24 | toda_periodic = .true. 25 | use_sdc = .true. 26 | Znuc=0.5 27 | E0=0.05 28 | / 29 | -------------------------------------------------------------------------------- /test/imk/facke_multi.nml: -------------------------------------------------------------------------------- 1 | &pf_params 2 | nlevels = 2 3 | niters = 20 4 | nnodes = 3 5 5 | nsweeps_pred = 1 1 6 | nsweeps = 1 1 7 | qtype = 1 8 | abs_res_tol = 1e-12 9 | rel_res_tol = 1e-12 10 | pipeline_pred = .true. 11 | pfasst_pred = .true. 12 | vcycle = .true. 13 | / 14 | 15 | ¶ms 16 | Nprob=2 17 | nterms=3 12 18 | fbase = "./output" 19 | tfin = 0.05 20 | nsteps = 128 21 | exptol = 1.d-15 22 | nparticles = 20 23 | save_solutions = .true. 24 | toda_periodic = .true. 25 | use_sdc = .false. 26 | Znuc=0.1 27 | E0=0.01 28 | / 29 | -------------------------------------------------------------------------------- /test/imk/probin.nml: -------------------------------------------------------------------------------- 1 | &pf_params 2 | nlevels = 3 3 | niters = 30 4 | nnodes = 3 3 3 5 | nsweeps_pred = 1 1 1 6 | nsweeps = 1 1 1 7 | qtype = 1 8 | abs_res_tol = 1e-12 9 | rel_res_tol = 1e-12 10 | pipeline_pred = .true. 11 | pfasst_pred = .true. 12 | vcycle = .false. 13 | / 14 | 15 | ¶ms 16 | fbase = "/home/minion/Sync/Codes/PFASST/libpfasst/test/imk/output" 17 | nterms = 3 3 3 18 | tfin = 1.0 19 | nsteps = 128 20 | exptol = 1.d-15 21 | nparticles = 11 22 | save_solutions = .false. 23 | toda_periodic = .true. 24 | use_sdc = .true. 25 | rk = .false. 26 | mkrk = .false. 27 | / 28 | -------------------------------------------------------------------------------- /test/imk/src/level.f90: -------------------------------------------------------------------------------- 1 | !------------------------------------------------------------------------------- 2 | ! Copyright (c) 2017, Brandon Krull. All rights reserved. 3 | !-------------------------------------------------------------------------------- 4 | ! MODULE: pf_my_level 5 | ! !> @author 6 | !> Brandon Krull, Berkeley Lab 7 | ! 8 | ! Description: 9 | !> This module extend the abstract level 10 | module pf_my_level 11 | use pf_mod_dtype 12 | use pf_mod_imk 13 | use mod_zmkpair 14 | use utils 15 | 16 | implicit none 17 | 18 | external :: zgemm 19 | 20 | type, extends(pf_user_level_t) :: imk_context 21 | contains 22 | procedure :: restrict => restrict 23 | procedure :: interpolate => interpolate 24 | end type imk_context 25 | 26 | 27 | contains 28 | 29 | 30 | subroutine restrict(this, f_lev, c_lev, f_vec, c_vec, t, flags) 31 | class(imk_context), intent(inout) :: this 32 | class(pf_level_t), intent(inout) :: f_lev, c_lev ! fine and coarse levels 33 | class(pf_encap_t), intent(inout) :: f_vec, c_vec ! fine and coarse vectors 34 | real(pfdp), intent(in ) :: t 35 | integer, intent(in), optional :: flags 36 | 37 | class(zmkpair), pointer :: f, g 38 | f => cast_as_zmkpair(f_vec) 39 | g => cast_as_zmkpair(c_vec) 40 | 41 | g%array = f%array 42 | g%y = f%y 43 | end subroutine restrict 44 | 45 | subroutine interpolate(this, f_lev, c_lev, f_vec, c_vec, t, flags) 46 | class(imk_context), intent(inout) :: this 47 | class(pf_level_t), intent(inout) :: f_lev, c_lev ! fine and coarse levels 48 | class(pf_encap_t), intent(inout) :: f_vec, c_vec ! fine and coarse vectors 49 | real(pfdp), intent(in ) :: t 50 | integer, intent(in), optional :: flags 51 | 52 | class(zmkpair), pointer :: f, g 53 | f => cast_as_zmkpair(f_vec) 54 | g => cast_as_zmkpair(c_vec) 55 | 56 | f%array = g%array 57 | f%y = g%y 58 | end subroutine interpolate 59 | 60 | end module pf_my_level 61 | -------------------------------------------------------------------------------- /test/imk/toda.nml: -------------------------------------------------------------------------------- 1 | 2 | &PF_PARAMS 3 | nlevels = 2 4 | niters = 30 5 | nnodes = 3 5 6 | nsweeps_pred = 1 1 7 | nsweeps = 1 1 8 | qtype = 1 9 | abs_res_tol = 1.0e-14 10 | rel_res_tol = 1.0e-14 11 | pipeline_pred = .false. 12 | PFASST_pred = .true. 13 | vcycle = .true. 14 | debug = .false. 15 | / 16 | 17 | &PARAMS 18 | nprob=1 19 | fbase = "output" 20 | nterms = 3 12 21 | Tfin = 3.0 22 | nsteps = 48 23 | exptol = 1.d-15 24 | nparticles = 11 25 | 26 | toda_periodic = .true. 27 | use_sdc = .true. 28 | 29 | / 30 | -------------------------------------------------------------------------------- /test/magpicard/.depend: -------------------------------------------------------------------------------- 1 | ./build/probin.o : src/probin.f90 2 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o ./build/utils.o 3 | ./build/main.o : src/main.f90 ./build/hooks.o ./build/sweeper.o ./build/probin.o 4 | ./build/hooks.o : src/hooks.f90 ./build/probin.o ./build/sweeper.o 5 | ./build/utils.o : src/utils.f90 ./build/probin.o 6 | -------------------------------------------------------------------------------- /test/magpicard/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for magpicard test 2 | LIBPFASST = ../.. 3 | BUILDDIR = build 4 | 5 | EXE = main.exe 6 | 7 | include $(LIBPFASST)/Makefile.defaults 8 | 9 | FSRC = probin.f90 sweeper.f90 main.f90 hooks.f90 utils.f90 10 | 11 | OBJ = $(addprefix $(BUILDDIR)/,$(FSRC:.f90=.o)) 12 | 13 | FFLAGS += -I$(LIBPFASST)/include 14 | LDFLAGS += -L$(LIBPFASST)/lib -lpfasst -lopenblas -llapack 15 | 16 | VPATHS = src 17 | include $(LIBPFASST)/Makefile.rules 18 | all: $(EXE) 19 | 20 | include $(PWD)/.depend 21 | main.exe : $(LIBPFASST)/lib/libpfasst.a 22 | -------------------------------------------------------------------------------- /test/magpicard/facke.nml: -------------------------------------------------------------------------------- 1 | &pf_params 2 | nlevels = 1 3 | niters = 50 4 | nnodes = 3 5 | nsweeps_pred = 1 6 | nsweeps = 1 7 | qtype = 5 8 | abs_res_tol = 1e-13 9 | rel_res_tol = 1e-13 10 | pipeline_pred = .true. 11 | pfasst_pred = .true. 12 | vcycle = .false. 13 | / 14 | 15 | ¶ms 16 | Nprob=2 17 | fbase = "./output02" 18 | magnus_order = 3 19 | tfin = 0.05 20 | nsteps = 128 21 | exptol = 1.d-15 22 | nparticles = 20 23 | save_solutions = .false. 24 | toda_periodic = .true. 25 | use_sdc = .false. 26 | Znuc=0.5 27 | E0=0.05 28 | / 29 | -------------------------------------------------------------------------------- /test/magpicard/final_solution: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/test/magpicard/final_solution -------------------------------------------------------------------------------- /test/magpicard/movie.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import matplotlib.animation as animation 3 | import numpy as np 4 | from subprocess import call 5 | from pf.pfasst import PFASST, Experiment, Params 6 | 7 | def init(): 8 | lines[0].set_data([], []) 9 | lines[1].set_data([], []) 10 | lines[2].set_data([], []) 11 | 12 | return lines 13 | 14 | def animate(i): 15 | # for j, line in enumerate(lines): 16 | # line.set_data(np.sin(q[i:i+10, j]), np.cos(q[i:i+10, j])) 17 | 18 | thisx = [0.75*np.sin(q[i, j])-0.02 for j in range(nparticles)] 19 | thisy = [0.75*np.cos(q[i, j]) for j in range(nparticles)] 20 | lines[0].set_data(thisx, thisy) 21 | 22 | histx.append([0.75*np.sin(q[i, j])-0.02 for j in [0]])#, nparticles-1]]) 23 | histy.append([0.75*np.cos(q[i, j]) for j in [0]])#, nparticles-1]]) 24 | lines[1].set_data(histx, histy) 25 | 26 | # histx.append([0.5*np.sin(q[i, j])-0.05 for j in [0]])#, nparticles-1]]) 27 | # histy.append([0.5*np.cos(q[i, j])-0.05 for j in [0]])#, nparticles-1]]) 28 | lines[2].set_data(histx, histy) 29 | return lines 30 | # return lines[0], lines[1], lines[2], lines[3], \ 31 | # lines[4], lines[5], lines[6], lines[7], \ 32 | # lines[8], lines[9], lines[10], time_text 33 | 34 | 35 | 36 | if __name__ == '__main__': 37 | exe = '/home/bkrull/devel/pfasst-nwchem/libpfasst/tests/toda/main.exe' 38 | exp = Experiment() 39 | cmap = plt.cm.Dark2.colors*2 40 | 41 | nsteps = 4096 42 | nparticles = 11 43 | periodic = True 44 | tfinal = 25.0 45 | 46 | dt = tfinal/nsteps 47 | 48 | params = Params(tfinal=tfinal, nodes=[3], magnus=[2], tasks=8, 49 | sweeps_pred=[2], 50 | particles=nparticles, periodic=periodic, tolerance=1e-10, 51 | iterations=20, nsteps=nsteps, solutions=True) 52 | toda = PFASST(exe, params) 53 | 54 | results = toda.run()[0] 55 | 56 | q, p = toda.get_toda_solutions(results) 57 | 58 | fig, ax = plt.subplots(figsize=(3,3), dpi=300) 59 | lines = [ax.plot([],[], marker='o', color=cmap[0])[0], 60 | ax.plot([],[], lw=1, color='red')[0], 61 | ax.plot([],[], lw=1, color='black')[0]] 62 | histx = [] 63 | histy = [] 64 | 65 | ax.set_xlim(-1, 1) 66 | ax.set_ylim(-1, 1) 67 | ax.axis('off') 68 | ax.grid(); 69 | 70 | ani = animation.FuncAnimation(fig, animate, np.arange(0, nsteps), \ 71 | interval=5, blit=True, init_func=init) 72 | 73 | ani.save('input.mp4', fps=60) 74 | #plt.show() 75 | 76 | #convert_to_gif = 'ffmpeg -i input.mp4 -r 10 -f image2pipe -vcodec ppm - | ' + 'convert -delay 5 -loop 0 - output.gif' 77 | 78 | #convert_to_gif = convert_to_gif.split() 79 | 80 | #shrink_gif = 'gifsicle output.gif --resize 300x300 > output300.gif'.split() 81 | 82 | #call(convert_to_gif) 83 | #call(shrink_gif, shell=True) 84 | -------------------------------------------------------------------------------- /test/magpicard/plotchain.m: -------------------------------------------------------------------------------- 1 | function fin_sol=plotchain(Nsteps,Np,fname) 2 | %Nsteps=64; 3 | %Np=20; 4 | sol=zeros(2,Nsteps,Np,Np); 5 | F=zeros(2,Nsteps,Np,Np); 6 | % Read the solution 7 | for k = 1:Nsteps 8 | file=strcat(fname,'/P_step_',sprintf("%5.5i ",k)); 9 | D=load(file); 10 | sol(1,k,:,:)=reshape(D(1,:),Np,Np); 11 | sol(2,k,:,:)=reshape(D(2,:),Np,Np); 12 | end 13 | 14 | % Read the Function values (Facke matrix) 15 | for k = 1:Nsteps 16 | file=strcat(fname,'/F_step_',sprintf("%5.5i ",k)); 17 | D=load(file); 18 | F(1,k,:,:)=reshape(D(1,:),Np,Np); 19 | F(2,k,:,:)=reshape(D(2,:),Np,Np); 20 | end 21 | 22 | figure(10); clf 23 | subplot(2,1,1) 24 | for j = 1:Np 25 | Dg=squeeze(sol(1,:,j,j)); 26 | plot(Dg); hold on; 27 | end 28 | hold off; 29 | subplot(2,1,2); 30 | %figure(2); clf 31 | for j = 1:Np-1 32 | Dg=squeeze(sol(2,:,j+1,j)); 33 | plot(Dg); hold on; 34 | end 35 | hold off; 36 | % $$$ figure(3); clf 37 | % $$$ for j = 1:Nsteps 38 | % $$$ trce(j)=trace(squeeze(sol(1,j,:,:))); 39 | % $$$ end 40 | % $$$ semilogy(abs(trce-trce(1))) 41 | % $$$ hold off; 42 | 43 | 44 | fin_sol=diag(squeeze(sol(1,end,:,:))); -------------------------------------------------------------------------------- /test/magpicard/probin.nml: -------------------------------------------------------------------------------- 1 | &pf_params 2 | nlevels = 1 3 | niters = 8 4 | nnodes = 3 3 5 | nsweeps_pred = 1 1 6 | nsweeps = 1 1 7 | qtype = 5 8 | abs_res_tol = 0e-13 9 | rel_res_tol = 0e-13 10 | pipeline_pred = .true. 11 | pfasst_pred = .true. 12 | vcycle = .false. 13 | / 14 | 15 | ¶ms 16 | fbase = "/home/minion/Sync/Codes/PFASST/pfasst-dev/chain/output" 17 | magnus_order = 3 18 | tfin = 0.25 19 | nsteps = 32 20 | exptol = 1.d-15 21 | nparticles = 20 22 | toda_periodic = .true. 23 | use_sdc = .false. 24 | Znuc=1.0 25 | E0=0.05 26 | / 27 | -------------------------------------------------------------------------------- /test/magpicard/run1.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | mpirun -n 1 ./main.exe facke.nml nsteps=64 abs_res_tol=1e-4 magnus_order=1 outdir=\" ./test_p1_n64_o1 \" 3 | mpirun -n 1 ./main.exe facke.nml nsteps=64 abs_res_tol=1e-5 magnus_order=2 outdir=\"./test_p1_n64_o2\" 4 | mpirun -n 1 ./main.exe facke.nml nsteps=64 abs_res_tol=1e-6 magnus_order=3 outdir=\"./test_p1_n64_o3\" 5 | mpirun -n 1 ./main.exe facke.nml nsteps=128 abs_res_tol=1e-4 magnus_order=1 outdir=\"./test_p1_n128_o1\" 6 | mpirun -n 1 ./main.exe facke.nml nsteps=128 abs_res_tol=1e-6 magnus_order=2 outdir=\"./test_p1_n128_o2\" 7 | mpirun -n 1 ./main.exe facke.nml nsteps=128 abs_res_tol=1e-8 magnus_order=3 outdir=\"./test_p1_n128_o3\" 8 | mpirun -n 1 ./main.exe facke.nml nsteps=256 abs_res_tol=1e-5 magnus_order=1 outdir=\"./test_p1_n256_o1\" 9 | mpirun -n 1 ./main.exe facke.nml nsteps=256 abs_res_tol=1e-7 magnus_order=2 outdir=\"./test_p1_n256_o2\" 10 | mpirun -n 1 ./main.exe facke.nml nsteps=256 abs_res_tol=1e-10 magnus_order=3 outdir=\"./test_p1_n256_o3\" 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/magpicard/toda.nml: -------------------------------------------------------------------------------- 1 | &pf_params 2 | nlevels = 1 3 | niters = 20 4 | nnodes = 3 5 | nsweeps_pred = 1 6 | nsweeps = 1 7 | qtype = 5 8 | abs_res_tol = 1e-12 9 | rel_res_tol = 1e-12 10 | pipeline_pred = .true. 11 | pfasst_pred = .true. 12 | vcycle = .false. 13 | / 14 | 15 | ¶ms 16 | Nprob=1 17 | fbase = "output" 18 | magnus_order = 3 19 | tfin = 10.0 20 | nsteps = 128 21 | exptol = 1.d-15 22 | nparticles = 11 23 | toda_periodic = .true. 24 | use_sdc = .true. 25 | / 26 | -------------------------------------------------------------------------------- /test/nagumo/.depend: -------------------------------------------------------------------------------- 1 | ./build/feval.o : src/feval.f90 ./build/solutions.o ./build/probin.o 2 | ./build/hooks.o : src/hooks.f90 ./build/solutions.o ./build/probin.o 3 | ./build/solutions.o : src/solutions.f90 ./build/probin.o 4 | ./build/probin.o : src/probin.f90 5 | ./build/pf_optimization.o : src/pf_optimization.f90 ./build/solutions.o ./build/probin.o ./build/feval.o ./build/level.o 6 | ./build/main_split.o : src/main_split.f90 ./build/solutions.o ./build/probin.o ./build/hooks.o ./build/feval.o ./build/level.o ./build/pf_optimization.o 7 | ./build/level.o : src/level.f90 ./build/feval.o ./build/solutions.o ./build/probin.o 8 | -------------------------------------------------------------------------------- /test/nagumo/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for nagumo example. 3 | # 4 | 5 | LIBPFASST ?= ../.. 6 | BUILDDIR = build 7 | 8 | EXE = main_split.exe 9 | 10 | include $(LIBPFASST)/Makefile.defaults 11 | 12 | 13 | FSRC = feval.f90 hooks.f90 solutions.f90 probin.f90 pf_optimization.f90 main_split.f90 level.f90 14 | CSRC = numpy.c 15 | 16 | OBJ = $(addprefix $(BUILDDIR)/,$(FSRC:.f90=.o) $(CSRC:.c=.o)) 17 | FFLAGS += -I$(LIBPFASST)/include 18 | 19 | all: $(EXE) 20 | 21 | VPATHS = src 22 | 23 | include $(LIBPFASST)/Makefile.rules 24 | # 25 | # dependencies 26 | # 27 | include $(PWD)/.depend 28 | -------------------------------------------------------------------------------- /test/nagumo/pfasst.nml: -------------------------------------------------------------------------------- 1 | &PF_PARAMS 2 | ! These are internal pfasst variables that must be set 3 | nlevels = 3 4 | 5 | ! These are internal pfasst variables that can be reset 6 | niters = 250 ! default is 5 7 | 8 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 9 | qtype = 1 10 | 11 | 12 | ! optional variables to control termination (defaults are 0.0) 13 | abs_res_tol = 1e-11 14 | rel_res_tol = 1e-11 15 | 16 | PFASST_pred = .false. 17 | 18 | 19 | / 20 | -------------------------------------------------------------------------------- /test/nagumo/probin.nml: -------------------------------------------------------------------------------- 1 | &PF_PARAMS 2 | ! These are internal pfasst variables that must be set 3 | nlevels = 3 4 | 5 | ! These are internal pfasst variables that can be reset 6 | niters = 250 ! default is 5 7 | 8 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 9 | qtype = 1 10 | 11 | 12 | ! optional variables to control termination (defaults are 0.0) 13 | abs_res_tol = 1e-11 14 | rel_res_tol = 1e-11 15 | 16 | PFASST_pred = .false. 17 | 18 | save_residuals = .false. 19 | 20 | / 21 | 22 | 23 | &PARAMS 24 | nprob = 0 25 | ndim = 1 26 | 27 | ! Nagumo 28 | nsteps = 32 29 | 30 | poutmod = 1 31 | v = 0.0 32 | nu = 1.0 33 | 34 | nvars = 32 64 128 35 | nnodes = 3 5 9 36 | 37 | sizex = 20.0 38 | dt = 0.1 39 | Tfin = 5 40 | 41 | alpha = 1e-6 42 | max_opt_iter = 200 43 | tol_grad = 1e-6 44 | tol_obj = 1e-6 45 | 46 | 47 | do_imex = 1 48 | warmstart = 0 49 | do_mixed = 0 50 | logfile = "progress.log" 51 | 52 | fbase = "pfasst_V" 53 | 54 | 55 | / 56 | -------------------------------------------------------------------------------- /test/nagumo/src/numpy.c: -------------------------------------------------------------------------------- 1 | /* Dump routines for the NumPy binary format */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define BUFLEN 256 10 | 11 | void ndarray_mkdir(char *dname, int dlen) 12 | { 13 | dname[dlen] = 0; 14 | mkdir(dname, 0755); 15 | } 16 | 17 | void ndarray_dump_numpy(char *dname, char *fname, char endian[5], int dim, int *shape, int nvars, double *array) 18 | { 19 | unsigned short i, len, pad; 20 | FILE* fp; 21 | char errmsg[BUFLEN]; 22 | char header[256*256]; 23 | char buf[128], shp[BUFLEN]; 24 | 25 | /* open output file */ 26 | snprintf(buf, BUFLEN, "%s/%s", dname, fname); 27 | fp = fopen(buf, "wb"); 28 | if (fp == NULL) { 29 | snprintf(errmsg, BUFLEN, "WARNING: Unable to create npy file (%s)", buf); 30 | perror(errmsg); 31 | return; 32 | } 33 | 34 | /* build shape string */ 35 | shp[0] = 0; 36 | for (i=0; i 256*254) { 46 | snprintf(errmsg, BUFLEN, "WARNING: Unable to create npy file (%s)", fname); 47 | fprintf(stderr, "%s: NumPy header too long.\n", errmsg); 48 | return; 49 | } 50 | 51 | pad = 16 - (8 + len + 1) % 16; 52 | for (i=len; i= 9.0 .and. x <= 11.0 ) q0%yflatarray(i) = 1.2*sqrt(3.0) 23 | ! if( x < 10.0 ) q0%yflatarray(i) = -1.2*sqrt(3.0) 24 | ! if( x > 10.0 ) q0%yflatarray(i) = 1.2*sqrt(3.0) 25 | end do 26 | 27 | !print *, 'initial', t0, tend 28 | !call exact_y(t0, size(q0%yflatarray), q0%yflatarray) 29 | q0%pflatarray = 0.0_pfdp ! for adjoint, all zero terminal condition 30 | !call exact_p(tend, size(q0%pflatarray), q0%pflatarray) 31 | 32 | end subroutine initial 33 | 34 | 35 | end module solutions 36 | -------------------------------------------------------------------------------- /test/run_tests.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | 4 | if ! [ -x "$(command -v pytest)" ]; then 5 | echo 'Error: 'pytest' is not installed.' >&2 6 | exit 1 7 | fi 8 | 9 | 10 | # Get path to PFASS root directory 11 | PFASSTDIR="$(dirname $0)/.." 12 | 13 | # Convert to absolute path 14 | PFASSTDIR="$(realpath $PFASSTDIR)" 15 | 16 | TESTDIR="$PFASSTDIR/test" 17 | 18 | echo "Using PFASSTDIR=$PFASSTDIR" 19 | echo "Using TESTDIR=$TESTDIR" 20 | 21 | 22 | # Change to test directory 23 | cd "$TESTDIR" 24 | test -h "pf" || ln -s "$PFASSTDIR/pf" 25 | 26 | cd "$TESTDIR/magpicard" 27 | test -h "pf" || ln -s "$PFASSTDIR/pf" 28 | 29 | cd "$TESTDIR/imk" 30 | test -h "pf" || ln -s "$PFASSTDIR/pf" 31 | 32 | echo "Building libpfasst" 33 | cd "$PFASSTDIR" 34 | make clean 35 | make -j || exit 1 36 | 37 | echo "Building magpicard" 38 | cd "$TESTDIR/magpicard" 39 | make clean 40 | make -j || exit 1 41 | 42 | echo "Building imk" 43 | cd "$TESTDIR/imk" 44 | make clean 45 | OMP=y make -j || exit 1 46 | 47 | echo "Building nagumo" 48 | cd "$TESTDIR/nagumo" 49 | make clean 50 | make -j || exit 1 51 | 52 | echo "Building EXP 1d" 53 | cd "$TESTDIR/EXP_adv_diff_fft/1d" 54 | make clean 55 | make -j || exit 1 56 | 57 | echo "Building ad 1d" 58 | cd "$TESTDIR/adv_diff_fft/1d" 59 | make clean 60 | make -j || exit 1 61 | 62 | echo "Building ad 2d" 63 | cd "$TESTDIR/adv_diff_fft/2d" 64 | make clean 65 | make -j 66 | 67 | 68 | cd "$PFASSTDIR" 69 | pytest 70 | -------------------------------------------------------------------------------- /test/test_encaps.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | 4 | echo "Testing zNdarray encap" 5 | echo "Making ERK" 6 | cd zNdarray/ERK_stepper 7 | make USE_FFTW=FALSE 8 | make DIM=2 USE_FFTW=FALSE 9 | make DIM=3 USE_FFTW=FALSE 10 | echo "Running ERK 1-d" 11 | mpirun -n 4 ./main.1d.exe test_1d.nml 12 | echo "Running ERK 2-d" 13 | mpirun -n 4 ./main.2d.exe test_2d.nml 14 | echo "Running ERK 3-d" 15 | mpirun -n 4 ./main.3d.exe test_3d.nml 16 | echo "Making RK " 17 | cd ../RK_stepper 18 | make USE_FFTW=FALSE 19 | make DIM=2 USE_FFTW=FALSE 20 | make DIM=3 USE_FFTW=FALSE 21 | echo "Running RK 1-d" 22 | mpirun -n 4 ./main.1d.exe test_1d.nml && 23 | echo "Running RK 2-d" 24 | mpirun -n 4 ./main.2d.exe test_2d.nml 25 | echo "Running RK 3-d" 26 | mpirun -n 4 ./main.3d.exe test_3d.nml 27 | echo "Making Running IMEX SDC " 28 | cd ../IMEX_sweeper 29 | make USE_FFTW=FALSE 30 | make DIM=2 USE_FFTW=FALSE 31 | make DIM=3 USE_FFTW=FALSE 32 | echo "Running IMEX SDC 1-d" 33 | mpirun -n 4 ./main.1d.exe test_1d.nml 34 | echo "Running IMEX SDC 2-d" 35 | mpirun -n 4 ./main.2d.exe test_2d.nml 36 | echo "Running IMEX SDC 3-d" 37 | mpirun -n 4 ./main.3d.exe test_3d.nml 38 | echo "Making Running EXP SDC " 39 | cd ../EXP_sweeper 40 | make USE_FFTW=FALSE USE_PETSC=FALSE 41 | make DIM=2 USE_FFTW=FALSE USE_PETSC=FALSE 42 | make DIM=3 USE_FFTW=FALSE USE_PETSC=FALSE 43 | echo "Running EXP SDC 1-d" 44 | mpirun -n 4 ./main.1d.exe test_1d.nml 45 | echo "Running EXP SDC 2-d" 46 | mpirun -n 4 ./main.2d.exe test_2d.nml 47 | echo "Running EXP SDC 3-d" 48 | mpirun -n 4 ./main.3d.exe test_3d.nml 49 | cd ../.. 50 | echo "Testing Ndarray encap" 51 | cd Ndarray/IMEX_sweeper 52 | make USE_FFTW=FALSE 53 | make DIM=2 USE_FFTW=FALSE 54 | make DIM=3 USE_FFTW=FALSE 55 | echo "Running IMEX SDC 1-d" 56 | mpirun -n 8 ./main.1d.exe test_1d.nml 57 | echo "Running IMEX SDC 2-d" 58 | mpirun -n 4 ./main.2d.exe test_2d.nml 59 | echo "Running IMEX SDC 3-d" 60 | mpirun -n 4 ./main.3d.exe test_3d.nml 61 | 62 | -------------------------------------------------------------------------------- /test/test_imk.py: -------------------------------------------------------------------------------- 1 | import glob 2 | import pytest 3 | from os import remove, mkdir 4 | from os.path import abspath 5 | from errno import EEXIST 6 | import numpy as np 7 | from pf.pfasst import PFASST, IMKParams 8 | 9 | # defined relative to root of project 10 | home = abspath('.') 11 | base_dir = home+'/test/imk' 12 | exe = base_dir+'/main.exe' 13 | output_dir = base_dir+'/output' 14 | 15 | try: 16 | mkdir(base_dir) 17 | except OSError as exc: 18 | if exc.errno == EEXIST: 19 | pass 20 | else: 21 | raise OSError, exc.message 22 | 23 | params = IMKParams(exe=exe, nodes=[3], nterms=[2], \ 24 | nsteps=128, tfinal=1.0, \ 25 | inttype='imk', nb=False, base_dir=output_dir) 26 | 27 | ref_particle0 = 1.6125274564234153 28 | ref_particle8 = -1.7151098584854585 29 | toda = PFASST(params) 30 | 31 | def make(): 32 | tests = [] 33 | for vcycle in [True, False]: 34 | for sdc in [True, False]: 35 | for nlevels in [1, 3]: 36 | for nodes in [[3]]: 37 | for nterms in [[3]]: 38 | tests.append((nlevels, vcycle, sdc, nodes, nterms)) 39 | return tests 40 | 41 | tests = make() 42 | @pytest.mark.parametrize('levels, vcycle, sdc, nodes, nterms', 43 | tests) 44 | def test_toda(levels, vcycle, sdc, nodes, nterms): 45 | params = IMKParams(exe=exe, levels=levels, nodes=nodes*levels, nterms=nterms*levels, 46 | sweeps=[1]*levels, sweeps_pred=[1]*levels, 47 | nsteps=128, tfinal=1.0, inttype='imk', 48 | nb=False, base_dir=output_dir) 49 | 50 | toda = PFASST(params) 51 | results = toda.run()[0] 52 | final_solution = results.loc[len(results)-1, 'solution'] 53 | 54 | particle0 = final_solution[0, 0] 55 | particle8 = final_solution[7, 7] 56 | 57 | e0 = particle0 - ref_particle0 58 | e8 = particle8 - ref_particle8 59 | 60 | print particle0 61 | print e0 62 | print particle8 63 | print e8 64 | 65 | print ref_particle8 66 | 67 | e = max(e0, e8) 68 | 69 | print 'e = {}'.format(e) 70 | 71 | assert abs(e) < 1e-6 72 | -------------------------------------------------------------------------------- /test/test_magpicard.old: -------------------------------------------------------------------------------- 1 | import glob 2 | import pytest 3 | from os import remove, mkdir 4 | from os.path import abspath 5 | from errno import EEXIST 6 | import numpy as np 7 | from pf.pfasst import PFASST, MagpicardParams 8 | 9 | # defined relative to root of project 10 | home = abspath('.') 11 | exe = home+'/test/magpicard/main.exe' 12 | base_dir = home+'/test/magpicard/output' 13 | 14 | try: 15 | mkdir(base_dir) 16 | except OSError as exc: 17 | if exc.errno == EEXIST: 18 | pass 19 | else: 20 | raise OSError, exc.message 21 | 22 | params = MagpicardParams(exe=exe, nodes=[3], magnus=[2], \ 23 | nsteps=128, tfinal=1.0, iterations=15, \ 24 | nb=False, base_dir=base_dir) 25 | 26 | ref_particle0 = 1.6125274564234153 27 | ref_particle8 = -1.7151098584854585 28 | toda = PFASST(params) 29 | 30 | def cleanup(): 31 | for fname in glob.iglob(base_dir+'/*pkl'): 32 | remove(fname) 33 | 34 | def make(): 35 | tests = [] 36 | for nodes in [[3]]: 37 | for magnus in [[2], [1]]: 38 | if nodes[0] == 2 and magnus[0] == 2: continue 39 | tests.append((nodes, magnus)) 40 | 41 | return tests 42 | 43 | tests = make() 44 | @pytest.mark.parametrize('nodes, magnus', tests) 45 | def test_toda(nodes, magnus): 46 | params = MagpicardParams(exe=exe, nodes=nodes, magnus=magnus, 47 | tolerance=1e-12, 48 | nsteps=128, tfinal=1.0, iterations=30, 49 | nb=False, base_dir=base_dir) 50 | 51 | toda = PFASST(params) 52 | results = toda.run()[0] 53 | final_solution = results.loc[len(results)-1, 'solution'] 54 | 55 | particle0 = final_solution[0, 0] 56 | particle8 = final_solution[7, 7] 57 | 58 | e0 = particle0 - ref_particle0 59 | e8 = particle8 - ref_particle8 60 | 61 | print particle0 62 | print e0 63 | print particle8 64 | print e8 65 | 66 | print ref_particle8 67 | 68 | e = max(e0, e8) 69 | 70 | print 'e = {}'.format(e) 71 | 72 | assert abs(e) < 1e-5 73 | -------------------------------------------------------------------------------- /test/zNdarray/ERK_stepper/.depend: -------------------------------------------------------------------------------- 1 | ./build/phi_mod.o : src/phi_mod.f90 2 | ./build/main.o : src/main.f90 ./build/sweeper.o 3 | ./build/sweeper.o : src/sweeper.f90 4 | -------------------------------------------------------------------------------- /test/zNdarray/ERK_stepper/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Exponential RK examples 3 | # 4 | 5 | LIBPFASST ?= ../../.. 6 | DO_EXP=TRUE 7 | DO_RK=TRUE 8 | 9 | DIM=1 10 | EXE = main.$(DIM)d.exe 11 | all: $(EXE) 12 | BUILDDIR = build 13 | 14 | include $(LIBPFASST)/Makefile.defaults 15 | FSRC = src/stepper_$(DIM)d.f90 16 | 17 | include ../Make.package 18 | OBJ = $(subst src, build,$(FSRC:.f90=.o) $(CSRC:.c=.o)) 19 | 20 | FFLAGS += -I$(LIBPFASST)/include 21 | 22 | all: $(EXE) 23 | 24 | VPATHS = src:../src 25 | 26 | 27 | include $(LIBPFASST)/Makefile.rules 28 | 29 | 30 | # dependencies 31 | # 32 | 33 | main.exe : $(LIBPFASST)/lib/libpfasst.a 34 | build/stepper_$(DIM)d.o : src/stepper_$(DIM)d.f90 build/phi_mod.o build/probin.o build/utils_$(DIM)d.o src/stepper_include.f90 35 | 36 | -------------------------------------------------------------------------------- /test/zNdarray/ERK_stepper/test_1d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | 11 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 12 | qtype = 1 13 | 14 | ! optional variables to control termination (defaults are 0.0) 15 | abs_res_tol = 1.0e-10 16 | rel_res_tol = 1.0e-10 17 | 18 | nnodes = 2 2 19 | 20 | save_timings=2 21 | save_residuals=.true. 22 | save_errors=.true. 23 | use_rk_stepper=.true. 24 | outdir="nls" 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 64 64 31 | 32 | Tfin = 0.26 33 | nsteps = 32 34 | nsteps_rk = 1 16 35 | rk_order = 1 4 36 | 37 | eq_type = 3 38 | ic_type = 1 39 | 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/zNdarray/ERK_stepper/test_2d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | 11 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 12 | qtype = 1 13 | 14 | ! optional variables to control termination (defaults are 0.0) 15 | abs_res_tol = 1.0e-10 16 | rel_res_tol = 1.0e-10 17 | 18 | nnodes = 2 2 19 | 20 | save_timings=2 21 | save_residuals=.true. 22 | save_errors=.true. 23 | use_rk_stepper=.true. 24 | outdir="nls" 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 64 64 31 | 32 | Tfin = 0.26 33 | nsteps = 32 34 | nsteps_rk = 1 16 35 | rk_order = 1 4 36 | 37 | eq_type = 3 38 | ic_type = 1 39 | 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/zNdarray/ERK_stepper/test_3d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | 11 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 12 | qtype = 1 13 | 14 | ! optional variables to control termination (defaults are 0.0) 15 | abs_res_tol = 1.0e-10 16 | rel_res_tol = 1.0e-10 17 | 18 | nnodes = 2 2 19 | 20 | save_timings=2 21 | save_residuals=.true. 22 | save_errors=.true. 23 | use_rk_stepper=.true. 24 | outdir="nls" 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 16 16 31 | 32 | Tfin = 0.25 33 | nsteps = 16 34 | nsteps_rk = 1 16 35 | rk_order = 1 4 36 | 37 | eq_type = 3 38 | ic_type = 1 39 | 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/zNdarray/EXP_sweeper/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Exponential SDC examples 3 | # 4 | DIM=1 5 | LIBPFASST ?= ../../.. 6 | 7 | DO_EXP=TRUE 8 | DO_RK=FALSE 9 | EXE = main.$(DIM)d.exe 10 | all: $(EXE) 11 | BUILDDIR = build 12 | 13 | include $(LIBPFASST)/Makefile.defaults 14 | 15 | FSRC = src/sweeper_$(DIM)d.f90 16 | 17 | include ../Make.package 18 | OBJ = $(subst src, build,$(FSRC:.f90=.o) $(CSRC:.c=.o)) 19 | 20 | FFLAGS += -I$(LIBPFASST)/include 21 | 22 | VPATHS = src:../src 23 | 24 | include $(LIBPFASST)/Makefile.rules 25 | 26 | # dependencies 27 | # 28 | 29 | main.exe : $(LIBPFASST)/lib/libpfasst.a $(OBJ) 30 | build/sweeper_$(DIM)d.o : src/sweeper_$(DIM)d.f90 ./build/probin.o ./build/phi_mod.o $(LIBPFASST)/lib/libpfasst.a build/utils_$(DIM)d.o src/sweeper_include.f90 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/zNdarray/EXP_sweeper/test_1d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 1 1 1 22 | nsweeps= 1 1 1 23 | 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 32 64 31 | nu = 0.01 32 | a = 1.0 33 | b = -1.0 34 | c = -0.5 35 | 36 | Tfin = 2.0 37 | nsteps = 32 38 | eq_type = 1 39 | ic_type = 1 40 | 41 | ! controls splitting (1 treats u_xx implicit and u_x expliciity, 2 treats u_xx and u_x exponentially) 42 | splitting = 1 43 | 44 | / 45 | -------------------------------------------------------------------------------- /test/zNdarray/EXP_sweeper/test_2d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 1 1 1 22 | nsweeps= 1 1 1 23 | 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 32 64 31 | nu = 0.01 32 | a = 1.0 33 | b = -1.0 34 | c = -0.5 35 | 36 | Tfin = 2.0 37 | nsteps = 32 38 | eq_type = 1 39 | ic_type = 1 40 | 41 | ! controls splitting (1 treats u_xx implicit and u_x expliciity, 2 treats u_xx and u_x exponentially) 42 | splitting = 1 43 | 44 | / 45 | -------------------------------------------------------------------------------- /test/zNdarray/EXP_sweeper/test_3d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 1 1 1 22 | nsweeps= 1 1 1 23 | 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 8 16 31 | nu = 0.01 32 | a = 1.0 33 | b = -1.0 34 | c = -0.5 35 | 36 | Tfin = 2.0 37 | nsteps = 32 38 | eq_type = 1 39 | ic_type = 1 40 | 41 | ! controls splitting (1 treats u_xx implicit and u_x expliciity, 2 treats u_xx and u_x exponentially) 42 | splitting = 1 43 | 44 | / 45 | -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/.depend: -------------------------------------------------------------------------------- 1 | ./build/sweeper.o : src/sweeper.f90 ./build/probin.o 2 | ./build/main.o : src/main.f90 ./build/utils_1d.o ./build/probin.o ./build/hooks.o ./build/level.o ./build/sweeper.o 3 | ./build/probin.o : src/probin.f90 4 | ./build/hooks.o : src/hooks.f90 ./build/sweeper.o ./build/probin.o ./build/utils_1d.o 5 | ./build/utils_1d.o : src/utils_1d.f90 ./build/probin.o ./build/sweeper.o 6 | ./build/level.o : src/level.f90 ./build/sweeper.o 7 | -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for mpi-advection example. 3 | # 4 | DIM=1 5 | LIBPFASST ?= ../../.. 6 | 7 | EXE = main.$(DIM)d.exe 8 | all: $(EXE) 9 | BUILDDIR = build 10 | 11 | include $(LIBPFASST)/Makefile.defaults 12 | 13 | FSRC = src/sweeper_$(DIM)d.f90 14 | include ../Make.package 15 | OBJ = $(subst src, build,$(FSRC:.f90=.o) $(CSRC:.c=.o)) 16 | 17 | 18 | FFLAGS += -I$(LIBPFASST)/include 19 | 20 | 21 | VPATHS = src:../src 22 | 23 | 24 | include $(LIBPFASST)/Makefile.rules 25 | 26 | 27 | 28 | 29 | # dependencies 30 | # 31 | 32 | main.exe : $(LIBPFASST)/lib/libpfasst.a $(OBJ) 33 | build/sweeper_$(DIM)d.o : src/sweeper_$(DIM)d.f90 ./build/probin.o ./build/utils_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a src/sweeper_include.f90 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/nls_sisdc_step.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/test/zNdarray/IMEX_sweeper/nls_sisdc_step.png -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/nls_sisdc_time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libpfasst/LibPFASST/67f75a92c9cde869a778ea75c7dd21dea9d4e2ef/test/zNdarray/IMEX_sweeper/nls_sisdc_time.png -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/src/sweeper_1d.f90: -------------------------------------------------------------------------------- 1 | ! MODULE: pf_my_sweeper_ad 2 | ! IMEX Sweeper for 1-D examples 3 | module pf_my_sweeper 4 | use pf_mod_dtype 5 | use pf_mod_zndarray 6 | use pf_mod_imex_sweeper 7 | use pf_mod_fftpackage 8 | use pf_mod_solutions 9 | use pf_mod_zutils 10 | use pf_mod_fftops 11 | implicit none 12 | 13 | !> extend the IMEX sweeper 14 | type, extends(pf_imex_sweeper_t) :: my_sweeper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | complex(pfdp), allocatable :: tmp(:) ! temp space for feval 20 | 21 | complex(pfdp), pointer :: p_tmp(:) ! Useful pointer 22 | 23 | ! Useful for making f_eval and f_comp generic 24 | class(pf_zndarray_t), pointer :: f_encap,rhs_encap,y_encap 25 | complex(pfdp), pointer :: yvec(:), rhsvec(:), fvec(:) 26 | 27 | contains 28 | 29 | procedure :: f_eval ! Computes the advection and diffusion terms 30 | procedure :: f_comp ! Computes the advection and diffusion terms 31 | procedure :: initialize 32 | procedure :: initialize_tmp 33 | procedure :: destroy 34 | end type my_sweeper_t 35 | 36 | contains 37 | !> Routine to initialize tmp array for local storage 38 | subroutine initialize_tmp(this) 39 | class(my_sweeper_t), intent(inout) :: this 40 | 41 | integer :: istat 42 | allocate(this%tmp(this%nx),STAT=istat) 43 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 44 | end subroutine initialize_tmp 45 | 46 | ! The rest of the stuff is dimension independent 47 | include 'sweeper_include.f90' 48 | end module pf_my_sweeper 49 | 50 | 51 | -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/src/sweeper_2d.f90: -------------------------------------------------------------------------------- 1 | ! MODULE: pf_my_sweeper 2 | ! IMEX Sweeper for 2-D example in spectral space: 3 | module pf_my_sweeper 4 | use pf_mod_dtype 5 | use pf_mod_zndarray 6 | use pf_mod_imex_sweeper 7 | use pf_mod_fftpackage 8 | use pf_mod_solutions 9 | use pf_mod_zutils 10 | use pf_mod_fftops 11 | implicit none 12 | 13 | !> extend the IMEX sweeper 14 | type, extends(pf_imex_sweeper_t) :: my_sweeper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | complex(pfdp), allocatable :: tmp(:,:) ! temp space for feval 20 | 21 | complex(pfdp), pointer :: p_tmp(:,:) ! Useful pointer 22 | 23 | ! Useful for making f_eval and f_comp generic 24 | class(pf_zndarray_t), pointer :: f_encap,rhs_encap,y_encap 25 | complex(pfdp), pointer :: yvec(:,:), rhsvec(:,:), fvec(:,:) 26 | 27 | contains 28 | 29 | procedure :: f_eval ! Computes the advection and diffusion terms 30 | procedure :: f_comp ! Computes the advection and diffusion terms 31 | procedure :: initialize 32 | procedure :: initialize_tmp 33 | procedure :: destroy 34 | end type my_sweeper_t 35 | 36 | contains 37 | 38 | subroutine initialize_tmp(this) 39 | class(my_sweeper_t), intent(inout) :: this 40 | 41 | integer :: istat 42 | allocate(this%tmp(this%nx,this%nx),STAT=istat) 43 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 44 | end subroutine initialize_tmp 45 | 46 | ! The rest of the stuff is dimension independent 47 | include 'sweeper_include.f90' 48 | 49 | end module pf_my_sweeper 50 | 51 | 52 | -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/src/sweeper_3d.f90: -------------------------------------------------------------------------------- 1 | ! MODULE: pf_my_sweeper 2 | ! IMEX Sweeper for 3-D examples in spectral space: 3 | module pf_my_sweeper 4 | use pf_mod_dtype 5 | use pf_mod_zndarray 6 | use pf_mod_imex_sweeper 7 | use pf_mod_fftpackage 8 | use pf_mod_solutions 9 | use pf_mod_zutils 10 | use pf_mod_fftops 11 | implicit none 12 | 13 | !> extend the IMEX sweeper 14 | type, extends(pf_imex_sweeper_t) :: my_sweeper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | complex(pfdp), allocatable :: tmp(:,:,:) ! temp space for feval 20 | 21 | complex(pfdp), pointer :: p_tmp(:,:,:) ! Useful pointer 22 | 23 | ! Useful for making f_eval and f_comp generic 24 | class(pf_zndarray_t), pointer :: f_encap,rhs_encap,y_encap 25 | complex(pfdp), pointer :: yvec(:,:,:), rhsvec(:,:,:), fvec(:,:,:) 26 | 27 | contains 28 | 29 | procedure :: f_eval ! Computes the advection and diffusion terms 30 | procedure :: f_comp ! Computes the advection and diffusion terms 31 | procedure :: initialize 32 | procedure :: initialize_tmp 33 | procedure :: destroy 34 | end type my_sweeper_t 35 | 36 | contains 37 | subroutine initialize_tmp(this) 38 | class(my_sweeper_t), intent(inout) :: this 39 | 40 | integer :: istat 41 | allocate(this%tmp(this%nx,this%nx,this%nx),STAT=istat) 42 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 43 | end subroutine initialize_tmp 44 | 45 | ! The rest of the stuff is dimension independent 46 | include 'sweeper_include.f90' 47 | 48 | end module pf_my_sweeper 49 | 50 | 51 | -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/test_1d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 1 1 1 22 | nsweeps= 1 1 1 23 | 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 32 64 31 | nu = 0.01 32 | a = 1.0 33 | b = -1.0 34 | c = -0.5 35 | 36 | Tfin = 2.0 37 | nsteps = 32 38 | eq_type = 1 39 | ic_type = 1 40 | 41 | ! controls splitting (1 treats u_xx implicit and u_x expliciity, 2 treats u_xx and u_x exponentially) 42 | splitting = 1 43 | 44 | / 45 | -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/test_2d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 1 1 1 22 | nsweeps= 1 1 1 23 | 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 32 64 31 | nu = 0.01 32 | a = 1.0 33 | b = -1.0 34 | c = -0.5 35 | 36 | Tfin = 2.0 37 | nsteps = 32 38 | eq_type = 1 39 | ic_type = 1 40 | 41 | ! controls splitting (1 treats u_xx implicit and u_x expliciity, 2 treats u_xx and u_x exponentially) 42 | splitting = 1 43 | 44 | / 45 | -------------------------------------------------------------------------------- /test/zNdarray/IMEX_sweeper/test_3d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | 9 | ! These are internal pfasst variables that can be reset 10 | niters = 50 ! default is 5 11 | 12 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 13 | qtype = 1 14 | 15 | ! optional variables to control termination (defaults are 0.0) 16 | abs_res_tol = 1.d-12 17 | rel_res_tol = 1.d-12 18 | 19 | nnodes = 3 5 9 20 | 21 | nsweeps_pred= 1 1 1 22 | nsweeps= 1 1 1 23 | 24 | 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 8 16 31 | nu = 0.01 32 | a = 1.0 33 | b = -1.0 34 | c = -0.5 35 | 36 | Tfin = 2.0 37 | nsteps = 32 38 | eq_type = 1 39 | ic_type = 1 40 | 41 | ! controls splitting (1 treats u_xx implicit and u_x expliciity, 2 treats u_xx and u_x exponentially) 42 | splitting = 1 43 | 44 | / 45 | -------------------------------------------------------------------------------- /test/zNdarray/Make.package: -------------------------------------------------------------------------------- 1 | # Include the standard 2 | FSRC += src/probin.f90 src/utils_$(DIM)d.f90 src/dim_$(DIM)d.f90 3 | 4 | # Choose the main and level to include 5 | ifeq ($(DO_RK),TRUE) 6 | FSRC += src/main_rk.f90 src/hooks_rk.f90 src/level_rk.f90 7 | else 8 | FSRC += src/main.f90 src/hooks.f90 src/level.f90 9 | endif 10 | ifeq ($(DO_EXP),TRUE) 11 | FSRC += src/phi_mod.f90 12 | endif 13 | 14 | build/main.o : ../src/main.f90 build/probin.o build/hooks.o build/level.o build/sweeper_$(DIM)d.o build/utils_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 15 | 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 16 | build/probin.o :../src/probin.f90 build/dim_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 17 | build/hooks.o : ../src/hooks.f90 build/sweeper_$(DIM)d.o build/probin.o build/utils_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 18 | build/level.o : ../src/level.f90 build/sweeper_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 19 | build/utils_$(DIM)d.o : ../src/utils_$(DIM)d.f90 build/probin.o 20 | build/dim_$(DIM)d.o : ../src/dim_$(DIM)d.f90 21 | build/phi_mod.o : ../src/phi_mod.f90 22 | build/level_rk.o : ../src/level_rk.f90 build/stepper_$(DIM)d.o $(LIBPFASST)/lib/libpfasst.a 23 | build/hooks_rk.o : ../src/hooks_rk.f90 build/stepper_$(DIM)d.o build/utils_$(DIM)d.o 24 | 25 | -------------------------------------------------------------------------------- /test/zNdarray/RK_stepper/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Exponential RK examples 3 | # 4 | 5 | LIBPFASST ?= ../../.. 6 | DO_EXP=FALSE 7 | DO_RK=TRUE 8 | 9 | DIM=1 10 | EXE = main.$(DIM)d.exe 11 | all: $(EXE) 12 | BUILDDIR = build 13 | 14 | include $(LIBPFASST)/Makefile.defaults 15 | FSRC = src/stepper_$(DIM)d.f90 16 | 17 | include ../Make.package 18 | OBJ = $(subst src, build,$(FSRC:.f90=.o) $(CSRC:.c=.o)) 19 | 20 | FFLAGS += -I$(LIBPFASST)/include 21 | 22 | all: $(EXE) 23 | 24 | VPATHS = src:../src 25 | 26 | 27 | include $(LIBPFASST)/Makefile.rules 28 | 29 | 30 | # dependencies 31 | # 32 | 33 | main.exe : $(LIBPFASST)/lib/libpfasst.a 34 | build/stepper_$(DIM)d.o : src/stepper_$(DIM)d.f90 build/probin.o build/utils_$(DIM)d.o src/stepper_include.f90 35 | 36 | -------------------------------------------------------------------------------- /test/zNdarray/RK_stepper/out: -------------------------------------------------------------------------------- 1 | ================================================ 2 | ----------- LibPFASST Parameters --------------- 3 | date: 20200208 4 | time: 232757.274 5 | method: parareal 6 | double precision: 8 bytes 7 | quad precision: 16 bytes 8 | Output directory: ARK4_N4096_P1 9 | Nprocs: 1 ! number of pfasst "time" processors 10 | Nlevels: 1 ! number of levels 11 | ================================================== 12 | 13 | Local Variables 14 | ---------------- 15 | Ndim: 1 ! Number of dimensions 16 | nsteps: 4096 ! Number of steps 17 | nsteps_rk: 1 ! Number of rk substeps 18 | rk_order: 4 ! Order of rk substeps 19 | Dt: 4.8828125000000000E-004 ! Time step size 20 | Tfin: 2.0000000000000000 ! Final time of run 21 | nx: 64 ! grid size per level 22 | Domain: 6.2831853071795862 6.2831853071795862 6.2831853071795862 ! domain size 23 | splitting: 2 ! 1,2, or 3 24 | Solving the nonlinear Schroedinger equation 25 | PFASST parameters read from input file nls_serial.nml 26 | ================================================== 27 | error: time: 2.0000 step: 4096 rank: 000 iter: 000 level: 01 error: 4.3275161E-10 resid: -1.0000000E+00 deltaq0: 0.0000000E+00 28 | -------------------------------------------------------------------------------- /test/zNdarray/RK_stepper/src/stepper_1d.f90: -------------------------------------------------------------------------------- 1 | !> RK stepper 2 | module pf_my_stepper 3 | use pf_mod_dtype 4 | use pf_mod_zndarray 5 | use pf_mod_rkstepper 6 | use pf_mod_fftpackage 7 | use pf_mod_solutions 8 | use pf_mod_zutils 9 | use pf_mod_fftops 10 | implicit none 11 | 12 | 13 | ! Define the derived stepper type 14 | type, extends(pf_ark_stepper_t) :: my_stepper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | complex(pfdp), allocatable :: tmp(:) ! Temp space for feval 20 | complex(pfdp), pointer :: p_tmp(:) ! a useful pointer 21 | 22 | ! Useful for making routines generic by dimension 23 | class(pf_zndarray_t), pointer :: f_encap,rhs_encap,y_encap 24 | complex(pfdp), pointer :: yvec(:), rhsvec(:), fvec(:) 25 | 26 | contains 27 | 28 | procedure :: f_eval ! Computes the advection and diffusion terms 29 | procedure :: f_comp ! Computes the advection and diffusion terms 30 | procedure :: initialize 31 | procedure :: initialize_tmp 32 | procedure :: destroy 33 | 34 | end type my_stepper_t 35 | 36 | contains 37 | subroutine initialize_tmp(this) 38 | class(my_stepper_t), intent(inout) :: this 39 | 40 | integer :: istat 41 | allocate(this%tmp(this%nx),STAT=istat) 42 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 43 | 44 | end subroutine initialize_tmp 45 | 46 | ! The rest of the stuff is dimension independent 47 | include 'stepper_include.f90' 48 | 49 | end module pf_my_stepper 50 | -------------------------------------------------------------------------------- /test/zNdarray/RK_stepper/src/stepper_2d.f90: -------------------------------------------------------------------------------- 1 | !> RK stepper 2 | module pf_my_stepper 3 | use pf_mod_dtype 4 | use pf_mod_zndarray 5 | use pf_mod_rkstepper 6 | use pf_mod_fftpackage 7 | use pf_mod_solutions 8 | use pf_mod_zutils 9 | use pf_mod_fftops 10 | implicit none 11 | 12 | 13 | ! Define the derived stepper type 14 | type, extends(pf_ark_stepper_t) :: my_stepper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | complex(pfdp), allocatable :: tmp(:,:) ! Temp space for feval 20 | complex(pfdp), pointer :: p_tmp(:,:) ! a useful pointer 21 | 22 | ! Useful for making routines generic by dimension 23 | class(pf_zndarray_t), pointer :: f_encap,rhs_encap,y_encap 24 | complex(pfdp), pointer :: yvec(:,:), rhsvec(:,:), fvec(:,:) 25 | 26 | contains 27 | 28 | procedure :: f_eval ! Computes the advection and diffusion terms 29 | procedure :: f_comp ! Computes the advection and diffusion terms 30 | procedure :: initialize 31 | procedure :: initialize_tmp 32 | procedure :: destroy 33 | 34 | end type my_stepper_t 35 | 36 | contains 37 | 38 | subroutine initialize_tmp(this) 39 | class(my_stepper_t), intent(inout) :: this 40 | 41 | integer :: istat 42 | allocate(this%tmp(this%nx,this%nx),STAT=istat) 43 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 44 | 45 | end subroutine initialize_tmp 46 | 47 | ! The rest of the stuff is dimension independent 48 | include 'stepper_include.f90' 49 | 50 | end module pf_my_stepper 51 | -------------------------------------------------------------------------------- /test/zNdarray/RK_stepper/src/stepper_3d.f90: -------------------------------------------------------------------------------- 1 | !> RK stepper 2 | module pf_my_stepper 3 | use pf_mod_dtype 4 | use pf_mod_zndarray 5 | use pf_mod_rkstepper 6 | use pf_mod_fftpackage 7 | use pf_mod_solutions 8 | use pf_mod_zutils 9 | use pf_mod_fftops 10 | implicit none 11 | 12 | 13 | ! Define the derived stepper type 14 | type, extends(pf_ark_stepper_t) :: my_stepper_t 15 | integer :: nx 16 | ! fft object and differentiaton matrices 17 | type(pf_fft_t), pointer :: fft_tool 18 | type(pf_fft_ops_t), pointer :: fft_ops 19 | complex(pfdp), allocatable :: tmp(:,:,:) ! Temp space for feval 20 | complex(pfdp), pointer :: p_tmp(:,:,:) ! a useful pointer 21 | 22 | ! Useful for making routines generic by dimension 23 | class(pf_zndarray_t), pointer :: f_encap,rhs_encap,y_encap 24 | complex(pfdp), pointer :: yvec(:,:,:), rhsvec(:,:,:), fvec(:,:,:) 25 | 26 | contains 27 | 28 | procedure :: f_eval ! Computes the advection and diffusion terms 29 | procedure :: f_comp ! Computes the advection and diffusion terms 30 | procedure :: initialize 31 | procedure :: initialize_tmp 32 | procedure :: destroy 33 | 34 | end type my_stepper_t 35 | 36 | contains 37 | subroutine initialize_tmp(this) 38 | class(my_stepper_t), intent(inout) :: this 39 | 40 | integer :: istat 41 | allocate(this%tmp(this%nx,this%nx,this%nx),STAT=istat) 42 | if (istat .ne. 0) call pf_stop(__FILE__,__LINE__,'Allocate failed ',istat) 43 | 44 | end subroutine initialize_tmp 45 | 46 | ! The rest of the stuff is dimension independent 47 | include 'stepper_include.f90' 48 | 49 | end module pf_my_stepper 50 | -------------------------------------------------------------------------------- /test/zNdarray/RK_stepper/test_1d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | 11 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 12 | qtype = 1 13 | 14 | ! optional variables to control termination (defaults are 0.0) 15 | abs_res_tol = 1.0e-10 16 | rel_res_tol = 1.0e-10 17 | 18 | nnodes = 2 2 19 | 20 | save_timings=2 21 | save_residuals=.true. 22 | save_errors=.true. 23 | use_rk_stepper=.true. 24 | outdir="nls" 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 64 64 31 | 32 | Tfin = 0.26 33 | nsteps = 32 34 | nsteps_rk = 1 16 35 | rk_order = 1 4 36 | 37 | eq_type = 3 38 | ic_type = 1 39 | 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/zNdarray/RK_stepper/test_2d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | 11 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 12 | qtype = 1 13 | 14 | ! optional variables to control termination (defaults are 0.0) 15 | abs_res_tol = 1.0e-10 16 | rel_res_tol = 1.0e-10 17 | 18 | nnodes = 2 2 19 | 20 | save_timings=2 21 | save_residuals=.true. 22 | save_errors=.true. 23 | use_rk_stepper=.true. 24 | outdir="nls" 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 64 64 31 | 32 | Tfin = 0.26 33 | nsteps = 32 34 | nsteps_rk = 1 16 35 | rk_order = 1 4 36 | 37 | eq_type = 3 38 | ic_type = 1 39 | 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/zNdarray/RK_stepper/test_3d.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | 11 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 12 | qtype = 1 13 | 14 | ! optional variables to control termination (defaults are 0.0) 15 | abs_res_tol = 1.0e-10 16 | rel_res_tol = 1.0e-10 17 | 18 | nnodes = 2 2 19 | 20 | save_timings=2 21 | save_residuals=.true. 22 | save_errors=.true. 23 | use_rk_stepper=.true. 24 | outdir="nls" 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 16 16 31 | 32 | Tfin = 0.25 33 | nsteps = 16 34 | nsteps_rk = 1 16 35 | rk_order = 1 4 36 | 37 | eq_type = 3 38 | ic_type = 1 39 | 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/zNdarray/nls.nml: -------------------------------------------------------------------------------- 1 | ! 2 | ! Test parameters for a 1-D advection diffusion 3 | ! 4 | 5 | &PF_PARAMS 6 | ! These are internal pfasst variables that must be set 7 | nlevels = 2 8 | ! These are internal pfasst variables that can be reset 9 | niters = 10 ! default is 5 10 | 11 | ! Type of quadrature nodes (default is 1=Gauss-Lobatto) 12 | qtype = 1 13 | 14 | ! optional variables to control termination (defaults are 0.0) 15 | abs_res_tol = 1.0e-10 16 | rel_res_tol = 1.0e-10 17 | 18 | nnodes = 2 2 19 | 20 | save_timings=2 21 | save_residuals=.true. 22 | save_errors=.true. 23 | use_rk_stepper=.true. 24 | outdir="nls" 25 | / 26 | 27 | ! Now define the local variables you need 28 | &PARAMS 29 | 30 | nx = 128 128 31 | 32 | Tfin = 2.0 33 | nsteps = 256 34 | nsteps_rk = 1 16 35 | rk_order = 4 4 36 | 37 | eq_type = 3 38 | ic_type = 1 39 | 40 | 41 | / 42 | -------------------------------------------------------------------------------- /test/zNdarray/src/dim_1d.f90: -------------------------------------------------------------------------------- 1 | module pf_mod_dim 2 | 3 | implicit none 4 | contains 5 | function echo_dim() result(N) 6 | integer :: N 7 | N=1 8 | end function echo_dim 9 | 10 | end module pf_mod_dim 11 | -------------------------------------------------------------------------------- /test/zNdarray/src/dim_2d.f90: -------------------------------------------------------------------------------- 1 | module pf_mod_dim 2 | 3 | implicit none 4 | contains 5 | function echo_dim() result(N) 6 | integer :: N 7 | N=2 8 | end function echo_dim 9 | 10 | end module pf_mod_dim 11 | -------------------------------------------------------------------------------- /test/zNdarray/src/dim_3d.f90: -------------------------------------------------------------------------------- 1 | module pf_mod_dim 2 | 3 | implicit none 4 | contains 5 | function echo_dim() result(N) 6 | integer :: N 7 | N=3 8 | end function echo_dim 9 | 10 | end module pf_mod_dim 11 | -------------------------------------------------------------------------------- /test/zNdarray/src/hooks.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pfasst 7 | use pf_mod_zndarray 8 | use pf_mod_zutils 9 | implicit none 10 | contains 11 | 12 | !> Output the error and residual in the solution 13 | subroutine echo_error(pf, level_index) 14 | use probin, only: grid_size 15 | use pf_my_sweeper, only: my_sweeper_t, as_my_sweeper 16 | type(pf_pfasst_t), intent(inout) :: pf 17 | integer, intent(in) :: level_index 18 | 19 | class(my_sweeper_t), pointer :: sweeper 20 | real(pfdp) :: maxerr,t 21 | type(pf_zndarray_t) :: y_ex !< the initial condition 22 | 23 | call zndarray_build(y_ex, pf%levels(level_index)%lev_shape) 24 | sweeper => as_my_sweeper(pf%levels(level_index)%ulevel%sweeper) 25 | 26 | 27 | !> compute the exact solution 28 | t=pf%state%t0+pf%state%dt 29 | call exact(sweeper%fft_tool,t, y_ex) 30 | 31 | !> compute error 32 | call y_ex%axpy(-1.0d0,pf%levels(level_index)%qend) 33 | 34 | !> compute error 35 | maxerr = y_ex%norm() 36 | print '("error: time: ", f8.4," step: ",i3.3," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," sweep: ",i2.2," error: ",es14.7," resid: ",es14.7," deltaq0: ",es14.7)', & 37 | t,pf%state%step+1, pf%rank, pf%state%iter,level_index,pf%state%sweep,maxerr,pf%levels(level_index)%residual,pf%levels(level_index)%max_delta_q0 38 | 39 | 40 | call flush(6) 41 | 42 | call zndarray_destroy(y_ex) 43 | 44 | end subroutine echo_error 45 | 46 | subroutine set_error(pf, level_index) 47 | use probin, only: grid_size 48 | use pf_my_sweeper, only: my_sweeper_t, as_my_sweeper 49 | type(pf_pfasst_t), intent(inout) :: pf 50 | integer, intent(in) :: level_index 51 | 52 | class(my_sweeper_t), pointer :: sweeper 53 | real(pfdp) :: maxerr,t 54 | type(pf_zndarray_t) :: y_ex !< the initial condition 55 | 56 | call zndarray_build(y_ex, pf%levels(level_index)%lev_shape) 57 | sweeper => as_my_sweeper(pf%levels(level_index)%ulevel%sweeper) 58 | 59 | !> compute the exact solution 60 | t=pf%state%t0+pf%state%dt 61 | call exact(sweeper%fft_tool,t, y_ex) 62 | 63 | !> compute error 64 | call y_ex%axpy(-1.0d0,pf%levels(level_index)%qend) 65 | 66 | !> compute error 67 | maxerr = y_ex%norm() 68 | 69 | call zndarray_destroy(y_ex) 70 | 71 | 72 | call pf_set_error(pf,level_index,maxerr) 73 | end subroutine set_error 74 | 75 | end module hooks 76 | -------------------------------------------------------------------------------- /test/zNdarray/src/hooks_rk.f90: -------------------------------------------------------------------------------- 1 | ! 2 | ! This file is part of LIBPFASST. 3 | ! 4 | !> User defined routines that can be called from inside libpfasst using hooks 5 | module hooks 6 | use pfasst 7 | use pf_mod_zndarray 8 | use pf_mod_zutils 9 | implicit none 10 | contains 11 | 12 | !> Output the error and residual in the solution 13 | subroutine echo_error(pf, level_index) 14 | use probin, only: grid_size 15 | use pf_my_stepper, only: my_stepper_t, as_my_stepper 16 | type(pf_pfasst_t), intent(inout) :: pf 17 | integer, intent(in) :: level_index 18 | 19 | class(my_stepper_t), pointer :: stepper 20 | real(pfdp) :: maxerr,t 21 | type(pf_zndarray_t) :: y_ex !< the initial condition 22 | 23 | call zndarray_build(y_ex, pf%levels(level_index)%lev_shape) 24 | stepper => as_my_stepper(pf%levels(level_index)%ulevel%stepper) 25 | 26 | 27 | !> compute the exact solution 28 | t=pf%state%t0+pf%state%dt 29 | call exact(stepper%fft_tool,t, y_ex) 30 | 31 | !> compute error 32 | call y_ex%axpy(-1.0d0,pf%levels(level_index)%qend) 33 | 34 | !> compute error 35 | maxerr = y_ex%norm() 36 | print '("error: time: ", f8.4," step: ",i8.1," rank: ",i3.3," iter: ",i4.3," level: ",i2.2," error: ",es14.7," resid: ",es14.7," deltaq0: ",es14.7)', & 37 | t,pf%state%step+1, pf%rank, pf%state%iter,level_index,maxerr,pf%levels(level_index)%residual,pf%levels(level_index)%max_delta_q0 38 | 39 | 40 | call flush(6) 41 | 42 | call zndarray_destroy(y_ex) 43 | 44 | end subroutine echo_error 45 | 46 | subroutine set_error(pf, level_index) 47 | use probin, only: grid_size 48 | use pf_my_stepper, only: my_stepper_t, as_my_stepper 49 | type(pf_pfasst_t), intent(inout) :: pf 50 | integer, intent(in) :: level_index 51 | 52 | class(my_stepper_t), pointer :: stepper 53 | real(pfdp) :: maxerr,t 54 | type(pf_zndarray_t) :: y_ex !< the initial condition 55 | 56 | call zndarray_build(y_ex, pf%levels(level_index)%lev_shape) 57 | stepper => as_my_stepper(pf%levels(level_index)%ulevel%stepper) 58 | 59 | !> compute the exact solution 60 | t=pf%state%t0+pf%state%dt 61 | call exact(stepper%fft_tool,t, y_ex) 62 | 63 | !> compute error 64 | call y_ex%axpy(-1.0d0,pf%levels(level_index)%qend) 65 | 66 | !> compute error 67 | maxerr = y_ex%norm() 68 | 69 | call zndarray_destroy(y_ex) 70 | 71 | call pf_set_error(pf,level_index,maxerr) 72 | end subroutine set_error 73 | end module hooks 74 | -------------------------------------------------------------------------------- /test/zNdarray/src/visc_burg.f90: -------------------------------------------------------------------------------- 1 | subroutine ex_visc_burg(this,yreal,t,fft,nx) 2 | use probin, only: nu, Lx 3 | class(my_sweeper_t), intent(inout) :: this 4 | complex(pfdp),intent(inout) :: yreal(:) 5 | type(pf_fft_t), intent(in), pointer :: fft 6 | real(pfdp), intent(in) :: t 7 | integer, intent(in) :: nx 8 | 9 | real(pfdp) :: x,uint 10 | complex(pfdp),pointer :: phi(:) 11 | complex(pfdp),pointer :: phihat(:) 12 | complex(pfdp),pointer :: phix(:) 13 | integer :: i 14 | 15 | allocate(phi(nx)) 16 | allocate(phihat(nx)) 17 | allocate(phix(nx)) 18 | 19 | 20 | ! Form phi(x,0) 21 | do i = 1, nx 22 | x = Lx*real(i-1-nx/2,pfdp)/real(nx,pfdp) 23 | ! phi(i) = exp(-(cos(two_pi*x)-1.0_pfdp)/(two_pi*2.0_pfdp*nu)) 24 | uint = -(cos(two_pi*x)-1.0_pfdp)/two_pi 25 | phi(i) = exp(-uint/(2.0_pfdp*nu)) 26 | end do 27 | 28 | ! Now solve the heat equation for phi 29 | call fft%fft(phi,phihat) 30 | if (t .gt. 0.0) then 31 | phihat=phihat*exp(this%lap*nu*t) 32 | end if 33 | 34 | 35 | ! Get phi back in real space 36 | call fft%ifft(phihat,phi) 37 | 38 | ! Get phi_x back in real space 39 | phihat=phihat*this%ddx 40 | call fft%ifft(phihat,phix) 41 | 42 | ! now the solution is the quotient 43 | do i = 1, nx 44 | yreal(i) = -2.0_pfdp*nu*phix(i)/phi(i) 45 | end do 46 | deallocate(phi,phihat,phix) 47 | end subroutine ex_visc_burg 48 | --------------------------------------------------------------------------------