Skip to content

Instantly share code, notes, and snippets.

View 338rajesh's full-sized avatar
😀

Rajesh Nakka 338rajesh

😀
View GitHub Profile
@338rajesh
338rajesh / rve_homogenization_post_processing.py
Last active November 24, 2022 05:34
This python method evaluates the average stresses and strains, given the odb path and step name.
"""
Suggested to run this script from terminal,
`abaqus cae noGUI="/path/to/this/file"`
"""
from visualization import *
import numpy as np
import os
import sys
import inspect
@338rajesh
338rajesh / RSA_spheres.py
Last active December 2, 2021 10:59
Placing spheres of known volume fraction using Random Sequential Adsorption algorithm.
"""
This module places spheres of known radius and volume fraction
in a cube of known min and max bounds using
Random Sequential Adsorption (RSA) logic.
"""
import numpy as np
from math import pi
def rsa_spheres(r,vf,bounds, min_sep=0.00, max_attempts=1000):
@338rajesh
338rajesh / write_abaqus_mesh_data.py
Created December 17, 2021 14:01
To write nodal coordinates and element connectivity data of a part, to text files
"""
This code writes nodal coordinates and mesh connectivity data of a part, to text file
"""
from abaqus import *
from abaqusConstants import *
import mesh
@338rajesh
338rajesh / filling_plots.py
Created April 1, 2022 03:47
Code for generating matplotlib based plots, where plot is saved at specified pixels in width and height direction and without axes, ticks, whitespace.
# source: this stackoverflow thread : https://stackoverflow.com/questions/8218608/scipy-savefig-without-frames-axes-only-content/8218887#8218887
#
width_pixels = 5
height_pixels = 5
using matplotlib.pyplot as plt
fig = plt.figure(frameon=False)
fig.set_size_inches(width_pixels, height_pixels)
#
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
@338rajesh
338rajesh / attrb_on_root_h5.jl
Created July 4, 2022 12:07
Snippet for adding attributes on the root of h5 file in Julia
h5open(data_set_path, "w") do h5file_id
attributes(h5file_id)["eqrad"] = 1.0
attributes(h5file_id)["inclusion_volume_fraction"] = 32.0
attributes(h5file_id)["rve_xlb"] = bbox[1]
attributes(h5file_id)["rve_ylb"] = bbox[2]
attributes(h5file_id)["rve_xub"] = bbox[3]
attributes(h5file_id)["rve_yub"] = bbox[4]
end
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import os
num_chunks = 6
img_size = (64, 64)
container_ID = "CIRCLES_VF10_RS10_R5"
cfd = os.path.dirname(__vsc_ipynb_file__)
container_dir = os.path.join(cfd, "containers", "rve", f"container_{container_ID}")
import time
import os
class ProgressBar:
def __init__(self, num_iters, header=None) -> None:
self.t0 = time.time()
self.n = num_iters
self.term_cols = (os.get_terminal_size().columns)*0.25
@338rajesh
338rajesh / clip_histogram.py
Created August 27, 2022 16:54
It clips the histogram by minimum frequency
import numpy as np
import matplotlib.pyplot as plt
def clip_histogram(data, get_indices=False, **hist_kwargs):
n, bns = np.histogram(data, **hist_kwargs)
bin_pairs = [(bns[i], bns[i+1]) for i in range(len(bns)-1)]
new_data = []
indices = []
for (i, (bnl, bnu)) in enumerate(bin_pairs):
bin_width = bnu - bnl
@338rajesh
338rajesh / get_curve_chunks.py
Last active November 15, 2022 12:17
Get the chunks of data points on curve about a pivot value.
import numpy as np
import matplotlib.pyplot as plt
import os
from scipy import integrate
CFD = os.path.dirname(__file__)
def get_chunks(x: np.ndarray[float], y: np.ndarray[float], pivot: float = 0.0):
sort_indices = np.argsort(x)
@338rajesh
338rajesh / shuffle_arrays_concurrently.py
Created May 3, 2023 03:55
Shuffles multiple arrays concurrently
import numpy as np
# shuffling arrays concurrently
def shuffle_arrays(*arr, order=1):
num_rows = arr[0].shape[0]
assert all([i.shape[0] == num_rows for i in arr])
indicies = np.array(list(range(num_rows)), dtype=np.int64)