Skip to content

Develop #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions examples/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import calfem.geometry as cfg
import calfem.mesh as cfm
import calfem.vis_mpl as cfv

g = cfg.Geometry()

# Add points

g.point([0, 0]) # 0
g.point([1, 0]) # 1
g.point([1, 1]) # 2
g.point([0, 1]) # 3

# Add points for circle

r = 0.20

g.point([0.5, 0.5]) # 4
g.point([0.5, 0.5+r]) # 5
g.point([0.5, 0.5-r]) # 6
g.point([0.5+r, 0.5]) # 7
g.point([0.5-r, 0.5]) # 8

# Add lines

g.spline([0, 1]) # 0
g.spline([1, 2]) # 1
g.spline([2, 3]) # 2
g.spline([3, 0]) # 3

# TODO: Add circles HERE

g.circle([5, 4, 7]) # 4
g.circle([7, 4, 6]) # 5
g.circle([6, 4, 8]) # 6
g.circle([8, 4, 5]) # 7

# Add surface and hole UPDATE

g.surface([0, 1, 2, 3], [[7, 6, 5, 4]])

#cfv.figure(fig_size=(10.0,10.0))
#cfv.draw_geometry(g)

mesh = cfm.GmshMesh(g)

# Mesh properties

mesh.el_type = 3
mesh.dofs_per_node = 1 # Degrees of freedom per node.
mesh.el_size_factor = 0.040 # Factor that changes element sizes.

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,
title="Example 01"
)

cfv.show_and_wait_mpl()
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ dependencies = [
"numpy",
"scipy",
"tabulate",
"visvis",
"vedo",
"pyvtk",
"qtpy",
"tabulate",
]

requires-python = ">=3.8"
readme = "README.md"
license = {text = "MIT"}
Expand Down Expand Up @@ -48,3 +44,9 @@ build-backend = "pdm.backend"

[tool.pdm]
distribution = true

[project.optional-dependencies]
visvis = [ "visvis" ]
vedo = [ "vedo" ]
pyvtk = [ "pyvtk" ]
qtpy = [ "qtpy" ]
Empty file added src/__init__.py
Empty file.
29 changes: 28 additions & 1 deletion src/calfem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,41 +58,62 @@ def disp(msg):
else:
print(msg)

def str_disp(msg):
return f"{msg}\n"

def disp_par(msg):
if type_of_script() == 'jupyter':
display(HTML(f"<p>{msg}</p>"))
else:
print(f"\nmsg\n")

def str_disp_par(msg):
return f"\n{msg}\n"

def disp_bold(msg):
if type_of_script() == 'jupyter':
display(HTML(f"<b>{msg}</b>"))
else:
print(f"**{msg}**")

def str_disp_bold(msg):
return f"**{msg}**"

def disp_bold_par(msg):
if type_of_script() == 'jupyter':
display(HTML(f"<p><b>{msg}</b></p>"))
else:
print(f"\n**{msg}**\n")

def str_disp_bold_par(msg):
return f"\n**{msg}**\n"

def disp_h1(msg):
if type_of_script() == 'jupyter':
display(HTML(f"<h1>{msg}</h1>"))
else:
print(f"\n# {msg}\n")

def str_disp_h1(msg):
return f"\n# {msg}\n"

def disp_h2(msg):
if type_of_script() == 'jupyter':
display(HTML(f"<h2>{msg}</h2>"))
else:
print(f"\n## {msg}\n")

def str_disp_h2(msg):
return f"\n## {msg}\n"

def disp_h3(msg):
if type_of_script() == 'jupyter':
display(HTML(f"<h3>{msg}</h3>"))
else:
print(f"\n## {msg}\n")
print(f"\n### {msg}\n")

def str_disp_h3(msg):
return f"\n### {msg}\n"

def disp_array(a, headers=[], fmt=".4e", tablefmt="psql", showindex=False):
"""
Expand All @@ -103,6 +124,12 @@ def disp_array(a, headers=[], fmt=".4e", tablefmt="psql", showindex=False):
else:
print(tab.tabulate(np.asarray(a), tablefmt=tablefmt, floatfmt=fmt, showindex=showindex, headers=headers))

def str_disp_array(a, headers=[], fmt=".4e", tablefmt="psql", showindex=False):
"""
Return a numpy array in a nice way as a string.
"""
return tab.tabulate(np.asarray(a), tablefmt=tablefmt, floatfmt=fmt, showindex=showindex, headers=headers)

class ElementProperties(object):
def __init__(self):
self.ep = {}
Expand Down