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

garysbranch #416

Merged
merged 8 commits into from
Oct 28, 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
42 changes: 42 additions & 0 deletions platform/build/make.inc.GFORTRAN_OSX_MACPORTS_mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#---------------------------------------------------
# OSX,gfortran+openmpi from MacPorts
# sudo port install openmpi netcdf-fortran fann
# sudo port install fftw-3 +openmpi
#---------------------------------------------------
IDENTITY="OSX gfortran+openmpi from MacPorts"

MAKE = make

NETCDF_PATH=/opt/local
MF90 = mpif90-openmpi-mp

# Compilers and flags
#
#set up for diff mpif90s
#

FC = ${MF90} -std=f2008 -fall-intrinsics -I$(GACODE_ROOT)/modules -J$(GACODE_ROOT)/modules -I/opt/local/include -fPIC
#F77 = ${MF90} -w -fallow-argument-mismatch
F77 = ${MF90} -w

FOMP = -fopenmp
FMATH = -fdefault-real-8 -fdefault-double-8
FOPT = -O3 -m64 -framework Accelerate
FDEBUG = -Wall -g -fcheck=all -fbacktrace -fbounds-check -O0 -Wextra -finit-real=nan -Wunderflow -ffpe-trap=invalid,zero,overflow
#F2PY = f2py-2.7

# System math libraries

LMATH = -L/opt/local/lib -lfftw3

NETCDF = -L${NETCDF_PATH}/lib -lnetcdff -lnetcdf
NETCDF_INC =${NETCDF_PATH}/include

# Archive

ARCH = ar cr

ifdef FANN_ROOT
# neural net libraries
NN_LIB=-L$(GACODE_ROOT)/../neural/ -I$(GACODE_ROOT)/../neural/ -lbrainfuse -lfann
endif
53 changes: 53 additions & 0 deletions platform/build/make.inc.OSX_VENTURA
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#---------------------------------------------------\
# OSX Ventura \
#\
# macport installation instructions for new Mac \
# running Ventura assuming OMFIT being installed as\
# well. YMMV \
#\
# 1) install OMFIT via macports- gets initial \
# dependencies\
# 2) sudo port install gcc12\
# 2) sudo port install openmpi-gcc12\
# 3) sudo port install netcdf-fortran\
# 4) determine local host name via uname -n\
# add following line to /etc/hosts\
# 127.0.0.1 <local host name>\
#\
#---------------------------------------------------\
\
# Compilers and flags\
\
MF90 = mpif90-openmpi-mp\
FC = $\{MF90\} -I$(GACODE_ROOT)/modules -J$(GACODE_ROOT)/modules -fPIC -framework Accelerate -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk\
F77 = mpif77 -std=legacy\
CC = $\{FC\}\
\
GOMPTEST := $(shell $\{CC\} -v 2>&1 | grep " version " | grep gcc >/dev/null; echo $$?)\
ifeq ($(GOMPTEST),0)\
FOMP =-fopenmp\
endif\
\
FMATH =-fdefault-real-8 -fdefault-double-8 \
FOPT =-O3 \
FDEBUG =-Wall -fcheck=all -ffpe-trap=invalid,zero,overflow -g -fbacktrace\
F2PY = f2py\
\
# System math libraries\
\
LMATH = /opt/local/lib/libfftw3.a\
FFTW_INC = /opt/local/include \
\
ifdef FANN_ROOT\
# neural net libraries\
NN_LIB=-L$(GACODE_ROOT)/../neural/ -I$(GACODE_ROOT)/../neural/ -lbrainfuse -lfann\
endif\
\
# NetCDF libraries\
\
NETCDF = -L/opt/local/lib -lnetcdff -L/opt/local/lib -Wl,-headerpad_max_install_names -lnetcdf -lnetcdf\
NETCDF_INC = /opt/local/include\
\
# Archive\
\
ARCH = ar cr}
293 changes: 293 additions & 0 deletions tglf/bin/gacodeinput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
#----------------------------------------------------------------------
# gacodeinput.py
#
# PURPOSE:
# Collection of classes for parsing of GACODE free-format input files.
#
# NOTES:
# SimpleInput : input.cgyro, input.neo, input.tglf
# ManagerInput : input.tgyro [see tgyro/bin/tgyro_parse.py]
#----------------------------------------------------------------------

