aboutsummaryrefslogtreecommitdiff
path: root/src/Output3D.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Output3D.c')
-rw-r--r--src/Output3D.c487
1 files changed, 487 insertions, 0 deletions
diff --git a/src/Output3D.c b/src/Output3D.c
new file mode 100644
index 0000000..41143a9
--- /dev/null
+++ b/src/Output3D.c
@@ -0,0 +1,487 @@
+ /*@@
+ @file Output3D.c
+ @date 01 Oct 1999
+ @author Jonghyun Lee
+ @desc Functions to deal 3D output of GFs
+ @enddesc
+ @history
+ @hendhistory
+ @@*/
+
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cctk.h"
+#include "cctk_Flesh.h"
+#include "cctk_Groups.h"
+#include "cctk_parameters.h"
+#include "cctk_GHExtensions.h"
+#include "cctk_WarnLevel.h"
+#include "cctk_Comm.h"
+#include "ioPandaGH.h"
+#include "Panda/c_interface.h"
+#include "CactusBase/IOUtil/src/ioGH.h"
+#ifdef CACTUSPUGH_PUGH
+#include "CactusPUGH/PUGH/src/include/pugh.h"
+#endif
+#ifdef SGI
+#include <time.h>
+#endif
+
+#include "external/IEEEIO/src/IOProtos.h"
+
+int IOPanda_Output3DVarAs (cGH *GH, const char *var, const char *alias);
+int IOPanda_TimeFor3D (cGH *GH, int index);
+void IOPanda_Timestep (cGH *GH, int index, const char *alias);
+void IOPanda_AddCommonAttributes (cGH *GH, int index, int timelevel, CCTK_INT *gsz, char *fname);
+void IOPanda_IEEEIOStructDump (cGH *GH, char *fname);
+
+/*@@
+ @routine IOPanda_Output3DGH
+ @date Sat March 6 1999
+ @author Gabrielle Allen
+ @desc
+ Loops over all variables and outputs them if necessary
+ @enddesc
+ @calls CCTK_GHExtensionHandle
+ CCTK_NumVars
+ CCTK_ImplementationFromVar
+ CCTK_VarName
+ IOPanda_TimeFor3D
+ IOPanda_Output3DVarAs
+ @calledby
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype cGH
+ @vio in
+ @vcomment
+ @endvar
+@@*/
+
+int IOPanda_Output3DGH (cGH *GH)
+{
+ int i;
+ pandaGH *myGH;
+ char *implementation;
+ char *name;
+ char *fullname;
+ DECLARE_CCTK_PARAMETERS
+
+ /* Get the GH extension for IOPanda */
+ myGH = (pandaGH *) GH->extensions [CCTK_GHExtensionHandle ("IOPanda")];
+
+ if (myGH->IO_3Devery <= 0)
+ return;
+
+ /* Loop over all variables */
+ for (i = 0; i < CCTK_NumVars (); i++) {
+ if (IOPanda_TimeFor3D (GH, i)) {
+ implementation = CCTK_ImpFromVarI (i);
+ name = CCTK_VarName (i);
+ fullname = (char *) malloc (strlen (implementation) +
+ strlen (name) + 3);
+ assert (fullname);
+ sprintf (fullname, "%s::%s", implementation, name);
+
+ if (verbose) {
+ printf ("IOPanda Output3DGH : \n");
+ printf (" fullname/name = %s/%s\n", fullname, name);
+ }
+
+ IOPanda_Output3DVarAs (GH, fullname, name);
+
+ free (fullname);
+
+ /* Register another 3D output for this GF */
+ myGH->IO_3Dnum [i]++;
+
+ /* Register GF as having 3D output this iteration */
+ myGH->IO_3Dlast [i] = GH->cctk_iteration;
+ }
+ }
+
+ return (0);
+}
+
+
+/*@@
+ @routine IOPanda_Output3DVarAs
+ @date Sat March 6 1999
+ @author Gabrielle Allen
+ @desc
+ unconditional output of a variable using the IOPanda 3D output method
+ @enddesc
+ @calls CCTK_DecomposeName
+ CCTK_VarIndex
+ CCTK_GHExtensionHandle
+ IOPanda_Write3D
+ @calledby IOPanda_Output3DGH
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype cGH
+ @vio in
+ @vcomment
+ @endvar
+ @var fullname
+ @vdesc complete name of variable to output
+ @vtype const char *
+ @vio in
+ @vcomment
+ @endvar
+ @var alias
+ @vdesc alias name of variable to output (used to generate output filename)
+ @vtype const char *
+ @vio in
+ @vcomment
+ @endvar
+@@*/
+
+int IOPanda_Output3DVarAs (cGH *GH, const char *fullname, const char *alias)
+{
+ DECLARE_CCTK_PARAMETERS
+ int index;
+ pandaGH *myGH;
+
+ index = CCTK_VarIndex(fullname);
+
+ /* Get the GH extension for IOPanda */
+ myGH = (pandaGH *) GH->extensions [CCTK_GHExtensionHandle ("IOPanda")];
+
+ if (verbose) {
+ printf ("\nIn IOPanda Output3DVarAs\n-------------------\n");
+ printf (" Fullname = -%s-\n", fullname);
+ printf (" Alias = -%s-\n", alias);
+ printf (" Index = %d\n", index);
+ }
+
+ /* Do the 3D output */
+ IOPanda_Timestep (GH, index, alias);
+
+ return (0);
+}
+
+
+/*@@
+ @routine IOPanda_TimeFor3D
+ @date Sat March 6 1999
+ @author Gabrielle Allen
+ @desc
+ Decides if it is time to output a variable using the IOPanda 3D output
+ method
+ @enddesc
+ @calls CCTK_GHExtensionHandle
+ CCTK_GroupTypeFromVarI
+ CCTK_WARN
+ CCTK_QueryGroupStorageI
+ CCTK_GroupNameFromVarI
+ @calledby IOPanda_Output3DGH
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype cGH
+ @vio in
+ @vcomment
+ @endvar
+ @var index
+ @vdesc index of variable
+ @vtype int
+ @vio in
+ @vcomment
+ @endvar
+@@*/
+
+int IOPanda_TimeFor3D (cGH *GH, int index)
+{
+ pandaGH *myGH;
+
+ /* Get the GH extension for IOPanda */
+ myGH = (pandaGH *) GH->extensions [CCTK_GHExtensionHandle ("IOPanda")];
+
+ /* Check this GF should be output */
+ if (! (myGH->IO_3Dnum [index] != 0 &&
+ GH->cctk_iteration % myGH->IO_3Devery == 0))
+ return (0);
+
+ /* Check GF not already output this iteration */
+ if (myGH->IO_3Dlast [index] == GH->cctk_iteration) {
+ CCTK_WARN (2, "Already done 3D output in IOPanda");
+ return (0);
+ }
+
+ /* Check GF has storage */
+ if (! CCTK_QueryGroupStorageI (GH,
+ CCTK_GroupIndexFromVarI(index))) {
+ char *fullname = CCTK_FullName (index);
+ char *msg = (char *) malloc (80 + strlen (fullname));
+
+ sprintf (msg, "No IOPandaIO 3D output for '%s' (no storage)", fullname);
+ CCTK_WARN (2, msg);
+ free (fullname);
+ free (msg);
+ return (0);
+ }
+
+ return (1);
+}
+
+
+/*@@
+ @routine IOPanda_TriggerOutput3D
+ @date Sat March 6 1999
+ @author Gabrielle Allen
+ @desc
+ Triggers the output a variable using the IOPanda 3D output
+ method
+ @enddesc
+ @calls CCTK_GHExtensionHandle
+ CCTK_VarName
+ IOPanda_Write3D
+ @calledby
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK GH
+ @vtype cGH
+ @vio in
+ @vcomment
+ @endvar
+ @var index
+ @vdesc index of variable to output
+ @vtype int
+ @vio in
+ @vcomment
+ @endvar
+@@*/
+
+int IOPanda_TriggerOutput3D (cGH *GH, int index)
+{
+ DECLARE_CCTK_PARAMETERS
+ pandaGH *myGH;
+ char *varname;
+
+ varname = CCTK_VarName (index);
+
+ /* Get the GH extension for IOPanda */
+ myGH = (pandaGH *) GH->extensions [CCTK_GHExtensionHandle ("IOPanda")];
+
+ if (verbose) {
+ printf("\nIn IOPanda TriggerOutput3D\n---------------------\n");
+ printf(" Index = %d\n", index);
+ printf(" Variable = -%s-\n", varname);
+ }
+
+ /* Do the 3D output */
+ IOPanda_Timestep (GH, index, varname);
+
+ /* Register another 3D output for this GF */
+ myGH->IO_3Dnum [index]++;
+
+ /* Register GF as having 3D output this iteration */
+ myGH->IO_3Dlast [index] = GH->cctk_iteration;
+
+ return (0);
+}
+
+void IOPanda_Timestep(cGH *GH, int index, const char *alias)
+{
+ DECLARE_CCTK_PARAMETERS
+ void *data;
+ int tmp[1], tmp1[3], tmp2[3];
+ Distribution dist1[3], dist2[3];
+ CCTK_INT4 bnd[9];
+ int free_flag, timelevel;
+ ArrayInfo ainfo;
+
+ ioGH *ioUtilGH;
+ pGH *pughGH;
+
+ if (CCTK_GroupTypeFromVarI (index) == GROUP_SCALAR) {
+ printf("##### %s is scalar\n", alias);
+ return;
+ }
+
+ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
+ pughGH = (pGH *) GH->extensions [CCTK_GHExtensionHandle ("PUGH")];
+
+ ainfo.name_ = (char *)alias;
+
+ ainfo.rank_ = 3;
+ tmp1[0] = GH->cctk_gsh[2];
+ tmp1[1] = GH->cctk_gsh[1];
+ tmp1[2] = GH->cctk_gsh[0];
+ ainfo.size_ = tmp1;
+
+ switch (CCTK_VarTypeI (index)) {
+ case CCTK_VARIABLE_CHAR:
+ ainfo.esize_ = CHAR;
+ break;
+ case CCTK_VARIABLE_INT:
+#ifdef CCTK_INTEGER_PRECISION_8
+ ainfo.esize_ = INT64;
+#elif CCTK_INTEGER_PRECISION_4
+ ainfo.esize_ = INT32;
+#elif CCTK_INTEGER_PRECISION_2
+ ainfo.esize_ = INT16;
+#endif
+ break;
+ case CCTK_VARIABLE_REAL:
+ if (ioUtilGH->out_single) ainfo.esize_ = FLOAT32;
+ else {
+#ifdef CCTK_REAL_PRECISION_8
+ ainfo.esize_ = FLOAT64;
+#elif CCTK_REAL_PRECISION_4
+ ainfo.esize_ = FLOAT32;
+#endif
+ }
+ }
+
+ ainfo.mem_rank_ = 3;
+ tmp2[0] = pughGH->nprocz; tmp2[1] = pughGH->nprocy; tmp2[2] = pughGH->nprocx;
+ ainfo.mem_layout_ = tmp2;
+ dist1[0] = dist1[1] = dist1[2] = BLOCK;
+ ainfo.mem_dist_ = dist1;
+
+ ainfo.disk_rank_ = 1;
+ dist2[0] = BLOCK; dist2[1] = dist2[2] = NONE;
+ tmp[0]= ((CCTK_nProcs(GH) - 1) / ioUtilGH->ioproc_every + 1);
+
+ ainfo.disk_layout_ = tmp;
+ ainfo.disk_dist_ = dist2;
+
+ timelevel = CCTK_NumTimeLevelsFromVarI (index) - 1;
+ if (timelevel > 0) timelevel--;
+
+ IOPanda_getDumpData(GH, index, timelevel, &data, &free_flag, bnd,
+ ainfo.esize_);
+ ainfo.data_ = (char *)data;
+ ainfo.stencil_width_ = pughGH->nghostzones;
+
+
+ PandaTimestep(&ainfo);
+ IOPanda_AddCommonAttributes(GH, index, timelevel, ainfo.size_, ainfo.name_);
+ if (PandaIsNewFile(ainfo.name_)) IOPanda_IEEEIOStructDump(GH, ainfo.name_);
+}
+
+void IOPanda_AddCommonAttributes (cGH *GH, int index, int timelevel,
+ CCTK_INT4 gsz [3], char *fname)
+{
+ DECLARE_CCTK_PARAMETERS
+ CCTK_REAL d3_to_IO [6]; /* buffer for writing doubles to IEEEIO */
+ CCTK_INT4 i_to_IO; /* buffer for writing an int to IEEEIO */
+ char *name, *gname;
+ ioGH *ioUtilGH;
+ char *char_time_date = "";
+
+#ifdef SGI
+ time_t t = time(NULL);
+ char_time_date = asctime (localtime (&t));
+#endif
+
+ /* Get the handle for IO extensions */
+ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
+
+ name = CCTK_FullName (index);
+
+ Panda_WriteAttribute (fname, "name", BYTE, strlen (name) + 1, name);
+
+ free (name);
+
+ gname = CCTK_GroupNameFromVarI (index);
+ Panda_WriteAttribute (fname, "groupname", BYTE, strlen (gname) + 1, gname);
+ free (gname);
+
+ i_to_IO = CCTK_GroupTypeFromVarI (index);
+ Panda_WriteAttribute (fname, "grouptype", INT32,
+ 1, &i_to_IO);
+
+ i_to_IO = CCTK_NumTimeLevelsFromVarI (index);
+ Panda_WriteAttribute (fname, "ntimelevels", INT32,
+ 1, &i_to_IO);
+
+ i_to_IO = timelevel;
+ Panda_WriteAttribute (fname, "timelevel", INT32,
+ 1, &i_to_IO);
+
+ if (char_time_date && out3D_datestamp)
+ Panda_WriteAttribute (fname, "date", BYTE,
+ strlen (char_time_date) + 1, char_time_date);
+
+ Panda_WriteAttribute (fname, "time", FLOAT64, 1,&GH->cctk_time);
+
+ d3_to_IO [0] = CCTK_CoordOrigin ("x");
+ d3_to_IO [1] = CCTK_CoordOrigin ("y");
+ d3_to_IO [2] = CCTK_CoordOrigin ("z");
+ Panda_WriteAttribute (fname, "origin", FLOAT64,3,d3_to_IO);
+ CCTK_CoordRange (GH, &d3_to_IO [0], &d3_to_IO [3], "x");
+ CCTK_CoordRange (GH, &d3_to_IO [1], &d3_to_IO [4], "y");
+ CCTK_CoordRange (GH, &d3_to_IO [2], &d3_to_IO [5], "z");
+ Panda_WriteAttribute (fname, "min_ext",FLOAT64,3,d3_to_IO);
+ Panda_WriteAttribute (fname, "max_ext",FLOAT64, 3,d3_to_IO+3);
+
+ d3_to_IO [0] = GH->cctk_delta_space [0] * ioUtilGH->downsample_x;
+ d3_to_IO [1] = GH->cctk_delta_space [1] * ioUtilGH->downsample_y;
+ d3_to_IO [2] = GH->cctk_delta_space [2] * ioUtilGH->downsample_z;
+ Panda_WriteAttribute (fname, "delta", FLOAT64, 3,d3_to_IO);
+
+ if (ioUtilGH->downsample_x > 1 ||
+ ioUtilGH->downsample_y > 1 ||
+ ioUtilGH->downsample_z > 1) {
+ d3_to_IO [0] = GH->cctk_delta_space [0];
+ d3_to_IO [1] = GH->cctk_delta_space [1];
+ d3_to_IO [2] = GH->cctk_delta_space [2];
+ Panda_WriteAttribute (fname, "evolution_delta", FLOAT64, 3, d3_to_IO);
+ }
+
+ Panda_WriteAttribute (fname, "global_size", INT32, 3, gsz);
+
+ i_to_IO = CCTK_nProcs (GH);
+ Panda_WriteAttribute (fname, "nprocs", INT32, 1, &i_to_IO);
+
+ i_to_IO = ioUtilGH->ioproc_every;
+ Panda_WriteAttribute (fname, "ioproc_every", INT32, 1, &i_to_IO);
+
+ i_to_IO = ioUtilGH->unchunked;
+ Panda_WriteAttribute (fname, "unchunked", INT32, 1, &i_to_IO);
+
+ i_to_IO = GH->cctk_iteration;
+ Panda_WriteAttribute (fname, "iteration", INT32, 1, &i_to_IO);
+}
+
+
+void IOPanda_IEEEIOStructDump (cGH *GH, char *fname)
+{
+
+ CCTK_INT4 i_temp;
+ CCTK_REAL d_temp;
+ ioGH *ioUtilGH;
+
+
+ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
+
+ i_temp = GH->cctk_iteration;
+ Panda_WriteAttribute (fname, "GH$iteration", INT32,
+ 1, &i_temp);
+
+ i_temp = ioUtilGH->ioproc_every;
+ Panda_WriteAttribute (fname, "GH$ioproc_every", INT32,
+ 1, &i_temp);
+
+ i_temp = CCTK_nProcs (GH);
+ Panda_WriteAttribute (fname, "GH$nprocs", INT32,
+ 1, &i_temp);
+
+ d_temp = GH->cctk_time;
+ Panda_WriteAttribute (fname, "GH$time", FLOAT64,
+ 1, &d_temp);
+}