24 September 2013

On Working in the Dark.

At 7 PM tonight, despite my father's long-standing advice about working on things when pressed for time, I start futzing with the right turn signal switch on a recently-new-to-me '99 BMW R1100S. The switch has been skittish the last two days. It's no fun to find out that traffic doesn't think you're switching lanes when you think you've been clearly signalling it for an eighth of a mile. Michelle has to leave to teach yoga at 7:45 PM. This leaves me forty-five minutes to work before I must watch the kiddo. Night is about to fall. Sans garage, I'm working in the driveway.

I have the handlebar control assembly down to the switch innards apart in five minutes, see some grime, and decide to make a run for some electrical cleaner rather than to try my luck applying to the contact surfaces the fine-grit sandpaper that I brought outside. To give Michelle a chance to get ready to teach, I snag the two-and-a-half-year-old in his PJs and we go by car to an auto store on East 7th. After a long, slow line, we're back at 7:30. I get the switch cleaned out (after accidentally shooting electrical cleaner into a hangnail. Don't. Ever. Do. This.) and start putting stuff back together.

Now it's getting dark. Michelle brings out a flashlight. I get the electrical bits back together. Michelle has to leave and brings out our shoeless son Ozark, his Magna Doodle, and his wooden toy pliers. She coaxes Ozark into staying put next to me on the driveway and takes off. He miraculously stays out of the small collection of bike parts and is content to play around on the driveway while I chew on a flashlight trying to point it in the right direction as I re-insert screws and curse the finicky-to-button-up assembly. Ozark disappears over to the left side of the bike and is farting around with his wooden pliers near the left fork. I ask him to come around to my side and he ignores me. No matter as he's being uncommonly good. I periodically inquire what he's up to and he responds promptly.

At 7:55 I get everything back together well-enough that the repair will sit for the night and I can double check it in the morning. I'm elated that nothing bad happened on a hurry-up repair job in the dusk. This has never happened to me in my life.

Suddenly, I hear a weird scritching sound. I ask Ozark what he's doing. Out of the dark on the far side of the bike a little voice proudly replies "I'm sanding the motorcycle". He's got the fine-grit sandpaper and is rubbing it against the fairing near the front headlight. Fortunately the cosmetic damage is light. I crack up. He cracks up. I call my dad to convey the story. Ozark re-cracks up when he hears my dad crack up on the phone. Then the kiddo and I go inside and drink far too much chocolate milk.

13 September 2013

An iostream insertion wrapper to provide full-precision floating point output for C++

In C++ one often wants output full precision floating point data. Iostreams make this a pain. Especially when you'd like the results to line up nicely in your terminal without requiring everything to be in scientific notation. Because reading "12" as 12 is easier than parsing 1.2e+01.

From my research code Suzerain, here's a header-only stream insertion wrapper up to the task. First, a simple use case with output:

using suzerain::fullprec;
cout << fullprec<>(1.23456789012345678e-5) << endl; // "   1.23456789012e-05"
cout << fullprec<>(1.23456789012345678e-4) << endl; // "   1.23456789012e-04"
cout << fullprec<>(1.23456789012345678e-3) << endl; // "   1.23456789012e-03"
cout << fullprec<>(1.23456789012345678e-2) << endl; // "   0.012345678901235"
cout << fullprec<>(1.23456789012345678e-1) << endl; // "   0.123456789012346"
cout << fullprec<>(1.23456789012345678e+0) << endl; // "   1.234567890123457"
cout << fullprec<>(1.23456789012345678e+1) << endl; // "  12.345678901234567"
cout << fullprec<>(1.23456789012345678e+2) << endl; // " 123.456789012345681"
cout << fullprec<>(1.23456789012345678e+3) << endl; // "   1.23456789012e+03"
cout << fullprec<>(1.23456789012345678e+4) << endl; // "   1.23456789012e+04"
cout << fullprec<>(1.23456789012345678e+5) << endl; // "   1.23456789012e+05"


Now the code. You'll need to swap real_t for double in your context as suzerain::real_t is defined elsewhere.

12 September 2013

Worst open source release ever: Suzerain

Though it's far from in a public-ready state, I'm tired of my research code, Suzerain, having no public presence whatsoever:

Though primarily my baby up until a year ago, the cast of characters now includes all of whom are affiliated with The Center for Predictive Engineering and Computational Science (PECOS) within The Institute for Computational Engineering and Sciences (ICES) at The University of Texas at Austin.

This work is supported by the Department of Energy [National Nuclear Security Administration] under Award Number [DE-FC52-08NA28615].

11 September 2013

Somewhat taming the bump function's derivatives

Often I need to initialize some smooth pulse in a simulation. Today, for example, I'm working with acoustic and entropy pulses to test the effectiveness of nonreflecting boundary conditions for the Euler equations (see, e.g., Baum et al). Bump functions are nice for this purpose as they're infinitely smooth and have compact support.

Awhile back I realized that using just a classical bump function produced large gradients which had to be resolved. Years ago I used Mathematica to see if taking some power of the classical bump function, which remains infinitely smooth, could produce smaller gradients better suited for numerical use.

The punchline is that using the fourth power of the bump function, BumpPower[4] in the following parlance, is Goodness (TM). The following Mathematica notebook demonstrates the problem and discusses how one arrives at this empirical result: