mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 22:20:35 +05:00
2D geometry Python examples
This commit is contained in:
parent
55e3841eea
commit
8ffe4259d1
33
python/gengeom.py
Normal file
33
python/gengeom.py
Normal file
@ -0,0 +1,33 @@
|
||||
from nglib.meshing import *
|
||||
from nglib.geom2d import *
|
||||
|
||||
geom = SplineGeometry()
|
||||
SplineGeometry.Plot = plotgeom
|
||||
SplineGeometry.ShowPoints = plotpointindex
|
||||
SplineGeometry.ShowDomains = plotdomainindex
|
||||
|
||||
# Define Points
|
||||
pi1 = geom.AppendPoint(0,0)
|
||||
pi2 = geom.AppendPoint(1,0)
|
||||
pi3 = geom.AppendPoint(1,1)
|
||||
pi4 = geom.AppendPoint(0,1)
|
||||
|
||||
# Define Segments
|
||||
geom.AppendSegment(pi1,pi2)
|
||||
geom.AppendSegment(pi2,pi3)
|
||||
geom.AppendSegment(pi3,pi4)
|
||||
geom.AppendSegment(pi4,pi1)
|
||||
|
||||
# Plot Geometry
|
||||
geom.Plot()
|
||||
|
||||
# Plot Point Index
|
||||
geom.ShowPoints()
|
||||
# Plot Domain Numbers
|
||||
geom.ShowDomains()
|
||||
|
||||
# Set Meshing Parameters
|
||||
mparam = MeshingParameters()
|
||||
mparam.maxh = 0.1
|
||||
|
||||
mesh = geom.GenerateMesh(mparam)
|
36
python/gengeom_curve.py
Normal file
36
python/gengeom_curve.py
Normal file
@ -0,0 +1,36 @@
|
||||
from nglib.meshing import *
|
||||
from nglib.geom2d import *
|
||||
|
||||
geom = SplineGeometry()
|
||||
SplineGeometry.Plot = plotgeom
|
||||
SplineGeometry.ShowPoints = plotpointindex
|
||||
SplineGeometry.ShowDomains = plotdomainindex
|
||||
|
||||
# Define Points
|
||||
pi1 = geom.AppendPoint(0,0)
|
||||
pi2 = geom.AppendPoint(1,0)
|
||||
pi3 = geom.AppendPoint(1,0.5)
|
||||
pi4 = geom.AppendPoint(1,1)
|
||||
pi5 = geom.AppendPoint(0.5,1)
|
||||
pi6 = geom.AppendPoint(0,1)
|
||||
|
||||
# Define Segments
|
||||
geom.AppendSegment(pi1,pi2)
|
||||
geom.AppendSegment(pi2,pi3)
|
||||
geom.AppendSegment(pi3,pi4,pi5)
|
||||
geom.AppendSegment(pi5,pi6)
|
||||
geom.AppendSegment(pi6,pi1)
|
||||
|
||||
# Plot Geometry
|
||||
geom.Plot()
|
||||
|
||||
# Plot Point Index
|
||||
geom.ShowPoints()
|
||||
# Plot Domain Numbers
|
||||
geom.ShowDomains()
|
||||
|
||||
# Set Meshing Parameters
|
||||
mparam = MeshingParameters()
|
||||
mparam.maxh = 0.1
|
||||
|
||||
mesh = geom.GenerateMesh(mparam)
|
10
python/geom2d.py
Normal file
10
python/geom2d.py
Normal file
@ -0,0 +1,10 @@
|
||||
from nglib.meshing import *
|
||||
from nglib.geom2d import *
|
||||
|
||||
geom = SplineGeometry()
|
||||
geom.Load("square.in2d")
|
||||
|
||||
param = MeshingParameters()
|
||||
param.maxh = 0.05
|
||||
|
||||
m1 = geom.GenerateMesh (param)
|
73
python/init_geom2d.py
Normal file
73
python/init_geom2d.py
Normal file
@ -0,0 +1,73 @@
|
||||
print ("Hello from init.py")
|
||||
# import ngfem_cf
|
||||
|
||||
def mydir(x=None):
|
||||
if x==None:
|
||||
return []
|
||||
else:
|
||||
return [i for i in dir(x) if not '__' in i]
|
||||
|
||||
def execfile(fname):
|
||||
exec(open(fname).read())
|
||||
|
||||
|
||||
def plotgeom(self):
|
||||
coords = self.PlotData()
|
||||
import matplotlib.pyplot as plt
|
||||
plt.plot(coords[2],coords[3])
|
||||
plt.axis('equal')
|
||||
plt.xlim(coords[0])
|
||||
plt.ylim(coords[1])
|
||||
plt.show(block=False)
|
||||
|
||||
def plotpointindex(self):
|
||||
pi = self.PointData()
|
||||
import matplotlib.pyplot as plt
|
||||
for i in range(0,len(pi[0])):
|
||||
plt.text(pi[0][i],pi[1][i],str(pi[2][i]))
|
||||
plt.show(block=False)
|
||||
|
||||
def plotdomainindex(self):
|
||||
segdata = self.SegmentData()
|
||||
import matplotlib.pyplot as plt
|
||||
for i in range(0,len(segdata[0])):
|
||||
if segdata[0][i][2]:
|
||||
horr = 'right'
|
||||
horl = 'left'
|
||||
else:
|
||||
horr = 'left'
|
||||
horl = 'right'
|
||||
if segdata[0][i][3]:
|
||||
vertr = 'top'
|
||||
vertl = 'bottom'
|
||||
else:
|
||||
vertr = 'bottom'
|
||||
vertl = 'top'
|
||||
|
||||
plt.text(segdata[0][i][0],segdata[0][i][1],str(segdata[2][i]),horizontalalignment=horl,verticalalignment=vertl)
|
||||
plt.text(segdata[1][i][0],segdata[1][i][1],str(segdata[3][i]),horizontalalignment=horr,verticalalignment=vertr)
|
||||
plt.show(block=False)
|
||||
|
||||
|
||||
def startConsole():
|
||||
import code
|
||||
try:
|
||||
import readline
|
||||
import rlcompleter
|
||||
readline.parse_and_bind("tab:complete") # autocomplete
|
||||
except:
|
||||
try:
|
||||
import pyreadline as readline
|
||||
import rlcompleter
|
||||
readline.parse_and_bind("tab:complete") # autocomplete
|
||||
except:
|
||||
print('readline not found')
|
||||
vars = globals()
|
||||
vars.update(locals())
|
||||
shell = code.InteractiveConsole(vars)
|
||||
shell.interact()
|
||||
|
||||
|
||||
startConsole()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user