HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
VlasovWriteSpatialField.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <string.h>
8 #include <basic.h>
9 #include <common.h>
10 #include <arrayfunctions.h>
11 #include <mathfunctions.h>
12 #include <io.h>
13 #include <mpivars.h>
14 #include <hypar.h>
15 #include <physicalmodels/vlasov.h>
16 
19  void *m,
20  double *a_field,
21  char *fname_root
25  )
26 {
27  HyPar *solver = (HyPar*) s;
28  MPIVariables *mpi = (MPIVariables*) m;
29  Vlasov *param = (Vlasov*) solver->physics;
30 
31  if (!solver->WriteOutput) return 0;
32 
33  if (solver->nsims > 1) {
34  char index[_MAX_STRING_SIZE_];
35  GetStringFromInteger(solver->my_idx, index, (int)log10(solver->nsims)+1);
36  strcat(fname_root, "_");
37  strcat(fname_root, index);
38  strcat(fname_root, "_");
39  }
40 
41  char filename[_MAX_STRING_SIZE_] = "";
42  strcat(filename,fname_root);
43  if (!strcmp(solver->op_overwrite,"no")) {
44  strcat(filename,"_");
45  strcat(filename,solver->filename_index);
46  }
47  strcat(filename,".dat");
48 
49  int d,
50  ghosts = solver->ghosts,
51  ndims_x = param->ndims_x;
52 
53  int dim_global_x[ndims_x];
54  _ArrayCopy1D_(solver->dim_global, dim_global_x, ndims_x);
55  int dim_local_x[ndims_x];
56  _ArrayCopy1D_(solver->dim_local, dim_local_x, ndims_x);
57 
58  /* gather the spatial coordinates into a global array */
59  double *xg;
60  {
61  int size_g = param->npts_global_x;
62  xg = (double*) calloc (size_g, sizeof(double));
63  _ArraySetValue_(xg, size_g, 0.0);
64 
65  int offset_global, offset_local;
66  offset_global = offset_local = 0;
67  for (d=0; d<ndims_x; d++) {
69  (mpi->rank?NULL:&xg[offset_global]),
70  &solver->x[offset_local+ghosts],
71  mpi->is[d],
72  mpi->ie[d],
73  solver->dim_local[d],
74  0);
75  offset_global += dim_global_x[d];
76  offset_local += dim_local_x [d] + 2*ghosts;
77  }
78  }
79 
80  /* gather the field into a global array */
81  double *field_g;
82  {
83  int size_g = param->npts_global_x * param->ndims_x;
84  field_g = (double*) calloc (size_g, sizeof(double));
85  _ArraySetValue_(field_g, size_g, 0.0);
86 
87  if (param->ndims_x > 1) {
88  if (!mpi->rank) {
89  fprintf(stderr,"Warning in VlasovWriteSpatialField():\n");
90  fprintf(stderr," field writing not yet supported for >1 spatial dimensions.\n");
91  }
92  } else {
94  (mpi->rank ? NULL : field_g),
95  (a_field+ghosts),
96  mpi->is[0],
97  mpi->ie[0],
98  solver->dim_local[0],
99  0);
100  }
101  }
102 
103  if (!mpi->rank) {
104  int idx[ndims_x];
105  WriteText( ndims_x,
106  1,
107  dim_global_x,
108  xg,
109  field_g,
110  filename,
111  idx );
112  }
113 
114  /* free up arrays */
115  free(xg);
116  free(field_g);
117 
118  return 0;
119 }
Definition: vlasov.h:57
Some common functions used here and there.
#define IERR
Definition: basic.h:16
MPI related function definitions.
char * filename_index
Definition: hypar.h:197
Contains function definitions for common mathematical functions.
int VlasovWriteSpatialField(void *s, void *m, double *a_field, char *fname_root)
int nsims
Definition: hypar.h:64
Some basic definitions and macros.
double * x
Definition: hypar.h:107
int WriteText(int, int, int *, double *, double *, char *, int *)
Definition: WriteText.c:27
Vlasov Equation.
long npts_global_x
Definition: vlasov.h:72
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _MAX_STRING_SIZE_
Definition: basic.h:14
int MPIGatherArray1D(void *, double *, double *, int, int, int, int)
Contains structure definition for hypar.
char op_overwrite[_MAX_STRING_SIZE_]
Definition: hypar.h:191
void GetStringFromInteger(int, char *, int)
int my_idx
Definition: hypar.h:61
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
void * physics
Definition: hypar.h:266
int(* WriteOutput)(int, int, int *, double *, double *, char *, int *)
Definition: hypar.h:211
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
Function declarations for file I/O functions.
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
int * dim_global
Definition: hypar.h:33
int ndims_x
Definition: vlasov.h:63