Skip to content

Instantly share code, notes, and snippets.

View wence-'s full-sized avatar

Lawrence Mitchell wence-

View GitHub Profile
void BoxMesh::build(const Point& p0, const Point& p1,
std::size_t nx, std::size_t ny, std::size_t nz)
{
Timer timer("Generate Box mesh");
// Receive mesh according to parallel policy
if (MPI::is_receiver(this->mpi_comm()))
{
MeshPartitioning::build_distributed_mesh(*this);
return;
mesh = firedrake.UnitSquareMesh(1, 1)
RTe = firedrake.FiniteElement("RT", firedrake.triangle, 1)
BrokenRT = firedrake.FunctionSpace(mesh, firedrake.BrokenElement(RTe))
DG = firedrake.FunctionSpace(mesh, "DG", 0)
TraceRT = firedrake.FunctionSpace(mesh, "CG", 1)
W = BrokenRT * DG
sigma, u = firedrake.TrialFunctions(W)
tau,v = firedrake.TestFunctions(W)
--download-chaco=1 --download-ctetgen=1 --download-exodusii=1 --download-hdf5=1 --download-hypre=1 --download-metis=1 --download-ml=1 --download-mumps=1 --download-netcdf=1 --download-parmetis=1 --download-ptscotch=1 --download-scalapack=1 --download-superlu=1 --download-superlu_dist=1 --download-triangle=1 --with-c2html=0 --with-debugging=0 --with-shared-libraries=1
from firedrake import *
from firedrake.petsc import PETSc
# Mixed poisson
# Homogeneous dirichlet BCs on all walls
# Forcing
# f = -\pi^2 (4 cos(\pi x) - 5 cos(\pi x/2) + 2) sin(\pi y)
# With exact solution
# sin(\pi x) tan(\pi x/4) sin(\pi y)
mesh = UnitSquareMesh(100, 100)
from firedrake import *
from firedrake.petsc import PETSc
# Mixed poisson
# Homogeneous dirichlet BCs on all walls
# Forcing
# f = -\pi^2 (4 cos(\pi x) - 5 cos(\pi x/2) + 2) sin(\pi y)
# With exact solution
# sin(\pi x) tan(\pi x/4) sin(\pi y)
mesh = UnitSquareMesh(100, 100)
if do_plotting:
### PLOTTING STUFF ###
mesh_cg_fs = VectorFunctionSpace(mesh, "CG", 1)
coords_orig = Function(mesh_cg_fs)
coords_stretch = Function(mesh_cg_fs)
coords_latlon = Function(mesh_dg_fs)
coords_orig.dat.data[:] = mesh.coordinates.dat.data[:]
coords_stretch.dat.data[:] = mesh_fake.coordinates.dat.data[:]
# lat-lon 'x' = atan2(y, x)
coords_latlon.dat.data[:,0] = np.arctan2(coords_dg.dat.data[:,1], coords_dg.dat.data[:,0])
from firedrake import *
import numpy as np
Dx = 0.1; Nx = 10
mesh = IntervalMesh(Nx, Nx*Dx)
V = FunctionSpace(mesh, "DG", 0)
def coord2idx(x, coords):
for i, cell in enumerate(coords.cell_node_map().values):
a, b = coords.dat.data_ro_with_halos[cell]
from firedrake import *
mesh = UnitSquareMesh(10, 10)
point_in_cell = """
void point_in_cell(double *out[1], double **coords,
double *point)
{
double x = point[0];
from firedrake import *
mesh = UnitTriangleMesh()
V = FunctionSpace(mesh, 'RT', 1)
u = TrialFunction(V)
v = TestFunction(V)
n = FacetNormal(mesh)
mu = Constant(1.0)
maxval = op2.Global(-1, dtype=float)
op2.par_loop(op2.Kernel("""void maxify(double *a, double *b)
{
a[0] = a[0] < fabs(b[0]) ? fabs(b[0]) : a[0];
}""", "maxify"),
oldv.dof_dset.set, maxval(op2.MAX), oldv.dat(op2.READ))