I am tryng to calfem https://calfem-for-python.readthedocs.io/en/latest/calfem_examples.html for heat transfer and found an good old exemple on a pdf: chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://www.byggmek.lth.se/fileadmin/byggnadsmekanik/publications/tvsm5000/web5187.pdf see exemple 7 on page 81 but at that time the program was pycalfem and some things change I tried to adapt every function and make it work on the new version but failed.
I was expeting the same results as the exemple I tried renaming the updated funtions and printing the varible to study the process but got lost :
import numpy as np
import calfem.geometry as cfg
import calfem.mesh as cfm
import calfem.vis_mpl as cfv
import calfem.utils as cfu
import calfem.core as cfc
import visvis as vv
# Problem constants
kx1 = 100
ky1 = 100
kx2 = 10
ky2 = 10
t = 1.0
n = 2 # Gauss points or integration points
ep = [t, n]
D1 = np.matrix([[kx1, 0.], [0., ky1]])
D2 = np.matrix([[kx2, 0.], [0., ky2]])
Ddict = {10: D1, 11: D2} # markers 10 & 11 will be used to specify different regions with different conductivity
# Create Geometry
g = cfg.Geometry()
# Add Points
points = [[0, 0], [0, 100], [0, 150], [100, 0], [150, 0], [100, -100], [150, -100]]
for p in points:
g.point(p)
# Add Splines
g.spline([1, 2], marker=2, el_on_curve=4)
g.spline([3, 4], el_on_curve=4)
g.circle([1, 0, 3], el_on_curve=10)
g.circle([2, 0, 4], el_on_curve=10)
g.spline([3, 5], el_on_curve=6)
g.spline([5, 6], marker=3, el_on_curve=4)
g.spline([6, 4], el_on_curve=6)
# Add Surfaces
g.structured_surface([0, 2, 1, 3], marker=10)
g.structured_surface([1, 4, 5, 6], marker=11)
elType = 16 # Element type 16 is 8-node-quad. (See gmsh manual for more element types)
dofsPerNode = 1 # Degrees of freedom per node
mesh = cfm.GmshMesh(g)
coords, edof, dofs, bdofs, elementmarkers = mesh.create()
cfv.figure(fig_size=(10, 10))
cfv.draw_mesh(coords=coords, edof=edof, dofs_per_node=mesh.dofs_per_node, el_type=mesh.el_type, filled=True)
print("edof shape:", edof.shape)
print("coords shape:", coords.shape)
print("dofs shape:", dofs.shape)
print("Assembling nDofs = size(dofs) system matrix ... ")
ex, ey = cfc.coordxtr(edof, coords, dofs)
print("ex shape:", ex.shape)
print("ey shape:", ey.shape)
nDofs = np.size(dofs)
K = np.zeros([nDofs, nDofs])
for i in range(len(ex)):
elx = ex[i]
ely = ey[i]
elMarker = elementmarkers[i]
Ke = cfc.flw2i8e(elx, ely, ep, Ddict[elMarker])
cfc.assem(edof[i], K, Ke)
print("Solving equation f = zeros([nDofs, 1])")
f = np.zeros([nDofs, 1])
print("Applying boundary conditions...")
bc = np.array([], 'i')
bcVal = np.array([], 'i')
bc, bcVal = cfu.applybc(bdofs, bc, bcVal, 2, 30.0)
bc, bcVal = cfu.applybc(bdofs, bc, bcVal, 3, 0.0)
a, r = cfu.solveq(K, f, bc, bcVal)
print("Computing element forces...")
ed = cfu.extractEldisp(edof, a)
for i in range(np.shape(ex)[0]):
es, et = cfc.flw2qs(ex[i, :], ey[i, :], ep, Ddict[elementmarkers[i]], ed[i, :])
# Do something with es, et here
print("Visualising...")
cfv.draw_geometry(g, title="Geometry")
vv.figure()
cfv.draw_mesh(coords, edof, dofsPerNode, elType, filled=False) # 8-node quads are drawn as simple quads
vv.figure()
cfv.draw_nodal_values(a, coords, edof, dofsPerNode, elType, title="Example 7")
cfv.get_colorbar().SetLabel("Temperature")
cfv.add_text("The bend")
cfv.add_text("This has part")
# Enter main loop
app = vv.use()
app.Create()
app.Run()