import os

#--------------------------------------------------------------------
# PARSER FOR input.cgyro, etc.
#--------------------------------------------------------------------
class SimpleInput:
"""Input parser for simple input.* files"""
def __init__(self):
self.data_dict = {}
self.data_orderlist = []
self.dep_dict = {}
self.dep_orderlist = []
self.user_dict = {}
self.error = 0
self.error_msg = ""
self.extension = ".gen"

def add(self,param,default,n=1):
if n == 1:
self.data_dict[param]=default
self.data_orderlist.append(param)
else:
for i in range(n):
p = param+'_'+str(i+1)
self.data_dict[p]=default
self.data_orderlist.append(p)

def dep(self,param,default):
self.dep_dict[param]=default
self.dep_orderlist.append(param)

def printdebug(self):
print(self.data_dict)
print(self.data_orderlist)
print(self.dep_dict)
print(self.dep_orderlist)
print(self.user_dict)
if self.error == 1:
print(self.error_msg)

def printmsg(self):
if self.error == 1:
print(self.error_msg)

def set_extension(self,text):
self.extension = text

def read_input(self,inputfile):
# 1. read user input file
with open(inputfile,'r') as fin:
for line in fin.readlines():

# Remove leading and trailing whitespace from line
line = line.strip()

# Skip blank lines
if len(line) > 0 and line[0] != '#':
x = line.split('=')
y = x[1].split('#')
arg = x[0].strip()
val = y[0].strip()

self.user_dict[arg] = val

# 2. build complete input file, looking for errors
for x in list(self.user_dict.keys()):
if x in self.data_dict:
self.data_dict[x] = self.user_dict[x]
elif x in self.dep_dict:
if self.dep_dict[x] == 'ignore':
print('WARNING: (gacodeinput.py) Ignoring parameter '+x)
else:
self.error=1
self.error_msg=self.error_msg+'ERROR: (gacodeinput) Deprecated parameter '+x+'\n'
self.error_msg=self.error_msg+' '+self.dep_dict[x]+'\n'
else:
self.error=1
self.error_msg=self.error_msg+"ERROR: (gacodeinput) Bogus parameter "+x+'\n'

if self.error == 0:
with open(inputfile+self.extension,'w') as f:
for x in self.data_orderlist:
f.write(self.data_dict[x]+' '+x+'\n')

#--------------------------------------------------------------------
# PARSER FOR input.tgyro
#--------------------------------------------------------------------
class ManagerInput:
"""Input parser for input.tgyro"""
def __init__(self):
self.data_dict = {}
self.data_orderlist = []
self.dep_dict = {}
self.dep_orderlist = []
self.user_dict = {}
self.error = 0
self.error_msg = ""
self.extension = ".gen"
self.slavepath = []
self.slaveproc = []
self.slaveradius = []
self.overlayfile = []
self.sum_proc = 0

def add(self,param,default):
self.data_dict[param]=default
self.data_orderlist.append(param)

def dep(self,param,default):
self.dep_dict[param]=default
self.dep_orderlist.append(param)

def printmsg(self):
if self.error == 1:
print(self.error_msg)

def write_proc(self,datafile):
with open(datafile,'w') as f:
f.write(str(len(self.slavepath))+'\n')
f.write(str(self.sum_proc))

def set_extension(self,text):
self.extension = text

def strip_tag(self,datafile):

with open(datafile+'.input','w') as file_input:

n = 0
with open(datafile,'r') as fdata:
datalines = fdata.readlines()

for line in datalines:
line_s = line.strip()

# Look for occurence of tag and put item in list.
if (line_s[0:3] == 'DIR'):
n = n+1
data = line_s.split(' ')

# data[0] -> DIR
# data[1] -> directory1, etc
# data[2] -> <n_cores>
# data[3,...] -> OVERLAY_VARIABLE [special option X=<xmin>]

