From: Adam C Powell IV <hazelsct@de...>  20080815 21:20:44

On Fri, 20080815 at 15:30 0500, Roy Stogner wrote: > On Fri, 15 Aug 2008, Adam C Powell IV wrote: > > > I'd like to calculate the integral of (grad u)^2 over my domain, after a > > calculation. > > > > Currently, I assign two new variables, and set up new equations for > > them: Jxdu/dx=0, Jydu/dy=0. Then I just square and add the results of > > calculate_norm (Jx and Jy, L2). It seems to work. But this adds two > > extra field variables and equations to the calculation, multiplying the > > memory usage and slowing things down a good bit. > > > > Alternatively, is it possible to calculate the L2 norm of the field > > derivative or gradient directly, through a method I've missed? > > Well, for future reference in general: it's possible to calculate the > L2 norm of the arctangent cubed of the field gradient directly, if > that's what you want. And what norm is that??? Oh, reading on... > Just loop over all the elements the same way > you would for a residual assembly, calculate whatever function you > need at each quadrature point, and sum the weighted values to > numerically integrate the result. Ah, makes sense. That would do the second separatethederivatives calculation thing. Silly that I didn't think of such a simple loop... > Helper methods like > calculate_norm() are intended to simplify common code, not to be a > straitjacket if you need to do something out of the ordinary. > > Hmm... I didn't mean that last paragraph to sound condescending, but > did it anyway? Apparently karma thinks I deserve to be embarrassed > now. Well, I deserve to be embarrassed for not simply writing a loop. > You see, the next thing I was going to say is that you can (in > the SVN and soon 0.6.3+ libMesh versions) just pass H1_SEMINORM to > calculate_norm() to get the square root of the integral of the > gradient squared, and then square that to get the number you want... Excellent. Somehow I figured that someone might have needed that common variation, and coded it, or part of it. :) > but glancing at the calculate_norm() implementation, I see I never > finished adding that feature; the code currently would give you an > inaccurate result. I'll go fix that now. Thank you! I'll see if I can easily add that patch to my (soontobe) 0.6.3 Debian/Ubuntu package. > > Or if there's nothing quite that convenient, is there a way of > > calculating the derivatives and putting them into a separate vector > > in the system, decoupled from the original calculation? > > All variables in a system are coupled by definition; if you really > needed to keep some postprocessed data around, the way to do it > efficiently would be to add an additional ExplicitSystem to your > EquationSystems object, then put the decoupled variables there. I see, not just another vector but a whole ExplicitSystem. I'll have other uses for that... Thanks again, Adam  GPG fingerprint: D54D 1AEE B11C CE9B A02B C5DD 526F 01E8 564E E4B6 Engineering consulting with open source tools http://www.opennovation.com/ 