HomerReid / scuff-em

A comprehensive and full-featured computational physics suite for boundary-element analysis of electromagnetic scattering, fluctuation-induced phenomena (Casimir forces and radiative heat transfer), nanophotonics, RF device engineering, electrostatics, and more. Includes a core library with C++ and python APIs as well as many command-line applications.
http://www.homerreid.com/scuff-em
GNU General Public License v2.0
126 stars 50 forks source link

Slow BEM matrix calculation on repeat runs. #143

Open Deadevilgrounds opened 7 years ago

Deadevilgrounds commented 7 years ago

It would be really helpful to have the BEM matrices cached, if possible, for multi electrode runs where the same mesh and voltage is applied in the static solver multiple times.

To describe the problem: We are simulating a Paul surface ion trap which has 32 DC electrodes plus 2 RF and 1 ground. The ground is always grounded but we want to export the field data when 1V is being applied to each electrode in turn, while all other electrodes are grounded. These data files we then combine in mathematica and multiply by the correct constants to scale the fields to define trapping parameters.

So multiple times the electrode/mesh is being defined as 0V and only once is it being defined as 1V.

So if you could cache the BEM generation and anything else that remains constant. Also if the cache could not be cleared but stored when the voltage changes so when we go back to 0V it can reuse the data.

Thanks

HomerReid commented 7 years ago

This kind of thing is easy to do via the C++ or python APIs, which allow this sort of flexibility in organizing calculations. If it would be helpful, I could provide an example.

Alternatively, the scuff-static command-line code already has an option called --SolutionFile that allows you to save and retrieve the solution to an electrostatics problem. It wouldn't be too hard to modify this to save the factorized BEM matrix. Then you could run scuff-static 32 times with different potential files and get 32 output files, with runs 2-32 being fast compared to run 1 as they would omit the calculation of the BEM matrix.

Another option would be to add an option --SingleConductorFields that would automatically do the calculation you want, i.e. loop over all N conductors in the geometry and compute the fields with 1V on that conductor and the others grounded, yielding N output files that you could combine with appropriate weights as a post-processing step.

Which of these do you prefer?

Deadevilgrounds commented 7 years ago

Thank you for your response.

Ultimately I would love to do the calculation in C++ or Python, I went for just generating bash scripts as it was quicker to implement without having to delve into the working on scuffem. So I would love some kind of tutorial of how to do this with C++ and Python.

Option three would also be great for us, esp members of our group who have no programming experience as it would give us exactly what we need in a single pass.

I can also imagine option two being useful for more generic cases where you can define any voltages multiple times for difference results or perhaps as part of an optimization loop.

So is it too bold of me to ask for all three options hehe but option three first :D I look forward to having ultimately some C tutorial as personally, I would love to add this functionality to larger projects.

Once again thanks for this great piece of software and all your hard work.

HomerReid commented 7 years ago

Could I use your geometry, or a facsimile of your geometry, to make a worked example for the SCUFF-STATIC documentation? It's nice to have real-world application examples. I will show how to do the calculation both via the command line and via the C++/python interface.

Deadevilgrounds commented 7 years ago

Paul150Trap.gz

Here are the files for the real trap layout. I have also included the scuffgeo file and one of the voltage files. The gmsh geo file is fully parameterized so you can reduce the number of electrodes if that helps with testing.

Thanks again.

HomerReid commented 7 years ago

Thanks for contributing this example. I've used it as the basis for this new tutorial:

http://homerreid.github.io/scuff-em-documentation/examples/PaulTrap/PaulTrap

This actually illustrates several new features I have added over the past month, including

http://homerreid.github.io/scuff-em-documentation/examples/PaulTrap/KitchenSink.png

All of these features are in the most recent repository commits. I haven't tested very extensively and would be grateful for your help on that. In any event, I hope you find this useful---let me know what you think. Also, I'd be happy to update the text with more information about your application and/or a link to your group if you'd like a little more recognition/publicity.