aromanrom
Computational Physics
25 posts
A branch of theoretical physics
Don't wanna be here? Send us removal request.
aromanrom · 2 months ago
Text
Machine Learning from scratch
Introduction This is the second project I already had when I posted Updates to project. Here is its repository: Machine Learning project on GitHub1. I started it as the Artificial Intelligence hype was going stronger, just to have a project on a domain that’s of big interest nowadays. At that point I was thinking to continue it with convolutional networks and at least recurrent networks, not…
0 notes
aromanrom · 9 months ago
Text
Quantum Computing Simulator
Introduction There is a ‘new’ repository on GitHub1. It’s not that new, I think I started it in September 2022, but I didn’t add any description on it here. So, here it is now: A quantum computation project. It’s a quantum computing simulator together with many algorithms as examples and tests. It started first as a very simple simulator, one that simply followed the math, with matrices, tensor…
Tumblr media
View On WordPress
4 notes · View notes
aromanrom · 10 months ago
Text
Updates to projects
Introduction I didn’t post on this blog for a long time. Nevertheless, I didn’t stop the work on the projects. Most of them have improvements, some of them even serious additions. Some bugs are fixed and I even did some code cleanup to many of them. There are even a couple of newer projects on GitHub: QCSim and MachineLearning. This post is not about those, though, but about the changes and…
View On WordPress
0 notes
aromanrom · 5 years ago
Text
Car-Parrinello Quantum Molecular Dynamics
Car-Parrinello Quantum Molecular Dynamics
Introduction
I have another repository on GitHub. I decided to have one where I’ll put python code for computational physics issues that are simpler / less complete than the code for the C++ projects. I’ll put there both jupyter notebooks and python scripts. At this moment there are only two of them, hopefully I’ll add more.
So, without much ado, here it is: PythonCompphys1.
At this moment only…
View On WordPress
1 note · View note
aromanrom · 5 years ago
Text
Variational Quantum Monte Carlo
Variational Quantum Monte Carlo
Introduction
  I’ll try to describe here briefly another project I have on GitHub1. There will not be much except links, but hopefully those will be useful. The project is far from being perfect, the simple averaging used there for example could be improved, as there are autocorrelations that one should be aware of, but I’ll do that maybe later. Also the way the Gaussian orbitals are combined…
