<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Thanks Christophe, I will have a look at this.</p>
<p><br>
</p>
<p>Yes I remember that at some point I saw some codes about optimization <br>
</p>
<p>in the sources of getp/gmsh/onelab (can't remember)<br>
</p>
<br>
<p>Thanks again.<br>
</p>
<p><br>
</p>
<p>Kind regards,</p>
<p><br>
</p>
<p>Ben<br>
</p>
<p><br>
</p>
<div id="x_Signature">
<div id="x_divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
---------------------------------------------------------------------------------------------------<br>
<b>Benjamin Vial</b><br>
Postdoctoral Research Assistant<br>
Antennas and Electromagnetics research group<br>
School of Electronics Engineering and Computer Science<br>
Queen Mary, University of London<br>
<a id="LPNoLP" href="http://benjaminvial.org/">http://benjaminvial.org/</a><br>
<a id="LPNoLP" href="http://antennas.eecs.qmul.ac.uk/">http://antennas.eecs.qmul.ac.uk/</a><br>
<a id="LPNoLP" href="http://www.quest-spatial-transformation.org/team/researchers/dr-benjamin-vial/">http://www.quest-spatial-transformation.org/team/researchers/dr-benjamin-vial/</a><br>
<br>
</div>
</div>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Christophe Geuzaine <cgeuzaine@ulg.ac.be><br>
<b>Sent:</b> 09 September 2016 09:33:03<br>
<b>To:</b> Benjamin Vial<br>
<b>Cc:</b> getdp@onelab.info; Erin Kuci<br>
<b>Subject:</b> Re: [Getdp] Multiple right hand side for the same stiffness matrix</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText"><br>
> On 08 Sep 2016, at 20:07, Benjamin Vial <b.vial@qmul.ac.uk> wrote:<br>
> <br>
> Dear all,<br>
> <br>
> First I would like to thank all getdp and gmsh authors/developers for such amazing pieces of software
<br>
> and to make them available open source!<br>
> <br>
> I am currently working on topology optimization problems in electromagnetism.<br>
> I'll try to keep it simple: I want to maximize square the norm of the electric field in some sub-domain Omega_target,
<br>
> by changing the permittivity value in a design sub-domain Omega_design.<br>
> I defined a formulation "helmoltz_scalar" for a 2D time-harmonic problem (xy plane), TE polarization<br>
> for the z component of the E-field, which I call u.<br>
> In matrix form :<br>
> A*u = b   (1)<br>
> where b is a known source term. <br>
> <br>
> Now gradient-based optimization algorithm needs information about the sensitivity of the
<br>
> objective function g with respect to the design variable epsilon. The most efficient way to obtain it
<br>
> is by solving an adjoint problem, namely <br>
> A*uadj = dg/du     (2)<br>
> In my case g=|u|^2 so the second member of the adjoint equation (2) is dg/du = 2*Re[u]<br>
> <br>
> Since the matrix A is the same for both problems, we do not need to assemble it twice<br>
> Is there a way to save time and generate only the right hand side for the adjoint equation?<br>
> It looks like the function GenerateRHSGroup might be useful (but it is not documented yet), together with SolveAgain.
<br>
> <br>
<br>
Indeed, these are the two functions you will need: SolveAgain will reuse the factorization (or in general the preconditioner) if it's available; and GenerateRHSGroup[A, region] will recompute the right-hand-side, and only evaluate the equation terms defined
 on "region".<br>
<br>
I'm CC:ing Erin Kuci, who is developing a Python optimization framework for ONELAB, for both shape and topology optimization.<br>
<br>
Christophe<br>
<br>
> This somehow similar to this old thread but maybe there is a more straightforward way to do it?<br>
> <a href="http://onelab.info/pipermail/getdp/2011/001383.html">http://onelab.info/pipermail/getdp/2011/001383.html</a><br>
> <br>
> <br>
> Here are the Formulation and Resolution parts of my .pro file:<br>
> <br>
> #############################################################################<br>
> Formulation{<br>
>     {Name helmoltz_scalar; Type FemEquation;<br>
>         Quantity {<br>
>         { Name u; Type Local; NameOfSpace Hgradu;}<br>
>         }   <br>
>         Equation {<br>
>         Galerkin { [k0^2*CompZZ[epsilonr[]]*Dof{u} , {u}];<br>
>         In Omega; Jacobian JVol; Integration Int_1;  }<br>
>         Galerkin { [-1/TensorDiag[CompYY[mur[]],CompXX[mur[]],CompXX[mur[]]]*Dof{Grad u} , {Grad u}];<br>
>         In Omega; Jacobian JVol; Integration Int_1; }<br>
>         Galerkin { [source[] , {u}];<br>
>         In Omega; Jacobian JVol; Integration Int_1;  }<br>
>         }<br>
>     }<br>
>     {Name adjoint_eq; Type FemEquation;<br>
>         Quantity {<br>
>         { Name u; Type Local; NameOfSpace Hgradu;}<br>
>         { Name uadj; Type Local; NameOfSpace Hgraduadj;}<br>
>         }    <br>
>         Equation {<br>
>         Galerkin { [  k0^2*CompZZ[epsilonr[]]*Dof{uadj} , {uadj}];<br>
>         In Omega; Jacobian JVol; Integration Int_1;  }<br>
>         Galerkin { [-1/TensorDiag[CompYY[mur[]],CompXX[mur[]],CompXX[mur[]]]*Dof{Grad uadj} , {Grad uadj}];<br>
>         In Omega; Jacobian JVol; Integration Int_1; }<br>
>         Galerkin { [2*Re[{u}], {uadj}];  // <br>
>         In Omega_target; Jacobian JVol; Integration Int_1;  } <br>
>         }<br>
>     }<br>
> <br>
> }<br>
> <br>
> <br>
> Resolution {<br>
>     { Name all<br>
>         System {<br>
>         { Name S; NameOfFormulation helmoltz_scalar; Type ComplexValue; Frequency Freq;}<br>
>         { Name Sadj; NameOfFormulation adjoint_eq; Type ComplexValue; Frequency Freq;}<br>
>         }<br>
>         Operation {<br>
>         Generate[S] ;Solve[S] ;SaveSolution[S] ;<br>
>         Generate[Sadj] ;Solve[Sadj] ; SaveSolution[Sadj] ;<br>
>         }<br>
>         <br>
>     }<br>
> }<br>
> <br>
> #############################################################################<br>
> <br>
> <br>
> <br>
> Thanks in advance!<br>
> <br>
> All best<br>
> <br>
> Benjamin<br>
> <br>
> <br>
> ---------------------------------------------------------------------------------------------------<br>
> Benjamin Vial<br>
> Postdoctoral Research Assistant<br>
> Antennas and Electromagnetics research group<br>
> School of Electronics Engineering and Computer Science<br>
> Queen Mary, University of London<br>
> <a href="http://benjaminvial.org/">http://benjaminvial.org/</a><br>
> <a href="http://antennas.eecs.qmul.ac.uk/">http://antennas.eecs.qmul.ac.uk/</a><br>
> <a href="http://www.quest-spatial-transformation.org/team/researchers/dr-benjamin-vial/">
http://www.quest-spatial-transformation.org/team/researchers/dr-benjamin-vial/</a><br>
> <br>
> _______________________________________________<br>
> getdp mailing list<br>
> getdp@onelab.info<br>
> <a href="http://onelab.info/mailman/listinfo/getdp">http://onelab.info/mailman/listinfo/getdp</a><br>
<br>
-- <br>
Prof. Christophe Geuzaine<br>
University of Liege, Electrical Engineering and Computer Science <br>
<a href="http://www.montefiore.ulg.ac.be/~geuzaine">http://www.montefiore.ulg.ac.be/~geuzaine</a><br>
<br>
Free software: <a href="http://gmsh.info">http://gmsh.info</a> | <a href="http://getdp.info">
http://getdp.info</a> | <a href="http://onelab.info">http://onelab.info</a><br>
<br>
</div>
</span></font>
</body>
</html>