Skip to content

Instantly share code, notes, and snippets.

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
export HOST_COLOR='\e[35m' #magenta
prompt () {
last_code="$?"
# glyph indicating rootness/previous command exit code
class ForgotInitError(Exception):
pass
class CallWatcher:
"""Wrapper for some callable, which makes a note of when the callable has been called once."""
def __init__(self, watched):
self.was_called = False
self.watched = watched
from __future__ import print_function
import json
import matplotlib
import itertools
import matplotlib.pyplot as plt
from math import log
from collections import defaultdict
from matplotlib import rcParams
from block import block_mat, block_vec, block_bc
from dolfin import *
from xii import *
import mshr
N = 10
_mesh = RectangleMesh(Point(0, -1), Point(1, 1), N, 2 * N)
from dolfin import *
from xii import *
N = 20
EPS = 1E-3
_mesh = RectangleMesh(Point(0, -1), Point(1, 1), N, 2 * N)
stokes_subdomain = dolfin.CompiledSubDomain(
"x[1] > 0", eps=EPS
)
@presheaf
presheaf / strange_assembly.py
Created April 1, 2018 14:35
I want to assemble the form specified on line 75, but am having no luck.
from block import block_mat, block_vec, block_bc
from dolfin import *
from xii import *
import mshr
N = 10
EPS = 1E-3
R = 0.25
box_domain = mshr.Box(dolfin.Point(0, 0, 0), dolfin.Point(1, 1, 1))
from block import block_mat, block_vec, block_bc
from dolfin import *
from xii import *
import mshr
dt, alpha, alpha_BJS, s0, mu_f, mu_p, lbd_f, lbd_p, K, Cp = [1] * 10
N = 10
@presheaf
presheaf / setup.py
Created March 21, 2018 13:17
I might as well just put a setup.py here if I'm going to keep copy/pasting it anyway. Works fine to install with e.g. 'pip install --user my_package_dir'
import os
from setuptools import setup, find_packages
setup(
name = "my_package",
version = "0.0.11",
packages=find_packages(),
)
@presheaf
presheaf / deblockify.py
Created February 19, 2018 14:34
Simple conversion of 'sympy block matrix' to numpy matrix
import numpy as np
def translate_single_block(entry, name_to_arr_dict, N_rows, N_columns):
try: # block may just be a bare number
entry = float(entry)
return np.ones((N_rows, N_columns)) * entry
except TypeError:
string_repr = str(entry)
arr = eval(string_repr, name_to_arr_dict)
### source this to make your prompt very aesthetically pleasing. Probably change bayaz to your computer's name.
RED='\033[0;31m'
GREEN='\033[0;32m'
INVERTED='\e[7m'
NC='\033[0m' # No Color
if [ $HOSTNAME = 'bayaz' ]