From f7fc1d4834afe5fbb4beb70906563d2d1494b77f Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Mon, 26 Jun 2017 18:05:24 -0700 Subject: [PATCH] User's Guide: AMR in Fortran interface --- Docs/AMReXUsersGuide/AMReXUsersGuide.tex | 12 ++-- Docs/AMReXUsersGuide/AmrCore/AmrCore.tex | 1 + Docs/AMReXUsersGuide/Fortran/Fortran.tex | 81 +++++++++++++++++++++++- Docs/AMReXUsersGuide/GNUmakefile | 3 +- 4 files changed, 87 insertions(+), 10 deletions(-) diff --git a/Docs/AMReXUsersGuide/AMReXUsersGuide.tex b/Docs/AMReXUsersGuide/AMReXUsersGuide.tex index 2c03553afca..a3154f2b0bd 100644 --- a/Docs/AMReXUsersGuide/AMReXUsersGuide.tex +++ b/Docs/AMReXUsersGuide/AMReXUsersGuide.tex @@ -335,8 +335,8 @@ \chapter{Visualization}\label{Chap:Visualization} \chapter{Profiling}\label{Chap:Profiling} \input{Profiling/Profiling} -\chapter{Debugging}\label{Chap:Debugging} -\input{Debugging/Debugging} +%\chapter{Debugging}\label{Chap:Debugging} +%\input{Debugging/Debugging} \chapter{CVODE}\label{Chap:CVODE} \input{CVODE/CVODE} @@ -349,9 +349,9 @@ \chapter{CVODE}\label{Chap:CVODE} % \bibliographystyle{plain} % \bibliography{refs,Verification/verification,Gravity/gr} -\cleardoublepage -\phantomsection -\addcontentsline{toc}{chapter}{Index} -\printindex +%\cleardoublepage +%\phantomsection +%\addcontentsline{toc}{chapter}{Index} +%\printindex \end{document} diff --git a/Docs/AMReXUsersGuide/AmrCore/AmrCore.tex b/Docs/AMReXUsersGuide/AmrCore/AmrCore.tex index 95da1370687..0a42a098ea4 100644 --- a/Docs/AMReXUsersGuide/AmrCore/AmrCore.tex +++ b/Docs/AMReXUsersGuide/AmrCore/AmrCore.tex @@ -238,6 +238,7 @@ \subsection{{\tt FillPatchUtil} and {\tt Interpolater}}\label{sec:amrcore:fillpa contained in the files {\tt AMReX\_INTERP\_F.H} and {\tt AMReX\_INTERP\_xD.F}. \subsection{Using {\tt FluxRegister}s} +\label{sec:amrcore:fluxreg} {\tt AMReX\_FluxRegister.cpp/H} contains the class {\tt FluxRegister}, which is derived from the class {\tt BndryRegister} (in {\tt Src/Boundary/AMReX\_BndryRegister}). In the most general terms, a {\tt FluxRegister} is a special type of {\tt BndryRegister} that diff --git a/Docs/AMReXUsersGuide/Fortran/Fortran.tex b/Docs/AMReXUsersGuide/Fortran/Fortran.tex index ceda20e4c9d..27594ded4b2 100644 --- a/Docs/AMReXUsersGuide/Fortran/Fortran.tex +++ b/Docs/AMReXUsersGuide/Fortran/Fortran.tex @@ -292,12 +292,87 @@ \section{Amr Core Infrastructure} use amrex_amr_module implicit none call amrex_amrcore_init() - call my_amr_init() ! user's own code + call my_amr_init() ! user's own code, not part of AMReX ! ... - call my_amr_finalize() ! user's own code + call my_amr_finalize() ! user's own code, not part of AMReX call amrex_amrcore_finalize() end subroutine amrex_fmain \end{lstlisting} -Here we need to call {\tt amrex\_amrcore\_init} and {\tt amrex\_amrcore\_finalize}. +Here we need to call {\tt amrex\_amrcore\_init} and {\tt + amrex\_amrcore\_finalize}. And usually we need to call application +code specific procedures to provide some ``hooks'' needed by \amrex. +In \cpp, this is achieved by using virtual functions. In Fortran, we +need to call +\begin{lstlisting}[language=fortran] + subroutine amrex_init_virtual_functions (mk_lev_scrtch, mk_lev_crse, & + mk_lev_re, clr_lev, err_est) + + ! Make a new level from scratch using provided boxarray and distromap + ! Only used during initialization. + procedure(amrex_make_level_proc) :: mk_lev_scrtch + ! Make a new level using provided boxarray and distromap, and fill + ! with interpolated coarse level data. + procedure(amrex_make_level_proc) :: mk_lev_crse + ! Remake an existing level using provided boxarray and distromap, + ! and fill with existing fine and coarse data. + procedure(amrex_make_level_proc) :: mk_lev_re + ! Delete level data + procedure(amrex_clear_level_proc) :: clr_lev + ! Tag cells for refinement + procedure(amrex_error_est_proc) :: err_est + end subroutine amrex_init_virtual_functions +\end{lstlisting} +We need to provide five functions and these functions have three types +of interfaces: +\begin{lstlisting}[language=fortran] + subroutine amrex_make_level_proc (lev, time, ba, dm) bind(c) + import + implicit none + integer, intent(in), value :: lev + real(amrex_real), intent(in), value :: time + type(c_ptr), intent(in), value :: ba, dm + end subroutine amrex_make_level_proc + + subroutine amrex_clear_level_proc (lev) bind(c) + import + implicit none + integer, intent(in) , value :: lev + end subroutine amrex_clear_level_proc + + subroutine amrex_error_est_proc (lev, tags, time, tagval, clearval) bind(c) + import + implicit none + integer, intent(in), value :: lev + type(c_ptr), intent(in), value :: tags + real(amrex_real), intent(in), value :: time + character(c_char), intent(in), value :: tagval, clearval + end subroutine amrex_error_est_proc +\end{lstlisting} +{\tt Tutorials/Amr/Advection\_F/Source/my\_amr\_mod.F90} shows an +example of the setup process. The user provided {\tt + procedure(amrex\_error\_est\_proc)} has a {\tt tags} argument that +is of type {\tt c\_ptr} and its value is a pointer to a \cpp\ {\tt + TagBoxArray} object. We need to convert this into a Fortran {\tt + amrex\_tagboxarray} object. +\begin{lstlisting}[language=fortran] + type(amrex_tagboxarray) :: tag + tag = tags +\end{lstlisting} + +Module {\tt amrex\_fillpatch\_module} provides interface to +\cpp\ functions {\tt FillPatchSinglelevel} and {\tt + FillPatchTwoLevels}. To use it, the application code needs to +provide procedures for interpolation and filling physical boundaries. +See {\tt Tutorials/Amr/Advection\_F/Source/fillpatch\_mod.F90} for an +example. + +Module {\tt amrex\_fluxregister\_module} provides interface to {\tt + FluxRegister} (Section~\ref{sec:amrcore:fluxreg}). Its usage is +demonstrated in the tutorial at {\tt + Tutorials/Amr/Advection\_F/}. + \section{Octree} \label{sec:fi:octree} + +%Some AMR codes are based on octree, whereas grids in \amrex\ are more +%general than octree. Nevertheless, \amrex\ can mimic the diff --git a/Docs/AMReXUsersGuide/GNUmakefile b/Docs/AMReXUsersGuide/GNUmakefile index 75e1e598656..b6994aa93b9 100644 --- a/Docs/AMReXUsersGuide/GNUmakefile +++ b/Docs/AMReXUsersGuide/GNUmakefile @@ -17,7 +17,8 @@ section_sources = Preface/Preface.tex \ Fortran/Fortran.tex \ Visualization/Visualization.tex \ Profiling/Profiling.tex \ - Debugging/Debugging.tex + Debugging/Debugging.tex \ + CVODE/CVODE.tex AMReXUsersGuide.pdf: AMReXUsersGuide.tex $(pdf_source) $(section_sources) $(pdf_source) pdflatex AMReXUsersGuide.tex < /dev/null