r/computationalphysics • • Aug 18 '26

[Project] capacitor-FEM: A Dependency-Free 2D FEM Electrostatics Solver in a Single File (Pure NumPy/SciPy/Matplotlib)

Post image
22 Upvotes

Hi everyone,

I wanted to share a 2D finite-element electrostatics solver (capacitor-fem) that I developed. It is designed specifically to be lightweight, easy to understand, and completely self-contained.

Most structural FEM tools require heavy native dependencies like gmsh or compiled C++ libraries, making them a pain to deploy in classrooms or on restricted environments. This solver is written in pure Python (using only NumPy, SciPy, and Matplotlib) in a single file and runs unchanged on desktops, Jupyter notebooks, and even mobile devices (like Pydroid 3 on Android).

Here is a breakdown of the physics, numerics, and architecture:

  • The Math: Solves the generalized Poisson equation div(epsilon * grad(V)) = 0 in weak variational form using linear triangular (P1) elements.

  • Mesh & Geometry: Uses a structured triangular mesh with optional graded Cartesian refinement (refined near electrode edges and gap zones). Supports CSG operations (|, &, -) on primitives like Rectangle, RoundedRectangle, and Circle.

  • Capacitance via Energy: Instead of integrating noisy boundary fluxes, it recovers the two-conductor capacitance per unit depth via the volumetric energy method C = 2W / (delta_V)^2, leading to much more stable results.

  • Vectorized Sparse Assembly: Element stiffness matrices are computed for all triangles simultaneously using NumPy broadcasting and assembled via SciPy’s csr_matrix triplets, avoiding slow element-by-element loops.

Verification & Educational Insights

The repo is heavily focused on validation rather than just showing pretty plots. I’ve included tests that demonstrate critical computational physics concepts:

  1. Exact Analytical Check: When tested against a translationally invariant parallel-plate setup (where fringing is geometrically impossible), the solver reproduces the analytical value to within 6e-16 relative error – proving the core FEM assembly is exact to machine precision.

  2. The Motz Problem (Corner Singularities): The solver demonstrates why the reported peak electric field |E| near a sharp 90-degree conductor wedge does not converge with mesh refinement (as h approaches 0), capturing the theoretical r^(-1/3) field divergence. It includes a RoundedRectangle fillet option to showcase how geometric rounding regularizes the singularity.

  3. Grid-Alignment Errors: It highlights the effect of domain truncation (domain_margin) and spatial classification errors when boundary coordinates are rounded via floating-point arithmetic.

Usage & Driver

I’ve built an external driver script (cfu_driver.py) to demonstrate how to use the solver as a frozen module. You can run two-axis convergence sweeps (mesh spacing 'h' x domain margin), inject air bubbles into dielectrics, or compare completely different configurations on a shared absolute color scale to keep visual comparisons honest.

The project is completely open-source and free to use for anyone looking for a clean, single-file template to teach FEM or prototyping elektrostatic problems without the boilerplate of commercial software.

Link to the Repository: Link to GitHub


r/computationalphysics • • May 16 '21

BSc Physics graduate looking for guidance

16 Upvotes

Hello people, I have a Bachelors in Physics that I completed this year and I find the field of Computational Physics interesting. I have very little exposure to programming (C++), What are the skills you suggest I should learn and get familiar with to get into computational physics

Assuming I am a complete beginner can you suggest a good place for me to start.

P.s: I apologize in advance if this career related question is inappropriate for this sub-reddit. Hoping I'll be able to get help here


r/computationalphysics • • Jul 03 '26

Gravity collapse, 2D n-body simulation

15 Upvotes

This was written in Processing. I used it to do casual accuracy comparisons between different versions of code. No collisions, so to deal with high body densities, there is a gravity-free zone around each body, within which other bodies simply coast through. The challenge was to get the longest run time without the symmetry breaking down. Smaller gravity-free zones caused faster breakdown. Different zone sizes created unique patterns.

The very first simulation starts with a random position distribution, just for reference.


r/computationalphysics • • Aug 23 '26

What career paths exists between computational mechanics, scientific computing (SciML), FEA (or meshfree) solver development, and HPC (GPU acceleration, porting codebases) ?? How about doing a PhD for improving the above?

14 Upvotes

I'm currently, technically, doing an MS in Structural Engineering. For me, my interest has been more towards computational side of mechanics rather than Structural design  or simply using am FEA software (although I do consider it as a backup)

So far I've taken courses in:

- Linear static, and dynamics FEM (soon taking non linear FEM too)

-  Structural Optimization (topology opt. and other general algorithms)

-  Structural Dynamics

-  Structural System Testing and model updation. (Parameter identification and optimization, signal processing)

Now, I plan to take these in the coming quarter:

- Numerical Linear Algebra

- Numerical PDE

- Fracture Mechanics ?

