Esempio n. 1
0
# coordinateLims = np.array( [ [0,1], [0,1] ] )
# meshPlane = mesher.regularMesh.meshInPlaneRegular( coordinateLims + extension * np.array([-1,1]).reshape((1,2)), corrMin/5/np.sqrt(3) )
# meshSpace = mesher.regularMesh.extendMeshRegularly( meshPlane, spacing = .4, num = 3 )
print("Compute Mesh in 3D")
meshSpace = mesher.regularMesh.meshInPlaneRegular(
    coordinateLims + extension * np.array([-1, 1]).reshape((1, 2)),
    corrMin / 5 / np.sqrt(3))

print("Plot 3D mesh")
# Plot
fig = plt.figure(1)
ax = plt.subplot(221, projection="3d")
plt.cla()

# ax.scatter3D( meshSpace.nodes[:,0], meshSpace.nodes[:,1], meshSpace.nodes[:,2], color="green" )
meshPlotter = mesher.MeshPlotter(meshSpace)
boundaryEdges = meshPlotter.getBoundaryLines()
ax.plot3D(boundaryEdges[0], boundaryEdges[1], boundaryEdges[2], color="red")

# %% Create FEM system

print("Set up FEM system")

# Define the random field
r = corrMin
nu = 2
sigma = 1

BCDirichlet = np.NaN * np.ones((meshSpace.N))
BCDirichlet[meshSpace.getBoundary()["nodes"]] = 0
BCDirichlet = None
Esempio n. 2
0
# %% Create 2D mesh

# Limits of coordinates
coordinateLims = np.array([[0, 1], [0, 1]])

print("Compute Mesh in 2D")
meshPlane = mesher.regularMesh.meshInPlaneRegular(coordinateLims, 0.1)

print("Plot mesh")

plt.figure(1)
ax = plt.subplot(221)
plt.cla()
ax.set_title("Mesh")
meshPlotter = mesher.MeshPlotter(meshPlane)
edges = meshPlotter.getLines()
plt.plot(edges[0], edges[1], color="blue")
edges = meshPlotter.getBoundaryLines()
plt.plot(edges[0], edges[1], color="red")

# %%

# Get edges
edges = mesher.Mesh.getEdges(meshPlane.triangles,
                             meshPlane.topD,
                             meshPlane.topD,
                             libInstance=meshPlane._libInstance)
