Skip to content

Instantly share code, notes, and snippets.

@akaszynski
akaszynski / surf_data_to_cells.py
Created June 6, 2024 22:13
Demonstrate mapping face centers from an external source to the cells of an unstructured grid.
"""
Demonstrate mapping face centers from an external source to the cells of an unstructured grid.
Assumptions:
- Points from the external source are close to the centers of the faces of the
extracted surface
"""
from pykdtree.kdtree import KDTree
@akaszynski
akaszynski / gen_cyclic_gmsh.py
Created October 30, 2023 21:14
Generates a hexahedral mesh model for rotor and stator geometry using the Gmsh library.
"""
This script generates a mesh model for rotor and stator geometry using the Gmsh library.
The mesh is then written to disk and subsequently read and converted into an archive file
with mapdl-archive for further FEM analysis. The module uses pyvista for optional visualization.
Generates a single cyclic sector.
Requirements
------------
@akaszynski
akaszynski / qt_tips.md
Created July 11, 2023 21:37
General PyQt tips and tricks

Implement Scaling

Scaling can only be set on initialization (or restart)

# Enable High DPI display with PyQt
os.environ.setdefault("QT_SCALE_FACTOR", str(rcParams["scale_factor"]))
if hasattr(QApplication, "setAttribute"):
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
    QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
@akaszynski
akaszynski / measure_widget.py
Created November 1, 2022 16:01
Add measure widget example
import time
import vtk
import pyvista as pv
cube = pv.Cube()
pl = pv.Plotter(notebook=False)
pl.add_mesh(cube) # <-- Add pygeometry stuff
@akaszynski
akaszynski / lego.py
Created October 10, 2022 15:42
gmsh + pymapdl + cadquery
#!/usr/bin/env python
# coding: utf-8
# In[12]:
import cadquery as cq
import pyvista as pv
from ansys.mapdl.reader import save_as_archive
@akaszynski
akaszynski / .emacs
Created May 17, 2022 19:55
My emacs init file
(require 'package);; init.el --- Emacs configuration
;; INSTALL PACKAGES
;; --------------------------------------
;; (add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/") t)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
@akaszynski
akaszynski / print_errors.py
Created March 23, 2022 15:05
Print errors redirected from sphinx.
"""Read errors output from a sphinx build and remove duplicate groups"""
import os
import pathlib
import sys
sys.tracebacklimit = 0
my_path = pathlib.Path(__file__).parent.resolve()
errors = set()
error_file = os.path.join(my_path, "build_errors.txt")
@akaszynski
akaszynski / script.py
Created January 27, 2022 21:59
Demo how to write output from MAPDL to disk with PyMAPDL
# enter the solver routine and solve
mapdl.slashsolu()
output = mapdl.solve()
# write output to disk
with open('mapdl_output.txt', 'w') as fid:
fid.write(outout)
@akaszynski
akaszynski / create_surf.py
Created January 18, 2022 23:23
Create a simple PyVista PolyData from a set of points.
"""
Basic example to show how to turn a set of points into a surface, assign values,
and plot it using PyVista.
Points are stored in "data.csv". Points are structured and it's possible, though
slightly harder, to create a pyvista.StructuredGrid using them. Instead, its
much easier to simply to use the delaunay_2d filter.
"""
import numpy as np
@akaszynski
akaszynski / refactor.py
Created May 24, 2021 04:46
refactor mapdl_functions
import re
import shutil
from pathlib import Path
import os
from typing import Optional, Union
from ansys.mapdl.core.mapdl_types import *