Skip to content

Instantly share code, notes, and snippets.

View Paulms's full-sized avatar

Paul E. Mendez Paulms

  • Escuela Politécnica Nacional
  • Quito, Ecuador
View GitHub Profile
@Paulms
Paulms / KerasDataGenerator.jl
Created September 9, 2020 19:16
Using Keras ImageDataGenerator in Julia
using PyCall
ImageDataGenerator = pyimport("keras").preprocessing.image.ImageDataGenerator
train = ImageDataGenerator(rescale = 1/255)
train_generator = train.flow_from_directory(train_dir, target_size = (150, 150), batch_size = 20, class_mode = "binary")
@Paulms
Paulms / autogrid.jl
Last active February 13, 2020 19:02
Makie auto grid
function ideal_rows_cols(N::Int)
root = max(1.0, sqrt(N))
nrows, ncols = ceil(Int, root), ceil(Int, root)
end
function gridify!(gridlayout)
nrows, ncols = ideal_rows_cols(length(gridlayout.content))
contentcopy = copy(gridlayout.content)
for (i, c) in enumerate(contentcopy)
row = ceil(Int, i / ncols)
col = (i - 1) % ncols + 1
@Paulms
Paulms / MeshDOFMapping.py
Last active December 8, 2019 19:59
Map dofs between meshes bmeshes and submeshes in fenics
import numpy
import dolfin
def SyncSum(vec):
""" Returns sum of vec over all mpi processes.
Each vec vector must have the same dimension for each MPI process """
comm = dolfin.MPI.comm_world
NormalsAllProcs = numpy.zeros(comm.Get_size()*len(vec), dtype=vec.dtype)
@Paulms
Paulms / DetJALE.py
Created December 8, 2019 19:33
Det J in ALE Fenics
from dolfin import *
import dolfin.cpp.function
mesh = UnitSquareMesh(1, 1)
V = FunctionSpace(mesh, 'DG', 0)
# Create boundary mesh:
boundary = BoundaryMesh(mesh, "exterior")
# Get initial configuration as CG1 vector-valued Function:
d = mesh.geometry().dim()
@Paulms
Paulms / LinElasticityALE.py
Created December 8, 2019 19:30
Linear Elasticity with ALE in Fenics
from dolfin import *
def solve_linear_elasticity(mesh, boundaries, d):
c = Constant(d)
V = VectorFunctionSpace(mesh, "Lagrange", 1)
u = TrialFunction(V)
v = TestFunction(V)
E, nu = 10.0, 0.3
@Paulms
Paulms / ALEEx1.c
Created November 7, 2019 18:19
ALE FreeFem++
MeshVeloc ; // computation of mesh velocity (cx,cy)
Th = movemesh(Th,[x+dt*cx,y+dt*cy]); // The mesh is moved
tmp=ux[]; pux=0; pux[]=tmp ; // the variable are pushed forward
@Paulms
Paulms / Custom_nonlinear_solver.py
Created August 21, 2019 16:21
Custom nonlinear solver for fenics
import matplotlib.pyplot as plt
from dolfin import *
class Problem(NonlinearProblem):
def __init__(self, J, F, bcs):
self.bilinear_form = J
self.linear_form = F
self.bcs = bcs
NonlinearProblem.__init__(self)
@Paulms
Paulms / revise_config.jl
Created April 12, 2019 13:33
Julia Revise
# on juno_satartup.jl
if isdefined(Main, :Revise) && isdefined(Main, :Atom)
getfield(Main, :Revise).setup_atom(getfield(Main, :Atom))
end
# on startup.jl
atreplinit() do repl
try
@eval using Revise
@async Revise.wait_steal_repl_backend()
catch
@Paulms
Paulms / ccache.sh
Created February 28, 2019 21:17
Config ccache
installation:
# Install package
sudo apt install -y ccache
# Update symlinks
sudo /usr/sbin/update-ccache-symlinks
# Prepend ccache into the PATH
echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc
@Paulms
Paulms / 0_reuse_code.js
Created May 9, 2017 15:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console