09 December 2010

Tradeoffs everywhere

Among the benefits of being a grad student is the ability to do literature review in one's hot tub.

Among the drawbacks of being in Ann Arbor is waking up to find the ambient temperature outside to be 5 °F.

02 December 2010

MC2011 proceedings bibliography style

In case anyone out there hasn't yet submitted their paper for the upcoming M&C conference, I have cooked up a BibTeX bibliography style file for the International Conference on Mathematics and Computational Methods that accurately reproduces their example references in the provided LaTeX template. Download it to save yourself the trouble of manually formatting your citations.

01 October 2010

New hobby

Combining my love of sailing and English by chuckling delightedly whenever I hear people use nautically originated phrases in everyday speech:

  • take aback
  • square away
  • give leeway
  • jump ship
  • stem to stern
  • etc.

06 August 2010

OED: Star Wars Collector's Edition

As a logophile, I occasionally browse both my copy of the Shorter Oxford English Dictionary and the OED Online. For one reason or another, I was reading the updated draft entry of remember, v.1 sense 5a, and I found the most startlingly nerdy quotation displayed:

G. LUCAS Star Wars Episode I: Phantom Menace 91, I made this for you. So you'd remember me. I carved it out of a japor snippet... It will bring you good fortune.

There you have it. It seems that some lexicographer out there chose to sacrifice literary integrity to make a nerdy allusion. I suppose I should also check the entries for "father," "force," "droid," …

26 July 2010

The Case-book of Linear Transport Theory

There are very few people who, upon glancing at the section titles in their neutron transport theory books, would chuckle because "The Case of Anisotropic Scattering," "The Albedo Problem," and "The X-Function Identities" all read like titles from a collection of mysteries.

22 June 2010

Alcohol isn't allowed at the sailing club

I might suggest a slogan for "designated sailor" awareness out on the lake: don't imbibe and jibe?

18 June 2010

Kids these days

Curse you, the internet, for your abhorrent mangling of the words "epic" and "fail." The Iliad is epic. Typical residents of the internet fail to appreciate the beauty of literate conversation.

11 June 2010

Time-dependent discrete ordinates transport

The discrete ordinates approximation for transport lumps "particles" into certain directions. In a 1-D time-dependent transport problem, the effect is the same as having several waves propagating at different speeds from the source region.

04 May 2010

Regression

A study titled The largest Last Supper: depictions of food portions and plate size increased over the millennium has attempted to extrapolate nominal meal portion sizes from paintings of The Last Supper created over an 800-year span. Now, tell me if this is not the worst regression analysis you've ever seen:

Really, a parabolic fit? One that extends 300 years beyond the range of the data? I'm no expert in regression analysis, but even an r-value of 0.5 does not seem worthy of the strong conclusions which the article draws.