View On WordPress
0 notes
aromanrom · 5 years ago
Text
Epidemic
Introduction
This is a very brief post, with a simulation written in javascript. It’s a very simple model of how a dissease can spread into a population. You may get the code, adjust the parameters and watch different outcomes. The idea of this project came from this: Why outbreaks like coronavirus spread exponentially, and how to ‘flatten the curve’. I highly recommend reading it.
Theory
I…
View On WordPress
0 notes
aromanrom · 5 years ago
Text
Korringa–Kohn–Rostoker method
Introduction
As I mentioned in the previous post, I already have a project on KKR on GitHub1. I won’t add here a lot of description, I’ll point you some references instead. Usually I also try to add links to some other projects that are small enough to be comprehensible in a reasonable time, this time I couldn’t find one, although I searched for one on GitHub and with google. Please let me know…
View On WordPress
0 notes
aromanrom · 5 years ago
Text
Augmented Plane Waves
Introduction
Again, I have a new project on GitHub. It’s not so new, it was working already last year (the APW part) but I didn’t have the patience to write a description for it until now. Actually, there are two new projects on GitHub, related, but this post is about the Augmented Plane Waves1one. Some things I’ll point out in this post are relevant to the KKR project, too. The description for…
View On WordPress
0 notes
aromanrom · 5 years ago
Text
DFT for an atom
DFT for an atom
Introduction
I have a new project on GitHub1. The project is using Density Functional Theory to do calculations for an atom. The project is actually not so new, I’ve put it on GitHub more than three months ago, but it had some issues I had to solve and also I did not have patience until now to write a new blog entry. I mentioned the post on Quantum Scatteringthat I will have some other project…
View On WordPress
1 note · View note
aromanrom · 6 years ago
Text
Introduction
The idea of this project1 came at the time when Nvidia released the RTX graphic cards. I’ve seen lots of comments on various sites about them and realized that many people do not understand what Ray Tracing is about. Since it has Monte Carlo, including importance sampling and obviously it is related with optics, I thought it would be a nice addition to the projects. The project is not about how it’s implemented by Nvidia, they had to use some ‘tricks’ to have it working in real-time, for example the number of reflections is cut out drastically, the number of rays/pixel is limited, the scene for ray tracing might be smaller than the normal one, the noise is eliminated by using ‘AI’, the model is a hybrid, using both rasterization and ray tracing and so on… The project is about regular ray tracing.
Program in action
Usually I record a movie showing the program during execution, but now I changed the code to record an animation, frame by frame, so I show that instead:
youtube
This is how I generated the movie from the frames, using gstreamer:
gst-launch-1.0 multifilesrc location="c:\\temp\\frame%06d.jpg" caps="image/jpeg,framerate=30/1" ! jpegdec ! x264enc pass=quant ! avimux ! filesink location="out.avi"
For the program execution, you’ll have to compile the code and look at it yourself, hopefully the UI is not a big deal, it allows you to generate either the ‘one weekend’ scene, a Cornell box or some other scene that allows you to specify a sky box and some obj file to load. The generated image can be saved in several image format files.
Some theory
This time I started by looking for articles, blog posts and so on before jumping onto implementing the project, I knew that there is a lot to find about it on internet. Indeed there is a lot, so I won’t repeat it here, instead I will point out links to useful info. The most important is that I found some free books2 by Peter Shirley which were very helpful. You may find his GitHub repositories3 very useful. I did not look into those when implementing the project, but the resemblances you may find are not a coincidence, you’ll have to parse the books to find out why.
Here are some other links you may want to check if you look into the project:
An Anisotropic Phong BRDF Model by Michael Ashikhmin and Peter Shirley4
Shape Distributions by Osada et All5
Fast, minimum storage ray-triangle intersection by Tomas Möller and Ben Trumbore6
Of course, those are only a start, you should find plenty of information starting from those links, though.
Some images generated while developing and testing
After the first book, ‘Ray Tracing in one weekend’
With local illumination, depth of field and textures
The Cornell box (during the ‘next week’ book)
Adding triangles, already beyond the ‘rest of your life’ book
Adding Beer-Lambert law for transparent objects
The first obj file loaded in the Cornell box
Making it transparent
Trying some other obj models
Now together with colors/textures
Implementing the Phong model
Trying it on a model, exponents are too high
More testing
Some new model for testing the features
Images generated while fixing some bugs in models loaded from obj files
One more
The code
Generalities
I followed the books quite carefully, although I skipped some more boring parts for me, as textures generation and motion blur, they are straightforward to implement. I chose some different class hierarchy and naming, also there are changes in implementation. Sometimes I chose something faster, as it is the case of ray intersection with the bounding box, sometimes out of convenience I chose a slower implementation, like the rotation for the rectangles. I chose to have a different class for colors, I used the vector class implementation that is already used in some projects for this blog and I used double instead of float for values. It does not make such a big difference in speed, the advantages from a better precision are more important. I also used smart pointers a lot and a C++ random number generator. The only library used is for UI: wxWidgets7. I went beyond the ‘rest of your life’ book, first I added triangles to objects, they I added an obj file loader. I thought about using the tinyobjloader library, but I preferred to implement my own. With some changes I might use it in the future in some other projects that use OpenGL. Maybe I’ll also enhance it in time, because it has various issues, one of the biggest is that it cannot load properly concave polygons.
Namespaces and Classes
In order to understand the code1, you’ll have to look over it and also over Perter Shirley’s books2 and referenced articles. I will describe here the namespaces and classes, very briefly.
The Camera class is similar with the one I used in the projects that use OpenGL, but simplified, with the addition of getRay function. Vector3D is the same as in the other projects, Color is a very simple class that contains r, g, b components. The ObjLoader class is obviously for loading obj files. It’s not portable and far from perfect, I wrote it very quickly, but it works in many cases. It can load not only the objects but also materials, with colors and textures. OrthoNormalBasis is for the local ortho normal basis. To see how it is used, check out for example the AnisotropicPhongPDF::Generate function. PointInfo and ScatterInfo are for some objects that are passed along, containing useful information. Random is for what the name suggests, it can generate various random number distributions. It uses std::mt19937_64. Ray represents, as you guessed, a ray and contains the origin and direction, together with the inverse of direction which is used to speed up computations. Scene implements the scene, it’s derived from Objects::VisibleObjectComposite and its main function is the one for ray casting, RayCast.
There are several namespaces in the project, separating classes depending on their purpose. The BVH namespace is for bounding volume hierarchy classes, it contains the AxisAlignedBoundingBox class and the BVHNode class. Materials contains material classes, such as Dielectric, Metal, Isotropic, Lambertian and AnisotropicPhong. Objects contains the objects such as Triangle, Sphere, Box and so on. PDFs contains probabilistic density function classes like CosinePDF and AnisotrophicPhongPDF. Textures contains texture classes like ColorTexture and ImageTexture. Actions contains some classes for transformations that could be applied on some objects, like TranslateAction or FlipNormal.
There are some other classes that are for UI implementation, options and so on, I’ll let you discover those in the project1.
Some resources
I’ve got some obj files for tests and displaying from here: free3d8. I downloaded the sky boxes from here9. The ‘Earth’ texture I used for some generated images is the same I used in the Newtonian Gravity project, so you can visit that page for a download link.
Conclusions
Such a program could be extended indefinitely. I would first try to improve its performance. Probably it could benefit from a better bounding volume hierarchy construction. If I would have patience and time, I would also go for some other performance enhancements. For example, I used the already built-in rotation in vector implementation, computing it again and again for rectangles, instead of caching the cosines and sines as in the book. That’s not exactly optimal. I bet the program could benefit from many such optimizations. Since the random number generation is used a lot, probably a faster number generator would help, but I guess it’s quite hard to find a good faster one than the one I used. If you find one, please let me know.
I would also switch to a spectral rendering, this way you could have truly realistic refractions, for example. Here is a nice way to start: Lazy spectral rendering on Peter Shirley’s blog. Spectral rendering was one reason why I have a Color class in the project instead of using the vector class as in the books. During development I also found a problem in the last book and associated project, so I signaled it: Importance Sampling issue. You can see the issue in action in the book, too, it manifests itself by those black dots in the images and it required the deNaN cleaning that is also described in the book. That’s why I love open source, people can contribute, they get something for free and give something in return. Thanks to Peter Shirley for sharing his experience!
As usual, if you have suggestions or you find bugs, please let me know, either here or on GitHub1.
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-78764756-1', 'auto'); ga('send', 'pageview');
RayTracer Project on GitHub ↩ ↩ ↩ ↩
Books ‘Ray Tracing in One Weekend’, ‘Ray Tracing: The Next Week’ and ‘Ray Tracing: The Rest of Your Life’ by Peter Shirley ↩ ↩
GitHub repositories for the above books ↩
An Anisotropic Phong BRDF Model by Michael Ashikhmin and Peter Shirley ↩
Shape Distributions Osada et All ↩
Fast, minimum storage ray-triangle intersection by Tomas Möller and Ben Trumbore, Journal of Graphics Tools, 2(1):21–28, 1997 ↩
wxWidgets The cross-platform GUI library ↩
free3d Some free obj models ↩
Sky Boxes ↩
Ray Tracing Introduction The idea of this project1 came at the time when Nvidia released the RTX graphic cards.
3 notes · View notes
aromanrom · 6 years ago
Text
Quantum Scattering
Introduction
I have a project on GitHub about Quantum Scattering1 on a Lennard-Jones potential. The idea is from chapter 2 of a book2I already mentioned on this blog. For this project I won’t put theory here, but refer you to the book instead. It’s a very good book, it’s worth having. I don’t know a better computational physics book that is also treating many topics, the ones that are better are…
View On WordPress
1 note · View note
aromanrom · 6 years ago
Text
Chaos
Introduction
People never cease to amaze me. By that I mean both laymen and ‘scientists’. I’ve seen many opinions of laymen about some sort of a ‘balance’ existing in all sorts of systems that no knowledgeable individual could claim to be in equilibrium. I’ve seen pretenses that the evil and sinning humans are ‘disrupting’ that balance. Salvation comes of course either through ascetism and…
View On WordPress
0 notes
aromanrom · 6 years ago
Text
Tight Binding
Introduction
There are many methods to calculate band structures of crystals. I implemented the Empirical Pseudopotential project, some of the code can be reused for other methods. One of the methods is simple and fast, the tight binding method, so I simply took the code from the last project, cut a part out and modified another part and here it is: Semi-Empirical Tight-Binding1.
Here is the…
View On WordPress
0 notes
aromanrom · 6 years ago
Text
Empirical Pseudopotential
Introduction
I did not write anything on the blog for a long time. I was very busy, I had less time for it. Nevertheless, I did some work on some projects related with it. One of them, a DFT program that calculates a molecule with the supercell method, was supposed to be the theme for a blog entry. I implemented it, it works (sort of) but it needs some checks and cleanup. I implemented it with…
View On WordPress
0 notes
aromanrom · 7 years ago
Text
DFT for a Quantum Dot
Introduction
This post is describing another project that is leading (hopefully) towards something a little more serious: DFT Quantum Dot1. It will be a very short description because it’s Sunday.
As usual, here is the program in action:
It displays the quantum dot ‘orbitals’ with VTKvolume rendering. Do not assign much physical…
View On WordPress
0 notes
aromanrom · 7 years ago
Text
Density Functional Theory
Introduction
As I already revealed in the last post, I intend to have several projects with Density Functional Theory on this blog. I already have a simple project on GitHub, about a ‘quantum dot’1 with volumetric visualization of orbitals with VTK.
I thought that exposing some theory in a separate post would be nice for further references, so without further ado, here it is.
Links On this blog
T…
View On WordPress
0 notes
aromanrom · 7 years ago
Text
Solving Poisson Equation
Introduction
When I started this blog I already expected to have projects that use the Fast Fourier Transform. I actually wrote down several topic ideas for the blog, both solving the Poisson equation and the subject this post will lead to were there, too. I already mentioned in the Relaxation Method post that one can use the Discrete Fourier Transformto solve the problem faster and here it is,…
View On WordPress
2 notes · View notes