[mesa-users] change physical constants

Bill Paxton paxton at kitp.ucsb.edu
Thu May 8 12:34:44 EDT 2014


On May 8, 2014, at 6:54 AM, Diego Bossini wrote:

> Hi all,
> 
> I was wondering if is possible change the values of some of the constants defined in 'const/public/const_def.f' without, of course, modify the standard mesa code.

Wow!! I didn't think anyone would ever ask!  If you take a close look at const_def, you see that some things, like pi, are defined as "real(dp), parameter".   That means the compiler treats them as fixed values that cannot be changed at runtime.The math constants are treated as parameters.   (sorry, you can't run mesa with pi = 22/7 unless you modify the code.)     But the physical constants are defined simply as "real(dp)" so the compiler allocates storage for them that is accessed at runtime.  So if your code uses "pi" from const_def, the compiler substitutes the value given in the source code.  But if your code uses "Lsun" from const_def, then the compiler accesses the value stored in that variable in the const_def data at runtime.  When mesa/star starts a run, it calls const_init in const/public/const_lib, and that routine stores the default values for physical constants like Lsun.   If you come along after const_init and change the value, then all the routines that get the value from const_def will get your modified value instead of the default.  You can do that in your run_star_extras extras_controls routine for example.


-B






More information about the Mesa-users mailing list