HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
VlasovWriteSpatialField.c File Reference

Write out the field to file. More...

#include <stdlib.h>
#include <string.h>
#include <basic.h>
#include <common.h>
#include <arrayfunctions.h>
#include <mathfunctions.h>
#include <io.h>
#include <mpivars.h>
#include <hypar.h>
#include <physicalmodels/vlasov.h>

Go to the source code of this file.

Functions

int VlasovWriteSpatialField (void *s, void *m, double *a_field, char *fname_root)
 

Detailed Description

Write out the field to file.

Author
Ping-Hsuan Tsai

Definition in file VlasovWriteSpatialField.c.

Function Documentation

◆ VlasovWriteSpatialField()

int VlasovWriteSpatialField ( void *  s,
void *  m,
double *  a_field,
char *  fname_root 
)

Write out a spatial field or variable to file

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
a_fieldVector field to write
fname_rootFilename root (extension is added automatically). For unsteady output, a numerical index is added that is the same as for the solution output files.

Definition at line 18 of file VlasovWriteSpatialField.c.

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
#define IERR
Definition: basic.h:16
char * filename_index
Definition: hypar.h:197
int nsims
Definition: hypar.h:64
double * x
Definition: hypar.h:107
int WriteText(int, int, int *, double *, double *, char *, int *)
Definition: WriteText.c:27
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)
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.
#define _ArrayCopy1D_(x, y, size)
int * dim_global
Definition: hypar.h:33
int ndims_x
Definition: vlasov.h:63