Hello all,
I am trying to visualize some eigenmodes I calculated with fenics.
I work with gmsh to generate my meshes:
import gmsh
import sys
lc=0.08
gmsh.initialize()
gmsh.model.add("Nanowire")
L,B,H,r = 1,1,1,0.2
gmsh.model.occ.addBox(0, 0, 0, L, B, H,1)
gmsh.model.occ.addCylinder(0.5, 0.5,0.1,0, 0, 0.8 , r, 2)
gmsh.model.occ.synchronize()
#Refine cylinder mesh
gmsh.model.mesh.field.add("Cylinder", 3)
gmsh.model.mesh.field.setNumber(3, "VIn", lc / 3)
gmsh.model.mesh.field.setNumber(3, "VOut", lc)
gmsh.model.mesh.field.setNumber(3, "Radius", 0.2)
gmsh.model.mesh.field.setNumber(3, "XCenter", 0.5)
gmsh.model.mesh.field.setNumber(3, "YCenter", 0.5)
gmsh.model.mesh.field.setNumber(3, "ZCenter", 0.1)
gmsh.model.mesh.field.setNumber(3, "XAxis", 0)
gmsh.model.mesh.field.setNumber(3, "YAxis", 0)
gmsh.model.mesh.field.setNumber(3, "ZAxis", 0.8)
gmsh.model.mesh.field.setAsBackgroundMesh(3)
gmsh.option.setNumber("Mesh.MeshSizeExtendFromBoundary", 0)
gmsh.option.setNumber("Mesh.MeshSizeFromPoints", 0)
gmsh.option.setNumber("Mesh.MeshSizeFromCurvature", 0)
gmsh.option.setNumber("Mesh.Algorithm", 6)
gmsh.model.mesh.generate(3)
gmsh.write("Nanowire.msh")
if '-nopopup' not in sys.argv:
gmsh.fltk.run()
gmsh.finalize()
I convert it to xdmf via
import meshio
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("gmsh:geometrical", cell_type)
out_mesh = meshio.Mesh(points=mesh.points, cells={
cell_type: cells}, cell_data={"name_to_read": [cell_data]})
if prune_z:
out_mesh.prune_z_0()
return out_mesh
msh = meshio.read("Nanowire.msh")
print(msh)
#triangle_mesh = create_mesh(msh, "triangle", prune_z=False)
#meshio.write("Nanowire2D_facets.xdmf", triangle_mesh)
tetra_mesh = create_mesh(msh, "tetra", prune_z=False)
meshio.write("Nanowire_tetra.xdmf", tetra_mesh)
and the use the mesh as
import numpy as np
import matplotlib.pyplot as plt
N=40
mesh = UnitCubeMesh(N,N,N)
with XDMFFile("Nanowire_tetra.xdmf") as file:
file.read(mesh)
V = VectorFunctionSpace(mesh, family='CG', degree=1, dim=3)
bc = DirichletBC(V,[0, 0, 0],boundary)
materials = MeshFunction("size_t", mesh, mesh.topology().dim(), 0)
eps = Permittivity(materials, 4, 1, degree=0)
subdomain_0 = Omega_0()
subdomain_1 = Omega_1()
subdomain_0.mark(materials, 0)
subdomain_1.mark(materials, 1)
space = helmholtz_wellposed(mesh, V, bc, 5E3, eps)
print(len(space))
for i,eigfun in enumerate(space):
vtkfile = File(str(i)+'.pvd')
vtkfile << eigfun
The problem statement is as follows:
u, v = TrialFunction(V), TestFunction(V)
a = inner(curl(u), curl(v))*dx(domain=mesh)
L = inner(Constant((0, 0, 0)), v)*dx(domain=mesh)
m = eps*inner(u,v)*dx(domain=mesh)
A, _ = assemble_system(a, L, bc)
B = assemble(m)
I am simulating a cylinder (lets call it nanowire) and I do get modes that conform to the symmetry, but there is some weird speckle-like pattern in the ParaView visualization, which can be seen here (a cut):
Does anybody know what this pattern is and how I can get rid of it? It changes shape when I turn the camera, so it is likely something to do with Paraview.
I am running linux:
$uname -v
#1 SMP Debian 4.19.235-1 (2022-03-17)
$ sudo lshw -C video
*-display
description: VGA compatible controller
product: Intel Corporation
vendor: Intel Corporation
physical id: 2
bus info: pci@0000:00:02.0
version: 00
width: 64 bits
clock: 33MHz
capabilities: pciexpress msi pm vga_controller bus_master cap_list rom
configuration: driver=i915 latency=0
resources: irq:128 memory:a1000000-a1ffffff memory:b0000000-bfffffff ioport:6000(size=64) memory:c0000-dffff
*-display UNCLAIMED
description: Display controller
product: Topaz XT [Radeon R7 M260/M265 / M340/M360 / M440/M445]
vendor: Advanced Micro Devices, Inc. [AMD/ATI]
physical id: 0
bus info: pci@0000:01:00.0
version: c3
width: 64 bits
clock: 33MHz
capabilities: pm pciexpress msi cap_list
configuration: latency=0
resources: memory:90000000-9fffffff memory:a0000000-a01fffff ioport:5000(size=256) memory:a2300000-a233ffff memory:a2340000-a235ffff