I also volunteered to aid in a RESEARCH in crack growth prediction using Auto-encoder and a (Thermodynamics-informed Latent Space Dynamics Identification) / LSTM surrogate model. It used phase-field-fracture simulation data and HPC resources to complete the whole thing.

What I keep finding myself interested in is not necessarily fracture or SHM specifically, but the computational methods underneath these problems... (does that make sense?)

For example, I'd like to become capable of doing things like:

- implementing (maintaining) numerical/FE method solvers rather than only running an established FEA software.

- developing surrogate/reduced-order models for expensive simulations 

- combining simulation with optimization, uncertainty/stochastic methods (took a course called Random vibrations, so...)

- parallelizing/accelerating scientific codes on CPUs/GPUs

- doing proper verification, convergence studies, benchmarking and performance work

- potentially developing or maintaining actual CAE/FEA solver software

- I'd also like to do all these for other Physics (GR, QM, etc.) simulations too, if possible, one day. 

I'm still interested in the underlying mechanics/physics, so I don't want to become a generic software engineer who happens to have once studied structures. But I'm also increasingly unsure that "structural engineer" describes the career I'm actually aiming for.

I've seen titles such as Computational Mechanics Engineer, R&D Engineer, Solver Developer, Scientific Software Engineer, CAE Software Developer, Research Engineer, Simulation/HPC Engineer, etc., but I'm trying to understand what these careers actually look like from people doing them.

So my main questions become:

1. Which industrial jobs genuinely involve developing numerical methods/solvers or computational tools?

2. Which of those are realistically accessible with an MS? Is there an entry path into solver-algorithm development/R&D without a PhD?

3. If I don't start a PhD immediately after my MS, would an R&D/software role at a simulation company (ANSYS etc.) be the obvious route? What other options would i have?

4. For the kind of work I'm describing, would you recommend a PhD? If so, is it reasonable for the PhD identity to be "computational mechanics/scientific computing" while fracture, composites, structural dynamics, soft materials, etc. serve as application problems rather than choosing one of those as my permanent specialization?

5. What skills most distinguish someone who is actually hireable for solver/scientific-computing work? I'm particularly wondering about C/C++/Fortran, Python, Linux, Git/build systems, MPI/OpenMP/CUDA, PETSc/Trilinos or similar libraries, numerical linear algebra, testing/verification, convergence studies and HPC performance work.

Basically, I'm neither here nor there atp. So I'd really appreciate all sorts of input. Where else do you think I could find answers to these? other subs? Linkedin profiles? 


r/computationalphysics • • Sep 11 '24

Make documentation in C

11 Upvotes

Hi everyone. I'm new in this subreddit. I'm currently studying Computational Physics, for an exam at the university. One of the things i have to do is to write code in C to compute integrals(using Simpson, Gauss, Importance Sampling and other methods). My professor suggests to write a library that include all the methods that i have to use for the exercises. Ok great, i'm writing the library and i want to make a documentation for it. I want to make it but i don't know how. In my mind i want to make it like Javadoc for the java documentations. Can someone suggests me something like Javadoc for the documentation in C? I hope my request is clear. Thanks you all :)


r/computationalphysics • • Jun 29 '26

How to start doing simulations?

10 Upvotes

Hi everyone. I am an undergrad physics major and I want to start doing plasma simulations. How to start doing it? I know python. Where is the best place to start computational plasma physics? Can anyone please guide me.


r/computationalphysics • • May 22 '21

Grad student struggling in computational physics class

10 Upvotes

I am a grad student, and we have computational physics course this semester, it includes all the stuff like boundary value problems ( shooting methods), linear algebra ,random numbers and all .Since the proffesor uses Fortran I generally struggle also the available text book numerical recepies is in c++ it's difficult too(I use python), I couldn't find any good lectures for this stuff, what would you guys suggest?


r/computationalphysics • • Jun 08 '23

Computational Physics Basics: Polynomial Interpolation

Thumbnail notjustphysics.com
9 Upvotes

r/computationalphysics • • Nov 18 '24

Fractal

Post image
7 Upvotes

r/computationalphysics • • Sep 12 '21

Are mathematical models and computer simulations used by (very) early stage startups to test their initial prototypes? Why or why not?

7 Upvotes

I'm posting this same question in several subreddits to get more diverse answers, hope that's ok.

It seems like the use of modelling and computer simulations is severely skewed towards big companies with very deep pockets. I was wondering if anyone in this subreddit knows about hard tech startups applying this technology to de-risk the initial stages of product development and test their technical hypotheses in a cost-efficient manner.


r/computationalphysics • • Apr 05 '23

A new subreddit for the scientific programmers out there: r/ScientificComputing

6 Upvotes

Hi,

I just made a new subreddit for the scientific programmers out there. Join me and let let me learn from you:

r/ScientificComputing/

Hi Mods, hope you're cool with this.


r/computationalphysics • • Mar 09 '23

I am currently starting out with GPU programming using the Kokkos library and here is a post about my first steps.

Thumbnail notjustphysics.com
6 Upvotes

