From e88bf8ce164c15cce86da04b486383443c21073b Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Sun, 26 May 2013 16:33:19 -0400 Subject: TestBBoxSet2: New thorn --- CarpetExtra/TestBBoxSet2/README | 10 + CarpetExtra/TestBBoxSet2/configuration.ccl | 3 + CarpetExtra/TestBBoxSet2/doc/documentation.tex | 144 +++++ CarpetExtra/TestBBoxSet2/interface.ccl | 7 + CarpetExtra/TestBBoxSet2/param.ccl | 10 + CarpetExtra/TestBBoxSet2/schedule.ccl | 7 + CarpetExtra/TestBBoxSet2/src/make.code.defn | 7 + CarpetExtra/TestBBoxSet2/src/test.cc | 786 +++++++++++++++++++++++++ CarpetExtra/TestBBoxSet2/test/bboxset2.par | 6 + 9 files changed, 980 insertions(+) create mode 100644 CarpetExtra/TestBBoxSet2/README create mode 100644 CarpetExtra/TestBBoxSet2/configuration.ccl create mode 100644 CarpetExtra/TestBBoxSet2/doc/documentation.tex create mode 100644 CarpetExtra/TestBBoxSet2/interface.ccl create mode 100644 CarpetExtra/TestBBoxSet2/param.ccl create mode 100644 CarpetExtra/TestBBoxSet2/schedule.ccl create mode 100644 CarpetExtra/TestBBoxSet2/src/make.code.defn create mode 100644 CarpetExtra/TestBBoxSet2/src/test.cc create mode 100644 CarpetExtra/TestBBoxSet2/test/bboxset2.par (limited to 'CarpetExtra') diff --git a/CarpetExtra/TestBBoxSet2/README b/CarpetExtra/TestBBoxSet2/README new file mode 100644 index 000000000..e6a6d5935 --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/README @@ -0,0 +1,10 @@ +Cactus Code Thorn TestBBoxSet2 +Author(s) : Erik Schnetter +Maintainer(s): Erik Schnetter +Licence : GPL +-------------------------------------------------------------------------- + +1. Purpose + +Test the new bboxset class by comparing its results to the old bboxset +class. diff --git a/CarpetExtra/TestBBoxSet2/configuration.ccl b/CarpetExtra/TestBBoxSet2/configuration.ccl new file mode 100644 index 000000000..bbc806dc2 --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/configuration.ccl @@ -0,0 +1,3 @@ +# Configuration definitions for thorn TestBBoxSet2 + +REQUIRES CarpetLib CycleClock diff --git a/CarpetExtra/TestBBoxSet2/doc/documentation.tex b/CarpetExtra/TestBBoxSet2/doc/documentation.tex new file mode 100644 index 000000000..77fa7f337 --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/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{Erik Schnetter \textless schnetter@gmail.com\textgreater} + +% The title of the document (not necessarily the name of the Thorn) +\title{TestBBoxSet2} + +% the date your document was last changed, if your document is in CVS, +% please use: +% \date{$ $Date: 2004-01-07 14:12:39 -0600 (Wed, 07 Jan 2004) $ $} +\date{March 30 2013} + +\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/CarpetExtra/TestBBoxSet2/interface.ccl b/CarpetExtra/TestBBoxSet2/interface.ccl new file mode 100644 index 000000000..d3df6b03e --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/interface.ccl @@ -0,0 +1,7 @@ +# Interface definition for thorn TestBBoxSet2 + +IMPLEMENTS: TestBBoxSet2 + +USES INCLUDES HEADER: cycleclock.h + +USES INCLUDE HEADER: bboxset.hh diff --git a/CarpetExtra/TestBBoxSet2/param.ccl b/CarpetExtra/TestBBoxSet2/param.ccl new file mode 100644 index 000000000..91cfad826 --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/param.ccl @@ -0,0 +1,10 @@ +# Parameter definitions for thorn TestBBoxSet2 + +BOOLEAN verbose "Provide verbose output" STEERABLE=always +{ +} "yes" + +INT components_goal "Approximate number of components to simulate" STEERABLE=always +{ + 1:* :: "" +} 10000 diff --git a/CarpetExtra/TestBBoxSet2/schedule.ccl b/CarpetExtra/TestBBoxSet2/schedule.ccl new file mode 100644 index 000000000..01a173a31 --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/schedule.ccl @@ -0,0 +1,7 @@ +# Schedule definitions for thorn TestBBoxSet2 + +SCHEDULE TestBBoxSet2_test AT paramcheck +{ + LANG: C + OPTIONS: meta +} "Test bboxset2" diff --git a/CarpetExtra/TestBBoxSet2/src/make.code.defn b/CarpetExtra/TestBBoxSet2/src/make.code.defn new file mode 100644 index 000000000..d403969cf --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/src/make.code.defn @@ -0,0 +1,7 @@ +# Main make.code.defn file for thorn TestBBoxSet2 + +# Source files in this directory +SRCS = test.cc + +# Subdirectories containing source files +SUBDIRS = diff --git a/CarpetExtra/TestBBoxSet2/src/test.cc b/CarpetExtra/TestBBoxSet2/src/test.cc new file mode 100644 index 000000000..8ab99d13e --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/src/test.cc @@ -0,0 +1,786 @@ +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + + + +namespace { + + + + const double nano = 1.0e-9; + + // Time a region of code + template + auto xtime(double& time, const F& f) -> + typename enable_if::value, void>::type + { + const ticks tb = getticks(); + f(); + const ticks te = getticks(); + time += seconds_per_tick() * elapsed(te, tb); + } + + template + auto xtime(double& time, const F& f) -> + typename enable_if::value, decltype(f())>::type + { + const ticks tb = getticks(); + const decltype(f()) ret = f(); + const ticks te = getticks(); + time += seconds_per_tick() * elapsed(te, tb); + return ret; + } + + + + // Convert to string + // (Would like to use to_string instead, but this doesn't seem to + // compile on Stampede) + template + string to_str(const T& x) + { + ostringstream buf; + buf << x; + return buf.str(); + } + + + + template + void check_equal(const string descr, + const A1& x1, + const A2& x2, + const bboxset1::bboxset& bset1, + const bboxset2::bboxset& bset2) + { + DECLARE_CCTK_PARAMETERS; + + if (verbose) { + cout << " <" << D << "> " << descr << "..."; + cout.flush(); + } + + set> v1, v2; + bset1.serialise(v1); + bset2.serialise(v2); + + bool eq = v1 == v2; + if (not eq) { + eq = (bset1 == bboxset1::bboxset(v2) and + bset2 == bboxset2::bboxset(v1)); + } + + if (eq) { + if (verbose) cout << " [success]\n"; + } else { + if (verbose) cout << " [failure]\n"; + cout.flush(); + cerr.flush(); + fflush(stdout); + fflush(stderr); + CCTK_VParamWarn(CCTK_THORNSTRING, + "Found difference in operation \"%s\":", descr.c_str()); + fflush(stdout); + fflush(stderr); + cout << "\n" + << "input1=" << x1 << "\n" + << "input2=" << x2 << "\n" + << "bset1=" << bset1 << "\n" + << "bset2=" << bset2 << "\n" + << "bset1.serialised=" << v1 << "\n" + << "bset2.serialised=" << v2 << "\n"; + cout.flush(); + cerr.flush(); + + const bboxset1::bboxset bs(v2); + cout << "bset1-bset2=" << bset1-bs << "\n" + << "bset2-bset1=" << bs-bset1 << "\n"; + } + } + + template + void check_equal(const string descr, + const bboxset1::bboxset& bset1, + const bboxset2::bboxset& bset2) + { + check_equal(descr, "", "", bset1, bset2); + } + + + +#define bvect bvect_ +#define b2vect b2vect_ +#define ivect ivect_ +#define i2vect i2vect_ +#define ibbox ibbox_ + template + struct full_boxes_t { + typedef ::vect bvect; + typedef ::vect b2vect; + typedef ::vect ivect; + typedef ::vect i2vect; + typedef ::bbox ibbox; + typedef bboxset1::bboxset ibset1; + typedef bboxset2::bboxset ibset2; + ibbox interior; + b2vect is_outer_boundary; + ibbox exterior; + ibset1 ghosts1; + ibset2 ghosts2; + ibbox communicated; + ibset1 outer_boundaries1; + ibset2 outer_boundaries2; + ibbox owned; + ibset1 boundaries1; + ibset2 boundaries2; + ibset1 buffers1; + ibset2 buffers2; + ibset1 overlaps1; + ibset2 overlaps2; + ibset1 active1; + ibset2 active2; + }; + template + struct level_boxes_t { + typedef ::vect bvect; + typedef ::vect b2vect; + typedef ::vect ivect; + typedef ::vect i2vect; + typedef ::bbox ibbox; + typedef bboxset1::bboxset ibset1; + typedef bboxset2::bboxset ibset2; + ibset1 buffers1; + ibset2 buffers2; + ibset1 active1; + ibset2 active2; + }; + + template + void test() + { + DECLARE_CCTK_PARAMETERS; + + CCTK_VInfo(CCTK_THORNSTRING, "Testing bboxset2<%d>...", D); + + // Prevent warnings about shadowing declarations + typedef ::vect bvect; + typedef ::vect b2vect; + typedef ::vect ivect; + typedef ::vect i2vect; + typedef ::bbox ibbox; + typedef bboxset1::bboxset ibset1; + typedef bboxset2::bboxset ibset2; + + const int str = 3; // a non-trivial stride + + double time1, time2, time1a, time2a, time_check; + + + + // Some warm-up gymnastics with emtpy sets + + ibset1 bs1; + ibset2 bs2; + xtime(time_check, [&]() { check_equal("create ibset", bs1, bs2); }); + assert(bs1.empty()); + assert(bs2.empty()); + + ibbox b; + bs1 |= b; + bs2 |= b; + + xtime(time_check, [&]() { + check_equal("union with empty ibbox", bs1, bs2); }); + assert(bs1.empty()); + assert(bs2.empty()); + + bs1 &= b; + bs2 &= b; + xtime(time_check, [&]() { + check_equal("intersection with empty ibbox", bs1, bs2); }); + assert(bs1.empty()); + assert(bs2.empty()); + + bs1 += b; + bs2 += b; + xtime(time_check, [&]() { + check_equal("symmetric union with empty ibbox", bs1, bs2); }); + assert(bs1.empty()); + assert(bs2.empty()); + + bs1 -= b; + bs2 -= b; + xtime(time_check, [&]() { + check_equal("difference with empty ibbox", bs1, bs2); }); + assert(bs1.empty()); + assert(bs2.empty()); + + + + // Some basic tests + + b = ibbox(ivect(0*str), ivect(9*str), ivect(str)); + bs1 += b; + bs2 += b; + xtime(time_check, [&]() { check_equal("add ibbox", bs1, bs2); }); + + bs1 -= b; + bs2 -= b; + xtime(time_check, [&]() { check_equal("subtract ibbox", bs1, bs2); }); + + bs1 |= b; + bs2 |= b; + xtime(time_check, [&]() { check_equal("union", bs1, bs2); }); + + bs1 &= b; + bs2 &= b; + xtime(time_check, [&]() { check_equal("intersection", bs1, bs2); }); + + ibset1 bs1a = bs1.shift(ivect(1)); + ibset2 bs2a = bs2.shift(ivect(1)); + xtime(time_check, [&]() { check_equal("shift", bs1a, bs2a); }); + + ibset1 bs1b = bs1.expand(ivect(1), ivect(1)); + ibset2 bs2b = bs2.expand(ivect(1), ivect(1)); + xtime(time_check, [&]() { check_equal("expand", bs1b, bs2b); }); + + ibset1 bs1c = bs1 & bs1a; + ibset2 bs2c = bs2 & bs2a; + xtime(time_check, [&]() { + check_equal("non-trivial intersection", bs1c, bs2c); }); + + ibset1 bs1d = bs1b - bs1; + ibset2 bs2d = bs2b - bs2; + xtime(time_check, [&]() { + check_equal("non-trivial difference", bs1d, bs2d); }); + + + + // Many tests with random sets + + bs1 = ibset1(); + bs2 = ibset2(); + xtime(time_check, [&]() { + check_equal("many dense bboxes (init)", bs1, bs2); }); + + time1 = time2 = time_check = 0.0; + for (int n=0; n<40; ++n) { + ivect lo, up; + for (int d=0; d> full_boxes(components); + level_boxes_t level_boxes; + for (int c=0; c::owned); }); + xtime(time2, [&]() { + allowned2 = ibset2(full_boxes, &full_boxes_t::owned); }); + xtime(time_check, [&]() { + check_equal("allowned", allowned1, allowned2); }); + xtime(time1a, [&]() { assert(allowned1 <= domain_active); }); + xtime(time2a, [&]() { assert(allowned2 <= domain_active); }); + + // All not-owned regions + ibset1 notowned1; + ibset2 notowned2; + xtime(time1, [&]() { notowned1 = domain_active - allowned1; }); + xtime(time2, [&]() { notowned2 = domain_active - allowned2; }); + xtime(time_check, [&]() { + check_equal("notowned", notowned1, notowned2); }); + + // All not-active points + ibset1 notactive1; + ibset2 notactive2; + xtime(time1, [&]() { + notactive1 = notowned1.expand(buffer_width + overlap_width); }); + xtime(time2, [&]() { + notactive2 = notowned2.expand(buffer_width + overlap_width); }); + xtime(time_check, [&]() { + check_equal("notactive", notactive1, notactive2); }); + + // All not-active points, in stages + int const num_substeps = + any(any(ghost_width == 0)) ? + 0 : + minval(minval(buffer_width / ghost_width)); + assert(all(all(buffer_width == num_substeps * ghost_width))); + vector notactive_stepped1(num_substeps+1); + vector notactive_stepped2(num_substeps+1); + notactive_stepped1.AT(0) = notowned1; + notactive_stepped2.AT(0) = notowned2; + for (int substep=1; substep<=num_substeps; ++substep) { + xtime(time1, [&]() { + notactive_stepped1.AT(substep) = + notactive_stepped1.AT(substep-1).expand(ghost_width); }); + xtime(time2, [&]() { + notactive_stepped2.AT(substep) = + notactive_stepped2.AT(substep-1).expand(ghost_width); }); + xtime(time_check, [&]() { + check_equal("notactive_stepped[" + to_str(substep) + "]", + notactive_stepped1.AT(substep), + notactive_stepped2.AT(substep)); }); + } + ibset1 notactive_overlaps1; + ibset2 notactive_overlaps2; + xtime(time1a, [&]() { + notactive_overlaps1 = + notactive_stepped1.AT(num_substeps).expand(overlap_width); }); + xtime(time2a, [&]() { + notactive_overlaps2 = + notactive_stepped2.AT(num_substeps).expand(overlap_width); }); + xtime(time_check, [&]() { + check_equal("notactive_overlaps", + notactive_overlaps1, notactive_overlaps2); }); + if (all(all(buffer_width == num_substeps * ghost_width))) { + xtime(time1a, [&]() { assert(notactive_overlaps1 == notactive1); }); + xtime(time2a, [&]() { assert(notactive_overlaps2 == notactive2); }); + } + + // All buffer zones + ibset1& allbuffers1 = level_boxes.buffers1; + ibset2& allbuffers2 = level_boxes.buffers2; + xtime(time1, [&]() { + allbuffers1 = allowned1 & notowned1.expand(buffer_width); }); + xtime(time2, [&]() { + allbuffers2 = allowned2 & notowned2.expand(buffer_width); }); + xtime(time_check, [&]() { + check_equal("allbuffers", allbuffers1, allbuffers2); }); + + // All overlap zones + ibset1 alloverlaps1; + ibset2 alloverlaps2; + xtime(time1, [&]() { + alloverlaps1 = (allowned1 & notactive1) - allbuffers1; }); + xtime(time2, [&]() { + alloverlaps2 = (allowned2 & notactive2) - allbuffers2; }); + xtime(time_check, [&]() { + check_equal("alloverlaps", alloverlaps1, alloverlaps2); }); + + // All active points + ibset1& allactive1 = level_boxes.active1; + ibset2& allactive2 = level_boxes.active2; + xtime(time1, [&]() { allactive1 = allowned1 - notactive1; }); + xtime(time2, [&]() { allactive2 = allowned2 - notactive2; }); + xtime(time_check, [&]() { + check_equal("allactive", allactive1, allactive2); }); + + // All stepped buffer zones + vector allbuffers_stepped1(num_substeps); + vector allbuffers_stepped2(num_substeps); + ibset1 allbuffers_stepped_combined1; + ibset2 allbuffers_stepped_combined2; + for (int substep=0; substep.", D); + } + +} // namespace + + + +extern "C" +void TestBBoxSet2_test(CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/CarpetExtra/TestBBoxSet2/test/bboxset2.par b/CarpetExtra/TestBBoxSet2/test/bboxset2.par new file mode 100644 index 000000000..cb54ea8ed --- /dev/null +++ b/CarpetExtra/TestBBoxSet2/test/bboxset2.par @@ -0,0 +1,6 @@ +ActiveThorns = "Carpet CarpetLib CoordBase IOUtil TestBBoxSet2" + +IOUtil::out_dir = $parfile + +TestBBoxSet2::verbose = no +TestBBoxSet2::components_goal = 20000 -- cgit v1.2.3