Skip to content

Instantly share code, notes, and snippets.

View zhulianhua's full-sized avatar
🎯
Focusing

Lianhua Zhu zhulianhua

🎯
Focusing
  • Somewhere
  • Shanghai
View GitHub Profile
@zhulianhua
zhulianhua / of41_user_bashrc.sh
Last active June 12, 2017 13:45
modified OpenFOAM 4.1 etc/bashrc for Archer HPC system
#LHZHU: Changed based on http://www.archer.ac.uk/documentation/software/openfoam/#4.1 compute
#DESC: Let user program compile on /work filesystem
#NOTE: should export CRAYPE_LINK_TYPE=dynamic to compile it, as Archer default use static link
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation |
#------------------------------------------------------------------------------
@zhulianhua
zhulianhua / png2flag.py
Created May 29, 2017 08:52
Convert from PNG image to ASCII flag (0/1) file
import numpy as np
import matplotlib.image as mpimg
def rgb2gray(rgb):
''' Convert rgb to gray '''
return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
def gray2bin(gray):
''' Convert gray to binary (0,1)'''
#return (gray>0.5).astype('uint8')
@zhulianhua
zhulianhua / cell2vtk.py
Last active February 2, 2017 20:46
convert a cell centered tecplot block ascii data to a VTK RECTILINEAR_GRID format data
from numpy import *
#filename = "data.txt"
datadir = "Tr0.8_Kn0.1/GH_16_16_16/"
filename = datadir+"creep3d.dat"
NX = 40
NZ = 40
NY = 80
@zhulianhua
zhulianhua / square_cylinder.geo
Created September 19, 2016 08:32
Gmsh script for generating structured mesh for flow past a square cylinder (no complete, just a backup)
D = 1.0;
R = D/2.0;
H = 4;
Ll = 4;
Lr = 6;
Lil = 2;
Lir = 2;
Hi = 2;
@zhulianhua
zhulianhua / tecplot_cellcentered.c
Created September 4, 2016 08:21
store CFD cell centered data in tecplot
if( ( fp=fopen(fname,"w"))==NULL) {printf(" File Open Error\n");exit(1);}
fprintf(fp,"TITLE=%s\n","Cavity_3D");
fprintf(fp,"Variables=%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s \n","X","Y","Z","RHO","Ux","Uy","Uz","Temperature","qx","qy","qz");
fprintf(fp,"Zone I=%d, J=%d, K=%d, DATAPACKING=BLOCK, VARLOCATION=([4,5,6,7,8,9,10,11]=CELLCENTERED) \n",(M),(N),(Q));
"""This file contains code for use with "Think Stats",
Copyright 2016 Lianhua Zhu
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""
import sys
import gzip
import os
import argparse
@zhulianhua
zhulianhua / plainToTecplot.py
Created August 24, 2016 07:32
Convert plain data to Tecplot format
#!/usr/bin/python
import numpy as np
from numpy import *
L = 1.0
N = 60;
dx = L/N;
x = (arange(N) + 0.5)*dx
y = (arange(N) + 0.5)*dx

Linux 命令行编辑快捷键

初学者在Linux命令窗口(终端)敲命令时,肯定觉得通过输入一串一串的字符的方式来控制计算是效率很低。 但是Linux命令解释器(Shell)是有很多快捷键的,熟练掌握可以极大的提高操作效率。 下面列出最常用的快捷键,这还不是完全版。

  • 命令行快捷键:
    • 常用:
      • Ctrl L :清屏
  • Ctrl M :等效于回车

Linux 文件操作

几点说明

  • 常用命令 ls, cp, rm, mv,pwd
  • 目录(directory)对应Windows中的"文件夹"概念;
  • ~代表你的home;
  • .代表当前目录;
  • ..代表当前目录的上一层目录;
  • 命令用法一般都是 命令名 操作对象, 操作对象可以是空格分隔的多个文件/目录
  • 区分绝对路径(/开头)和相对路径,根据实际情况哪个方便用哪个;
@zhulianhua
zhulianhua / getM.c
Created September 29, 2015 01:54
Construct M matrix from given discrete velocity set order for MRT D3Q19 lattice model in lattice Boltzmann method
/*
*construct M from c
*refer to D'Humières, Dominique Ginzburg, Irina Krafczyk, Manfred Lallemand, Pierre Luo, Li-Shi
2012
*/
#include <stdio.h>
#define Q 19