Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eqcoeff version number #495

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions post_processing/reference_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

class equation_coefficients:
""" equation coeff class """
nconst = 10
nconst = 11 # new "version 2" default
nfunc = 14
version=1
version=2
c_dict = {'two_omega':1, 'buoy_fact':2, 'p_fact':3, 'lorentz_fact':4, 'visc_fact':5,
'diff_fact':6, 'resist_fact':7, 'nu_heat_fact':8, 'ohm_heat_fact':9,
'luminosity':10}
'luminosity':10, 'dsdr_scale': 11}
f_dict = {'density':1, 'buoy':2, 'nu':3, 'temperature':4, 'kappa':5, 'heating':6,
'eta':7, 'd_ln_rho':8, 'd2_ln_rho':9, 'd_ln_T':10, 'd_ln_nu':11, 'd_ln_kappa':12,
'd_ln_eta':13, 'ds_dr':14}
Expand Down Expand Up @@ -65,9 +65,13 @@ def write(self, filename='ecoefs.dat'):
pi = numpy.array([314],dtype='int32')
nr = numpy.array([self.nr],dtype='int32')
version = numpy.array([self.version],dtype='int32')
nconst = numpy.array([self.nconst],dtype='int32')
nfunc = numpy.array([self.nfunc],dtype='int32')
fd = open(filename,'wb')
pi.tofile(fd)
version.tofile(fd)
nconst.tofile(fd)
nfunc.tofile(fd)
self.cset.tofile(fd)
self.fset.tofile(fd)
self.constants.tofile(fd)
Expand All @@ -77,20 +81,33 @@ def write(self, filename='ecoefs.dat'):
fd.close()

def read(self, filename='equation_coefficients'):

class_version = self.version
fd = open(filename,'rb')
picheck = numpy.fromfile(fd,dtype='int32',count=1)[0]

self.version = numpy.fromfile(fd,dtype='int32', count=1)[0]
if self.version > 1:
self.nconst = numpy.fromfile(fd,dtype='int32', count=1)[0]
self.nfunc = numpy.fromfile(fd,dtype='int32', count=1)[0]
else: # if the version is 1, nconst was 10
self.nconst = 10
self.cset = numpy.fromfile(fd,dtype='int32',count=self.nconst)
self.fset = numpy.fromfile(fd,dtype='int32',count=self.nfunc)
self.constants = numpy.fromfile(fd,dtype='float64',count=self.nconst)
self.constants = numpy.fromfile(fd,dtype='float64',count=self.nconst)
self.nr = numpy.fromfile(fd,dtype='int32',count=1)[0]
self.radius = numpy.fromfile(fd,dtype='float64',count=self.nr)
functions=numpy.fromfile(fd,dtype='float64',count=self.nr*self.nfunc)
self.functions = numpy.reshape(functions, (self.nfunc,self.nr))
fd.close()

# now if we read in v. 1, convert current instance to v. 2
if self.version == 1:
self.nconst = 11
self.version = class_version
self.constants[10] = 1.
print("Version of input file was 1.")
print("Converting current equation_coefficients instance's version to %i." %class_version)

class background_state:
nr = None
radius = None
Expand Down
9 changes: 7 additions & 2 deletions src/Physics/PDE_Coefficients.F90
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Module PDE_Coefficients

! Version number for the "equation_coefficients" container that is output to the simulation directory
! (i.e., the human-obtainable version of "ref")
Integer, Parameter :: eqn_coeff_version = 1
Integer, Parameter :: eqn_coeff_version = 2

! Which background state to use; default 1 (non-dimensional Boussinesq)
Integer :: reference_type = 1
Expand Down Expand Up @@ -1222,6 +1222,8 @@ Subroutine Write_Equation_Coefficients_File(filename)
Write(15) eqn_coeff_version
ra_constant_set(:) = 1
ra_function_set(:) = 1
Write(15) n_ra_constants
Write(15) n_ra_functions
Write(15) (ra_constant_set(i), i=1,n_ra_constants)
Write(15) (ra_function_set(i), i=1,n_ra_functions)
Write(15) (ra_constants(i), i=1,n_ra_constants)
Expand All @@ -1240,7 +1242,7 @@ Subroutine Read_Custom_Reference_File(filename)
Character*120, Intent(In) :: filename
Character*120 :: ref_file
Integer :: pi_integer,nr_ref, eqversion
Integer :: i, k, j, n_scalars
Integer :: i, k, j, n_scalars, dummy
Integer :: cset(1:n_ra_constants), fset(1:n_ra_functions)
Real*8 :: input_constants(1:n_ra_constants)
Real*8, Allocatable :: ref_arr_old(:,:), rtmp(:), rtmp2(:)
Expand Down Expand Up @@ -1288,6 +1290,9 @@ Subroutine Read_Custom_Reference_File(filename)
cset(11) = 1 ! treat this as if c_11 = 1 was specified in the custom reference file
input_constants(11) = 1.0d0
Else
Read(15) dummy ! n_ra_constants, but its up to the user to make sure this is the same
! same number specified in Rayleigh via "n_active_scalars"
Read(15) dummy ! n_ra_functions, which Rayleigh should already know
Read(15) cset(1:n_ra_constants)
Read(15) fset(1:n_ra_functions)
Read(15) input_constants(1:n_ra_constants)
Expand Down
Loading