From 64766fe372e77ca035c2a87ac06f19c336f4483c Mon Sep 17 00:00:00 2001 From: herrmann Date: Thu, 17 Mar 2005 18:52:07 +0000 Subject: initial commit. git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/Norms/trunk@2 f4913095-0e4f-0410-abea-a123d184f1f3 --- README | 12 ++++ doc/documentation.tex | 144 +++++++++++++++++++++++++++++++++++++++ interface.ccl | 41 +++++++++++ param.ccl | 45 ++++++++++++ schedule.ccl | 17 +++++ src/Compute_Norm.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/Setup_Vars.c | 163 ++++++++++++++++++++++++++++++++++++++++++++ src/make.code.defn | 8 +++ 8 files changed, 614 insertions(+) create mode 100644 README create mode 100644 doc/documentation.tex create mode 100644 interface.ccl create mode 100644 param.ccl create mode 100644 schedule.ccl create mode 100644 src/Compute_Norm.c create mode 100644 src/Setup_Vars.c create mode 100644 src/make.code.defn diff --git a/README b/README new file mode 100644 index 0000000..854e218 --- /dev/null +++ b/README @@ -0,0 +1,12 @@ +CVS info : $Header$ + +Cactus Code Thorn Norms +Thorn Author(s) : Frank Herrmann + : Erik Schnetter +Thorn Maintainer(s) : Frank Herrmann + : Erik Schnetter +-------------------------------------------------------------------------- + +Purpose of the thorn: + +compute norms for mexico tests. diff --git a/doc/documentation.tex b/doc/documentation.tex new file mode 100644 index 0000000..cb2b5f5 --- /dev/null +++ b/doc/documentation.tex @@ -0,0 +1,144 @@ +% *======================================================================* +% Cactus Thorn template for ThornGuide documentation +% Author: Ian Kelley +% Date: Sun Jun 02, 2002 +% $Header$ +% +% Thorn documentation in the latex file doc/documentation.tex +% will be included in ThornGuides built with the Cactus make system. +% The scripts employed by the make system automatically include +% pages about variables, parameters and scheduling parsed from the +% relevant thorn CCL files. +% +% This template contains guidelines which help to assure that your +% documentation will be correctly added to ThornGuides. More +% information is available in the Cactus UsersGuide. +% +% Guidelines: +% - Do not change anything before the line +% % START CACTUS THORNGUIDE", +% except for filling in the title, author, date, etc. fields. +% - Each of these fields should only be on ONE line. +% - Author names should be separated with a \\ or a comma. +% - You can define your own macros, but they must appear after +% the START CACTUS THORNGUIDE line, and must not redefine standard +% latex commands. +% - To avoid name clashes with other thorns, 'labels', 'citations', +% 'references', and 'image' names should conform to the following +% convention: +% ARRANGEMENT_THORN_LABEL +% For example, an image wave.eps in the arrangement CactusWave and +% thorn WaveToyC should be renamed to CactusWave_WaveToyC_wave.eps +% - Graphics should only be included using the graphicx package. +% More specifically, with the "\includegraphics" command. Do +% not specify any graphic file extensions in your .tex file. This +% will allow us to create a PDF version of the ThornGuide +% via pdflatex. +% - References should be included with the latex "\bibitem" command. +% - Use \begin{abstract}...\end{abstract} instead of \abstract{...} +% - Do not use \appendix, instead include any appendices you need as +% standard sections. +% - For the benefit of our Perl scripts, and for future extensions, +% please use simple latex. +% +% *======================================================================* +% +% Example of including a graphic image: +% \begin{figure}[ht] +% \begin{center} +% \includegraphics[width=6cm]{MyArrangement_MyThorn_MyFigure} +% \end{center} +% \caption{Illustration of this and that} +% \label{MyArrangement_MyThorn_MyLabel} +% \end{figure} +% +% Example of using a label: +% \label{MyArrangement_MyThorn_MyLabel} +% +% Example of a citation: +% \cite{MyArrangement_MyThorn_Author99} +% +% Example of including a reference +% \bibitem{MyArrangement_MyThorn_Author99} +% {J. Author, {\em The Title of the Book, Journal, or periodical}, 1 (1999), +% 1--16. {\tt http://www.nowhere.com/}} +% +% *======================================================================* + +% If you are using CVS use this line to give version information +% $Header$ + +\documentclass{article} + +% Use the Cactus ThornGuide style file +% (Automatically used from Cactus distribution, if you have a +% thorn without the Cactus Flesh download this from the Cactus +% homepage at www.cactuscode.org) +\usepackage{../../../../doc/latex/cactus} + +\begin{document} + +% The author of the documentation +\author{Frank Herrmann \textless herrmann@aei.mpg.de\textgreater \\ Erik Schnetter \textless Erik.Schnetter@aei.mpg.de\textgreater} + +% The title of the document (not necessarily the name of the Thorn) +\title{} + +% the date your document was last changed, if your document is in CVS, +% please use: +% \date{$ $Date$ $} +\date{March 17 2005} + +\maketitle + +% Do not delete next line +% START CACTUS THORNGUIDE + +% Add all definitions used in this documentation here +% \def\mydef etc + +% Add an abstract for this thorn's documentation +\begin{abstract} + +\end{abstract} + +% The following sections are suggestive only. +% Remove them or add your own. + +\section{Introduction} + +\section{Physical System} + +\section{Numerical Implementation} + +\section{Using This Thorn} + +\subsection{Obtaining This Thorn} + +\subsection{Basic Usage} + +\subsection{Special Behaviour} + +\subsection{Interaction With Other Thorns} + +\subsection{Examples} + +\subsection{Support and Feedback} + +\section{History} + +\subsection{Thorn Source Code} + +\subsection{Thorn Documentation} + +\subsection{Acknowledgements} + + +\begin{thebibliography}{9} + +\end{thebibliography} + +% Do not delete next line +% END CACTUS THORNGUIDE + +\end{document} diff --git a/interface.ccl b/interface.ccl new file mode 100644 index 0000000..4395b91 --- /dev/null +++ b/interface.ccl @@ -0,0 +1,41 @@ +# Interface definition for thorn Norms +# $Header$ + +implements: Norms +inherits: + + +private: +INT do_nothing_group TYPE=SCALAR +{ + do_nothing +} "if equal to 1, then won't do anything" + + +INT handles_group TYPE=SCALAR +{ + sum_handle +} "handles for reduction operators" + + +INT varinfo TYPE=ARRAY DIM=1 SIZE=max_nr_vars +{ + varindices_1st, varindices_2nd, norm_type +} "variable info - which vars to compute norms for" + +INT nrdecvar_gr TYPE=SCALAR +{ + nr1stvars, nr2ndvars +} "number of vars to compute for 1st & 2nd order vars" + +REAL norm_group TYPE=SCALAR +{ + norm +} "computed norm" + +REAL diff_term_group TYPE=GF +{ + diff_term +} "diff terms for norm" + + diff --git a/param.ccl b/param.ccl new file mode 100644 index 0000000..790ec2f --- /dev/null +++ b/param.ccl @@ -0,0 +1,45 @@ +# Parameter definitions for thorn Norms +# $Header$ + + +INT max_nr_vars "maximum number of variables for which norms to compute" +{ + 0:* :: "positive" +} 100 + +INT verbose "verbosity of output" +{ + 0:9 :: "higher number means more verbose output" +} 1 + +INT out_every "At which iterations should we be called" STEERABLE=always +{ + *:* :: "" +} 1 + +STRING gridfunctions_1st "Set of grid functions to compute norms for 2nd order variables" +{ + ".*" :: "List of grid function names" +} "" + +STRING gridfunctions_2nd "Set of grid functions to compute norms for 2nd order variables" +{ + ".*" :: "List of grid function names" +} "" + + + +############################################################################# +shares: IO + +USES STRING out_dir AS io_out_dir +USES INT out_every AS io_out_every +USES BOOLEAN new_filename_scheme + +EXTENDS KEYWORD out_fileinfo +{ + "axis labels" :: "add axis labels information to output files" +} + + + diff --git a/schedule.ccl b/schedule.ccl new file mode 100644 index 0000000..4067605 --- /dev/null +++ b/schedule.ccl @@ -0,0 +1,17 @@ +# Schedule definitions for thorn Norms +# $Header$ + +STORAGE: do_nothing_group,handles_group,varinfo,nrdecvar_gr,norm_group,diff_term_group + + + +schedule Norms_Setup_Vars at ANALYSIS +{ + LANG: C +} "check norm_type and setup the vars info" + + +schedule Norms_Compute_Norms at ANALYSIS +{ + LANG: C +} "compute the norm" diff --git a/src/Compute_Norm.c b/src/Compute_Norm.c new file mode 100644 index 0000000..083f498 --- /dev/null +++ b/src/Compute_Norm.c @@ -0,0 +1,184 @@ +/* XXX cleanup the include files ! */ + +#include +#include +#include +#include + +#include "cctk.h" +#include "cctk_Arguments.h" +#include "cctk_Parameters.h" + +#include "util_ErrorCodes.h" +#include "util_Table.h" + + +static const char * rcsid = "$Header$"; + +CCTK_FILEVERSION(Norms_Compute_Norm_c); + + +void Norms_Compute_Norms (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + int vind; /* variable index */ + CCTK_REAL *data; + int index,indexp, i,j,k; + int ierr; + int istart, iend, jstart, jend, kstart, kend; + int npoints; + CCTK_REAL hd, dx,dy,dz; + CCTK_REAL deriv; + int target_proc,reduction_handle; + CCTK_REAL result; + + if (verbose>1) + CCTK_INFO("computing norms"); + + *norm=0.; + result=0.; + + dx = CCTK_DELTA_SPACE(0); + dy = CCTK_DELTA_SPACE(1); + dz = CCTK_DELTA_SPACE(2); + + /* XXX ghost size */ + istart = 1; + jstart = 1; + kstart = 1; + + iend = cctk_lsh[0]-1; + jend = cctk_lsh[1]-1; + kend = cctk_lsh[2]-1; + + for (k=kstart;k2) + fprintf(stderr," nr1stvars %d nr2ndvars %d\n", + *nr1stvars,*nr2ndvars); + + /* L2-norm of 1st order variables */ + for (vind=0; vind< *nr1stvars; vind++) { + ierr=CCTK_Reduce(cctkGH,target_proc,reduction_handle,1, + CCTK_VARIABLE_REAL,&result,1,varindices_1st[vind]); + if (ierr<0) + CCTK_WARN(1,"reduction failed"); + *norm=*norm+result*result; + } + + if (verbose>2) + fprintf(stderr," after 1st order vars norm=%16.8g\n",*norm); + + /* L2-norm of 2nd order variables */ + for (vind=0; vind< *nr2ndvars; vind++) { + ierr=CCTK_Reduce(cctkGH,target_proc,reduction_handle,1, + CCTK_VARIABLE_REAL,&result,1,varindices_2nd[vind]); + if (ierr<0) + CCTK_WARN(1,"reduction failed"); + *norm=*norm+result*result; + } + + if (verbose>2) + fprintf(stderr," after 2nd order vars norm=%16.8g\n",*norm); + + /* L2-norm of D_{+i} terms */ + /* d_x */ + for (vind=0; vind< *nr2ndvars; vind++) { + data=CCTK_VarDataPtrI(cctkGH,0,varindices_2nd[vind]); + for (k=kstart;k2) + fprintf(stderr," after dx 2nd order terms norm=%16.8g\n",*norm); + + /* d_y */ + for (vind=0; vind< *nr2ndvars; vind++) { + data=CCTK_VarDataPtrI(cctkGH,0,varindices_2nd[vind]); + for (k=kstart;k2) + fprintf(stderr," after dy 2nd order terms norm=%16.8g\n",*norm); + + /* d_z */ + for (vind=0; vind< *nr2ndvars; vind++) { + data=CCTK_VarDataPtrI(cctkGH,0,varindices_2nd[vind]); + for (k=kstart;k2) + fprintf(stderr," after dz 2nd order terms norm=%16.8g\n",*norm); + + if (verbose>2) + fprintf(stderr," after 2nd order vars (incl. D_{+i}): norm=%16.8g\n", + *norm); + if (verbose>2) + fprintf(stderr,"final norm^2=%16.8g on this CPU\n",*norm); + + *norm=sqrt(*norm); + + /* multiply with h^d - see discussion above Eq. (12) in + * gr-qc/XXX */ + hd=dx*dy*dz; + *norm=*norm*hd; + + CCTK_VInfo(CCTK_THORNSTRING,"norm= %16.8g",*norm); + +} diff --git a/src/Setup_Vars.c b/src/Setup_Vars.c new file mode 100644 index 0000000..b09b594 --- /dev/null +++ b/src/Setup_Vars.c @@ -0,0 +1,163 @@ +#include +#include +#include +#include + +#include "cctk.h" +#include "cctk_Arguments.h" +#include "cctk_Parameters.h" + +#include "util_ErrorCodes.h" +#include "util_Table.h" + + +static const char * rcsid = "$Header$"; + +CCTK_FILEVERSION(Norms_Setup_Vars_c); + + +struct norms_opts { + int active; + int vi; /* variable index */ + int norm_type; +}; + + +static void getopt (int const idx, + const char * const optstring, + void * const opts) +{ + struct norms_opts * norms_opts; + int table; + int cnt; + int ierr; + int norm_type; + + + assert (idx >= 0 && idx < CCTK_NumVars()); + assert (opts); + + norms_opts = &((struct norms_opts *)opts)[idx]; + + assert (! norms_opts->active); + + if (optstring) { + assert (optstring); + table = Util_TableCreateFromString (optstring); + if (table < 0) { + char * fullname = CCTK_FullName (idx); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "The variable \"%s\" is ignored because it has an invalid option specification in the parameter \"Norms::gridfunctions...\"", + fullname); + free (fullname); + return; + } + assert (table >= 0); + } + + norms_opts->active = 1; + norms_opts->vi = idx; + + if (optstring) { + /* XXX norm_type is not used currently !*/ + cnt = Util_TableGetInt (table, &norm_type , "norm_type"); + + if (cnt < 0) { + norms_opts->norm_type = -100; /* XXX magic value */ + } else { + norms_opts->norm_type = norm_type; + } + + ierr = Util_TableDestroy (table); + assert (!ierr); + } + + /* Don't compute norms if not output was requested */ + if (norms_opts->active) { + if (norms_opts->norm_type==-100) { + norms_opts->active = 0; + } + } + +} + + + + + +void Norms_Setup_Vars (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + int nvars; + struct norms_opts * norms_opts_1st; + struct norms_opts * norms_opts_2nd; + + int n,i; + + int ierr; + + /* init */ + *nr1stvars=0; + *nr2ndvars=0; + + if (verbose>6) + CCTK_INFO("here we are in Setup_vars"); + + if (verbose>0) + CCTK_VInfo(CCTK_THORNSTRING,"Starting Norms Computation at time %f", + cctkGH->cctk_time); + if (cctk_iteration % out_every != 0) + { + *do_nothing=1; + return; + } + else + *do_nothing=0; + + + nvars = CCTK_NumVars(); + assert (nvars >= 0); + norms_opts_1st = malloc (nvars * sizeof *norms_opts_1st); + norms_opts_2nd = malloc (nvars * sizeof *norms_opts_2nd); + assert (norms_opts_1st); + assert (norms_opts_2nd); + for (n=0; n= 0); + ierr = CCTK_TraverseString + (gridfunctions_2nd, getopt, norms_opts_2nd, CCTK_GROUP_OR_VAR); + assert (ierr >= 0); + + i=0; + if (verbose>0) + CCTK_INFO("We will compute norms for the following variables"); + for (n=0; n0) { + CCTK_VInfo(CCTK_THORNSTRING," %s (1st order var)", + CCTK_FullName(varindices_1st[i])); + } + *nr1stvars=*nr1stvars+1; + } + if (norms_opts_2nd[n].active) { + varindices_2nd[i]=norms_opts_2nd[n].vi; + if (verbose>0) { + CCTK_VInfo(CCTK_THORNSTRING," %s (2nd order var)", + CCTK_FullName(varindices_2nd[i])); + } + *nr2ndvars=*nr2ndvars+1; + } + } + if (verbose>2) + fprintf(stderr," nr1stvars %d nr2ndvars %d\n",*nr1stvars,*nr2ndvars); + + free (norms_opts_1st); + free (norms_opts_2nd); +} diff --git a/src/make.code.defn b/src/make.code.defn new file mode 100644 index 0000000..67bfb8e --- /dev/null +++ b/src/make.code.defn @@ -0,0 +1,8 @@ +# Main make.code.defn file for thorn Norms +# $Header$ + +# Source files in this directory +SRCS = Setup_Vars.c Compute_Norm.c + +# Subdirectories containing source files +SUBDIRS = -- cgit v1.2.3