HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SparseGridsDefine.cpp
Go to the documentation of this file.
1 
7 
34  int a_nproc
35  )
36 {
37  m_rank = a_rank;
38  m_nproc = a_nproc;
39 
40  if (m_sim_fg != NULL) {
41  fprintf(stderr, "Error in SparseGridsSimulation::define() -\n");
42  fprintf(stderr, " m_sim_fg not NULL!\n");
43  exit(1);
44  }
45 
46  /* default values */
47  m_imin = 2;
50  m_interp_order = 6;
51 
52  if (!m_rank) {
53 
54  FILE *in;
55  in = fopen(_SPARSEGRIDS_SIM_INP_FNAME_,"r");
56 
57  if (!in) {
58 
59  fprintf(stderr, "Error in SparseGridsSimulation::Define() -\n");
60  fprintf(stderr, " %s file not found.\n", _SPARSEGRIDS_SIM_INP_FNAME_);
61  exit(1);
62 
63  } else {
64 
65  int ferr;
66  char word[_MAX_STRING_SIZE_];
67  ferr = fscanf(in,"%s", word); if (ferr != 1) return(1);
68 
69  if (std::string(word) == "begin") {
70 
71  while (std::string(word) != "end") {
72 
73  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
74 
75  if (std::string(word) == "log2_imin") {
76 
77  ferr = fscanf(in,"%d",&m_imin); if (ferr != 1) return(1);
78 
79  } else if (std::string(word) == "interp_order") {
80 
81  ferr = fscanf(in,"%d",&m_interp_order); if (ferr != 1) return(1);
82 
83  } else if (std::string(word) == "write_sg_solutions") {
84 
85  char answer[_MAX_STRING_SIZE_];
86  ferr = fscanf(in,"%s",answer); if (ferr != 1) return(1);
87  m_write_sg_solutions = (strcmp(answer,"yes") ? 0 : 1);
88 
89  } else if (std::string(word) == "write_sg_errors") {
90 
91  char answer[_MAX_STRING_SIZE_];
92  ferr = fscanf(in,"%s",answer); if (ferr != 1) return(1);
93  m_print_sg_errors = (strcmp(answer,"yes") ? 0 : 1);
94 
95  } else if (std::string(word) != "end") {
96 
97  char useless[_MAX_STRING_SIZE_];
98  ferr = fscanf(in,"%s",useless);
99  printf("Warning: keyword %s in file \"%s\" with value %s not recognized or extraneous. Ignoring.\n",
100  _SPARSEGRIDS_SIM_INP_FNAME_, word, useless );
101 
102  }
103 
104  if (ferr != 1) return(1);
105  }
106 
107  } else {
108  fprintf( stderr, "Error: Illegal format in file \"%s\". Word read is: %s\n",
110  return 1;
111  }
112 
113  fclose(in);
114 
115  }
116 
117  /* print useful stuff to screen */
118  printf("Sparse grids inputs:\n");
119  printf(" log2 of minimum grid size: %d\n", m_imin);
120  printf(" interpolation order: %d\n", m_interp_order);
121  printf( " write sparse grids solutions? %s\n",
122  ( m_write_sg_solutions == 1 ? "yes" : "no" ) );
123  }
124 
125 #ifndef serial
126  MPI_Bcast(&m_imin,1,MPI_INT,0,MPI_COMM_WORLD);
127  MPI_Bcast(&m_interp_order,1,MPI_INT,0,MPI_COMM_WORLD);
128  MPI_Bcast(&m_write_sg_solutions,1,MPI_INT,0,MPI_COMM_WORLD);
129  MPI_Bcast(&m_print_sg_errors,1,MPI_INT,0,MPI_COMM_WORLD);
130 #endif
131 
133  /* the following are deliberately set to junk values
134  * to ensure they are never used */
135  m_sim_fg->solver.my_idx = -1;
136  m_sim_fg->solver.nsims = -1;
137  /* these are okay */
138  m_sim_fg->mpi.rank = m_rank;
140 
141  if (!m_rank) {
142  printf("Allocated full grid simulation object(s).\n");
143  }
144 
145  m_is_defined = true;
146  return 0;
147 }
#define _SPARSEGRIDS_SIM_INP_FNAME_
int nsims
Definition: hypar.h:64
#define _MAX_STRING_SIZE_
Definition: basic.h:14
Structure defining a simulation.
int my_idx
Definition: hypar.h:61