# slavepath stores directory
self.slavepath.append(data[1])
# slaveproc stores number of cores
self.slaveproc.append(data[2])

# Now manage overlays and optional radii
if (len(data) > 3):
# Overlay or optional radius
if data[3][0:1] == 'X':
# This is the special option X=<xmin> for min(r/a) or min(rho)
self.slaveradius.append(data[3].split('=')[1])
# Need to subtract 4 because X is not an overlay
nover = len(data)-4
nj = 4
else:
nover = len(data)-3
nj = 3
self.slaveradius.append("-1")
else:
# No overlay
self.slaveradius.append("-1")
nover = 0

# Overlay parameters reside in data[3], ...
self.overlayfile.append('overlay.'+str(n))
with open('overlay.'+str(n),'w') as file_overlay:

#----------------------------------------------------------
# This loop writes each overlay parameter list to overlay.*
for j in range(nover):
file_overlay.write(data[j+nj]+'\n')

#----------------------------------------------------------

else:

file_input.write(line)


def read_input(self,datafile):

# Eventual output file
# For example: datafile = input.cgyro
# extension = .gen
outfile = datafile+self.extension

# Split datafile into datafile.input (pure input)
# and overlay.n, where n is the number of tags.
self.strip_tag(datafile)

# Parse simple input part
z = SimpleInput()
z.data_dict = self.data_dict
z.data_orderlist = self.data_orderlist
z.dep_dict = self.dep_dict

# NOTE: 'datafile'.input (input.tgyro.input) contains the TGYRO inputs
# (with DIR lines stripped)
z.read_input(datafile+'.input')
self.error = z.error
self.error_msg = z.error_msg

# Something went wrong in SimpleInput (bogus parameter),
# so let's just return
if self.error == 1:
return

# File generated above
genfile = datafile+'.input'+z.extension

n_path = len(self.slavepath)

os.system('mv '+genfile+' '+outfile)
os.system('rm '+datafile+'.input')
with open(outfile,'a') as file_outfile:
file_outfile.write(str(n_path)+'\n')

# Logging
print('INFO: (gacodeinput) Number of code instances: '+str(n_path))

for p in range(len(self.slavepath)):
self.sum_proc = self.sum_proc + int(self.slaveproc[p])
basedir = self.slavepath[p]

# Detect the code to be run in each directory
if os.path.isfile(basedir+'/input.gyro'):
code='gyro'
elif os.path.isfile(basedir+'/input.cgyro'):
code='cgyro'
elif os.path.isfile(basedir+'/input.tglf'):
code='tglf'
elif os.path.isfile(basedir+'/input.ifs'):
code='ifs'
elif os.path.isfile(basedir+'/input.glf23'):
code='glf23'
elif os.path.isfile(basedir+'/input.etg'):
code='etg'
else:
code='unknown'
self.error=1
self.error_message='Could not identify code'

file_outfile.write(basedir+' '+self.slaveproc[p]+' '+self.slaveradius[p]+' '+code+'\n')

if code == 'unknown':
print('ERROR: (gacodeinput.py) No code found in '+basedir)
continue
if code == 'ifs':
print('INFO: (gacodeinput.py) Found ifs input in '+basedir)
continue
else:
print('INFO: (gacodeinput.py) Found '+code+' input in '+basedir)

basefile = basedir+'/input.'+code
tempfile = basefile+'.temp'

with open(basefile,'r') as file_base:
with open(tempfile,'w') as file_temp:

for line in file_base.readlines():
if line[0:18] != "# -- Begin overlay":
file_temp.write(line)
else:
break

# Overlay parameters
os.system('echo "# -- Begin overlay" >> '+tempfile)
os.system('cat '+self.overlayfile[p]+' >> '+tempfile)
os.system('mv '+tempfile+' '+basefile)

# Run code in test mode
os.system(code+' -i '+basedir+' -n 1 -p $PWD > out.log')

os.system('rm '+self.overlayfile[p])

print('INFO: (gacodeinput) Required MPI tasks in TGYRO: '+str(self.sum_proc))

Binary file added tglf/src/filter/TGLF_New_Filter_24_05_2024.pdf
Binary file not shown.
Loading