cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physconst.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 #include "cddefines.h"
4 
5 static int register_physconst(const char* name, double value);
6 
7 // First define all the constants
8 #include "physconst.h"
9 
10 // Load template file with alternate action
11 #define NEW_CONSTANT(NAME, VALUE) \
12  static int UNUSED physconst_##NAME = register_physconst(#NAME,VALUE)
13 #include "physconst_template.h"
14 #undef NEW_CONSTANT
15 
16 static int register_physconst(const char* name, double value)
17 {
18  t_physconst::Inst().add_constant( name, value );
19  return 1;
20 }
21 
23 {
24 #ifndef HAVE_CONSTEXPR
25 // dprintf( ioQQQ, "MILNE_CONST %.16e SAHA %.16e\n", SPEEDLIGHT*sqrt(pow3(FINE_STRUCTURE2)*pow3(TE1RYD)/PI),
26 // sqrt(pow3(HION_LTE_POP)) );
27  if (!fp_equal(MILNE_CONST,
28  SPEEDLIGHT*sqrt(pow3(FINE_STRUCTURE2)*pow3(TE1RYD)/PI) ))
29  {
30  fprintf(stderr," PROBLEM - Failed consistency check for MILNE_CONSTANT\n");
31  exit(1);
32  }
33  if (!fp_equal(SAHA,
34  sqrt(pow3(HION_LTE_POP))))
35  {
36  fprintf(stderr," PROBLEM - Failed consistency check for SAHA\n");
37  exit(1);
38  }
39 #endif
40 }
41 
42 //
43 // the macro NEW_CONSTANT calls a function to set a static global
44 // integer for every constant. the constructor of that class will
45 // populate the list of constants in the t_physconst singleton by
46 // calling the add_constant() method.
47 //
48 // these integers are not used anywhere else: need to check if the
49 // linker would optimize this module away if the routine below
50 // wouldn't exist and be used in parse_print.cpp.
51 //
52 // this routine can be removed if this file is merged with other files that
53 // instantiate global data.
54 //
55 void prt_phys_constants(FILE* io)
56 {
58 }
T pow3(T a)
Definition: cddefines.h:988
static t_physconst & Inst()
Definition: cddefines.h:209
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:854
static int register_physconst(const char *name, double value)
Definition: physconst.cpp:16
void prt_constants(FILE *io) const
Definition: physconst.h:21
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
void add_constant(const string &s, double v)
Definition: physconst.h:17
void prt_phys_constants(FILE *io)
Definition: physconst.cpp:55