r/computationalphysics • • Oct 20 '20

Simulation of the Double Slit Experiment with Incoherent and Coherent Light at three different time scales

Thumbnail
youtube.com
6 Upvotes

r/computationalphysics • • Aug 30 '26

[Book Announcement] Finite Difference Time Domain Method with Moving Structures (Springer Nature, Feb 2027)

Post image
5 Upvotes

r/computationalphysics • • Sep 11 '24

Introducing pipefunc: Streamline Physics Simulations with DAG-based Workflows in Python

5 Upvotes

As a computational physicist, I am excited to share my latest open-source project, pipefunc! It's a lightweight Python library that simplifies function composition and pipeline creation. Less bookkeeping, more doing!

tl;dr: check out this physics based example

What My Project Does:

With minimal code changes turn your functions into a reusable pipeline.

  • Automatic execution order

  • Pipeline visualization

  • Resource usage profiling

  • N-dimensional map-reduce support

  • Type annotation validation

  • Automatic parallelization on your machine or a SLURM cluster

pipefunc is perfect for data processing, scientific computations, machine learning workflows, or any scenario involving interdependent functions.

It helps you focus on your code's logic while handling the intricacies of function dependencies and execution order.

  • 🛠️ Tech stack: Built on top of NetworkX, NumPy, and optionally integrates with Xarray, Zarr, and Adaptive.

  • 🧪 Quality assurance: >500 tests, 100% test coverage, fully typed, and adheres to all Ruff Rules.

Key Advantages of PipeFunc:

An major advantage of pipefunc is its adept handling of N-dimensional parameter sweeps, a frequent requirement in scientific research. For instance, in computational neuroscience, you might encounter a 4D sweep over parameters x, y, z, and time. Traditional tools create a separate task for every parameter combination, leading to computational bottlenecks—imagine a 50 x 50 x 50 x 50 grid generating 6.5 million tasks before computation even starts.

pipefunc simplifies this with an index-based approach, using four axes, each a list of length 50, with indices pointing to positions. This not only streamlines the setup by focusing on the pipeline but also reduces overhead with a manageable range of indices. Starting on a cluster or locally is as simple as a single function call!

Target Audience:

  • 🖥️ Scientific HPC Workflows: Efficiently manage complex computational tasks in high-performance computing environments.

Happy to answer any question!


r/computationalphysics • • Mar 04 '23

Laptop and OS for computational sciences

5 Upvotes

Hi guys,

Next semester I will enter a master program in computational science focused on physics simulations (so my main use will not be ML, data science, computational statistics...). I plan to work on multi-physics simulations (with mechanics, fluid dynamics, electromagnetism...)

I need to change my 10 year old macbook. What do you think would be the perfect laptop and OS for my use?

Also, I want to be able to run heavy programs directly on my computer, when I do projects on my own for fun, and don't have a cluster to run the codes on.

Thanks!


r/computationalphysics • • Mar 05 '22

7emL - Ferritin - Octahedral symmetry

Thumbnail
youtube.com
5 Upvotes

r/computationalphysics • • Sep 29 '21

The history of how computational physics and computers have influenced each other

Thumbnail
symmetrymagazine.org
5 Upvotes

r/computationalphysics • • Sep 23 '26

A coupled Regge-Maxwell toy model on a dynamic icosahedral mesh with exact energy conservation (Python + DEC)

Thumbnail github.com
4 Upvotes

r/computationalphysics • • May 15 '26

Introduction to Integration methods

Thumbnail
youtu.be
4 Upvotes

I’m building a physics engine and will be sharing my research and eventually the code as well.


r/computationalphysics • • Oct 01 '24

M-dimensional sphere

4 Upvotes

Hi, i have to write a program in C that compute the volume of the sphere(radius r=1) in M-dimensions (M =2,3,...7) with the Monte Carlo integration and Mid-Point Rule. The part with the Monte Carlo is good, but now i'm struggling with the Mid-Point Rule. Can anyone help me with some algorithm for this method?


r/computationalphysics • • Apr 18 '23

Is taking numerical analysis in undergrad necessary for grad school

Thumbnail self.csmajors
4 Upvotes

r/computationalphysics • • Dec 14 '22

Anyone using rust in their work?

4 Upvotes

I've been learning rust recently and am starting to like the language. I am surprised by the lack of scientific packages / APIs though. Curious if anyone is using it in their work or research.


r/computationalphysics • • Sep 03 '22

Any good books that give a wide array of forward and inverse solvers?

4 Upvotes

Going through research papers, I come across several different types of solvers with various approaches, like sparse methods, newton-based methods, born approximation, subspaces, machine learning based, etc. Most of the papers just explain some theory behind the method, which, understandably, helps little to actually implement it in code.

So, I want a book that covers a wide range of solvers and provides some help to actually implement it, not necessarily through actual code, just some insights on math-to-code conversion, or algorithm-style explanation would help.