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

Write out the electric field and potential 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 *, void *, double *, char *)
 
int VlasovPlotSpatialField (void *, void *, double *, double, char *)
 
int VlasovWriteEFieldAndPotential (void *s, void *m, double a_t)
 

Detailed Description

Write out the electric field and potential to file.

Author
Debojyoti Ghosh

Definition in file VlasovWriteEFieldAndPotential.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

◆ VlasovPlotSpatialField()

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

Plot a spatial field or variable to file

Plot out a spatial field or variable to file

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
a_fieldVector field to write
a_timeCurrent simulation time
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 26 of file VlasovPlotSpatialField.c.

33 {
34  HyPar *solver = (HyPar*) s;
35  MPIVariables *mpi = (MPIVariables*) m;
36  Vlasov *param = (Vlasov*) solver->physics;
37 
38  if (solver->nsims > 1) {
39  char index[_MAX_STRING_SIZE_];
40  GetStringFromInteger(solver->my_idx, index, (int)log10(solver->nsims)+1);
41  strcat(fname_root, "_");
42  strcat(fname_root, index);
43  strcat(fname_root, "_");
44  }
45 
46  char filename[_MAX_STRING_SIZE_] = "";
47  strcat(filename,fname_root);
48  if (!strcmp(solver->op_overwrite,"no")) {
49  strcat(filename,"_");
50  strcat(filename,solver->filename_index);
51  }
52  strcat(filename,".png");
53 
54  int d,
55  ghosts = solver->ghosts,
56  ndims_x = param->ndims_x;
57 
58  int dim_global_x[ndims_x];
59  _ArrayCopy1D_(solver->dim_global, dim_global_x, ndims_x);
60  int dim_local_x[ndims_x];
61  _ArrayCopy1D_(solver->dim_local, dim_local_x, ndims_x);
62 
63  /* gather the spatial coordinates into a global array */
64  double *xg;
65  {
66  int size_g = param->npts_global_x;
67  xg = (double*) calloc (size_g, sizeof(double));
68  _ArraySetValue_(xg, size_g, 0.0);
69 
70  int offset_global, offset_local;
71  offset_global = offset_local = 0;
72  for (d=0; d<ndims_x; d++) {
74  (mpi->rank?NULL:&xg[offset_global]),
75  &solver->x[offset_local+ghosts],
76  mpi->is[d],
77  mpi->ie[d],
78  solver->dim_local[d],
79  0);
80  offset_global += dim_global_x[d];
81  offset_local += dim_local_x [d] + 2*ghosts;
82  }
83  }
84 
85  /* gather the field into a global array */
86  double *field_g;
87  {
88  int size_g = param->npts_global_x * param->ndims_x;
89  field_g = (double*) calloc (size_g, sizeof(double));
90  _ArraySetValue_(field_g, size_g, 0.0);
91 
92  if (param->ndims_x > 1) {
93  if (!mpi->rank) {
94  fprintf(stderr,"Warning in VlasovPlotSpatialField():\n");
95  fprintf(stderr," field plotting not yet supported for >1 spatial dimensions.\n");
96  }
97  } else {
99  (mpi->rank ? NULL : field_g),
100  (a_field+ghosts),
101  mpi->is[0],
102  mpi->ie[0],
103  solver->dim_local[0],
104  0);
105  }
106  }
107 
108  if (!mpi->rank) {
109 #ifdef with_python
110 #ifdef with_python_numpy
111  import_array();
112  PyObject* py_plt_func = (PyObject*) solver->py_plt_func;
113  PyObject* py_plt_func_args = (PyObject*) solver->py_plt_func_args;
114  py_plt_func_args = PyTuple_New(7);
115  {
116  PyObject* py_obj = Py_BuildValue("i", ndims_x);
117  PyTuple_SetItem(py_plt_func_args, 0, py_obj);
118  }
119  {
120  PyObject* py_obj = Py_BuildValue("i", 1);
121  PyTuple_SetItem(py_plt_func_args, 1, py_obj);
122  }
123  {
124  npy_intp shape[1] = {ndims_x};
125  PyObject* size_arr = PyArray_SimpleNewFromData(1,shape,NPY_INT,dim_global_x);
126  PyTuple_SetItem(py_plt_func_args, 2, size_arr);
127  }
128  {
129  PyObject* py_obj = Py_BuildValue("d", a_time);
130  PyTuple_SetItem(py_plt_func_args, 3, py_obj);
131  }
132  {
133  npy_intp shape[1] = {param->npts_global_x};
134  PyObject* x_arr = PyArray_SimpleNewFromData(1,shape,NPY_DOUBLE,xg);
135  PyTuple_SetItem(py_plt_func_args, 4, x_arr);
136  }
137  {
138  npy_intp shape[1] = {param->npts_global_x * param->ndims_x};
139  PyObject* u_arr = PyArray_SimpleNewFromData(1,shape,NPY_DOUBLE,field_g);
140  PyTuple_SetItem(py_plt_func_args, 5, u_arr);
141  }
142  {
143  PyObject* py_obj = Py_BuildValue("s", filename);
144  PyTuple_SetItem(py_plt_func_args, 6, py_obj);
145  }
146  if (!py_plt_func) {
147  fprintf(stderr,"Error in PlotArraySerial(): solver->py_plt_func is NULL!\n");
148  } else {
149  PyObject_CallObject(py_plt_func, py_plt_func_args);
150  }
151 #else
152  fprintf(stderr,"Error in PlotArraySerial(): HyPar needs to be compiled with Numpy support (-Dwith_python_numpy) to use this feature..\n");
153 #endif
154 #else
155  fprintf(stderr,"Error in PlotArraySerial(): HyPar needs to be compiled with Python support (-Dwith_python) to use this feature..\n");
156 #endif
157  }
158 
159  /* free up arrays */
160  free(xg);
161  free(field_g);
162 
163  return 0;
164 }
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
void * py_plt_func
Definition: hypar.h:466
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 ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
int * dim_global
Definition: hypar.h:33
void * py_plt_func_args
Definition: hypar.h:467
int ndims_x
Definition: vlasov.h:63

