r/CFD • • Aug 01 '18

[August] Adjoint optimization

As per the discussion topic vote, August's monthly topic is Adjoint optimization

15 Upvotes

50 comments sorted by

View all comments

Show parent comment

1

u/Rodbourn Aug 01 '18

That's more of what it does ;) I'm hoping to get a nice 'lay' description of what an 'adjoint' itself is.

8

u/Overunderrated Aug 01 '18 edited Aug 01 '18

I have it on good authority that adjoint itself is total black magic and if anyone tells you they have an intuitive understanding of it, they're lying to you and should not be trusted.

Adjoint itself is not "optimization", but rather a way to compute local gradients of an objective function with respect to design variables. The natural way to do this is to do finite difference; say you want to know how three design variables affect lift - simulate at one point, then perturb one design variable and solve it again, and again for each additional design variable, and you have a FD approximation to the local gradient.

Say your design variable is a wing, parameterized by 1000 geometric points in space defining it. Computing the local gradient is then going to take 1000 flow solutions.

Enter adjoint and why it's black magic. Say your flow solution is defined by 5 equations of NS. You can definite the adjoint operator of that, which in the functional analysis world is nothing more than a generalization of a conjugate transpose to infinite dimension / functions. Now you have 5 additional "adjoint equations" which can be solved by methods very similar to how you solve the original equations (eg FV).

By now solving these 10 equations (the flow solution and adjoint solution) you can somehow compute "exact" gradients with respect to those 1000 design variables, even an infinite number of variables. And that aspect is wildly unintuitive, and really feels like it has to be intuitively false.

You can prove it's true with pretty rudimentary functional analysis, you can see it to be true with incredible demonstrations, yet it seems impossible.

3

u/Rodbourn Aug 01 '18

Love it, but I'm trying to think of a way to explain it that doesn't require you to already understand it.

which in the functional analysis world is nothing more than a generalization of a conjugate transpose to infinite dimension / functions.

2

u/Overunderrated Aug 02 '18

Do you mean like "what is an adjoint operator?" I guess at some point you just have to rely on what the definitions and properties are - adjoint operators, and especially self-adjoint operators come up a lot in functional analysis and study of differential equations, e.g. see Sturm liouville equations, and when you get into Hilbert and Banach spaces. Can't say I ever encountered them until graduate applied math courses. Simple definition is that given a linear operator L and vectors u and v, and inner product < , >, if <Lu,v>=<u,L*v>, then L^* is defined as the adjoint of L. Not an interesting definition on its own. Some things follow obviously, like if L is a real symmetric matrix then it's self-adjoint.

I like this blurb on the wiki page,

If one thinks of operators on a complex Hilbert space as "generalized complex numbers", then the adjoint of an operator plays the role of the complex conjugate of a complex number.

So hand wavy you could think of the adjoint operator as being some kind of mirror image of the original operator. This analogy holds up in practice, if your flow equations have an inflow boundary, the adjoint equations have outflow on that boundary. If it's unsteady, the adjoint goes backward in time.

2

u/ilikeplanesandcows Aug 02 '18

lol yeah black magic you say? Anything which starts off by taking derivatives of a residual which is equal to 0 is quite innovative and dubious to say the least lol

2

u/anointed9 Aug 02 '18 edited Aug 02 '18

Well you're welcome to try to come up with an adjoint formulation which doesn't rely on 0 residual. But it's difficult.

0

u/[deleted] Aug 03 '18

[deleted] — view deleted comment

2

u/anointed9 Aug 03 '18

The residual of a boundary cell or node depending on how your scheme is centered

0

u/[deleted] Aug 03 '18

[deleted] — view deleted comment

2

u/anointed9 Aug 03 '18

I don't understand exactly what you're asking. But the adjoint is as I've said elsewhere is a green's function relating the residual operator at a converged state to an output of interest. The residual operator is essentially a measure of how unconverged your flow is and (in explicit time stepping) a gradient of how to change your state vector to obtain better convergence, which we multiply by time-steps and the like. The adjoint will tell you that if you put a vector of source terms into your residual operator how your functional will change. When we call a flow converged (or 0 residual) is in fact when a norm of the residual is at approximately machine zero. I hope this answers your question, but I didn't exactly understand what you were asking.

0

u/[deleted] Aug 03 '18

[deleted] — view deleted comment

2

u/anointed9 Aug 03 '18

Yes and no. It correspond to the residual operator, which gives you your convergence residuals. Imagine when solving your primal flow you instead of using the typical residual or flux operator you added source terms in each volume. That's what the adjoint is answering. Your adjoint also has a residual corresponding either to how well you converged the linear system (discrete adjoint) or the nonlinear system (continuous).

→ More replies

1

u/cherrytomatosalad Aug 08 '18

Optimisation is what I really want to do research on and my thesis (alongside the lab associated with it) is well known for their focus on it.

So despite trying to learn the inner working of the adjoint, I still feel like I don't know where it comes from.

Finite differences make sense. Forward mode makes sense. Reverse mode does not make sense. Cue me trying to explain it to an engineer at an interview and everyone still looking puzzled/astounded that something like this exists.

I foolishly thought that the code will offer more insight. It just made things worse, although I do know about techniques like operator overloading now so it had some worth.

Would you happen to have any resources that give a good explanation of reverse mode?

1

u/Overunderrated Aug 09 '18

Sounds like part of what you're confusing is automatic differentiation with adjoint? As far as I know, AD can be used to compute gradients but isn't itself adjoint.

1

u/dxfdwg Oct 19 '18

If you're still looking for a resource on adjoint optimization, this section of the dolfin-adjoint website is the best resource I've come across so far: dolfin-adjoint mathematical background

If you'd rather skip the parts about why adjoints are useful and the shortcomings of other ways to solve PDE-constrained optimization problems, the section that gets to the heart of how adjoints magically make the reverse mode work is this one.

5

u/Divueqzed Aug 02 '18

I performed countless adjoint projects and wrote hundreds of lines of code. Derived my own boundary conditions and coded up derivations from several papers. I still don't have a clue of what adjoint really is.