本文整理汇总了Python中scipy.constants方法的典型用法代码示例。如果您正苦于以下问题:Python scipy.constants方法的具体用法?Python scipy.constants怎么用?Python scipy.constants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy
的用法示例。
在下文中一共展示了scipy.constants方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import constants [as 别名]
def __init__(self):
self.kappa = 0. # inverse of Debye length
self.restart = 0 # Restart of GMRES
self.tol = 0. # Tolerance of GMRES
self.max_iter = 0 # Max number of GMRES iterations
self.P = 0 # Order of Taylor expansion
self.eps = 0 # Epsilon machine
self.Nm = 0 # Number of terms in Taylor expansion
self.NCRIT = 0 # Max number of targets per twig box
self.theta = 0. # MAC criterion for treecode
self.K = 0 # Number of Gauss points per element
self.K_fine = 0 # Number of Gauss points per element for near singular integrals
self.threshold = 0. # L/d criterion for semi-analytic intergrals
self.Nk = 0 # Gauss points per side for semi-analytical integrals
self.BSZ = 0 # CUDA block size
self.Nround = 0 # Max size of sorted target array
self.BlocksPerTwig = 0 # Number of CUDA blocks that fit per tree twig
self.N = 0 # Total number of elements
self.Neq = 0 # Total number of equations
self.qe = scipy.constants.e
self.Na = scipy.constants.Avogadro
self.E_0 = scipy.constants.epsilon_0
self.REAL = 0 # Data type
self.E_field = [] # Regions where energy will be calculated
self.GPU = -1 # =1: with GPU, =0: no GPU
示例2: preprocess_ods
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import constants [as 别名]
def preprocess_ods(*require, require_mode=['warn_through', 'warn_skip', 'raise'][0]):
'''
Decorator function that:
* checks that required quantities are there
'''
def _req(f):
from functools import wraps
@wraps(f)
def wrapper(*args1, **kw1):
args, kw = args_as_kw(f, args1, kw1)
# handle missing required quantities
missing = []
for k in require:
if k not in kw['ods']:
missing.append(k)
if len(missing):
txt = 'could not evaluate %s because of missing %s ODS' % (f.__name__, missing)
if require_mode == 'warn_through':
printe(txt)
elif require_mode == 'warn_skip':
printe(txt)
return kw['ods']
elif require_mode == 'raise':
raise RuntimeError(txt)
# run function
return f(*args, **kw)
return wrapper
return _req
# constants class that mimics scipy.constants
示例3: SetMaterial
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import constants [as 别名]
def SetMaterial(self, name):
"""
Set a particular material in the database as the actual material. All
operations like setting and getting optical constants are done for this
particular material.
Parameters
----------
name : str
name of the material
"""
if self.matname == name:
return
try:
self.h5group = self.h5file[name]
except KeyError:
print("XU.materials.database: material '%s' not existing!" % name)
try:
self.f0_params = self.h5group['f0']
except KeyError:
self.f0_params = None
try:
self.f1_en = self.h5group['en_f12']
self.f1 = self.h5group['f1']
except KeyError:
self.f1_en = None
self.f1 = None
try:
self.f2_en = self.h5group['en_f12']
self.f2 = self.h5group['f2']
except KeyError:
self.f2_en = None
self.f2 = None
try:
self.weight = self.h5group.attrs['atomic_standard_weight']
except KeyError:
self.weight = None
try:
self.radius = self.h5group.attrs['atomic_radius']
except KeyError:
self.radius = numpy.nan
try:
self.color = self.h5group.attrs['color']
except KeyError:
self.color = None
self.matname = name
示例4: add_mass_from_NIST
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import constants [as 别名]
def add_mass_from_NIST(db, nistfile, verbose=False):
"""
Read atoms standard mass and save it to the database.
The mass of the natural isotope mixture is taken from the NIST data!
"""
# some regular expressions
isotope = re.compile(r"^Atomic Number =")
standardw = re.compile(r"^Standard Atomic Weight")
relativew = re.compile(r"^Relative Atomic Mass")
number = re.compile(r"[0-9.]+")
multiblank = re.compile(r"\s+")
# parse the nist file
with open(nistfile, "r") as nf:
while True:
lb = nf.readline()
if lb == "":
break
lb = lb.strip()
if isotope.match(lb):
# found new element
lb = multiblank.split(lb)
lb = nf.readline()
lb = lb.strip()
lb = multiblank.split(lb)
ename = lb[-1]
if verbose:
print("set element %s" % ename)
db.SetMaterial(ename)
# read data
while True:
lb = nf.readline()
lb = lb.strip()
if relativew.match(lb):
lb = multiblank.split(lb)
# extract fallback weight
w = float(number.findall(lb[-1])[0])
db.SetWeight(w * scipy.constants.atomic_mass)
elif standardw.match(lb):
lb = multiblank.split(lb)
# extract average weight
try:
w = float(number.findall(lb[-1])[0])
db.SetWeight(w * scipy.constants.atomic_mass)
except IndexError:
pass
break