-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
336 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from dolfin import * | ||
import sympy as sp | ||
# Credits: | ||
# https://github.com/pf4d/fenics_scripts/calc_surface_area.py | ||
|
||
x, y = sp.symbols('x, y') | ||
|
||
# surface : | ||
def s(x,y): return sp.exp(x) | ||
|
||
# x-derivative of surface | ||
def dsdx(x,y): return s(x,y).diff(x, 1) | ||
|
||
# y-derivative of surface | ||
def dsdy(x,y): return s(x,y).diff(y, 1) | ||
|
||
# outward-pointing-normal-vector magnitude at surface : | ||
def n_mag_s(x,y): return sp.sqrt(1 + dsdx(x,y)**2 + dsdy(x,y)**2) | ||
|
||
# surface area of surface : | ||
def area(x,y): return sp.integrate(n_mag_s(x,y), (x,0,1), (y,0,1)) | ||
|
||
A_exact = area(x,y) | ||
|
||
for n in [5,10,100,500]: | ||
mesh = UnitSquareMesh(n,n) | ||
Q = FunctionSpace(mesh, "CG", 1) | ||
e = Expression('exp(x[0])', degree=2) | ||
f = interpolate(e, Q) | ||
A_num = assemble( sqrt(f.dx(0)**2 + f.dx(1)**2 + 1) * dx) | ||
print('for n = %i -- error = %.2e' % (n, abs(A_exact.evalf()-A_num))) | ||
|
||
n = 10 | ||
mesh = UnitSquareMesh(n,n) | ||
Q = FunctionSpace(mesh, "CG", 1) | ||
e = Expression('exp(x[0])', degree=2) | ||
f = interpolate(e, Q) | ||
A_vector = project( sqrt(f.dx(0)**2 + f.dx(1)**2 + 1), Q) | ||
|
||
|
||
from vtkplotter.dolfin import plot | ||
plot(A_vector) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from dolfin import * | ||
from mshr import Circle, generate_mesh | ||
from vtkplotter.dolfin import plot, printc | ||
# Credits: | ||
# https://github.com/pf4d/fenics_scripts/pi_estimate.py | ||
|
||
domain = Circle(Point(0.0,0.0), 1.0) | ||
|
||
for res in [2**k for k in range(8)]: | ||
mesh = generate_mesh(domain, res) | ||
A = assemble(Constant(1) * dx(domain=mesh)) | ||
printc("resolution = %i, \t |A - pi| = %.5e" % (res, abs(A-pi))) | ||
printc('~pi is about', A, c='yellow') | ||
|
||
plot(mesh, style=1, axes=3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
This demo solves the Stokes equations, using quadratic elements for | ||
the velocity and first degree elements for the pressure (Taylor-Hood elements). | ||
""" | ||
# Credits: | ||
# https://github.com/pf4d/fenics_scripts/blob/master/cbc_block/stokes.py | ||
from dolfin import * | ||
from time import time | ||
from vtkplotter.dolfin import plot, datadir | ||
|
||
t0 = time() | ||
print("calculating... please wait...") | ||
|
||
# Load mesh and subdomains | ||
mesh = Mesh(datadir+"dolfin_fine.xml") | ||
sub_domains = MeshFunction("size_t", mesh, | ||
datadir+"dolfin_fine_subdomains.xml.gz") | ||
|
||
# Define function spaces | ||
P2 = VectorElement("Lagrange", mesh.ufl_cell(), 2) | ||
P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1) | ||
TH = P2 * P1 | ||
W = FunctionSpace(mesh, TH) | ||
|
||
# No-slip boundary condition for velocity | ||
noslip = Constant((0, 0)) | ||
bc0 = DirichletBC(W.sub(0), noslip, sub_domains, 0) | ||
|
||
# Inflow boundary condition for velocity | ||
inflow = Expression(("-sin(x[1]*pi)", "0.0"), degree=2) | ||
bc1 = DirichletBC(W.sub(0), inflow, sub_domains, 1) | ||
bcs = [bc0, bc1] | ||
|
||
# Define variational problem | ||
(u, p) = TrialFunctions(W) | ||
(v, q) = TestFunctions(W) | ||
f = Constant((0, 0)) | ||
a = (inner(grad(u), grad(v)) - div(v)*p + q*div(u))*dx | ||
L = inner(f, v)*dx | ||
w = Function(W) | ||
|
||
solve(a == L, w, bcs, solver_parameters={'linear_solver' : 'mumps'}) | ||
tf = time() | ||
print("time to solve:", tf-t0) | ||
|
||
# Split the mixed solution using a shallow copy | ||
(u, p) = w.split() | ||
|
||
################################## | ||
plot(u, at=0, N=2, text="velocity", mode='mesh and arrows', | ||
scale=.03, wire=1, scalarbar=False, style=1) | ||
plot(p, at=1, text="pressure", cmap='jet') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.