Environment variables or global definitions in input files?

I’m wondering - is there a way to include environment variables in ASPECT input files? I could imagine this being useful in a couple of ways - first, on TACC systems, users-specific $SCRATCH and $WORK directories are defined. Second, it is often useful to have global definitions like $R for planet radius that appear many times within function expressions in input files.

Thanks!

Max

Hi @maxrudolph,

I’ve wondered about this too.

As far as I know, ASPECT does not currently support general environment-variable expansion in input files. $ASPECT_SOURCE_DIR is a special case, but variables like $SCRATCH or $WORK are not automatically expanded in .prm files.

For function expressions, muparser supports Function constants, for example:

set Function constants = R=6371e3

but these are only local to a single function subsection. So R can be reused within that subsection, but not defined once globally and shared across multiple parts of the input file.

One possible idea might be to add a global constants mechanism at the .prm level, for example something like

subsection Global constants
  set Constants = R=6371e3, eta0=1e21
end

or perhaps a simpler form such as

set Global constants = R=6371e3, eta0=1e21, DATA=$SCRATCH/my_case

That could help with both repeated physical constants and machine-specific paths.

A global variable or macro mechanism for .prm files would be very useful.

Best,
Ninghui

@maxrudolph Interesting idea. That wouldn’t be too difficult to implement. My suggestion is to use the syntax $ENV{VAR} to query an environment variable VAR – this syntax is already used in other languages.

The right place to implement this would be in main.cc, at the bottom of the read_parameter_file() function.

Best
W.

Thanks! I will take a look at this and see if the implementation would be straightforward.

Perhaps list them where set Dimension, set End time etc live? Setting global constants sometimes avoid inconsistent parameters, which may hide bugs. :+1:

Cheers,
MM