cloudy  trunk
vary_input.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*vary_input sets input lines to feed into cloudy in optimization runs */
4 #include "cddefines.h"
5 #include "input.h"
6 #include "optimize.h"
7 #include "mpi_utilities.h"
8 #include "save.h"
9 #include "grid.h"
10 
11 void vary_input(bool *lgLimOK,
12  int grid_index)
13 {
14  long int i,
15  np;
16 
17  DEBUG_ENTRY( "vary_input()" );
18 
19  // this would indicate int overflow, but is mainly there to keep the compiler from
20  // whining about an unused variable...
21  if( grid_index < -1 )
22  TotalInsanity();
23 
24  /* set up chCardSav(n) array like Gary's input file, using input
25  * variable parameters p(i), and format information held in
26  * the common block /parmv/. Results written to common /kardsv/.
27  */
28 
29  /* will be set false if limit to a variable exceeded
30  * this is returned to calling code as problem indication*/
31  *lgLimOK = true;
32 
33  if( cpu.i().lgMaster() || !grid.lgGrid )
34  fprintf( ioQQQ, " **************************************************\n" );
35 
36  /* echo the variable input lines for this run */
37  for( i=0; i < optimize.nvary; i++ )
38  {
39  bool lgLimitHit = false;
40 
41  np = optimize.nvfpnt[i];
42 
43  // check if the keyword _LOG is present; the optimizer may not work
44  // correctly if it is not optimizing logarithmic quantities.
45  //
46  // exceptions are the commands ILLUMINATE and RATIO since they vary
47  // quantities of order unity anyway, and the commands DLAW and FUDGE
48  // since they are entirely defined by the user.
49  //
50  // it is ok not to convert to upper case first since the command line
51  // image is completely under our own control.
53  {
54  if( !nMatch( " LOG", optimize.chVarFmt[i] ) )
55  {
56  fprintf( ioQQQ, " vary_input: internal error - keyword _LOG not found!\n" );
57  TotalInsanity();
58  }
59  }
60 
61  /* write formatted to the character string chCardSav(np),
62  * using the format held in chVarFmt(np) */
63 
64  /* >>chng 05 aug 09, by RP, both were == change to > and < */
65  if( grid.paramIncrements[i] >= 0. &&
66  ( optimize.vparm[0][i] < optimize.varang[i][0] ||
67  optimize.vparm[0][i] > optimize.varang[i][1] ) )
68  {
69  *lgLimOK = false;
70  lgLimitHit = true;
71  }
72  if( grid.paramIncrements[i] < 0. &&
73  ( optimize.vparm[0][i] > optimize.varang[i][0] ||
74  optimize.vparm[0][i] < optimize.varang[i][1] ) )
75  {
76  *lgLimOK = false;
77  lgLimitHit = true;
78  }
79 
80  /* now generate the actual command with parameter,
81  * there will be from 1 to 3 numbers on the line */
82  if( optimize.nvarxt[i] == 1 )
83  {
84  /* case with 1 parameter */
85  sprintf( input.chCardSav[np], optimize.chVarFmt[i], optimize.vparm[0][i] );
86  }
87 
88  else if( optimize.nvarxt[i] == 2 )
89  {
90  /* case with 2 parameters */
91  sprintf( input.chCardSav[np], optimize.chVarFmt[i], optimize.vparm[0][i],
92  optimize.vparm[1][i] );
93  }
94 
95  else if( optimize.nvarxt[i] == 3 )
96  {
97  /* case with 3 parameters */
98  sprintf( input.chCardSav[np], optimize.chVarFmt[i], optimize.vparm[0][i],
99  optimize.vparm[1][i], optimize.vparm[2][i] );
100  }
101 
102  else if( optimize.nvarxt[i] == 4 )
103  {
104  /* case with 4 parameters */
105  sprintf( input.chCardSav[np], optimize.chVarFmt[i], optimize.vparm[0][i],
106  optimize.vparm[1][i], optimize.vparm[2][i], optimize.vparm[3][i] );
107  }
108 
109  else if( optimize.nvarxt[i] == 5 )
110  {
111  /* case with 5 parameters */
112  sprintf( input.chCardSav[np], optimize.chVarFmt[i],
113  optimize.vparm[0][i], optimize.vparm[1][i], optimize.vparm[2][i],
114  optimize.vparm[3][i], optimize.vparm[4][i]);
115  }
116 
117  else
118  {
119  fprintf(ioQQQ,"The number of variable options on this line makes no sense to me5\n");
121  }
122 
123  if( cpu.i().lgMaster() || !grid.lgGrid )
124  {
125  fprintf( ioQQQ, " %s\n", input.chCardSav[np] );
126  if( lgLimitHit )
127  fprintf( ioQQQ, " >>> Limit to variable exceeded.\n" );
128  }
129  }
130 
131  if( cpu.i().lgMaster() && grid.lgGrid )
132  {
133  // write the line images to an input script, one file for each grid point
134  fstream io;
135  string fnam = GridPointPrefix(grid_index) + save.chRedirectPrefix + ".in";
136  open_data( io, fnam.c_str(), mode_w, AS_LOCAL_ONLY );
137  // input.nSave has unusual definition, it is one less than the number of lines stored
138  for( int i=0; i <= input.nSave; ++i )
139  io << input.chCardSav[i] << endl;
140  }
141 
142  return;
143 }
vary_input
void vary_input(bool *lgLimOK, int grid_index)
Definition: vary_input.cpp:11
open_data
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
Definition: cpu.cpp:625
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
grid
t_grid grid
Definition: grid.cpp:5
AS_LOCAL_ONLY
@ AS_LOCAL_ONLY
Definition: cpu.h:208
t_input::chCardSav
char chCardSav[NKRD][INPUT_LINE_LENGTH]
Definition: input.h:32
cpu
static t_cpu cpu
Definition: cpu.h:355
t_grid::paramIncrements
realnum paramIncrements[LIMPAR]
Definition: grid.h:34
grid.h
t_cpu_i::lgMaster
bool lgMaster() const
Definition: cpu.h:327
input
t_input input
Definition: input.cpp:12
optimize
t_optimize optimize
Definition: optimize.cpp:5
t_cpu::i
t_cpu_i & i()
Definition: cpu.h:347
t_optimize::vparm
realnum vparm[LIMEXT][LIMPAR]
Definition: optimize.h:188
t_optimize::chVarFmt
char chVarFmt[LIMPAR][FILENAME_PATH_LENGTH_2]
Definition: optimize.h:263
EXIT_FAILURE
#define EXIT_FAILURE
Definition: cddefines.h:140
cddefines.h
GridPointPrefix
string GridPointPrefix(int n)
Definition: mpi_utilities.h:150
optimize.h
TotalInsanity
NORETURN void TotalInsanity(void)
Definition: service.cpp:886
nMatch
long nMatch(const char *chKey, const char *chCard)
Definition: service.cpp:451
t_optimize::nvarxt
long int nvarxt[LIMPAR]
Definition: optimize.h:194
mode_w
const ios_base::openmode mode_w
Definition: cpu.h:213
mpi_utilities.h
cdEXIT
#define cdEXIT(FAIL)
Definition: cddefines.h:434
save.h
t_optimize::nvary
long int nvary
Definition: optimize.h:200
t_optimize::varang
realnum varang[LIMPAR][2]
Definition: optimize.h:198
t_input::nSave
long int nSave
Definition: input.h:46
t_optimize::lgOptimizeAsLinear
bool lgOptimizeAsLinear[LIMPAR]
Definition: optimize.h:180
t_optimize::nvfpnt
long int nvfpnt[LIMPAR]
Definition: optimize.h:195
t_save::chRedirectPrefix
string chRedirectPrefix
Definition: save.h:310
input.h
t_grid::lgGrid
bool lgGrid
Definition: grid.h:40
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684
save
t_save save
Definition: save.cpp:5