Skip to content

Commit 7f1ab30

Browse files
committed
(FEATURE) created a base support for interpolation
schemes allowing for the support to be reshaped
1 parent 32026d3 commit 7f1ab30

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import numpy as np
2+
class BaseStructuredSupport:
3+
"""
4+
5+
"""
6+
def __init__(self,
7+
origin=np.zeros(3),
8+
nsteps=np.array([10, 10, 10]),
9+
step_vector=np.ones(3),
10+
):
11+
"""
12+
13+
Parameters
14+
----------
15+
origin - 3d list or numpy array
16+
nsteps - 3d list or numpy array of ints
17+
step_vector - 3d list or numpy array of int
18+
"""
19+
# the geometry in the mesh can be calculated from the
20+
# nsteps, step vector and origin
21+
# we use property decorators to update these when different parts of
22+
# the geometry need to change
23+
# inisialise the private attributes
24+
self._nsteps = nsteps
25+
self._step_vector = step_vector
26+
self._origin = np.array(origin)
27+
self.supporttype='Base'
28+
29+
@property
30+
def nsteps(self):
31+
return self._nsteps
32+
@nsteps.setter
33+
def nsteps(self,nsteps):
34+
#if nsteps changes we need to change the step vector
35+
change_factor = nsteps/self.nsteps
36+
change_factor
37+
self._step_vector/=change_factor
38+
self._nsteps = nsteps
39+
40+
41+
@property
42+
def step_vector(self):
43+
return self._step_vector
44+
45+
@step_vector.setter
46+
def step_vector(self,step_vector):
47+
change_factor = step_vector/self.step_vector
48+
newsteps = self._nsteps/change_factor
49+
self._nsteps =np.ceil(newsteps).astype(int)
50+
self._step_vector = step_vector
51+
52+
@property
53+
def origin(self):
54+
return self._origin
55+
@origin.setter
56+
def origin(self,origin):
57+
origin = np.array(origin)
58+
length = self.maximum-origin
59+
length /= self.step_vector
60+
self._nsteps = np.ceil(length).astype(int)
61+
self._origin = origin
62+
@property
63+
def maximum(self):
64+
return self.origin+self.nsteps*self.step_vector
65+
@maximum.setter
66+
def maximum(self,maximum):
67+
"""
68+
update the number of steps to fit new boundary
69+
"""
70+
maximum = np.array(maximum)
71+
length = maximum-self.origin
72+
length /= self.step_vector
73+
self.nsteps = np.ceil(length).astype(int)
74+
@property
75+
def n_nodes(self):
76+
return np.product(self.nsteps)
77+
78+
@property
79+
def nsteps_cells(self):
80+
return self.nsteps -1
81+
@property
82+
def n_elements(self):
83+
return np.product(self.nsteps_cells)
84+
def __str__(self):
85+
return 'LoopStructural interpolation support: {} \n'\
86+
'Origin: {} {} {} \n'\
87+
'Maximum: {} {} {} \n'\
88+
'Step Vector: {} {} {} \n'\
89+
'Number of Steps: {} {} {} \n'\
90+
'Degrees of freedon {}'.format(self.supporttype,self.origin[0],self.origin[1],self.origin[2],\
91+
self.maximum[0],self.maximum[1],self.maximum[2],\
92+
self.step_vector[0],self.step_vector[1],self.step_vector[2],\
93+
self.nsteps[0],self.nsteps[1],self.nsteps[2],self.n_nodes)
94+
@property
95+
def nodes(self):
96+
max = self.origin + self.nsteps_cells * self.step_vector
97+
x = np.linspace(self.origin[0], max[0], self.nsteps[0])
98+
y = np.linspace(self.origin[1], max[1], self.nsteps[1])
99+
z = np.linspace(self.origin[2], max[2], self.nsteps[2])
100+
xx, yy, zz = np.meshgrid(x, y, z, indexing='ij')
101+
return np.array([xx.flatten(order='F'), yy.flatten(order='F'),
102+
zz.flatten(order='F')]).T

0 commit comments

Comments
 (0)