HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OutputSolution.cpp
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <math.h>
10 #include <basic.h>
11 #include <common_cpp.h>
12 #include <arrayfunctions.h>
13 #include <io_cpp.h>
14 #include <plotfuncs_cpp.h>
15 #include <timeintegration_cpp.h>
16 #include <mpivars_cpp.h>
17 #include <simulation_object.h>
18 
19 #if defined(HAVE_CUDA)
20 # include <arrayfunctions_gpu.h>
21 #endif
22 
23 /* Function declarations */
24 extern "C" void IncrementFilenameIndex(char*,int);
25 
27 int OutputSolution( void* s,
28  int nsims,
29  double a_time )
30 {
31  SimulationObject* simobj = (SimulationObject*) s;
32  int ns;
34 
35  for (ns = 0; ns < nsims; ns++) {
36 
37  HyPar* solver = &(simobj[ns].solver);
38  MPIVariables* mpi = &(simobj[ns].mpi);
39 
40  if ((!solver->WriteOutput) && (strcmp(solver->plot_solution,"yes"))) continue;
41 
42  /* time integration module may have auxiliary arrays to write out, so get them */
43  int NSolutions = 0;
44  IERR TimeGetAuxSolutions(&NSolutions,NULL,solver,-1,ns); CHECKERR(ierr);
45  if (NSolutions > 10) NSolutions = 10;
46 
47  int nu;
48  char fname_root[_MAX_STRING_SIZE_];
49  char aux_fname_root[_MAX_STRING_SIZE_];
50  strcpy(fname_root, solver->op_fname_root);
51  strcpy(aux_fname_root, solver->aux_op_fname_root);
52 
53  if (nsims > 1) {
54  char index[_MAX_STRING_SIZE_];
55  GetStringFromInteger(ns, index, (int)log10(nsims)+1);
56  strcat(fname_root, "_");
57  strcat(fname_root, index);
58  strcat(aux_fname_root, "_");
59  strcat(aux_fname_root, index);
60  }
61 
62  for (nu=0; nu<NSolutions; nu++) {
63 
64  double *uaux = NULL;
65  IERR TimeGetAuxSolutions(&NSolutions,&uaux,solver,nu,ns); CHECKERR(ierr);
66 
67  IERR WriteArray( solver->ndims,
68  solver->nvars,
69  solver->dim_global,
70  solver->dim_local,
71  solver->ghosts,
72  solver->x,
73  uaux,
74  solver,
75  mpi,
76  aux_fname_root ); CHECKERR(ierr);
77 
78  aux_fname_root[2]++;
79  }
80 
81 #if defined(HAVE_CUDA)
82  if (solver->use_gpu) {
83  /* Copy values from GPU memory to CPU memory for writing. */
84  gpuMemcpy(solver->x, solver->gpu_x, sizeof(double)*solver->size_x, gpuMemcpyDeviceToHost);
85 
86 #ifdef CUDA_VAR_ORDERDING_AOS
87  gpuMemcpy( solver->u,
88  solver->gpu_u,
89  sizeof(double)*solver->ndof_cells_wghosts,
91 #else
92  double *h_u = (double *) malloc(sizeof(double)*solver->ndof_cells_wghosts);
93  gpuMemcpy(h_u, solver->gpu_u, sizeof(double)*solver->ndof_cells_wghosts, gpuMemcpyDeviceToHost);
94  for (int i=0; i<solver->npoints_local_wghosts; i++) {
95  for (int v=0; v<solver->nvars; v++) {
96  solver->u[i*solver->nvars+v] = h_u[i+v*solver->npoints_local_wghosts];
97  }
98  }
99  free(h_u);
100 #endif
101  }
102 #endif
103 
104  WriteArray( solver->ndims,
105  solver->nvars,
106  solver->dim_global,
107  solver->dim_local,
108  solver->ghosts,
109  solver->x,
110  solver->u,
111  solver,
112  mpi,
113  fname_root );
114 
115  if (!strcmp(solver->plot_solution, "yes")) {
116  PlotArray( solver->ndims,
117  solver->nvars,
118  solver->dim_global,
119  solver->dim_local,
120  solver->ghosts,
121  solver->x,
122  solver->u,
123  a_time,
124  solver,
125  mpi,
126  fname_root );
127  }
128 
129  /* increment the index string, if required */
130  if ((!strcmp(solver->output_mode,"serial")) && (!strcmp(solver->op_overwrite,"no"))) {
132  }
133 
134  }
135 
136  return(0);
137 }
int npoints_local_wghosts
Definition: hypar.h:42
int * dim_global
Definition: hypar.h:33
double * u
Definition: hypar.h:116
char aux_op_fname_root[_MAX_STRING_SIZE_]
Definition: hypar.h:208
Function declarations for file I/O functions.
void GetStringFromInteger(int, char *, int)
char plot_solution[_MAX_STRING_SIZE_]
Definition: hypar.h:194
int * dim_local
Definition: hypar.h:37
void gpuMemcpy(void *, const void *, size_t, enum gpuMemcpyKind)
int TimeGetAuxSolutions(int *, double **, void *, int, int)
Contains C++ function declarations for time integration.
int ghosts
Definition: hypar.h:52
char * filename_index
Definition: hypar.h:197
char op_fname_root[_MAX_STRING_SIZE_]
Definition: hypar.h:206
int size_x
Definition: hypar.h:48
int WriteArray(int, int, int *, int *, int, double *, double *, void *, void *, char *)
Definition: WriteArray.c:27
#define _MAX_STRING_SIZE_
Definition: basic.h:14
double * gpu_u
Definition: hypar.h:459
char op_overwrite[_MAX_STRING_SIZE_]
Definition: hypar.h:191
int ndof_cells_wghosts
Definition: hypar.h:47
double * gpu_x
Definition: hypar.h:457
Contains function definitions for common array operations on GPU.
Simulation object.
int nvars
Definition: hypar.h:29
Some common functions used here and there (C++ declarations)
#define CHECKERR(ierr)
Definition: basic.h:18
int OutputSolution(void *, int, double)
int PlotArray(int, int, int *, int *, int, double *, double *, double, void *, void *, char *)
Definition: PlotArray.c:31
int use_gpu
Definition: hypar.h:449
Structure defining a simulation.
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Function declarations for plotting functions.
Contains macros and function definitions for common array operations.
#define IERR
Definition: basic.h:16
int index_length
Definition: hypar.h:199
Structure of MPI-related variables.
double * x
Definition: hypar.h:107
C++ declarations for MPI-related functions.
char output_mode[_MAX_STRING_SIZE_]
Definition: hypar.h:183
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
void IncrementFilenameIndex(char *f, int len)
int(* WriteOutput)(int, int, int *, double *, double *, char *, int *)
Definition: hypar.h:211
#define _DECLARE_IERR_
Definition: basic.h:17