diff options
-rw-r--r-- | doc/documentation.tex | 104 | ||||
-rw-r--r-- | src/Boundary.h | 155 | ||||
-rw-r--r-- | src/ScalarBoundary.c | 552 |
3 files changed, 528 insertions, 283 deletions
diff --git a/doc/documentation.tex b/doc/documentation.tex index aa1874d..c950930 100644 --- a/doc/documentation.tex +++ b/doc/documentation.tex @@ -1,5 +1,10 @@ \documentclass{article} +\parskip = 2 pt +\oddsidemargin = 0 cm +\textwidth = 16 cm +\topmargin = -1 cm +\textheight = 24 cm %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % MANPAGE like description setting for options, use as @@ -32,8 +37,6 @@ {\end{entry}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - \begin{document} \title{Boundary} @@ -48,9 +51,12 @@ grid functions, or groups of grid functions. Available for 1D, 2D and \section{Purpose} Allows you to apply standard boundary conditions to grid functions -or groups of grid functions, taking into account a parallel -decomposition of the grid. The routines are callable from -C or Fortran. These routines are available for 1D, 2D and 3D. +or groups of grid functions on a Cartesian grid, taking into account +a parallel decomposition of the grid. The routines are callable from +C or Fortran. These routines are available for 1D, 2D and 3D grid functions, +and there are interfaces for applying boundary conditions in individual +directions or in all directions at once. + The boundary conditions available are \begin{itemize} \item Scalar @@ -86,6 +92,17 @@ condition to the variable with the specified variable index. \item{\em goup index}: Suffix: {\tt GI} apply the boundary condition to all variable in the group with the specified group index. \end{itemize} +\item{} For the boundary conditions in individual coordinate directions, + +\begin{tabular}{ll} +{\tt dir=-1} & apply at $x=x_{max}$ \\ +{\tt dir=1} & apply at $x=x_{max}$ \\ +{\tt dir=-2} & apply at $y=y_{min}$ \\ +{\tt dir=2} & apply at $y=y_{min}$ \\ +{\tt dir=-3} & apply at $z=z_{max}$ \\ +{\tt dir=3} & apply at $z=z_{max}$ \\ +\end{tabular} + \end{itemize} \subsection{Scalar Boundary Condition} @@ -95,6 +112,8 @@ field or fields at the boundary is set to a given scalar value, for example zero. \subsubsection*{Calling from C:} + +{\bf All Coordinate Directions:} \begin{verbatim} int ierr = BndScalarVN(cGH *cctkGH, int *stencil_size, CCTK_REAL var0, char *variable_name) @@ -105,25 +124,63 @@ int ierr = BndScalarVI(cGH *cctkGH, int *stencil_size, int ierr = BndScalarGI(cGH *cctkGH, int *stencil_size, CCTK_REAL var0, int variable_index) \end{verbatim} +{\bf Individual Coordinate Directions:} +\begin{verbatim} +int ierr = BndScalarDirVN(cGH *cctkGH, int stencil, int dir, + CCTK_REAL var0, char *variable_name) +int ierr = BndScalarDirGN(cGH *cctkGH, int stencil, int dir, + CCTK_REAL var0, char *group_name) +int ierr = BndScalarDirVI(cGH *cctkGH, int stencil, int dir, + CCTK_REAL var0, int group_index) +int ierr = BndScalarDirGI(cGH *cctkGH, int stencil, int dir, + CCTK_REAL var0, int variable_index) +\end{verbatim} + \subsubsection*{Calling from Fortran:} +{\bf All Coordinate Directions:} \begin{verbatim} call BndScalarVN(ierr, cctkGH, stencil_size, var0, variable_name) call BndScalarGN(ierr, cctkGH, stencil_size, var0, group_name) call BndScalarVI(ierr, cctkGH, stencil_size, var0, variable_index) call BndScalarGI(ierr, cctkGH, stencil_size, var0, group_index) \end{verbatim} +{\bf Individual Coordinate Directions:} +\begin{verbatim} +call BndScalarDirVN(ierr, cctkGH, dir, stencil, var0, variable_name) +call BndScalarDirGN(ierr, cctkGH, dir, stencil, var0, group_name) +call BndScalarDirVI(ierr, cctkGH, dir, stencil, var0, variable_index) +call BndScalarDirGI(ierr, cctkGH, dir, stencil, var0, group_index) +\end{verbatim} where +{\tt +\begin{tabbing} +character*(*) \= variable\_name\=\kill +integer \> ierr \\ +CCTK\_POINTER \> cctkGH\\ +integer \> dir\\ +integer \> stencil\\ +integer \> stencil\_width(dim)\\ +CCTK\_REAL \> var0 \\ +character*(*) \> variable\_name\\ +character*(*) \> group\_name\\ +integer \> variable\_index\\ +integer \> group\_index\\ +\end{tabbing} +} + +\subsection*{Arguments} \begin{Lentry} -\item[{\tt integer ierr}] Return value, negative value indicates the +\item[{\tt ierr}] Return value, negative value indicates the boundary condition was not successfully applied -\item[{\tt CCTK\_POINTER cctkGH}] Grid hierarchy pointer -\item[{\tt CCTK\_REAL var0}] Scalar value to apply -\item[{\tt integer stencil\_size(dim)}] Array with dimension of the grid function, containing the stencil width to apply the boundary at -\item[{\tt character*(*) variable\_name}] Name of the variable -\item[{\tt character*(*) group\_name}] Name of the group -\item[{\tt integer variable\_index}] Variable index -\item[{\tt integer group\_index}] Group index +\item[{\tt cctkGH}] Grid hierarchy pointer +\item[{\tt var0}] Scalar value to apply +\item[{\tt dir}] Coordinate direction in which to apply boundary condition +\item[{\tt stencil\_size}] Array with dimension of the grid function, containing the stencil width to apply the boundary at +\item[{\tt variable\_name}] Name of the variable +\item[{\tt group\_name}] Name of the group +\item[{\tt variable\_index}] Variable index +\item[{\tt group\_index}] Group index \end{Lentry} @@ -230,28 +287,28 @@ Notice that this speed does not have to be 1. \subsubsection*{Calling from C:} \begin{verbatim} int ierr = BndRadiativeVN(cGH *cctkGH, int *stencil_size, - CCTK_REAL var0, CCTK_REAL v0, + CCTK_REAL speed, CCTK_REAL limit, char *variable_name, char *variable_name_past) int ierr = BndRadiativeGN(cGH *cctkGH, int *stencil_size, - CCTK_REAL var0, CCTK_REAL v0, + CCTK_REAL speed, CCTK_REAL limit, char *group_name, char *group_name_past) int ierr = BndRadiativeVI(cGH *cctkGH, int *stencil_size, - CCTK_REAL var0, CCTK_REAL v0, + CCTK_REAL speed, CCTK_REAL limit, int variable_index, int variable_index_past) int ierr = BndRadiativeGI(cGH *cctkGH, int *stencil_size, - CCTK_REAL var0, CCTK_REAL v0, + CCTK_REAL speed, CCTK_REAL limit, int group_index, int group_index_past) \end{verbatim} \subsubsection*{Calling from Fortran:} \begin{verbatim} -call BndRadiativeVN(ierr, cctkGH, stencil_size, var0, v0, +call BndRadiativeVN(ierr, cctkGH, stencil_size, speed, limit, variable_name, variable_name_past) -call BndRadiativeVN(ierr, cctkGH, stencil_size, var0, v0, +call BndRadiativeVN(ierr, cctkGH, stencil_size, speed, limit, group_name, group_name_past) -call BndRadiativeVN(ierr, cctkGH, stencil_size, var0, v0, +call BndRadiativeVN(ierr, cctkGH, stencil_size, speed, limit, variable_index, variable_index_past) -call BndRadiativeVN(ierr, cctkGH, stencil_size, var0, v0, +call BndRadiativeVN(ierr, cctkGH, stencil_size, speed, limit, group_index, group_index_past) \end{verbatim} where @@ -262,8 +319,9 @@ value {\em negative} \item[{\tt integer stencil\_size(dim)}] array of size {\tt dim} (dimension of the gridfunction). To how many points from the outer boundary to apply the boundary condition. -\item[{\tt CCTK\_REAL var0}] radation constant -\item[{\tt CCTK\_REAL v0}] radation constant +\item[{\tt CCTK\_REAL speed}] wave speed used for boundary condition ($v$). + +\item[{\tt CCTK\_REAL limit}] radation constant \item[{\tt character*(*) variable\_name}] the name of the grid function to which the boundary condition will be applied diff --git a/src/Boundary.h b/src/Boundary.h index 5ab8b5c..a07ebe9 100644 --- a/src/Boundary.h +++ b/src/Boundary.h @@ -15,60 +15,47 @@ extern "C" { #endif -/***********************/ -/* Constant boundaries */ -int BndConstantGI(cGH *GH, - int *stencil, - CCTK_REAL var0, - int gi); -int BndConstantGN(cGH *GH, - int *stencil_size, - CCTK_REAL var0, - const char *impgn); -int BndConstantVI(cGH *GH, - int *stencil, - CCTK_REAL var0, - int vi); -int BndConstantVN(cGH *GH, - int *stencil_size, - CCTK_REAL var0, - const char *impvn); - -/* Constant boundaries - DEPRECATED */ -int ConstantBCVar(cGH *GH, - CCTK_REAL var0, - int *stencil_size, - const char *impvarname); -int ConstantBCVarI(cGH *GH, + +/* Scalar boundaries */ +int BndScalarDirGI(cGH *GH, + int stencil_size, + int dir, + CCTK_REAL var0, + int gi); +int BndScalarDirGN(cGH *GH, + int stencil_size, + int dir, + CCTK_REAL var0, + const char *impgn); +int BndScalarDirVI(cGH *GH, + int stencil_size, + int dir, CCTK_REAL var0, - int *stencil_size, int vi); -int ConstantBCGroup(cGH *GH, - CCTK_REAL var0, - int *stencil_size, - const char *impgrpname); -int ConstantBCGroupI(cGH *GH, - CCTK_REAL var0, - int *stencil_size, - int gi); - -int ScalarBCVar(cGH *GH, +int BndScalarDirVN(cGH *GH, + int stencil_size, + int dir, + CCTK_REAL var0, + const char *impvn); + +int BndScalarGI(cGH *GH, + int *stencil_size, CCTK_REAL var0, + int gi); +int BndScalarGN(cGH *GH, int *stencil_size, - const char *impvarname); -int ScalarBCVarI(cGH *GH, - CCTK_REAL var0, - int *stencil_size, - int vi); -int ScalarBCGroup(cGH *GH, - CCTK_REAL var0, - int *stencil_size, - const char *impgrpname); -int ScalarBCGroupI(cGH *GH, - CCTK_REAL var0, - int *stencil_size, - int gi); -/***********************/ + CCTK_REAL var0, + const char *impgn); +int BndScalarVI(cGH *GH, + int *stencil_size, + CCTK_REAL var0, + int vi); +int BndScalarVN(cGH *GH, + int *stencil_size, + CCTK_REAL var0, + const char *impvn); + + /* Copying boundaries */ int BndCopyGI(cGH *GH, int *stencil, @@ -87,28 +74,7 @@ int BndCopyVN(cGH *GH, const char *vn_to, const char *vn_from); -/* Copying boundaries - DEPRECATED */ -int CopyBCVar(cGH *GH, - int *stencil_size, - const char *impvarname, - const char *imppvarname); -int CopyBCVarI(cGH *GH, - int *stencil_size, - int vi, - int vip); - -int CopyBCGroup(cGH *GH, - int *stencil_size, - const char *impgrpname, - const char *imppgrpname); - -int CopyBCGroupI(cGH *GH, - int *stencil_size, - int gi, - int gip); - -/************************/ /* Radiative boundaries */ int BndRadiativeGI(cGH *GH, int *sw, @@ -138,27 +104,7 @@ int BndRadiativeVN(cGH *GH, const char *vn, const char *vn_p); -/* Radiative boundaries - DEPRECATED */ -int RadiativeBCVar(cGH *GH, - CCTK_REAL var0, - CCTK_REAL v0, - int *sw, - const char *vn, - const char *vn_p); -int RadiativeBCVarI(cGH *GH, - CCTK_REAL var0, - CCTK_REAL v0, - int *sw, - int vi, - int vi_p); -int RadiativeBCGroupI(cGH *GH, - CCTK_REAL var0, - CCTK_REAL v0, - int *sw, - int gi, - int gi_p); - -/************************/ + /* Robin boundaries */ int BndRobinGI(cGH *GH, int *stencil, @@ -184,7 +130,7 @@ int BndRobinVN(cGH *GH, int npow, const char *vn); -/************************/ + /* Flat boundaries */ int BndFlatGI(cGH *GH, int *stencil, @@ -199,29 +145,6 @@ int BndFlatVN(cGH *GH, int *sw, const char *vn); -/* Flat boundaries - DEPREACTED */ -int FlatBCVar(cGH *GH, - int *stencil_size, - const char *impvarname); -int FlatBCVarI(cGH *GH, - int *stencil_size, - int vi); -int FlatBCGroup(cGH *GH, - int *stencil_size, - const char *impgrpname); -int FlatBCGroupI(cGH *GH, - int *stencil_size, - int gi); - - - - - - -/* Backward compatible prototypes */ -int ApplyFlatBC(cGH *GH, int *stencil_size, const char *name); -int ApplyRadiativeBC(cGH *GH, CCTK_REAL var0, CCTK_REAL v0, int *sw, - char *name, char *name_p); #ifdef __cplusplus } diff --git a/src/ScalarBoundary.c b/src/ScalarBoundary.c index 3c0fa6f..d39c28b 100644 --- a/src/ScalarBoundary.c +++ b/src/ScalarBoundary.c @@ -20,37 +20,38 @@ #include "BoundarySymmetries.h" #include "Boundary.h" +#define DEBUG_BOUNDARY + /* Internal routine prototypes */ static int BndApplyScalar1Di(cGH *GH, - int gdim, - int *doBC, + int doBC, int *lssh, - int *stencil, - CCTK_REAL var0, + int *stencil_size, + CCTK_REAL scalar_val, CCTK_REAL *var); static int BndApplyScalar2Di(cGH *GH, - int gdim, - int *doBC, + int doBC, int *lssh, int *stencil_size, - CCTK_REAL var0, + CCTK_REAL scalar_val, CCTK_REAL *var); static int BndApplyScalar3Di(cGH *GH, - int gdim, - int *doBC, + int doBC, int *lssh, int *stencil_size, - CCTK_REAL var0, + CCTK_REAL scalar_val, CCTK_REAL *var); static int ApplyBndScalar(cGH *GH, - int *stencil, - CCTK_REAL var0, + int stencil, + int *stencil_array, + CCTK_REAL scalar_val, int first_var, - int num_vars); + int num_vars, + int dir); /* Local variables */ @@ -61,6 +62,43 @@ static int ApplyBndScalar(cGH *GH, ********************************************************************/ /*@@ + @routine BndScalarDirVI + @date Tue Jan 16 2001 + @author Gabrielle Allen + @desc + Apply scalar boundaries by variable index in given direction + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +int BndScalarDirVI(cGH *GH, + int stencil_size, + int dir, + CCTK_REAL scalar_val, + int vi) +{ + return ApplyBndScalar(GH,stencil_size,NULL,scalar_val,vi,1,dir); +} + +void CCTK_FCALL CCTK_FNAME(BndScalarDirVI) + (int *ierr, + cGH *GH, + int *stencil_size, + int *dir, + CCTK_REAL *scalar_val, + int *vi) +{ + *ierr=BndScalarDirVI(GH, *stencil_size, *dir, *scalar_val, *vi); + return; +} + + + /*@@ @routine BndScalarVI @date Thu Mar 2 11:07:11 2000 @author Gerd Lanfermann @@ -76,21 +114,64 @@ static int ApplyBndScalar(cGH *GH, @@*/ int BndScalarVI(cGH *GH, - int *stencil, - CCTK_REAL var0, + int *stencil_size, + CCTK_REAL scalar_val, int vi) { - return ApplyBndScalar(GH,stencil,var0,vi,1); + return ApplyBndScalar(GH,-1,stencil_size,scalar_val,vi,1,0); } void CCTK_FCALL CCTK_FNAME(BndScalarVI) (int *ierr, cGH *GH, int *stencil_size, - CCTK_REAL *var0, + CCTK_REAL *scalar_val, int *vi) { - *ierr=BndScalarVI(GH, stencil_size, *var0, *vi); + *ierr=BndScalarVI(GH, stencil_size, *scalar_val, *vi); + return; +} + + + + /*@@ + @routine BndScalarDirGI + @date Tue Jan 16 2001 + @author Gabrielle Allen + @desc + Apply scalar boundaries by group index in given direction + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +int BndScalarDirGI(cGH *GH, + int stencil_size, + int dir, + CCTK_REAL scalar_val, + int gi) +{ + int numvars, first_vi; + + first_vi = CCTK_FirstVarIndexI(gi); + numvars = CCTK_NumVarsInGroupI(gi); + + return ApplyBndScalar(GH,stencil_size,NULL,scalar_val,first_vi,numvars,dir); +} + +void CCTK_FCALL CCTK_FNAME(BndScalarDirGI) + (int *ierr, + cGH *GH, + int *stencil_size, + int *dir, + CCTK_REAL *scalar_val, + int *gi) +{ + *ierr=BndScalarDirGI(GH, *stencil_size, *dir, *scalar_val, *gi); return; } @@ -101,7 +182,7 @@ void CCTK_FCALL CCTK_FNAME(BndScalarVI) @date Thu Mar 2 11:07:11 2000 @author Gerd Lanfermann @desc - Apply constant boundaries by group index + Apply scalar boundaries by group index @enddesc @calls @calledby @@ -112,8 +193,8 @@ void CCTK_FCALL CCTK_FNAME(BndScalarVI) @@*/ int BndScalarGI(cGH *GH, - int *stencil, - CCTK_REAL var0, + int *stencil_size, + CCTK_REAL scalar_val, int gi) { int numvars, first_vi; @@ -121,28 +202,85 @@ int BndScalarGI(cGH *GH, first_vi = CCTK_FirstVarIndexI(gi); numvars = CCTK_NumVarsInGroupI(gi); - return ApplyBndScalar(GH,stencil,var0,first_vi,numvars); + return ApplyBndScalar(GH,-1,stencil_size,scalar_val,first_vi,numvars,0); } void CCTK_FCALL CCTK_FNAME(BndScalarGI) (int *ierr, cGH *GH, int *stencil_size, - CCTK_REAL *var0, + CCTK_REAL *scalar_val, int *gi) { - *ierr=BndScalarGI(GH, stencil_size, *var0, *gi); + *ierr=BndScalarGI(GH, stencil_size, *scalar_val, *gi); return; } /*@@ + @routine BndScalarDirGN + @date Tue Jan 16 2001 + @author Gabrielle Allen + @desc + Apply scalar boundaries by group name in given direction + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +int BndScalarDirGN(cGH *GH, + int stencil_size, + int dir, + CCTK_REAL scalar_val, + const char *impgn) +{ + int retval; + int gi; + + gi = CCTK_GroupIndex(impgn); + + if(gi > -1) + { + retval = BndScalarDirGI(GH, stencil_size, dir, scalar_val, gi); + } + else + { + CCTK_VWarn(2,__LINE__,__FILE__,"Boundary", + "BndScalarDirGN: Cannot find group index for %s",impgn); + retval = -1; + } + + return retval; + +} + +void CCTK_FCALL CCTK_FNAME(BndScalarDirGN) + (int *ierr, + cGH *GH, + int *stencil_size, + int *dir, + CCTK_REAL *scalar_val, + ONE_FORTSTRING_ARG) +{ + ONE_FORTSTRING_CREATE(impgn) + *ierr=BndScalarDirGN(GH, *stencil_size, *dir, *scalar_val, impgn); + free(impgn); + return; +} + + + + /*@@ @routine BndScalarGN @date Thu Mar 2 11:07:11 2000 @author Gerd Lanfermann @desc - Apply constant boundaries by group name + Apply scalar boundaries by group name @enddesc @calls @calledby @@ -154,7 +292,7 @@ void CCTK_FCALL CCTK_FNAME(BndScalarGI) int BndScalarGN(cGH *GH, int *stencil_size, - CCTK_REAL var0, + CCTK_REAL scalar_val, const char *impgn) { int retval; @@ -164,7 +302,7 @@ int BndScalarGN(cGH *GH, if(gi > -1) { - retval = BndScalarGI(GH, stencil_size, var0, gi); + retval = BndScalarGI(GH, stencil_size, scalar_val, gi); } else { @@ -181,11 +319,11 @@ void CCTK_FCALL CCTK_FNAME(BndScalarGN) (int *ierr, cGH *GH, int *stencil_size, - CCTK_REAL *var0, + CCTK_REAL *scalar_val, ONE_FORTSTRING_ARG) { ONE_FORTSTRING_CREATE(impgn) - *ierr=BndScalarGN(GH, stencil_size, *var0, impgn); + *ierr=BndScalarGN(GH, stencil_size, *scalar_val, impgn); free(impgn); return; } @@ -193,11 +331,67 @@ void CCTK_FCALL CCTK_FNAME(BndScalarGN) /*@@ + @routine BndScalarDirVN + @date Tue Jan 16 2001 + @author Gabrielle Allen + @desc + Apply scalar boundaries by variable name in given direction + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +int BndScalarDirVN(cGH *GH, + int stencil_size, + int dir, + CCTK_REAL scalar_val, + const char *impvn) +{ + int vi; + int retval; + + vi = CCTK_VarIndex(impvn); + + if (vi>-1) + { + retval = BndScalarDirVI(GH, stencil_size, dir, scalar_val, vi); + } + else + { + CCTK_VWarn(2,__LINE__,__FILE__,"Boundary", + "BndScalarDirVN: Cannot find variable index for %s ",impvn); + retval = -1; + } + + return retval; +} + +void CCTK_FCALL CCTK_FNAME(BndScalarDirVN) + (int *ierr, + cGH *GH, + int *stencil_size, + int *dir, + CCTK_REAL *scalar_val, + ONE_FORTSTRING_ARG) +{ + ONE_FORTSTRING_CREATE(impvn) + *ierr = BndScalarDirVN(GH, *stencil_size, *dir, *scalar_val, impvn); + free(impvn); + return; +} + + + + /*@@ @routine BndScalarVN @date Thu Mar 2 11:07:11 2000 @author Gerd Lanfermann @desc - Apply constant boundaries by variable name + Apply scalar boundaries by variable name @enddesc @calls @calledby @@ -209,7 +403,7 @@ void CCTK_FCALL CCTK_FNAME(BndScalarGN) int BndScalarVN(cGH *GH, int *stencil_size, - CCTK_REAL var0, + CCTK_REAL scalar_val, const char *impvn) { int vi; @@ -219,7 +413,7 @@ int BndScalarVN(cGH *GH, if (vi>-1) { - retval = BndScalarVI(GH, stencil_size, var0, vi); + retval = BndScalarVI(GH, stencil_size, scalar_val, vi); } else { @@ -235,11 +429,11 @@ void CCTK_FCALL CCTK_FNAME(BndScalarVN) (int *ierr, cGH *GH, int *stencil_size, - CCTK_REAL *var0, + CCTK_REAL *scalar_val, ONE_FORTSTRING_ARG) { ONE_FORTSTRING_CREATE(impvn) - *ierr = BndScalarVN(GH, stencil_size, *var0, impvn); + *ierr = BndScalarVN(GH, stencil_size, *scalar_val, impvn); free(impvn); return; } @@ -249,6 +443,7 @@ void CCTK_FCALL CCTK_FNAME(BndScalarVN) /******************************************************************** ********************* Local Routines ************************* ********************************************************************/ + /*@@ @routine ApplyBndScalar @date Tue Jul 18 18:10:33 2000 @@ -265,20 +460,38 @@ void CCTK_FCALL CCTK_FNAME(BndScalarVN) @@*/ static int ApplyBndScalar(cGH *GH, - int *stencil, - CCTK_REAL var0, + int stencil, + int *stencil_array, + CCTK_REAL scalar_val, int first_var, - int num_vars) + int num_vars, + int dir) { int symmetry_handle; /* handle for the optional symmetry structure */ int vi, gi, dim; + int coord; int idim; int berr,ierr; - int *doBC, *dstag; + int dirloop1,dirloop2; + int doBC, count; + int *dstag; int *lssh; + int *sw; int timelevel; /* timelevel that condition applied on */ SymmetryGHex *sGHex; +#ifdef DEBUG_BOUNDARY + printf("Input arguments for ApplyBndScalar:\n"); + printf("GH = %x\n",GH); + printf("stencil = %d\n",stencil); + printf("stencil_array = %x\n",stencil_array); + printf("scalar_val = %f\n",scalar_val); + printf("first_var = %d\n",first_var); + printf("num_vars = %d\n",num_vars); + printf("dir = %d\n",dir); + printf("-----------------------------------\n"); +#endif + /* See if we have a symmetry array */ symmetry_handle = CCTK_GHExtensionHandle("Symmetry"); if (symmetry_handle < 0) @@ -293,8 +506,32 @@ static int ApplyBndScalar(cGH *GH, /* Get group dimension */ dim = CCTK_GroupDimFromVarI(first_var); + /* Set up stencil width array if needed */ + if (stencil_array) + { + sw = stencil_array; + } + else + { + int i; + sw = (int *)malloc(dim*sizeof(int)); + for (i=0;i<dim;i++) + { + sw[i] = 0; + } + if (dir > 0) + { + sw[dir-1] = stencil; + coord = dir-1; + } + else + { + sw[-dir-1] = stencil; + coord = -dir-1; + } + } + /* allocate arrays */ - doBC = (int *)malloc((2*dim)*sizeof(int)); dstag = (int *)malloc(dim*sizeof(int)); lssh = (int *)malloc(dim*sizeof(int)); @@ -304,100 +541,117 @@ static int ApplyBndScalar(cGH *GH, /* get the current timelevel */ timelevel = CCTK_NumTimeLevelsFromVarI (first_var) - 1; - /* if (timelevel > 0) - timelevel--;*/ - + /* Treat all boundaries or just one? */ + if (dir>0) + { + dirloop1 = 2*(dir-1)+1; + dirloop2 = dirloop1+1; + } + else if (dir<0) + { + dirloop1 = 2*(-dir-1); + dirloop2 = dirloop1+1; + } + else + { + dirloop1 = 0; + dirloop2 = 2*dim; + } + for (vi=first_var; vi<first_var+num_vars; vi++) { - /* Apply condition if: + boundary is not a symmetry boundary (no symmetry or unset(=unsed)) + boundary is a physical boundary + have enough grid points */ - if (sGHex) + + for (idim=0;idim<dim;idim++) { - for (idim=0;idim<dim;idim++) - { - doBC[idim*2] = (((sGHex->GFSym[vi][idim*2]==GFSYM_NOSYM)|| - (sGHex->GFSym[vi][idim*2]==GFSYM_UNSET)) && - GH->cctk_lsh[idim]>1 && GH->cctk_bbox[idim*2]); - doBC[idim*2+1] = (((sGHex->GFSym[vi][idim*2+1]==GFSYM_NOSYM)|| - (sGHex->GFSym[vi][idim*2+1]==GFSYM_UNSET)) && - GH->cctk_lsh[idim]>1 && GH->cctk_bbox[idim*2+1]); lssh[idim] = (int)GH->cctk_lssh[CCTK_LSSH_IDX(dstag[idim],idim)]; - } } - else + + for (count=dirloop1;count<dirloop2;count++) { - for (idim=0;idim<dim;idim++) + if (sGHex) { - doBC[idim*2] = (GH->cctk_lsh[idim]>1 && GH->cctk_bbox[idim*2]); - doBC[idim*2+1] = (GH->cctk_lsh[idim]>1 && GH->cctk_bbox[idim*2+1]); - lssh[idim] = (int)GH->cctk_lssh[CCTK_LSSH_IDX(dstag[idim],idim)]; - } - } + doBC = ( + ( (sGHex->GFSym[vi][count]==GFSYM_NOSYM) || + (sGHex->GFSym[vi][count]==GFSYM_UNSET) ) && + GH->cctk_lsh[coord]>1 && GH->cctk_bbox[count]) ? + count : -1; + } + else + { + doBC = (GH->cctk_lsh[coord]>1 && GH->cctk_bbox[count]) ? + count : -1 ; + } - - switch (dim) - { - case 1: - berr = BndApplyScalar1Di(GH, - dim, - doBC, - lssh, - stencil, - var0, - GH->data[vi][timelevel]); - break; - case 2: - berr = BndApplyScalar2Di(GH, - dim, - doBC, - lssh, - stencil, - var0, - GH->data[vi][timelevel]); - break; - case 3: - berr = BndApplyScalar3Di(GH, - dim, - doBC, - lssh, - stencil, - var0, - GH->data[vi][timelevel]); - break; - default : - berr = -1; - CCTK_VWarn(1,__LINE__,__FILE__,"Boundary", - "No scalar boudnary for dim>3: grid variable '%s'", - CCTK_VarName(vi)); + if (doBC >=0) + { + switch (dim) + { + case 1: + berr = BndApplyScalar1Di(GH, + doBC, + lssh, + sw, + scalar_val, + GH->data[vi][timelevel]); + break; + case 2: + berr = BndApplyScalar2Di(GH, + doBC, + lssh, + sw, + scalar_val, + GH->data[vi][timelevel]); + break; + case 3: + berr = BndApplyScalar3Di(GH, + doBC, + lssh, + sw, + scalar_val, + GH->data[vi][timelevel]); + break; + default : + berr = -1; + CCTK_VWarn(1,__LINE__,__FILE__,"Boundary", + "No scalar boundary for dim>3: grid variable '%s'", + CCTK_VarName(vi)); + } + } } berr = (berr>-1) ? 0 : -1; } free(dstag); - free(doBC); free(lssh); - + + if (!stencil_array) + { + free(sw); + } + return ierr; } + + /*@@ @routine BndApplyScalar3Di @date Thu Mar 2 11:08:49 2000 @author Gerd Lanfermann @desc - Apply the constant boundary condition for 3d variables - -internal routine + Apply the scalar boundary condition for 3d variables @enddesc @calls - @calledby BndScalarGI, BndScalarVI, BndScalarVN, BndScalarGN, + @calledby @history @endhistory @@ -405,17 +659,19 @@ static int ApplyBndScalar(cGH *GH, @@*/ static int BndApplyScalar3Di(cGH *GH, - int gdim, - int *doBC, - int *lsh, + int doBC, + int *lsh, int *stencil_size, - CCTK_REAL var0, + CCTK_REAL scalar_val, CCTK_REAL *var) { int i,j,k,sw; - if (doBC[0] == 1) + if (doBC == 0) { +#ifdef DEBUG_BOUNDARY + printf("Applying scalar boundary %f (lower x)\n",scalar_val); +#endif for (k=0;k<lsh[2];k++) { for (j=0;j<lsh[1];j++) @@ -423,13 +679,16 @@ static int BndApplyScalar3Di(cGH *GH, for (sw=0;sw<stencil_size[0];sw++) { var[CCTK_GFINDEX3D(GH,sw,j,k)] - = var0; + = scalar_val; } } } } - if (doBC[1] == 1) + else if (doBC == 1) { +#ifdef DEBUG_BOUNDARY + printf("Applying scalar boundary %f (upper x)\n",scalar_val); +#endif for (k=0;k<lsh[2];k++) { for (j=0;j<lsh[1];j++) @@ -437,14 +696,16 @@ static int BndApplyScalar3Di(cGH *GH, for (sw=0;sw<stencil_size[0];sw++) { var[CCTK_GFINDEX3D(GH,lsh[0]-sw-1,j,k)] - = var0; + = scalar_val; } } } } - - if (doBC[2] == 1) + else if (doBC == 2) { +#ifdef DEBUG_BOUNDARY + printf("Applying scalar boundary %d (lower y)\n",scalar_val); +#endif for (k=0;k<lsh[2];k++) { for (i=0;i<lsh[0];i++) @@ -452,14 +713,16 @@ static int BndApplyScalar3Di(cGH *GH, for (sw=0;sw<stencil_size[1];sw++) { var[CCTK_GFINDEX3D(GH,i,sw,k)] - = var0; + = scalar_val; } } } } - - if (doBC[3] == 1) + else if (doBC == 3) { +#ifdef DEBUG_BOUNDARY + printf("Applying scalar boundary %f (upper y)\n",scalar_val); +#endif for (k=0;k<lsh[2];k++) { for (i=0;i<lsh[0];i++) @@ -467,14 +730,16 @@ static int BndApplyScalar3Di(cGH *GH, for (sw=0;sw<stencil_size[1];sw++) { var[CCTK_GFINDEX3D(GH,i,lsh[1]-sw-1,k)] - = var0; + = scalar_val; } } } } - - if (doBC[4] == 1) + else if (doBC == 4) { +#ifdef DEBUG_BOUNDARY + printf("Applying scalar boundary %f (lower z)\n",scalar_val); +#endif for (j=0;j<lsh[1];j++) { for (i=0;i<lsh[0];i++) @@ -482,14 +747,16 @@ static int BndApplyScalar3Di(cGH *GH, for (sw=0;sw<stencil_size[2];sw++) { var[CCTK_GFINDEX3D(GH,i,j,sw)] - = var0; + = scalar_val; } } } } - - if (doBC[5] == 1) + else if (doBC == 5) { +#ifdef DEBUG_BOUNDARY + printf("Applying scalar boundary %f (upper z)\n",scalar_val); +#endif for (j=0;j<lsh[1];j++) { for (i=0;i<lsh[0];i++) @@ -497,7 +764,7 @@ static int BndApplyScalar3Di(cGH *GH, for (sw=0;sw<stencil_size[2];sw++) { var[CCTK_GFINDEX3D(GH,i,j,lsh[2]-sw-1)] - = var0; + = scalar_val; } } } @@ -512,8 +779,7 @@ static int BndApplyScalar3Di(cGH *GH, @date Thu Mar 2 11:08:49 2000 @author Gerd Lanfermann @desc - Apply the constant boundary condition for 2d variables - -internal routine + Apply the scalar boundary condition for 2d variables @enddesc @history @@ -522,63 +788,62 @@ static int BndApplyScalar3Di(cGH *GH, @@*/ static int BndApplyScalar2Di(cGH *GH, - int gdim, - int *doBC, + int doBC, int *lsh, int *stencil_size, - CCTK_REAL var0, + CCTK_REAL scalar_val, CCTK_REAL *var) { int i,j,sw; /* lower x */ - if (doBC[0] == 1) + if (doBC == 0) { for (j=0;j<lsh[1];j++) { for (sw=0;sw<stencil_size[0];sw++) { var[CCTK_GFINDEX2D(GH,sw,j)] - = var0; + = scalar_val; } } } /* upper x */ - if (doBC[1] == 1) + else if (doBC == 1) { for (j=0;j<lsh[1];j++) { for (sw=0;sw<stencil_size[0];sw++) { var[CCTK_GFINDEX2D(GH,lsh[0]-sw-1,j)] - = var0; + = scalar_val; } } } /* lower y */ - if (doBC[2] == 1) + else if (doBC == 2) { for (i=0;i<lsh[0];i++) { for (sw=0;sw<stencil_size[1];sw++) { var[CCTK_GFINDEX2D(GH,i,sw)] - = var0; + = scalar_val; } } } /* upper y */ - if (doBC[3] == 1) + else if (doBC == 3) { for (i=0;i<lsh[0];i++) { for (sw=0;sw<stencil_size[1];sw++) { var[CCTK_GFINDEX2D(GH,i,lsh[1]-sw-1)] - = var0; + = scalar_val; } } } @@ -592,7 +857,7 @@ static int BndApplyScalar2Di(cGH *GH, @date Thu Mar 2 11:08:49 2000 @author Gerd Lanfermann @desc - Apply the constant boundary condition for 1d variables + Apply the scalar boundary condition for 1d variables -internal routine @enddesc @history @@ -602,32 +867,31 @@ static int BndApplyScalar2Di(cGH *GH, @@*/ static int BndApplyScalar1Di(cGH *GH, - int gdim, - int *doBC, + int doBC, int *lsh, - int *stencil, - CCTK_REAL var0, + int *stencil_size, + CCTK_REAL scalar_val, CCTK_REAL *var) { int sw; /* lower x */ - if (doBC[0] == 1) + if (doBC == 0) { - for (sw=0;sw<stencil[0];sw++) + for (sw=0;sw<stencil_size[0];sw++) { var[CCTK_GFINDEX1D(GH,sw)] - = var0; + = scalar_val; } } /* upper x */ - if (doBC[1] == 1) + else if (doBC == 1) { - for (sw=0;sw<stencil[0];sw++) + for (sw=0;sw<stencil_size[0];sw++) { var[CCTK_GFINDEX1D(GH,GH->cctk_lsh[0]-sw-1)] - = var0; + = scalar_val; } } return(0); |