# Get neighbors if simplices
neighs = mesher.Mesh.getSimplexNeighbors(edges["simplicesForEdges"],
                                         edges["edgesForSimplices"],
Esempio n. 3
0
fig = plt.figure(1)
fig.clf()


# Set bounding box
coordinateLims = np.array([ [0,1], [0,1], [0,1] ])
# Get 2D mesh
mesh = mesher.regularMesh.meshInPlaneRegular( coordinateLims[:2, :], np.array([0.3, 0.3]) )
# # Remove one of the triangles
# mesh.triangles = mesh.triangles[:1,:]
# mesh = mesher.Mesh( mesh.triangles, mesh.nodes )

ax = plt.subplot(221)
ax.cla()        
meshPlotter = mesher.MeshPlotter( mesh )
edges = meshPlotter.getLines()
plt.plot(edges[0], edges[1], color="blue")
edges = meshPlotter.getBoundaryLines()
plt.plot(edges[0], edges[1], color="red")

# for iter in range(mesh.triangles.shape[0]):   
#     triangles = np.concatenate( (mesh.triangles, mesh.triangles[:,0:1]), axis = 1)
#     plt.plot( mesh.nodes[triangles[iter, :], 0], mesh.nodes[triangles[iter, :], 1], color="blue" )



# Extend to 3D mesh
mesh3D = mesher.regularMesh.extendMeshRegularly( mesh, spacing = 1, num = 1 )
    
        
print("")


fig = plt.figure(1)
plt.clf()



# %% 1D curved submanifold


meshCircle, neighsCircle = mesher.Mesh.meshOnCircle( maxDiam = 0.3, maxNumNodes = int(6), radius = 1 )

meshPlotter = mesher.MeshPlotter( meshCircle ) 
edges = meshPlotter.getLines()
plt.plot(edges[0], edges[1], color="blue")
edges = meshPlotter.getBoundaryLines()
plt.plot(edges[0], edges[1], color="red")



# %% Define three points of observation


points = np.array([ [np.cos(angle), np.sin(angle)] for angle in np.linspace( 90, 120, num=3 ) * np.pi/180.0 ])
points[0,:] = np.sin( 2*np.pi/6 ) * points[0,:]
points[2,:] = 1.1 * points[2,:]
plt.scatter(points[:,0], points[:,1])
Esempio n. 5
0
ax = fig.add_subplot(322, )
ax.set_title( "Mesh refine 1" )    
plt.plot( meshm1.nodes[:,0], 0 * meshm1.nodes[:,0], marker="x" )


# %% Create simplest 2D mesh


# Create unrefined sphere
mesh0 = mesher.Mesh( np.array([ [0,1,2], [1,2,3]], dtype=np.uintc), np.array( [ [0,0], [0,1], [1,0], [1,1] ], dtype=np.float64) )



ax = fig.add_subplot(323, )
ax.set_title( "Mesh refine 0" )    
meshPlotter = mesher.MeshPlotter( mesh0 ) 
edges = meshPlotter.getLines()
plt.plot(edges[0], edges[1], color="blue")
edges = meshPlotter.getBoundaryLines()
plt.plot(edges[0], edges[1], color="red")

# Set maximum diameter for each node
maxDiamArray = 0.8 * np.ones( (mesh0.N) )
maxDiamArray[0] = 0.1

# Create refined mesh
mesh1 = mesh0.refine( maxDiam = maxDiamArray, maxNumNodes = mesh0.N + 50 )

ax = fig.add_subplot(324)
ax.set_title( "Mesh refine 1" )   
meshPlotter = mesher.MeshPlotter( mesh1 ) 
# Create refined sphere
meshSphere = meshSphere.refine( \
    maxDiam = 2/5 * np.sin( corrMin / 180.0 * np.pi / 2.0 ), \
    maxNumNodes = meshSphere.N + 10000, \
    transformation = mesher.geometrical.mapToHypersphere )

print("Plot mesh")

fig = plt.figure(1)
ax = fig.add_subplot(221, projection='3d')
ax.cla()
ax.set_title("Mesh")

# Plot mesh
meshPlotter = mesher.MeshPlotter(meshSphere)
edges = meshPlotter.getLines()
ax.plot(edges[0], edges[1], edges[2], color="blue")
edges = meshPlotter.getBoundaryLines()
ax.plot(edges[0], edges[1], edges[2], color="red")

temp = mesher.geometrical.lonlat2Sphere(dataPoints.transpose())
ax.scatter(temp[0, :], temp[1, :], temp[2, :], color="red")

# %% Create FEM system

print("Set up FEM system")

# Define the random field
nu = 2
sigma = 1
Esempio n. 7
0
# # Plot a randomly chosen simplex and its neighbors
# chosenSimplex = np.random.randint( 0, mesh2.NT )
# meshPlotter = mesher.MeshPlotter( mesh2 )
# edges = meshPlotter.getSimplicesLines( neighs2[chosenSimplex,:] )
# plt.plot(edges[0], edges[0]*0, color="green", linewidth=3)
# edges = meshPlotter.getSimplicesLines( np.array([chosenSimplex]) )
# plt.plot(edges[0], edges[0]*0, color="black", linewidth=3)

# Plot a randomly chosen point and its neighboring simplices
chosenPoint = mesh2.getBoundingBox()
chosenPoint = np.random.uniform(size=mesh2.embD) * (
    chosenPoint[:, 1] - chosenPoint[:, 0]) + chosenPoint[:, 0]
chosenPoint = mesh2.nodes[10, :]
chosenPoint = np.array([-1])
meshPlotter = mesher.MeshPlotter(mesh2)
partOfSimplices = np.array([
    implicitMesh.pointInSimplex(chosenPoint, iter) for iter in range(mesh2.NT)
])
edges = meshPlotter.getSimplicesLines(partOfSimplices)
plt.plot(edges[0], edges[0] * 0, color="green", linewidth=3)
plt.scatter(chosenPoint[0], chosenPoint[0] * 0, color="black")

# %% 2D case

# Create unrefined mesh
mesh3 = mesher.Mesh(
    np.array([[0, 1, 2], [1, 2, 3]], dtype=int),
    np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float64))
# Set maximum diameter for each node
maxDiamArray = 1