Skip to content

Commit

Permalink
Add xgyro (#425)
Browse files Browse the repository at this point in the history
* Add basic xgyro framework

* Add full CGYRO simulation logic in, and fix xgyro paths

* Add xgyro python wrapper

* Write errors on stderr

* Print sub-simulation info into out.xgyro.info

* Fix xgyro dir creation from template, and add xgyro to top Makefile

* Add regression support for xgyro

* Add xgyro reg02 and reg03

* Add support for MPI_RANK_ORDER=2, add reg test
  • Loading branch information
sfiligoi authored Nov 27, 2024
1 parent 984b488 commit 9d562fb
Show file tree
Hide file tree
Showing 72 changed files with 16,529 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ all:
cd vgen ; make
cd tglf ; make
cd cgyro ; make
cd xgyro ; make
cd gyro ; make
cd tgyro ; make
cd profiles_gen ; make
Expand All @@ -21,6 +22,7 @@ clean:
cd vgen ; make clean
cd tglf ; make clean
cd cgyro ; make clean
cd xgyro ; make clean
cd gyro ; make clean
cd tgyro ; make clean
cd profiles_gen ; make clean
Expand All @@ -42,6 +44,7 @@ distclean:
cd neo ; make clean
cd tglf ; make clean
cd cgyro ; make clean
cd xgyro ; make clean
cd gyro ; make clean
cd tgyro ; make clean
cd profiles_gen ; make clean
Expand Down
14 changes: 11 additions & 3 deletions f2py/pygacode/gacodeinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def add(self,param,default,n=1):
self.data_dict[p]=default
self.data_orderlist.append(p)

def rename(self,org_param,new_param):
self.data_dict[new_param] = self.data_dict[org_param]
del self.data_dict[org_param]
self.data_orderlist[self.data_orderlist.index(org_param)] = new_param

def dep(self,param,default):
self.dep_dict[param]=default
self.dep_orderlist.append(param)
Expand All @@ -56,7 +61,7 @@ def printmsg(self):
def set_extension(self,text):
self.extension = text

def read_input(self,inputfile):
def read_input(self,inputfile,write_ext=True):
# 1. read user input file
with open(inputfile,'r') as fin:
for line in fin.readlines():
Expand Down Expand Up @@ -88,8 +93,11 @@ def read_input(self,inputfile):
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:
if write_ext and (self.error == 0):
self.write_parsed(inputfile+self.extension)

def write_parsed(self,outfile):
with open(outfile,'w') as f:
for x in self.data_orderlist:
f.write(self.data_dict[x]+' '+x+'\n')

Expand Down
31 changes: 27 additions & 4 deletions shared/bin/gacode_reg_do
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#
# EXAMPLE:
# gacode_reg_do 2 1 0 neo 1e-5
# gacode_reg_do 2 1 0 xgyro/cgyro 1e-5
#----------------------------------------------------

n=$#
Expand All @@ -23,10 +24,14 @@ fi
n_proc=${1}
n_omp=${2}
reset=${3}
code=${4}
code_raw=${4}
tol=${5}
scase=${6}

# if a / is present in code_raw string, use the part after / to signify another code
code=`python3 -c "import sys; print(sys.argv[1].split('/')[0])" ${code_raw}`
code2=`python3 -c "import sys; carr=sys.argv[1].split('/'); print(carr[1] if (len(carr)==2) else '')" ${code_raw}`

echo "REGRESSION TESTING: $code"

testdir=$PWD/${code}_regression_test
Expand All @@ -44,7 +49,11 @@ then
compdir=$GACODE_ADD_ROOT/$code/tools/input
fi

precfile=out.$code.prec
if [ "x${code2}" == "x" ]; then
precfile=out.${code}.prec
else
precfile=out.${code2}.prec
fi

if [ "$scase" == "" ]
then
Expand All @@ -59,13 +68,27 @@ cd $testdir
for sim in $list
do
$code -g $sim -p $testdir > out.$sim
rm -f $sim/$precfile
if [ "x${code2}" == "x" ]; then
rm -f $sim/$precfile
else
# this is actually a bundled test, check subdirs
for dname in `(cd $sim && ls -p |grep / | sed 's#/##')`; do
rm -f $sim/$dname/$precfile
done
fi
if [ $n_omp -eq 1 ] && [ $n_proc -eq 1 ] ; then
$code -e $sim -p $testdir > out.$sim
else
$code -e $sim -n $n_proc -nomp $n_omp -p $testdir > out.$sim
fi
gacode_reg $sim $compdir $precfile $tol
if [ "x${code2}" == "x" ]; then
gacode_reg $sim $compdir $precfile $tol
else
# this is actually a bundled test, check subdirs
for dname in `(cd $sim && ls -p |grep / | sed 's#/##')`; do
gacode_reg $sim/$dname $compdir $precfile $tol
done
fi
if [ $reset -eq 1 ]
then
# Overwrite regression data with current data
Expand Down
51 changes: 36 additions & 15 deletions shared/bin/gacode_reg_do_restart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# EXAMPLE:
# gacode_reg_do_restart 2 1 0 cgyro 1e-6 reg01
# gacode_reg_do_restart 2 1 0 xgyro/cgyro 1e-6 reg01
#----------------------------------------------------

n=$#
Expand All @@ -24,10 +25,14 @@ fi
n_proc=${1}
n_omp=${2}
reset=${3}
code=${4}
code_raw=${4}
tol=${5}
scase=${6}

# if a / is present in code_raw string, use the part after / to signify another code
code=`python3 -c "import sys; print(sys.argv[1].split('/')[0])" ${code_raw}`
code2=`python3 -c "import sys; carr=sys.argv[1].split('/'); print(carr[1] if (len(carr)==2) else '')" ${code_raw}`

echo "REGRESSION TESTING: $code"

testdir=$PWD/${code}_regression_test
Expand All @@ -45,8 +50,13 @@ then
compdir=$GACODE_ADD_ROOT/$code/tools/input
fi

precfile=out.$code.prec
infile=input.$code
if [ "x${code2}" == "x" ]; then
precfile=out.${code}.prec
infile=input.${code}
else
precfile=out.${code2}.prec
infile=input.${code2}
fi

if [ "$scase" == "" ]
then
Expand All @@ -61,33 +71,44 @@ cd $testdir
for sim in $list
do
$code -g $sim -p $testdir > out.$sim
rm -f $sim/$precfile
# patch input file to have frequent checkpointing
mv $sim/$infile $sim/$infile.org
grep -v RESTART_STEP $sim/$infile.org > $sim/$infile
echo "RESTART_STEP=1" >> $sim/$infile
if [ "x${code2}" == "x" ]; then
dnames="$sim"
else
dnames=`(ls -p -d ${sim}/* |grep '/$' |sed 's/.$//' )`
fi
for dname in $dnames; do
rm -f ${dname}/$precfile
# patch input file to have frequent checkpointing
mv ${dname}/$infile ${dname}/$infile.org
grep -v RESTART_STEP ${dname}/$infile.org > ${dname}/$infile
echo "RESTART_STEP=1" >> ${dname}/$infile
done
# now run it 3 times
for ((i=0; $i<3; i=$i+1))
do
if [ $i -ne 0 ]
then
cp $sim/$precfile $sim/$precfile.$oi
for dname in $dnames; do
cp ${dname}/$precfile ${dname}/$precfile.$oi
done
fi
if [ $n_omp -eq 1 ] && [ $n_proc -eq 1 ] ; then
$code -e $sim -p $testdir > out.$sim
else
$code -e $sim -n $n_proc -nomp $n_omp -p $testdir > out.$sim
fi
cp $sim/$precfile $sim/$precfile.$i
if [ $i -eq 0 ]
then
for dname in $dnames; do
cp ${dname}/$precfile ${dname}/$precfile.$i
if [ $i -eq 0 ]
then
# reuse the non-checkpointed result from original regression test
myprecfile=$precfile
else
else
# use the additional iterations else
myprecfile=$precfile.$i
fi
gacode_reg $sim $compdir $myprecfile $tol
fi
gacode_reg $dname $compdir $myprecfile $tol
done
oi=$i
done
if [ $reset -eq 1 ]
Expand Down
1 change: 1 addition & 0 deletions shared/bin/gacode_setup
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export PATH=$GACODE_ROOT/tgyro/bin:${PATH}
export PATH=$GACODE_ROOT/gyro/bin:${PATH}
export PATH=$GACODE_ROOT/cgyro/bin:${PATH}
export PATH=$GACODE_ROOT/xgyro/bin:${PATH}
export PATH=$GACODE_ROOT/neo/bin:${PATH}
export PATH=$GACODE_ROOT/vgen/bin:${PATH}
export PATH=$GACODE_ROOT/tglf/bin:${PATH}
Expand Down
27 changes: 27 additions & 0 deletions xgyro/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#----------------------------
# Toplevel makefile for xgyro
#----------------------------

include ${GACODE_ROOT}/platform/build/make.inc.${GACODE_PLATFORM}

export EXTRA_LIBS = \
${GACODE_ROOT}/cgyro/src/cgyro_lib.a \
${GACODE_ROOT}/f2py/expro/expro_lib.a \
${GACODE_ROOT}/f2py/geo/geo_lib.a \
${GACODE_ROOT}/shared/math/math_lib.a

all:
gacode_getversion > .VERSION
cd ${GACODE_ROOT}/cgyro && make
cd src && make

clean:
cd ${GACODE_ROOT}/modules && rm -f xgyro*.mod
cd src && make clean

deepclean:
cd ${GACODE_ROOT}/cgyro && make deepclean
cd ${GACODE_ROOT}/modules && rm -f xgyro*.mod
cd src && make clean

.IGNORE:
Loading

0 comments on commit 9d562fb

Please sign in to comment.