def demo02(show=Show, stop=False): print('------ demo02 --------') print("oTh=OrthMesh(2,[12,5],type='orthotope',box=[[-1,1],[0,1]])") print('----------------------') oTh = OrthMesh(2, [12, 5], type='orthotope', box=[[-1, 1], [0, 1]]) print(oTh) if show: if not isModuleFound('matplotlib'): print( '[fc-hypermesh] Needs matplotlib package to be installed for graphics' ) return plt.close('all') plt.ion() plt.figure(1) oTh.plotmesh(legend=True) set_axes_equal() plt.figure(2) oTh.plotmesh(m=1, legend=True, linewidth=3) set_axes_equal() plt.axis('off') plt.figure(3) oTh.plotmesh(m=1, color='black') oTh.plotmesh(m=0, legend=True, s=105) # see matplotlib.pyplot.scatter options set_axes_equal() plt.axis('off')
def plotmesh(self, **kwargs): """ plotmesh(self,**kwargs) """ if not isModuleFound('matplotlib'): print('plotmesh needs matplotlib package!') return import matplotlib.pyplot as plt if self.d > 3: print('Unable to plot in dimension %d > 3!' % self.d) return m = kwargs.pop('m', self.d) assert m in range(self.d + 1) legend = kwargs.pop('legend', False) fig = plt.gcf() if m == self.d: Legend_handle, Labels = self.Mesh.plotmesh(**kwargs) Legend_handle = [Legend_handle] Labels = [Labels] else: Legend_handle = [] Labels = [] idx = self.getFacesIndex(m) F = self.Faces[idx] nF = len(F) for i in range(nF): Leg, Lab = F[i].plotmesh(**kwargs) Legend_handle.append(Leg) Labels.append(Lab) fig = plt.gcf() ax = fig.axes[0] if self.d == 3: ax.set_zlim(self.box[2, 0], self.box[2, 1]) ax.set_xlim(self.box[0, 0], self.box[0, 1]) ax.set_ylim(self.box[1, 0], self.box[1, 1]) ax.set_xlabel('x') ax.set_ylabel('y') if self.d == 3: ax.set_zlabel('z') #-> No background ax.patch.set_facecolor('None') fig.patch.set_visible(False) #<- if legend: plt.legend(Legend_handle, Labels, loc='best', ncol=int(len(Legend_handle) / 10) + 1).draggable()
def demo07(show=Show, stop=False): import numpy as np print('------ demo07 --------') print( 'trans=lambda q: np.array([q[0]+np.sin(4*np.pi*q[1]), 10*q[1]-1, q[2]+np.cos(4*np.pi*q[1])])' ) print("oTh=OrthMesh(3,[3,25,3],type='simplicial',mapping=trans)") print('----------------------') trans = lambda q: np.array([ q[0] + np.sin(4 * np.pi * q[1]), 10 * q[1] - 1, q[2] + np.cos(4 * np.pi * q[1]) ]) oTh = OrthMesh(3, [3, 25, 3], type='simplicial', mapping=trans) print(oTh) if show: if not isModuleFound('matplotlib'): print( '[fc-hypermesh] Needs matplotlib package to be installed for graphics' ) return plt.close('all') plt.ion() plt.figure(1) oTh.plotmesh(legend=True) set_axes_equal() plt.figure(2) oTh.plotmesh(m=2, legend=True, edgecolor=[0, 0, 0]) set_axes_equal() plt.figure(3) oTh.plotmesh(m=2, edgecolor='lightgray', facecolor=None, alpha=0.3) oTh.plotmesh(m=1, legend=True, linewidth=2) set_axes_equal() plt.figure(4) oTh.plotmesh(m=1, color='black') oTh.plotmesh(m=0, legend=True, s=55) set_axes_equal() plt.show(block=stop)
def demo01(show=Show, stop=False): """ OrthMesh """ print('------ demo01 --------') print( "oTh=OrthMesh(3,[10,5,10],type='orthotope', box=[[-1,1],[0,1],[0,2]])") print('----------------------') oTh = OrthMesh(3, [10, 5, 10], type='orthotope', box=[[-1, 1], [0, 1], [0, 2]]) print(oTh) if show: if not isModuleFound('matplotlib'): print( '[fc-hypermesh] Needs matplotlib package to be installed for graphics' ) return plt.close('all') plt.ion() fig = plt.figure(1) oTh.plotmesh(legend=True) set_axes_equal() plt.figure(2) oTh.plotmesh(m=2, legend=True, edgecolor=[0, 0, 0]) set_axes_equal() plt.axis('off') plt.figure(3) oTh.plotmesh(m=2, facecolor=None, edgecolor=str2rgb('LightGray')) oTh.plotmesh(m=1, legend=True, linewidth=2) set_axes_equal() plt.axis('off') plt.figure(4) oTh.plotmesh(m=1, color='black') oTh.plotmesh(m=0, legend=True, s=55) # see matplotlib.pyplot.scatter options set_axes_equal() plt.axis('off')
def demo06(show=Show, stop=False): import numpy as np print('------ demo06 --------') print( 'trans=lambda q: np.array([20*q[0],2*(2*q[1]-1+np.cos(2*np.pi*q[0]))])' ) print("oTh=OrthMesh(2,[100,20],type='simplicial',mapping=trans") print('----------------------') trans = lambda q: np.array( [20 * q[0], 2 * (2 * q[1] - 1 + np.cos(2 * np.pi * q[0]))]) oTh = OrthMesh(2, [100, 20], type='simplicial', mapping=trans) print(oTh) if show: if not isModuleFound('matplotlib'): print( '[fc-hypermesh] Needs matplotlib package to be installed for graphics' ) return plt.close('all') plt.ion() plt.figure(1) oTh.plotmesh(legend=True) plt.axis('equal') plt.figure(2) oTh.plotmesh(color='lightgray') oTh.plotmesh(m=1, legend=True, linewidth=3) plt.axis('equal') plt.axis('off') plt.figure(3) oTh.plotmesh(color='lightgray') oTh.plotmesh(m=1, color='black') oTh.plotmesh(m=0, legend=True, s=105) # see matplotlib.pyplot.scatter options plt.axis('equal') plt.axis('off')
def demo03(show=Show, stop=False): print('------ demo03 --------') print("oTh=OrthMesh(3,[10,5,10],box=[[-1,1],[0,1],[0,2]])") print('----------------------') oTh = OrthMesh(3, [10, 5, 10], box=[[-1, 1], [0, 1], [0, 2]]) print(oTh) if show: if not isModuleFound('matplotlib'): print( '[fc-hypermesh] Needs matplotlib package to be installed for graphics' ) return plt.close('all') plt.ion() plt.figure(1) oTh.plotmesh(legend=True, linewidth=0.5) set_axes_equal() plt.figure(2) oTh.plotmesh(m=2, legend=True, edgecolor=[0, 0, 0]) set_axes_equal() plt.axis('off') plt.figure(3) oTh.plotmesh(m=2, edgecolor=[0, 0, 0], color='none') oTh.plotmesh(m=1, legend=True, linewidth=2, alpha=0.3) set_axes_equal() plt.axis('off') plt.figure(4) oTh.plotmesh(m=1, color='black', alpha=0.3) oTh.plotmesh(m=0, legend=True, s=55) set_axes_equal() plt.axis('off') plt.show(block=stop)
class EltMesh: """ class EltMesh This class is used to store an elementary mesh given by its vertices array `q` and its connectivity array `me` see description in `Class object OrthMesh` in the report. """ def __init__(self, d, m, q, me, **kwargs): import numpy as np color = kwargs.get('color', [0, 0, 1]) label = kwargs.get('label', '') type = kwargs.get('type', None) toGlobal = kwargs.get('toGlobal', None) assert m <= d assert q.shape[0] == d self.d = d self.m = m self.q = q self.me = me if type is None: if (me.shape[0] == m + 1): # m-simplicial self.type = 0 elif (me.shape[0] == 2**m): # m-orthotope self.type = 1 else: raise NameError('Trouble with "me" dimension!') else: assert type in [0, 1] assert ((type == 0) and (me.shape[0] == m + 1)) or ((type == 1) and (me.shape[0] == 2**m)) self.type = type self.nq = q.shape[1] self.nme = me.shape[1] if toGlobal is None: self.toGlobal = None else: self.toGlobal = np.array(toGlobal, dtype=int) self.color = color self.label = label def __repr__(self): strret = ' %s object \n' % self.__class__.__name__ strret += ' type (str): %s\n' % self.strtype() strret += ' type : %d\n' % self.type strret += ' d : %d\n' % self.d strret += ' m : %d\n' % self.m strret += ' q : (%d,%d)\n' % self.q.shape strret += ' me : (%d,%d)\n' % self.me.shape # strret += 'toGlobal : (%d,)\n'%self.toGlobal.shape return strret def strtype(self): if self.type == 0: return 'simplicial' if self.type == 1: return 'orthotope' return 'unknow' if isModuleFound('matplotlib'): from .Matplotlib import plotmesh
and meshed by simplices 7. demo07: [0,1]x[0,1]x[0,1] mapped by (x,y,z)->(x+sin(4*pi*y),10*y-1,z+cos(4*pi*y)) and meshed by simplices Example 1 --------- >>> import fc_hypermesh.demos >>> demos.demo03() """ from fc_tools.colors import str2rgb from fc_tools.others import isModuleFound from fc_hypermesh.OrthMesh import OrthMesh if isModuleFound('matplotlib'): import matplotlib.pyplot as plt from fc_tools.Matplotlib import DisplayFigures, set_axes_equal, SaveAllFigsAsFiles def savefigs(basename, **kwargs): savedir = kwargs.get('savedir', None) if savedir is not None: SaveAllFigsAsFiles(basename, dir=savedir) Show = isModuleFound('matplotlib') def alldemos(show=Show, **kwargs): ListOfDemos = [ 'demo01', 'demo02', 'demo03', 'demo04', 'demo05', 'demo06', 'demo07'