浏览代码

Completed cfg file query

Snow 8 年之前
父节点
当前提交
7016eff45d
共有 5 个文件被更改,包括 13 次插入7 次删除
  1. 4 0
      MANIFEST.in
  2. 0 1
      hdpg1d/config.json
  3. 6 2
      hdpg1d/preprocess.py
  4. 3 4
      setup.py
  5. 0 0
      test/test_solve_test_problems.py

+ 4 - 0
MANIFEST.in

@@ -0,0 +1,4 @@
+include hdpg1d/config/config.json
+include LICENSE
+include README.md
+include requirements.txt

+ 0 - 1
hdpg1d/config.json

@@ -9,7 +9,6 @@
 		"tauMinus": 1
 	},
 	"forcing": "x",
-	"flux": "x",
 	"boundary": {
 		"left": 0,
 		"right": 0

+ 6 - 2
hdpg1d/preprocess.py

@@ -6,14 +6,17 @@ import numpy as np
 from collections import namedtuple
 from scipy.linalg import block_diag
 
-for loc in os.curdir, os.path.expanduser("~"), "/etc/hdpg1d":
+# load the configuration file
+installDir = os.path.split(__file__)[0]
+cfgPath = os.path.join(installDir, "config")
+for loc in os.curdir, os.path.expanduser("~"), cfgPath:
     try:
         with open(os.path.join(loc, "config.json")) as source:
             configdata = json.load(source)
     except IOError:
         pass
 
-# supported operators
+# evaluate the input json function with only these math operators
 operators = {ast.Add: op.add, ast.Sub: op.sub, ast.Mult: op.mul,
              ast.Div: op.truediv, ast.Pow: op.pow, ast.BitXor: op.xor,
              ast.USub: op.neg}
@@ -94,6 +97,7 @@ def forcing(x):
     f = np.zeros(len(x))
     for i, forcingItem in enumerate(x):
         forcingExpr = configdata["forcing"]
+        # replace the 'x' in the json file with the function parameters
         f[i] = eval_expr(forcingExpr.replace("x", str(forcingItem)))
     return f
 

+ 3 - 4
setup.py

@@ -1,9 +1,6 @@
 #!/usr/bin/env python
 
 from setuptools import setup, find_packages
-import os
-
-# here = os.path.abspath(os.path.dirname(__file__))
 
 
 setup(name='hdpg1d',
@@ -12,9 +9,11 @@ setup(name='hdpg1d',
       Petrov-Galerkin method',
       author='Keyi Ni',
       author_email='[email protected]',
-      url='test',
+      url='https://github.com/asdf123101/HDPG1D',
       license='MIT',
       packages=find_packages(),
+      data_files=[('config', ['hdpg1d/config/config.json'])],
+      include_package_data=True,
       entry_points={
           'console_scripts': [
               'PGsolve = hdpg1d.cmd:main'

tests/test_solve_test_problems.py → test/test_solve_test_problems.py