preliminary modifications for N-S
This commit is contained in:
43
pina/span.py
43
pina/span.py
@@ -20,9 +20,27 @@ class Span(Location):
|
||||
else:
|
||||
raise TypeError
|
||||
|
||||
def sample(self, n, mode='random'):
|
||||
def sample(self, n, mode='random', variables='all'):
|
||||
|
||||
bounds = np.array(list(self.range_.values()))
|
||||
if variables=='all':
|
||||
spatial_range_ = list(self.range_.keys())
|
||||
spatial_fixed_ = list(self.fixed_.keys())
|
||||
bounds = np.array(list(self.range_.values()))
|
||||
fixed = np.array(list(self.fixed_.values()))
|
||||
else:
|
||||
bounds = []
|
||||
spatial_range_ = []
|
||||
spatial_fixed_ = []
|
||||
fixed = []
|
||||
for variable in variables:
|
||||
if variable in self.range_.keys():
|
||||
spatial_range_.append(variable)
|
||||
bounds.append(list(self.range_[variable]))
|
||||
elif variable in self.fixed_.keys():
|
||||
spatial_fixed_.append(variable)
|
||||
fixed.append(int(self.fixed_[variable]))
|
||||
fixed = torch.Tensor(fixed)
|
||||
bounds = np.array(bounds)
|
||||
if mode == 'random':
|
||||
pts = np.random.uniform(size=(n, bounds.shape[0]))
|
||||
elif mode == 'chebyshev':
|
||||
@@ -41,23 +59,24 @@ class Span(Location):
|
||||
from scipy.stats import qmc
|
||||
sampler = qmc.LatinHypercube(d=bounds.shape[0])
|
||||
pts = sampler.random(n)
|
||||
|
||||
# Scale pts
|
||||
pts *= bounds[:, 1] - bounds[:, 0]
|
||||
pts += bounds[:, 0]
|
||||
|
||||
pts = pts.astype(np.float32)
|
||||
pts = torch.from_numpy(pts)
|
||||
|
||||
fixed = torch.Tensor(list(self.fixed_.values()))
|
||||
pts_fixed_ = torch.ones(pts.shape[0], len(self.fixed_),
|
||||
dtype=pts.dtype) * fixed
|
||||
pts_range_ = LabelTensor(pts, list(self.range_.keys()))
|
||||
pts_fixed_ = LabelTensor(pts_fixed_, list(self.fixed_.keys()))
|
||||
pts_range_ = LabelTensor(pts, spatial_range_)
|
||||
|
||||
if not len(spatial_fixed_)==0:
|
||||
pts_fixed_ = torch.ones(pts.shape[0], len(spatial_fixed_),
|
||||
dtype=pts.dtype) * fixed
|
||||
|
||||
pts_fixed_ = LabelTensor(pts_fixed_, spatial_fixed_)
|
||||
pts_range_ = pts_range_.append(pts_fixed_)
|
||||
|
||||
return pts_range_
|
||||
|
||||
if self.fixed_:
|
||||
return pts_range_.append(pts_fixed_)
|
||||
else:
|
||||
return pts_range_
|
||||
|
||||
def meshgrid(self, n):
|
||||
pts = np.array([
|
||||
|
||||
Reference in New Issue
Block a user