HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
OutputROMSolution.cpp File Reference

Write out the solution to file. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <basic.h>
#include <common_cpp.h>
#include <arrayfunctions.h>
#include <io_cpp.h>
#include <plotfuncs_cpp.h>
#include <mpivars_cpp.h>
#include <simulation_object.h>

Go to the source code of this file.

Functions

void IncrementFilenameIndex (char *, int)
 
int OutputROMSolution (void *s, int nsims, double a_time)
 

Detailed Description

Write out the solution to file.

Author
Debojyoti Ghosh

Definition in file OutputROMSolution.cpp.

Function Documentation

◆ IncrementFilenameIndex()

void IncrementFilenameIndex ( char *  f,
int  len 
)

Increment the output filename of the form op_nnnnn.dat by 1, i.e., the number represented by the string nnnnn is incremented by 1.

Increment a character string representing an integer by 1. For example: "00002" -> "00003"; "3421934" -> "3421935"; "999" -> "000". The string can be of arbitrary length.

Parameters
fCharacter string representing the integer
lenLength of the string

Definition at line 46 of file IncrementFilename.c.

50 {
51  int i;
52  for (i=len-1; i>=0; i--) {
53  if (f[i] == '9') {
54  f[i] = '0';
55  if (!i) fprintf(stderr,"Warning: file increment hit max limit. Resetting to zero.\n");
56  } else {
57  f[i]++;
58  break;
59  }
60  }
61 }

◆ OutputROMSolution()

int OutputROMSolution ( void *  s,
int  nsims,
double  a_time 
)

Write out the ROM solution to file

Parameters
sArray of simulation objects of type SimulationObject
nsimsNumber of simulation objects
a_timeCurrent simulation time

Definition at line 24 of file OutputROMSolution.cpp.

27 {
28  SimulationObject* simobj = (SimulationObject*) s;
29  int ns;
30 
31  for (ns = 0; ns < nsims; ns++) {
32 
33  HyPar* solver = &(simobj[ns].solver);
34  MPIVariables* mpi = &(simobj[ns].mpi);
35 
36  if ((!solver->WriteOutput) && (strcmp(solver->plot_solution,"yes"))) continue;
37 
38  char fname_root[_MAX_STRING_SIZE_];
39  strcpy(fname_root, solver->op_rom_fname_root);
40 
41  if (nsims > 1) {
42  char index[_MAX_STRING_SIZE_];
43  GetStringFromInteger(ns, index, (int)log10(nsims)+1);
44  strcat(fname_root, "_");
45  strcat(fname_root, index);
46  }
47 
48  WriteArray( solver->ndims,
49  solver->nvars,
50  solver->dim_global,
51  solver->dim_local,
52  solver->ghosts,
53  solver->x,
54  solver->u_rom_predicted,
55  solver,
56  mpi,
57  fname_root );
58 
59  if (!strcmp(solver->plot_solution, "yes")) {
60  PlotArray( solver->ndims,
61  solver->nvars,
62  solver->dim_global,
63  solver->dim_local,
64  solver->ghosts,
65  solver->x,
66  solver->u,
67  a_time,
68  solver,
69  mpi,
70  fname_root );
71  }
72 
73  /* increment the index string, if required */
74  if ((!strcmp(solver->output_mode,"serial")) && (!strcmp(solver->op_overwrite,"no"))) {
76  }
77 
78  }
79 
80  return 0;
81 }
char plot_solution[_MAX_STRING_SIZE_]
Definition: hypar.h:194
int nvars
Definition: hypar.h:29
char * filename_index
Definition: hypar.h:197
Structure defining a simulation.
int PlotArray(int, int, int *, int *, int, double *, double *, double, void *, void *, char *)
Definition: PlotArray.c:31
char op_rom_fname_root[_MAX_STRING_SIZE_]
Definition: hypar.h:407
double * u
Definition: hypar.h:116
char output_mode[_MAX_STRING_SIZE_]
Definition: hypar.h:183
double * x
Definition: hypar.h:107
void IncrementFilenameIndex(char *, int)
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _MAX_STRING_SIZE_
Definition: basic.h:14
char op_overwrite[_MAX_STRING_SIZE_]
Definition: hypar.h:191
int WriteArray(int, int, int *, int *, int, double *, double *, void *, void *, char *)
Definition: WriteArray.c:27
void GetStringFromInteger(int, char *, int)
int index_length
Definition: hypar.h:199
int * dim_local
Definition: hypar.h:37
int(* WriteOutput)(int, int, int *, double *, double *, char *, int *)
Definition: hypar.h:211
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
double * u_rom_predicted
Definition: hypar.h:403
int * dim_global
Definition: hypar.h:33