Skip to content

Instantly share code, notes, and snippets.

@santiago-salas-v
santiago-salas-v / pen_15.py
Created June 30, 2024 11:57
15 pendula solution
from numpy import linspace,array,outer,sqrt,cos,pi
from matplotlib import pyplot as plt
from seaborn import color_palette
n=15
L=array([0.625+0.05/2*j for j in range(n)]) # m
omega=sqrt(9.81/L) # 1/s
n_range=[10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160]
fig,ax_list=plt.subplots(len(n_range),1,figsize=(15,10),constrained_layout=True)
@santiago-salas-v
santiago-salas-v / get_gists.py
Last active July 14, 2023 01:29 — forked from leoloobeek/get_gists.py
Download all gists for a specific user
# first: mkdir user && cd user && cp /path/to/get_gists.py .
# python3 get_gists.py user
# ref. selimslab/get_gists.py: git@gist.github.com:958e2255a105f9a3f4b421896bce715d.git
# ref. change_file_date_to_name_date.py: https://gist.github.com/santiago-salas-v/7f001a8d80534ebf9ec5104d409420bf
import sys
from os import walk,utime,listdir
from os.path import abspath,sep
from subprocess import call,getoutput
import json
from datetime import datetime
@santiago-salas-v
santiago-salas-v / modelica.xml
Last active April 22, 2022 03:38
Modelica functionList xml for Notepad++ (see https://npp-user-manual.org/docs/function-list/)
<?xml version="1.0" encoding="UTF-8" ?>
<!-- ==========================================================================\
|
| To learn how to make your own language parser, please check the following
| link:
| https://npp-user-manual.org/docs/function-list/
|
\=========================================================================== -->
<NotepadPlus>
<functionList>
@santiago-salas-v
santiago-salas-v / time_power.cpp
Last active October 14, 2020 16:05
compare time to calculate power function by 1) cmath pow, 2) log & exp and 3) direct multiplication.
#include <iostream> // for cin, cout
#include <cmath> // for log, exp, pow
#include <stdio.h> // for printf
#include "timeit.h"
using namespace std; // std::cout ,...
float pow1(float base, float exponent){ // method 1 through direct multiplication
float result=1;
for(int i=1;i<=exponent;i++)result*=base;
@santiago-salas-v
santiago-salas-v / alkanes_llv_hhv.py
Last active October 11, 2020 21:46
Higher and lower heating values of alkanes series C1-C20
from numpy import float,array,arange,ones,mean,linspace,linalg
from matplotlib import pyplot as plt
# source data: Poling, B. E., Prausnitz, J. M., & O'connell, J. P. (2001). The properties of gases and liquids (Vol. 5). New York: Mcgraw-hill.
data_source="""z_i;cas_no;phase;formula;formula_name_structure;ant_name;poling_no;poling_formula;poling_name;poling_molwt [g/mol] ;poling_tfp [K] ;poling_tb [K] ;poling_tc [K] ;poling_pc [bar] ;poling_vc [cm3/mol] ;poling_zc;poling_omega;poling_delhf0 [kJ/mol] ;poling_delgf0 [kJ/mol] ;poling_delhb [kJ/mol] ;poling_delhm [kJ/mol] ;poling_v_liq [cm3/mol] ;poling_t_liq [K] ;poling_dipole [Debye] ;p_ant_a;p_ant_b [K] ;p_ant_c [K] ;p_ant_tmin [K] ;p_ant_tmax [K] ;p_ant_pvpmin [bar] ;p_ant_pvpmax [bar] ;eant_to [K] ;eant_n;eant_e;eant_f;eant_tmin [K] ;eant_tmax [K] ;eant_pvpmin [bar] ;eant_pvpmax [bar] ;wagn_a;wagn_b;wagn_c;wagn_d;wagn_tmin [K] ;wagn_tmax [K] ;wagn_pvpmin [bar] ;wagn_pvpmax [bar] ;range_tmin_to_1000 [K] ;range_1000_to_tmax [K] ;molecular_weight [g/mol] ;hf29
@santiago-salas-v
santiago-salas-v / WBzT_current_voltage.py
Last active July 30, 2023 15:28
Tafel plots (Atkins 8. Ed. Ch. 25), using twin x axis with twiny
import matplotlib.pyplot as plt
from numpy import array, ones, log, exp, concatenate, linspace, mean, sqrt
from numpy.linalg import inv
eta=array([float(x) for x in '50 100 150 200 250'.split(' ')]) # mV
i=array([float(x) for x in '8.8 25.0 58.0 131 298'.split(' ')]) # mA
j=i/2 # mA/cm^2
ln_j=log(j)
import re
a="""Stream 1 2 19 13 20 21 unit
molar phaseFraction [Vapor] 0.78573872 1 0.84155574 N/A 1 N/A
molar phaseFraction [Liquid] 0.21426128 0 0.15844426 1 0 1
Vapor mole fraction [Methane] 0.0065941603 0.0065941603 0.0076360162 N/A 0.0076360162 N/A
Vapor mole fraction [Ethane] 0.00051999558 0.00051999558 0.00051098128 N/A 0.00051098128 N/A
Vapor mole fraction [Propane] 0.00069927477 0.00069927477 0.00045905695 N/A 0.00045905695 N/A
Vapor mole fraction [N-butane] 0.010953157 0.010953157 0.0032409075 N/A 0.0032409075 N/A
Vapor mole fraction [N-pentane] 0.018269691 0.018269691 0.0016300124 N/A 0.0016300124 N/A
@santiago-salas-v
santiago-salas-v / mechanical_critical_point.ipynb
Last active February 19, 2020 12:08
Mechanical critical point, analytical solution according to Watson H. A., Barton, P. I. 2017. Reliable Flash Calculations: Part 3. A Nonsmooth Approach to Density Extrapolation and Pseudoproperty Evaluation, Ind. Eng. Chem. Res. 2017, 56, 14832−14847
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@santiago-salas-v
santiago-salas-v / fast_plot_from_data_pairs.m
Last active October 8, 2019 10:27
fast plot from data pairs python, matlab
fid = fopen('webplotdigitizer_output.csv');
output = textscan(fid,'%s %s', 'Delimiter', ';');
fclose(fid);
x = arrayfun(@(x) str2double(replace(x, ',', '.')), output{1});
y = arrayfun(@(x) str2double(replace(x, ',', '.')), output{2});
plot(x, y);
@santiago-salas-v
santiago-salas-v / wake_sleep_from_event_log.py
Last active October 7, 2019 11:52
on-off time from win event log
import win32evtlog
import win32evtlogutil
import win32con
import winerror
import time
import sys
import traceback
from os.path import exists
from pandas import read_csv
from matplotlib import pyplot as plt