◆ VlasovWriteEFieldAndPotential()

int VlasovWriteEFieldAndPotential ( void *  s,
void *  m,
double  a_t 
)

Write out the electric field and potential to file

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
a_tCurrent simulation time

Definition at line 23 of file VlasovWriteEFieldAndPotential.c.

26 {
27  HyPar *solver = (HyPar*) s;
28  MPIVariables *mpi = (MPIVariables*) m;
29  Vlasov *param = (Vlasov*) solver->physics;
30 
31  {
32  char fname_root[_MAX_STRING_SIZE_] = "efield";
33  VlasovWriteSpatialField( solver, mpi, param->e_field, fname_root );
34  if (!strcmp(solver->plot_solution,"yes")) {
35  VlasovPlotSpatialField( solver, mpi, param->e_field, a_t, fname_root );
36  }
37  }
38 
39  if (param->self_consistent_electric_field) {
40  char fname_root[_MAX_STRING_SIZE_] = "potential";
41  VlasovWriteSpatialField( solver, mpi, param->potential, fname_root );
42  if (!strcmp(solver->plot_solution,"yes")) {
43  VlasovPlotSpatialField( solver, mpi, param->potential, a_t, fname_root );
44  }
45  }
46 
47  return 0;
48 }
Definition: vlasov.h:57
char plot_solution[_MAX_STRING_SIZE_]
Definition: hypar.h:194
double * potential
Definition: vlasov.h:84
int self_consistent_electric_field
Definition: vlasov.h:60
double * e_field
Definition: vlasov.h:81
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _MAX_STRING_SIZE_
Definition: basic.h:14
int VlasovPlotSpatialField(void *, void *, double *, double, char *)
int VlasovWriteSpatialField(void *, void *, double *, char *)
void * physics
Definition: hypar.h:266
Structure of MPI-related variables.