-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated ci script and added to python tools
- Loading branch information
Showing
12 changed files
with
107 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,7 @@ | |
from .proc_spec import * | ||
from . import plot | ||
from . import math | ||
from . import external | ||
from . import ci | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# import the test script | ||
|
||
import test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@author: Caoxiang Zhu ([email protected]) | ||
For any help, type ./compare_spec.py -h | ||
""" | ||
import numpy as np | ||
from py_spec import SPEC | ||
import argparse | ||
|
||
# parse command line arguments | ||
parser = argparse.ArgumentParser(description="Compare two SPEC HDF5 outputs") | ||
parser.add_argument("filename", type=str, help="file name to be compared") | ||
parser.add_argument("reference", type=str, help="reference data") | ||
parser.add_argument("-t", "--tol", type=float, default=1E-12, help="difference tolerance") | ||
|
||
args = parser.parse_args() | ||
print('Compare SPEC outputs in {:s} and {:s} with tolerance {:12.5E}'.format( | ||
args.filename, args.reference, args.tol)) | ||
data_A = SPEC(args.filename) | ||
data_B = SPEC(args.reference) | ||
tol = args.tol | ||
match = True | ||
|
||
|
||
def compare(data, reference): | ||
global match | ||
for key, value in vars(data).items(): | ||
if isinstance(value, SPEC): # recurse data | ||
print('------------------') | ||
print('Elements in '+key) | ||
compare(value, reference.__dict__[key]) | ||
else: | ||
if key in ['filename', 'version']: # not compare filename and version | ||
continue | ||
elif key == 'iterations': # skip iteration data (might be revised) | ||
continue | ||
else: | ||
# print(key) | ||
diff = np.linalg.norm(np.abs(np.array(value) - np.array(reference.__dict__[key]))) | ||
unmatch = diff > tol | ||
if unmatch: | ||
match = False | ||
print('UNMATCHED: '+key, ', diff={:12.5E}'.format(diff)) | ||
else : | ||
print('ok: '+key) | ||
return | ||
|
||
compare(data_A, data_B) | ||
print('===================') | ||
if match : | ||
print('All the terms are within tolerance.') | ||
else : | ||
print('Differences in some elements are larger than the tolerence.') | ||
|
||
exit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# import the math functions | ||
|
||
from .fourier_surface import * | ||
from .fourier_surface import fourier_surface | ||
from .interface_current import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,15 @@ | |
# coded by @zhucaoxiang ([email protected]) | ||
# adapted by @smiet ([email protected]) | ||
# | ||
|
||
import numpy as np | ||
|
||
class fourier_surface(object): | ||
import numpy as np | ||
''' | ||
toroidal surface in Fourier representation | ||
R = \sum RBC cos(mu-nv) + RBS sin(mu-nv) | ||
Z = \sum ZBC cos(mu-nv) + ZBS sin(mu-nv) | ||
''' | ||
def __init__(self, xm=[], xn=[], rbc=[], zbs=[], rbs=[], zbc=[]): | ||
import numpy as np | ||
"""Initialization with Fourier harmonics. | ||
Parameters: | ||
|
@@ -45,7 +43,6 @@ def read_spec_output(cls, spec_out, ns=-1): | |
Returns: | ||
fourier_surface class | ||
""" | ||
import numpy as np | ||
# check if spec_out is in correct format | ||
#if not isinstance(spec_out, SPEC): | ||
# raise TypeError("Invalid type of input data, should be SPEC type.") | ||
|
@@ -74,7 +71,6 @@ def read_vmec_output(cls, woutfile, ns=-1): | |
Returns: | ||
fourier_surface class | ||
""" | ||
import numpy as np | ||
import xarray as ncdata # read netcdf file | ||
vmec = ncdata.open_dataset(woutfile) | ||
xm = vmec['xm'].values | ||
|
@@ -108,7 +104,6 @@ def read_focus_input(cls, filename, Mpol=9999, Ntor=9999): | |
Returns: | ||
fourier_surface class | ||
""" | ||
import numpy as np | ||
with open(filename, 'r') as f: | ||
line = f.readline() #skip one line | ||
line = f.readline() | ||
|
@@ -152,7 +147,6 @@ def read_winding_surfce(cls, filename, Mpol=9999, Ntor=9999): | |
Returns: | ||
fourier_surface class | ||
""" | ||
import numpy as np | ||
with open(filename, 'r') as f: | ||
line = '' | ||
while "phip_edge" not in line: | ||
|
@@ -205,7 +199,6 @@ def rz(self, theta, zeta, normal=False): | |
r, z -- float array_like | ||
r, z, [rt, zt], [rz, zz] -- if normal | ||
""" | ||
import numpy as np | ||
assert len(np.atleast_1d(theta)) == len(np.atleast_1d(zeta)), "theta, zeta should be equal size" | ||
# mt - nz (in matrix) | ||
_mtnz = np.matmul( np.reshape(self.xm, (-1,1)), np.reshape(theta, (1,-1)) ) \ | ||
|
@@ -243,7 +236,6 @@ def xyz(self, theta, zeta, normal=False): | |
x, y, z -- float array_like | ||
x, y, z, [nx, ny, nz] -- if normal | ||
""" | ||
import numpy as np | ||
data = self.rz(theta, zeta, normal) | ||
r = data[0] | ||
z = data[1] | ||
|
@@ -277,7 +269,6 @@ def areaVolume(self, theta0=0.0, theta1=2*np.pi, zeta0=0.0, zeta1=2*np.pi, \ | |
area -- surface area | ||
volume -- surface volume | ||
""" | ||
import numpy as np | ||
# get mesh data | ||
_theta = np.linspace(theta0, theta1, npol, endpoint=False) | ||
_zeta = np.linspace(zeta0, zeta1, ntor, endpoint=False) | ||
|
@@ -299,7 +290,6 @@ def get_area(self): | |
Returns: | ||
area | ||
""" | ||
import numpy as np | ||
self.area, _volume = self._areaVolume() | ||
return self.area | ||
|
||
|
@@ -325,7 +315,6 @@ def plot(self, zeta=0.0, npoints=360, **kwargs): | |
line class in matplotlib.pyplot | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
# get figure and ax data | ||
if plt.get_fignums(): | ||
fig = plt.gcf() | ||
|
@@ -363,7 +352,6 @@ def plot3d(self, engine='pyplot', theta0=0.0, theta1=2*np.pi, zeta0=0.0, zeta1=2 | |
Returns: | ||
xsurf, ysurf, zsurf -- arrays of x,y,z coordinates on the surface | ||
""" | ||
import numpy as np | ||
# get mesh data | ||
_theta = np.linspace(theta0, theta1, npol) | ||
_zeta = np.linspace(zeta0, zeta1, ntor) | ||
|
@@ -405,7 +393,6 @@ def tovtk(self, vtkname, npol=360, ntor=360, **kwargs): | |
Returns: | ||
""" | ||
import numpy as np | ||
from pyevtk.hl import gridToVTK # save to binary vtk | ||
_xx, _yy, _zz = self.plot3d('noplot', zeta0=0.0, zeta1=2*np.pi, | ||
theta0=0.0, theta1=2*np.pi, npol=npol, ntor=ntor) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# source.sh | ||
# This file sets the PATH to the current directory, which | ||
# is the directory where the xspec file is located. | ||
# | ||
# It also updates the $PYTHONPATH variable so that the | ||
# regression testing can be executed. | ||
# | ||
|
||
# Test if this is the folder where xspec lives then export paths or exit with error | ||
if ( [ -e ./xspec ] && \ | ||
[ -e ./xspech.f90 ] ); then | ||
export PATH=${PATH}:$PWD | ||
export PYTHONPATH=${PYTHONPATH}:$PWD/Utilities/pythontools | ||
else | ||
echo "xspec executable does not exist, will not modify your path" | ||
exit 1 | ||
fi | ||
|
||
|