Aside from the poor correlation coefficient, and assuming the very method of linking plate-to-head ratio to portion size is valid, it looks like their extrapolation hinges entirely on one outlier (the most recent painting) and a century of plenty (in the 1500's, where there were not only small portions but large portions). This is a crock.

12 March 2010

It's science, ok

Today I had a little fun with my code. As I've mentioned too often, it's written with a Python front end. That means I can very easily interact with the hundreds of Python modules out there. Well, this being a Friday afternoon, I decided to tie it into an image processing library, which will let me turn an image into a series of values, which I can then define as a field on my mesh (e.g., the total cross section). So I did that with a test image, and ran it through my transport code.

The code to load an image as grayscale, create the mesh, and set the cross sections:

    im = Image.open(fname).convert("L").transpose(Image.FLIP_TOP_BOTTOM )
    values = ( (255.0 - x) / 255.0 for x in im.getdata() )
    args = list(im.size) + list( 10.0 * float(i) / max(im.size)
                                  for i in im.size )
    mesh = meshlib.Mesh(*args)
    sigma_t = meshlib.CellFieldFloat(mesh, meshlib.VectorFloat(values) )

I also did this with a picture of my advisor.

26 February 2010

Vim: strip trailing whitespace on write

Git is picky about leave trailing whitespace (spaces at the end of a line) in your code. To keep it from being a problem, I modified some helpful scripts to my exacting specifications: it will notify you if it replaces trailing whitespace, it won't change your cursor position, and it won't affect innocent bystander files. Add it to your $HOME/.vim/ftplugin/cpp.vim ftplugin file.

" automatically remove trailing whitespace before write
function! StripTrailingWhitespace()
  normal mZ
  %s/\s\+$//e
  if line("'Z") != line(".")
    echo "Stripped whitespace\n"
  endif
  normal `Z
endfunction
autocmd BufWritePre *.cpp,*.hpp,*.i :call StripTrailingWhitespace()

I like Vim, but I despise Vimscript. Trying to get it to do exactly what I want takes so much guessing and consequently far too much time.

17 February 2010

SWIG iterators and generators, continued

This is a continuation of my previous post on Python generators with SWIG. I've improved the code, added an iterator class so that the same generator method can be called multiple times concurrently, and added a couple of macros to allow easy instantiation of the SWIG code.

A SWIG file (use with the %include directive) is available for download, and further updates will be posted on my projects page.

As an example of how this would be used, see an excerpt of a 2D diffusion input file that uses my mesh library:

for c in mesh.cells():
    source[c] = max(  math.cos( c.getCenter()[0] / 2 * math.pi )
                    + math.cos( c.getCenter()[1] / 2 * math.pi ),
                  0)

UPDATE 4/25/2011: my project that uses this file is now posted on github.

15 February 2010

Easy Python generators using SWIG

In my research code, I have a number of classes that act as wrappers for containers, and they provide begin and end functions. I want an easy way to provide a generator for looping over these embedded containers. Because of the way SWIG's STL wrappers work, it's not (easily?) possible to wrap a vector of pointers, and we'd like to avoid all the extra overhead those wrappers have anyway: all we need is a way to increment a pointer and to tell if it's at the end.

So, my solution is to create a thin wrapper for only the increment operator ++, and extend the class with a function to return the "beginning" iterator and to check whether the iterator is at the end position.

For this particular instance, I have a class Mesh that has methods for beginLeftBoundaryFaces and endLeftBoundaryFaces—which return STL vector iterators that point to a Face *.

%inline %{
//! Thin wrapper for ONLY the increment operator
void _bfiter_incr( std::vector<Face *>::const_iterator* iter )
{
    // increment the iterator
    ++(*iter);
}
%}

%extend Mesh {
%insert("python") %{
    def left_boundary_faces(self):
        "A generator to iterate through boundary faces."
        faceIter = self._beginLeftBoundaryFaces()
        keepLooping = True
        while keepLooping == True:
            face = self._bfiter_dereference_Left( faceIter )
            if face:
                _bfiter_incr( faceIter )
                yield face
            else:
                keepLooping = False
%}

//! get the first element in the vector
std::vector<Face *>::const_iterator* _beginLeftBoundaryFaces()
{
    return new std::vector<Face *>::const_iterator(
            ($self->beginLeftBoundaryFaces()) );
}

//! dereference the iterator; return NULL if at the end
const Face* _bfiter_dereference_Left(
        const std::vector<Face *>::const_iterator* iter )
{
    // if at the end, return NULL
    if (*iter == ($self)->endLeftBoundaryFaces() ) {
        return NULL;
    }
    // otherwise, return the face to which this iterator points
    return **iter;
}
}

So now I can do:

for f in mesh.left_boundary_faces():
    print f.area()

or, of course, anything else now that I'm using Python.

See further updates on the thin Python wrappers for C++ iterators.

21 January 2010

Reference people

A couple of days ago, a rather malformed email with the subject "Reference man....bad? should it be changed?" arrived in my inbox:

Hi,

I am and one of the cases is talking about how the nuclear clean-up sites standards should be changed from not only including the Reference Man...but other age groups as well.

Do you think this would be an effective policy to put in place? Or do you see places where they might have problems?

Thanks!

~Chrissy

I am still baffled by the first half of the first sentence, but I attempted a coherent answer nonetheless, since I have the feeling that this individual is a grade schooler asking for information for a research report. Conceivably, my answer may be of use to some other fledgeling researcher, so I'm posting it here.

Dear Chrissy,

If I understand your question correctly, you're asking if the Reference Man model is too inaccurate to continue being used. In short, the answer is no; however, there are a number of applications where its use as model would be inappropriate. In fact, in the 35 years since ICRP 23 (which defined Reference Man) was released, a number of other reference individuals have been created. According to the book for my health physics class [James E. Turner, Atoms, Radiation, and Radiation Protection, 2nd ed., John Wiley & Sons, Inc., New York, 1995, pp. 487--489], "reference data have been compiled for an adult female and for children and infants of various ages." So, actually, part of what you're asking has already been done.

Reference Man's purpose is to simulate the effect of an internal radiation dose (i.e., inhaling radioactive dust that sticks inside the lungs) on the rest of a person's body. For the most part, these estimates for effective radiation doses are very rough, accurate to perhaps on the order of ten percent. Since Reference Man is primarily used to estimate values for workmen, it would usually approximate an average worker pretty well. (Children, for example, are not often radiation cleanup workers.) For other cases where more accurate doses to particular people need to be calculated, one of the other reference models can be used.

When high precision is needed, the models used are far more detailed. As an example, consider radiation therapy for cancer, where very high doses of radiation are needed to very specific areas of a person (the cancerous parts). Cancer tissue is more susceptible to radiation than healthy tissue, but healthy parts are still damaged by large amounts of radiation. Therefore, the medical physicists need to make very accurate representations of the person, which is usually done by taking a detailed scan of them with MRI or CT scans. Then, once they have determined the proper settings that will eliminate the cancer but not the person, they do the therapy. No professional would consider using a rough model like Reference Man for a one-shot, high-precision job like that.

In summary, Reference Man is only a tool. He is a model used as a good first-order approximation to the general public. As such, it's not necessary to impose extra policies: when more precision is needed, better models are used.

I hope this answers your question satisfactorily.

Regards,
Seth Johnson

15 January 2010

ANS transaction summary example

It's "call to papers" time for the ANS transactions, and a number of hits regarding a LaTeX template for it are increasing. (For whatever reason, the ANS only provides an example file in MS Word.)  I've had a request for an example file showing how to use them; for any other interested parties, the example has now been uploaded.

12 January 2010

New design

Five years after this blog's inception, I've updated the appearance. I have too much else going on to make everything pixel-perfect, but its current state is satisfactory compared to the previous stale design.