aboutsummaryrefslogtreecommitdiff
path: root/src/patch
diff options
context:
space:
mode:
authorjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-17 17:13:47 +0000
committerjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-17 17:13:47 +0000
commit30801866f7ecdaca9f718025372ad5f85b041da3 (patch)
tree06cdd8875eaea4089a7fa26a5b78dd8504109488 /src/patch
parent5dfff7277b864a32e79527ad50b0985f37fabad7 (diff)
merge common code in print nominal/ghosted routines into new
print_unknown_gridfn() routines, both in patch:: and patch_system:: also new patch:: read routines also declarations (but no code yet) for patch_system:: read routines git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@534 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/patch')
-rw-r--r--src/patch/grid.hh2
-rw-r--r--src/patch/patch.cc139
-rw-r--r--src/patch/patch.hh44
-rw-r--r--src/patch/patch_system.cc56
-rw-r--r--src/patch/patch_system.hh23
5 files changed, 185 insertions, 79 deletions
diff --git a/src/patch/grid.hh b/src/patch/grid.hh
index e365abf..a5cf316 100644
--- a/src/patch/grid.hh
+++ b/src/patch/grid.hh
@@ -39,6 +39,8 @@
// There are separate sets of nominal-grid and ghosted-grid gridfns.
// We identify a gridfn by a small-integer "grid function number", a.k.a.
// "gfn". There are separate gfns for nominal and ghosted gridfns.
+// In a very few places we refer to "unknown-grid" gridfns; these might
+// be either nominal-grid or ghosted-grid.
//
// For our application (apparent horizon finding), it's useful for the
// storage for a single gridfn to be contiguous *across all patches*.
diff --git a/src/patch/patch.cc b/src/patch/patch.cc
index a56a6e3..5465be9 100644
--- a/src/patch/patch.cc
+++ b/src/patch/patch.cc
@@ -18,8 +18,7 @@
// patch::edge_adjacent_to_patch
// patch::assert_all_ghost_zones_fully_setup
//
-// patch::print_gridfn
-// patch::print_ghosted_gridfn
+// patch::print_unknown_gridfn
//
// patch_info::grid_array_pars
// patch_info::grid_pars
@@ -422,24 +421,37 @@ max_sigma_ghost_zone().assert_fully_setup();
//******************************************************************************
//
-// This function prints a nominal-grid gridfn in ASCII format to an
+// This function prints an unknown-grid gridfn in ASCII format to an
// already-open stdio stream. The output format is suitable for a
// gnuplot 'splot' command. Individual patches may be selected with
// the select.patch program (perl script).
//
-void patch::print_gridfn(int gfn, FILE *output_fp = stdout)
+void patch::print_unknown_gridfn(bool ghosted_flag, int unknown_gfn,
+ FILE *output_fp = stdout,
+ bool want_ghost_zones = true)
const
{
+if (want_ghost_zones && !ghosted_flag)
+ then error_exit(PANIC_EXIT,
+"***** patch::print_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" can't have want_ghost_zones && !ghosted_flag !\n"
+,
+ name(), unknown_gfn); /*NOTREACHED*/
+
fprintf(output_fp, "### %s patch\n", name());
-fprintf(output_fp, "# gfn=%d\n", gfn);
+fprintf(output_fp, "# %s_gfn=%d\n",
+ (ghosted_flag ? "ghosted" : "nominal"), unknown_gfn);
fprintf(output_fp, "# dpx = %s\n", name_of_dpx());
fprintf(output_fp, "# dpy = %s\n", name_of_dpy());
fprintf(output_fp, "#\n");
-fprintf(output_fp, "# dpx\tdpy\tgridfn\tirho\tisigma\n");
- for (int irho = min_irho() ; irho <= max_irho() ; ++irho)
+fprintf(output_fp, "# dpx\tdpy\tgridfn\n");
+
+ for (int irho = effective_min_irho(want_ghost_zones) ;
+ irho <= effective_max_irho(want_ghost_zones) ;
+ ++irho)
{
- for (int isigma = min_isigma() ;
- isigma <= max_isigma() ;
+ for (int isigma = effective_min_isigma(want_ghost_zones) ;
+ isigma <= effective_max_isigma(want_ghost_zones) ;
++isigma)
{
const fp rho = rho_of_irho(irho);
@@ -448,49 +460,104 @@ fprintf(output_fp, "# dpx\tdpy\tgridfn\tirho\tisigma\n");
const fp dpy = dpy_of_rho_sigma(rho, sigma);
fprintf(output_fp,
"%g\t%g\t%.15g\n",
- dpx, dpy, gridfn(gfn,irho,isigma));
+ dpx, dpy,
+ (ghosted_flag ? ghosted_gridfn(unknown_gfn, irho,isigma)
+ : gridfn(unknown_gfn, irho,isigma)));
}
fprintf(output_fp, "\n");
}
}
//******************************************************************************
+//******************************************************************************
+//******************************************************************************
//
-// This function prints a ghosted-grid gridfn in ASCII format to an
-// already-open stdio stream. The output format is suitable for a
-// gnuplot 'splot' command. Individual patches may be selected with
-// the select.patch program (perl script).
+// This function reads an unknown-grid gridfn in ASCII format from an
+// already-open stdio stream. Comments ('#' in column 1) and blank lines
+// are ignored, otherwise the input format matches that written by
+// print_unknown_gridfn().
//
-void patch::print_ghosted_gridfn(int ghosted_gfn,
- FILE *output_fp = stdout,
- bool want_ghost_zones = true)
- const
+// Line numbers (1-origin) are used only for error messages.
+// The function return value is the next line number to be read.
+//
+int patch::read_unknown_gridfn(bool ghosted_flag, int unknown_gfn,
+ int starting_line_number = 1,
+ FILE *input_fp = stdin,
+ bool want_ghost_zones = true)
{
-fprintf(output_fp, "### %s patch\n", name());
-fprintf(output_fp, "# ghosted_gfn=%d\n", ghosted_gfn);
-fprintf(output_fp, "# dpx = %s\n", name_of_dpx());
-fprintf(output_fp, "# dpy = %s\n", name_of_dpy());
-fprintf(output_fp, "#\n");
-fprintf(output_fp, "# dpx\tdpy\tgridfn\tirho\tisigma\n");
+if (want_ghost_zones && !ghosted_flag)
+ then error_exit(PANIC_EXIT,
+"***** patch::read_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" can't have want_ghost_zones && !ghosted_flag !\n"
+,
+ name(), unknown_gfn); /*NOTREACHED*/
+
+int line_number = starting_line_number;
for (int irho = effective_min_irho(want_ghost_zones) ;
irho <= effective_max_irho(want_ghost_zones) ;
++irho)
{
- for (int isigma = effective_min_isigma(want_ghost_zones) ;
- isigma <= effective_max_isigma(want_ghost_zones) ;
- ++isigma)
+ for (int isigma = effective_min_isigma(want_ghost_zones) ;
+ isigma <= effective_max_isigma(want_ghost_zones) ;
+ ++isigma)
+ {
+ const fp rho = rho_of_irho(irho);
+ const fp sigma = sigma_of_isigma(isigma);
+ const fp dpx = dpx_of_rho_sigma(rho, sigma);
+ const fp dpy = dpy_of_rho_sigma(rho, sigma);
+
+ const int N_buffer = 100;
+ char buffer[N_buffer];
+ // read/discard comments and blank lines
+ do
{
- const fp rho = rho_of_irho(irho);
- const fp sigma = sigma_of_isigma(isigma);
- const fp dpx = dpx_of_rho_sigma(rho, sigma);
- const fp dpy = dpy_of_rho_sigma(rho, sigma);
- fprintf(output_fp,
- "%g\t%g\t%.15g\n",
- dpx, dpy, ghosted_gridfn(ghosted_gfn,irho,isigma));
- }
- fprintf(output_fp, "\n");
+ if (fgets(buffer, N_buffer, input_fp) == NULL)
+ then error_exit(ERROR_EXIT,
+"***** patch::read_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" I/O error or unexpected end-of-file on input!\n"
+" at irho=%d of [%d,%d], isigma=%d of [%d,%d]\n"
+" dpx=%g dpy=%g\n"
+,
+ name(), unknown_gfn,
+ irho, effective_min_irho(want_ghost_zones),
+ effective_max_irho(want_ghost_zones),
+ isigma,
+ effective_min_isigma(want_ghost_zones),
+ effective_max_isigma(want_ghost_zones),
+ dpx, dpy); /*NOTREACHED*/
+ ++line_number;
+ } while ((buffer[0] == '#') || (buffer[0] == '\n'));
+
+ double read_dpx, read_dpy, read_gridfn_value;
+ if (sscanf(buffer, "%lf %lf %lf",
+ &read_dpx, &read_dpy, &read_gridfn_value) != 3)
+ then error_exit(ERROR_EXIT,
+"***** patch::read_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" bad input data at input line %d!\n"
+,
+ name(), unknown_gfn,
+ line_number); /*NOTREACHED*/
+ if (! ( jtutil::fuzzy<fp>::EQ(read_dpx,dpx)
+ && jtutil::fuzzy<fp>::EQ(read_dpy,dpy) ) )
+ then error_exit(ERROR_EXIT,
+"***** patch::read_unknown_gridfn(%s patch, unknown_gfn=%d):\n"
+" wrong (dpx,dpy) at input line %d!\n"
+" expected (%g,%g)\n"
+" read (%g,%g)\n"
+,
+ name(), unknown_gfn,
+ line_number,
+ dpx, dpy,
+ read_dpx, read_dpy); /*NOTREACHED*/
+
+ if (ghosted_flag)
+ then ghosted_gridfn(unknown_gfn, irho,isigma) = read_gridfn_value;
+ else gridfn(unknown_gfn, irho,isigma) = read_gridfn_value;
}
+ }
+
+return line_number;
}
//******************************************************************************
diff --git a/src/patch/patch.hh b/src/patch/patch.hh
index 7bfdc37..14cfafd 100644
--- a/src/patch/patch.hh
+++ b/src/patch/patch.hh
@@ -186,13 +186,53 @@ public:
//
// ***** I/O *****
//
- // these print a gridfn to an already-open stdio stream
- void print_gridfn(int gfn, FILE *output_fp = stdout) const;
+
+ // print a gridfn to an already-open stdio stream
+public:
+ void print_gridfn(int gfn, FILE *output_fp = stdout) const
+ { print_unknown_gridfn(false, gfn, output_fp, false); }
void print_ghosted_gridfn(int ghosted_gfn,
FILE *output_fp = stdout,
bool want_ghost_zones = true)
+ const
+ {
+ print_unknown_gridfn(true, ghosted_gfn,
+ output_fp, want_ghost_zones);
+ }
+private:
+ // ... internal worker function for all printing
+ void print_unknown_gridfn(bool ghosted_flag, int unknown_gfn,
+ FILE *output_fp = stdout,
+ bool want_ghost_zones = true)
const;
+ // read a gridfn to an already-open stdio stream
+ // line numbers (1-origin) are used only for error messages
+ // return value is next line number to be read
+public:
+ int read_gridfn(int gfn,
+ int starting_line_number = 1,
+ FILE *input_fp = stdin)
+ {
+ return read_unknown_gridfn(false, gfn,
+ starting_line_number, input_fp,
+ false); }
+ int read_ghosted_gridfn(int ghosted_gfn,
+ int starting_line_number = 1,
+ FILE *input_fp = stdin,
+ bool want_ghost_zones = true)
+ {
+ return read_unknown_gridfn(true, ghosted_gfn,
+ starting_line_number, input_fp,
+ want_ghost_zones);
+ }
+private:
+ // ... internal worker function for all reading
+ int read_unknown_gridfn(bool ghosted_flag, int unknown_gfn,
+ int starting_line_number = 1,
+ FILE *input_fp = stdin,
+ bool want_ghost_zones = true);
+
//
// ***** (rho,sigma,tau) coordinate conversions *****
diff --git a/src/patch/patch_system.cc b/src/patch/patch_system.cc
index 0598077..453f339 100644
--- a/src/patch/patch_system.cc
+++ b/src/patch/patch_system.cc
@@ -20,10 +20,8 @@
// patch_system::patch_number_of_name
// patch_system::synchronize_ghost_zones
//
-// patch_system::read_gridfn
-// patch_system::read_ghosted_gridfn
-// patch_system::print_gridfn
-// patch_system::print_ghosted_gridfn
+// patch_system::print_unknown_gridfn
+// patch_system::read_unknown_gridfn
//
#include <cstdio>
@@ -1049,59 +1047,39 @@ void patch_system::synchronize_ghost_zones(int ghosted_min_gfn_to_sync,
//******************************************************************************
//
-// This function prints a nominal-grid gridfn in ASCII format to a
+// This function prints an unknown-grid gridfn in ASCII format to a
// named output file. The output format is suitable for a gnuplot
// 'splot' command. Individual patches may be selected with the
// select.patch program (perl script).
//
-void patch_system::print_gridfn(int gfn, const char output_file_name[])
- const
-{
-FILE *output_fp = std::fopen(output_file_name, "w");
-if (output_fp == NULL)
- then error_exit(ERROR_EXIT,
-"***** patch_system::print_gridfn(gfn=%d):\n"
-" can't open output file \"%s\"\n!"
-,
- gfn,
- output_file_name); /*NOTREACHED*/
-
- for (int pn = 0 ; pn < N_patches() ; ++pn)
- {
- const patch& p = ith_patch(pn);
- p.print_gridfn(gfn, output_fp);
- fprintf(output_fp, "\n");
- }
-
-std::fclose(output_fp);
-}
-
-//******************************************************************************
-
-//
-// This function prints a ghosted-grid gridfn in ASCII format to a
-// named output file. The output format is suitable for a gnuplot
-// 'splot' command. Individual patches may be selected with the
-// select.patch program (perl script).
-//
-void patch_system::print_ghosted_gridfn(int ghosted_gfn,
+void patch_system::print_unknown_gridfn(bool ghosted_flag, int unknown_gfn,
const char output_file_name[],
bool want_ghost_zones = true)
const
{
+if (want_ghost_zones && !ghosted_flag)
+ then error_exit(PANIC_EXIT,
+"***** patch_system::print_unknown_gridfn(unknown_gfn=%d):\n"
+" can't have want_ghost_zones && !ghosted_flag !\n"
+,
+ unknown_gfn); /*NOTREACHED*/
+
FILE *output_fp = std::fopen(output_file_name, "w");
if (output_fp == NULL)
then error_exit(ERROR_EXIT,
-"***** patch_system::print_ghosted_gridfn(ghosted_gfn=%d):\n"
+"***** patch_system::print_unknown_gridfn(unknown_gfn=%d):\n"
" can't open output file \"%s\"\n!"
,
- ghosted_gfn,
+ unknown_gfn,
output_file_name); /*NOTREACHED*/
for (int pn = 0 ; pn < N_patches() ; ++pn)
{
const patch& p = ith_patch(pn);
- p.print_ghosted_gridfn(ghosted_gfn, output_fp, want_ghost_zones);
+ if (ghosted_flag)
+ then p.print_ghosted_gridfn(unknown_gfn,
+ output_fp, want_ghost_zones);
+ else p.print_gridfn(unknown_gfn, output_fp);
fprintf(output_fp, "\n");
}
diff --git a/src/patch/patch_system.hh b/src/patch/patch_system.hh
index e11432f..e731251 100644
--- a/src/patch/patch_system.hh
+++ b/src/patch/patch_system.hh
@@ -122,12 +122,31 @@ public:
//
public:
// print to a named file (newly (re)created)
- void print_gridfn(int gfn, const char output_file_name[]) const;
+ void print_gridfn(int gfn, const char output_file_name[]) const
+ { print_unknown_gridfn(false, gfn, output_file_name, false); }
void print_ghosted_gridfn(int ghosted_gfn,
const char output_file_name[],
bool want_ghost_zones = true)
+ const
+ {
+ print_unknown_gridfn(true, ghosted_gfn,
+ output_file_name, want_ghost_zones);
+ }
+private:
+ // ... internal worker function for all printing
+ void print_unknown_gridfn(bool ghosted_flag, int unknown_gfn,
+ const char output_file_name[],
+ bool want_ghost_zones = true)
+ const;
+
+ // read from a named file
+ void read_gridfn(int gfn, const char input_file_name[]) const;
+ void read_ghosted_gridfn(int ghosted_gfn,
+ const char input_file_name[],
+ bool want_ghost_zones = true)
const;
+
//
// ***** misc stuff *****
//
@@ -140,7 +159,6 @@ public:
int ghosted_max_gfn_to_sync);
-
//
// ***** constructor, destructor *****
//
@@ -219,6 +237,7 @@ private:
// assert() that all ghost zones of all patches are fully setup
void assert_all_ghost_zones_fully_setup() const;
+
private:
// we forbid copying and passing by value
// by declaring the copy constructor and assignment operator