cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
zero.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*zero zero out or initialize variables, called by cdInit, but also by optimize_func during optimization,
4  * this is called before any commands are parsed, called one time per model, at very start */
5 #include "cddefines.h"
6 #include "init.h"
7 #include "iterations.h"
8 #include "grains.h"
9 #include "ionbal.h"
10 #include "atmdat_adfa.h"
11 #include "yield.h"
12 #include "secondaries.h"
13 #include "called.h"
14 #include "mole.h"
15 #include "thermal.h"
16 #include "trace.h"
17 
18 // //////////////////////////////////////////////////////////////////////////
19 //
20 //
21 // NB DO NOT ADD VARIABLES TO THIS FILE! THE GOAL IS TO REMOVE THIS FILE
22 // initialization of variables should be done in one of the ini_*.cpp routines
23 //
24 //
25 // //////////////////////////////////////////////////////////////////////////
26 
27 
28 static void allocate()
29 {
30  iterations.alloc();
31 
33 
34  ionbal.alloc();
35 
36  mole.alloc();
37 }
38 
39 /* zero out or initialize variables, called by cdInit, but also by optimize_func
40  * during optimization, called before command parser, one time per model,
41  * in a grid one time per grid point (so called nGrid times),
42  * only one time in multi-iteration models */
43 void zero(void)
44 {
45  DEBUG_ENTRY( "zero()" );
46 
47  /* this is used to signify the first call to this routine. At that
48  * stage some memory has not been allocated so must not initialize,
49  * set false at very end of this routine */
50  static bool lgFirstCall = true;
51  /* >>chng 06 jun 27, only malloc on first call - memory leak */
52  if (lgFirstCall)
53  {
54  allocate();
55  lgFirstCall = false;
56  }
57 
58  /* this routine is called exactly one time at the start of
59  * the calculation of a single model. When the code is used as a subroutine
60  * this routine is called one time for each model. It is called before
61  * the boundary conditions are read in, and is never called again
62  * during that calculation of the one model.
63  * All default variables that must be initialized before a calculation starts
64  * must appear in the routine. In a grid they are reset for each model
65  */
66 
67  /* general abort flag */
68  lgAbort = false;
69 
70  /* this option, use the new atmdat_rad_rec recombination rates */
72 
73  /**********************************************************************
74  * these are options to print errors to special window,
75  * set with print errors command,
76  * output will go to standard error
77  * defined in cdInit
78  **********************************************************************/
79  lgPrnErr = false;
80  ioPrnErr = stderr;
81 
82  /* main arrays to save ionization fractions*/
83  vector<module*>& mods=module_list::Inst().m_l;
84  for (vector<module*>::iterator mi = mods.begin(); mi != mods.end(); ++mi)
85  {
86  if ( trace.lgTrace )
87  fprintf(ioQQQ,"Zeroing %s\n",(*mi)->chName());
88  (*mi)->zero();
89  }
90 
91  /* now set physical conditions array
92  * following will force updating all temperature - density variables */
93  TempChange( 1e4 , true);
94 
95  fnzone = 0.;
96  nzone = 0;
97  /* save initial condition for talk in case PRINT LAST used */
99 
100  /* this tells the code to use standard Auger yields */
102 
103  /* there was a call to TestCode */
104  lgTestCodeCalled = false;
105  /* test code enabled with set test command */
106  lgTestCodeEnabled = false;
107 
108  /* zero out some grain variables */
109  GrainZero();
110 
111  /* this is flag saying whether this is very first call,
112  * a time when space has not been allocated */
113  return;
114 }
void alloc()
Definition: iterations.cpp:35
static void allocate()
Definition: zero.cpp:28
vector< module * > m_l
Definition: module.h:14
FILE * ioQQQ
Definition: cddefines.cpp:7
long int nzone
Definition: cddefines.cpp:14
bool lgTalk
Definition: called.h:12
void zero(void)
Definition: zero.cpp:43
void TempChange(double TempNew, bool lgForceUpdate)
Definition: temp_change.cpp:32
static t_ADfA & Inst()
Definition: cddefines.h:209
t_trace trace
Definition: trace.cpp:5
t_ionbal ionbal
Definition: ionbal.cpp:8
bool lgTrace
Definition: trace.h:12
t_mole_local mole
Definition: mole.cpp:8
t_iterations iterations
Definition: iterations.cpp:6
bool lgTestCodeEnabled
Definition: cddefines.cpp:12
bool lgTalkSave
Definition: called.h:15
FILE * ioPrnErr
Definition: cddefines.cpp:9
void alloc()
Definition: ionbal.cpp:10
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
void alloc()
Definition: mole.cpp:91
bool lgTestCodeCalled
Definition: cddefines.cpp:11
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
void reset_yield()
Definition: yield.h:79
bool lgPrnErr
Definition: cddefines.cpp:13
t_secondaries secondaries
Definition: secondaries.cpp:5
double fnzone
Definition: cddefines.cpp:15
void GrainZero()
Definition: grains.cpp:479
void set_version(phfit_version val)
Definition: atmdat_adfa.h:50
t_called called
Definition: called.cpp:4
bool lgAbort
Definition: cddefines.cpp:10