Skip to content

Commit

Permalink
Deploying to gh-pages from @ faf691c 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
Luplz committed Aug 10, 2023
1 parent d569563 commit bccf44b
Show file tree
Hide file tree
Showing 4 changed files with 378 additions and 11 deletions.
359 changes: 359 additions & 0 deletions shapo/implementation.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Implementation in Feel++ :: Feel++ ShapO // Docs</title>
<link rel="canonical" href="https://feelpp.github.io/feelpp-shapo/shapo/implementation.html">
<meta name="description" content="Geometric Shape Optimisation implementation">
<meta name="generator" content="Antora 3.1.4">
<link rel="stylesheet" href="../_/css/site.css">
<link rel="icon" href="../_/img/favicon.ico" type="image/x-icon">
Expand Down Expand Up @@ -229,9 +230,367 @@ <h3 class="title"><a href="index.html">Feel++ ShapO</a></h3>
</aside>
<article class="doc">
<h1 class="page">Implementation in Feel++</h1>
<div id="toc" class="toc">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_json_files">1. Json files</a>
<ul class="sectlevel2">
<li><a href="#_primal_problem">1.1. Primal problem</a></li>
<li><a href="#_dual_problem">1.2. Dual problem</a></li>
<li><a href="#_postprocessing">1.3. Postprocessing</a></li>
<li><a href="#_postprocessing_of_xi_j">1.4. Postprocessing of \(\xi_J\)</a></li>
<li><a href="#_transpose_of_dg">1.5. Transpose of \(Dg\)</a></li>
<li><a href="#_expansion">1.6. Expansion</a></li>
<li><a href="#_parameters">1.7. Parameters</a></li>
</ul>
</li>
<li><a href="#_algorithm">2. Algorithm</a></li>
</ul>
</div>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>The code is based on Lucas Palazzolo&#8217;s course. For more details, see <a href="#internship_Palazzolo">[internship_Palazzolo]</a>.</p>
</div>
<div class="paragraph">
<p>The <code>shape_opti.py</code> code for solving geometric shape optimization problems relies on the Feel++ toolboxes, specifically <code>cfpdes</code>, <code>fluid</code>, and <code>solid</code>. To solve a problem of this nature, a set of JSON files is required, each serving a specific purpose in the optimization process. Here, we&#8217;ll provide an overview of these JSON files and their roles within the implementation.</p>
</div>
<div class="paragraph">
<p>The <code>Models</code> in the JSON files correspond to different toolboxes and problem types. The following is a list of the valid <code>Models</code> names:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>primal_cfpdes</code></p>
</li>
<li>
<p><code>primal_fluid</code></p>
</li>
<li>
<p><code>primal_solid</code></p>
</li>
<li>
<p><code>dual_cfpdes</code></p>
</li>
<li>
<p><code>dual_fluid</code></p>
</li>
<li>
<p><code>dual_solid</code></p>
</li>
<li>
<p><code>expansion</code></p>
</li>
<li>
<p><code>postproc</code></p>
</li>
<li>
<p><code>dgtranspose</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The choice of <code>Model</code> depends on the toolbox you are using and the specific type of optimization problem you intend to solve. Here&#8217;s an example to help illustrate how these JSON files are used:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">"Models": <i class="conum" data-value="1"></i><b>(1)</b>
{
"primal_cfpdes":<i class="conum" data-value="2"></i><b>(2)</b>
{
"equations" : ...
}
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>start section <code>Models</code> defined by the toolbox to define the main configuration and particularly the set of equations to be solved</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>toolbox keyword</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>For some json files, it will be necessary to use save fields in order to use them as parameters. To do this, fill in the "Meshes" field as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">"Meshes":
{
"expansion":
{

"Fields": <i class="conum" data-value="1"></i><b>(1)</b>
{
"primal_u" :
{
"filename":"$cfgdir/../feelppdb/shape_opti_stokes/np_1/primal_fluid.save/velocity.h5",
"basis":"Pchv2"
},
"dual_u" :
{
"filename":"$cfgdir/../feelppdb/shape_opti_stokes/np_1/dual_fluid.save/velocity.h5",
"basis":"Pchv2"
},
"DgT":
{
"filename":"$cfgdir/../feelppdb/shape_opti_stokes/np_1/Dgtranspose.save/DgT.h5",
"basis":"Pchv1"
}
}
}

}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The different fields that we want to import by specifying the path and the basis.</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_json_files"><a class="anchor" href="#_json_files"></a>1. Json files</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_primal_problem"><a class="anchor" href="#_primal_problem"></a>1.1. Primal problem</h3>
<div class="paragraph">
<p>Solves the primal problem. The json file of the primal problem must contain in the <code>Models</code> field: <code>primal_cfpdes</code>, <code>primal_fluid</code> or <code>primal_solid</code>. Don&#8217;t forget to save all fields in post-processing.</p>
</div>
</div>
<div class="sect2">
<h3 id="_dual_problem"><a class="anchor" href="#_dual_problem"></a>1.2. Dual problem</h3>
<div class="paragraph">
<p>Solves the dual problem. The json file of the dual problem must contain in the <code>Models</code> field: <code>dual_cfpdes</code>, <code>dual_fluid</code>, or <code>dual_solid</code>. Don&#8217;t forget to save all fields in post-processing.</p>
</div>
</div>
<div class="sect2">
<h3 id="_postprocessing"><a class="anchor" href="#_postprocessing"></a>1.3. Postprocessing</h3>
<div class="paragraph">
<p>Computes some data needed to compute the \(\theta\) displacement field. The json file for the associated problem must contain <code>postproc</code> in the <code>Models</code> field. Load the various fields required. In postprocessing, save the following fields:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>cost_function</code> : Cost function</p>
</li>
<li>
<p><code>volume</code> : Volume of the domain</p>
</li>
<li>
<p><code>gradient</code> : Shape gradient</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>If GD :</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>surface_movable</code> : Surface of the movable part of the domain</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>If NSGF :</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>DgDgT</code> : Computation of \(DgDg^T\).</p>
</li>
<li>
<p><code>DggradJ</code> : Computation of \(Dg\nabla J\).</p>
</li>
<li>
<p><code>norm_inf_DgT</code> : Computation of \(\|Dg^T\|\).</p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_postprocessing_of_xi_j"><a class="anchor" href="#_postprocessing_of_xi_j"></a>1.4. Postprocessing of \(\xi_J\)</h3>
<div class="paragraph">
<p>Only necessary when using the NSGF method. Computes the infinite norm of \(\xi_J\). The json file for the associated problem must contain <code>postproc</code> in the <code>Models</code> field. You need to load the various fields required. In postprocessing, save <code>norm_inf_xij</code>, which corresponds to the infinite norm of \(\xi_J\).</p>
</div>
</div>
<div class="sect2">
<h3 id="_transpose_of_dg"><a class="anchor" href="#_transpose_of_dg"></a>1.5. Transpose of \(Dg\)</h3>
<div class="paragraph">
<p>Solve the PDE to obtein the transpose of \(Dg\). The json file for the associated problem must contain <code>dgtranspose</code> in the <code>Models</code> field. In postprocessing, save all the fields.</p>
</div>
</div>
<div class="sect2">
<h3 id="_expansion"><a class="anchor" href="#_expansion"></a>1.6. Expansion</h3>
<div class="paragraph">
<p>Computes the displacement field. The json file for the expansion problem must contain <code>expansion</code> in the <code>Models</code> field. Load the various fields required. In post-processing, save the \(\|\theta\|_{H^1}\).</p>
</div>
</div>
<div class="sect2">
<h3 id="_parameters"><a class="anchor" href="#_parameters"></a>1.7. Parameters</h3>
<div class="paragraph">
<p>Contains all the information needed to solve the optimization problem. Depending on the field, certain subfields must be specified in order to refer to dedicated problems: <code>primal</code>, <code>dual</code>, <code>expansion</code>, <code>postproc</code>, <code>config</code>, <code>postprocxij</code>, <code>dgt</code>. The json must have the following form:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">{
"is_compliant" : 0, <i class="conum" data-value="1"></i><b>(1)</b>
"geometry" : "stokes/3D/sphere3D.geo", <i class="conum" data-value="2"></i><b>(2)</b>
"name" : "fluid_K11", <i class="conum" data-value="3"></i><b>(3)</b>
"required_facets" : "GammaB", <i class="conum" data-value="4"></i><b>(4)</b>
"folders" : { "folder" : "shape_opti_stokes", "primal" : "stokes/3D/fluid/primal3D_fluid.json", "dual" : "stokes/3D/fluid/dual3D_fluid.json", "expansion" : "stokes/3D/fluid/expansion3D_P1_fluid.json", "postproc" : "stokes/3D/fluid/postprocess3D_fluid.json", "config" : "stokes/stokes_lu.cfg"}, <i class="conum" data-value="5"></i><b>(5)</b>
"h" : 0.2, <i class="conum" data-value="6"></i><b>(6)</b>
"dim" : 3, <i class="conum" data-value="7"></i><b>(7)</b>
"opti_type" : "GD", <i class="conum" data-value="8"></i><b>(8)</b>
"type" : {"primal" : "fluid", "dual" : "fluid", "expansion" : "cfpdes", "postproc" : "cfpdes"}, <i class="conum" data-value="9"></i><b>(9)</b>
"param_primal" : {"Mu": 1, "U_1": 1, "U_1x" : 0, "U_1y" : 0, "U_1z" : 0, "U_2": 0 , "U_2x" : 0, "U_2y" : 0, "U_2z" : 0, "U_3" : 0, "U_3x" : 0, "U_3y" : 0, "U_3z" : 0, "Uinf_1": 0, "Uinf_2": 0, "Uinf_3" : 0}, <i class="conum" data-value="10"></i><b>(10)</b>
"param_dual" : {"Mu":1, "alpha_1": 1, "alpha_1x" : 0, "alpha_1y" : 0, "alpha_1z" : 0, "alpha_2": 0, "alpha_2x" : 0, "alpha_2y" : 0, "alpha_2z" : 0, "alpha_3" : 0, "alpha_3x" : 0, "alpha_3y" : 0, "alpha_3z" : 0}, <i class="conum" data-value="11"></i><b>(11)</b>
"param_expansion" : {"Mu":1, "t":0.03, "l":20}, <i class="conum" data-value="12"></i><b>(12)</b>
"param_postproc" : {"Mu" : 1, "alpha_1": 1, "alpha_1x" : 0, "alpha_1y" : 0, "alpha_1z" : 0, "alpha_2": 0, "alpha_2x" : 0, "alpha_2y" : 0, "alpha_2z" : 0, "alpha_3" : 0, "alpha_3x" : 0, "alpha_3y" : 0, "alpha_3z" : 0}, <i class="conum" data-value="13"></i><b>(13)</b>
"param_dgt" : {"Eps" : }, <i class="conum" data-value="14"></i><b>(14)</b>
"param_optimization" : {"l":20, "t":0.03, "a":0.05, "b":0.5, "c" : 1000, "Nmax" : 1000, "etol" : 1e-7} <i class="conum" data-value="15"></i><b>(15)</b>
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>0</code> if no dual problem, <code>1</code> otherwise</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>path of the initial mesh file</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>name of the study case</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>faced of the mesh that we don&#8217;t want to remesh</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td>path of the folder where the various data are/will be stored and path of json files</td>
</tr>
<tr>
<td><i class="conum" data-value="6"></i><b>6</b></td>
<td>mesh size</td>
</tr>
<tr>
<td><i class="conum" data-value="7"></i><b>7</b></td>
<td>dimension of the problem</td>
</tr>
<tr>
<td><i class="conum" data-value="8"></i><b>8</b></td>
<td>type of optimization : gradient descent <code>GD</code> or null space gradient flow <code>NSGF</code></td>
</tr>
<tr>
<td><i class="conum" data-value="9"></i><b>9</b></td>
<td>type of tooloboxes used for the json files : <code>cfpdes</code>, <code>fluid</code>, <code>solid</code></td>
</tr>
<tr>
<td><i class="conum" data-value="10"></i><b>10</b></td>
<td>parameters of the primal json</td>
</tr>
<tr>
<td><i class="conum" data-value="11"></i><b>11</b></td>
<td>parameters of the dual json</td>
</tr>
<tr>
<td><i class="conum" data-value="12"></i><b>12</b></td>
<td>parameters of the expansion json</td>
</tr>
<tr>
<td><i class="conum" data-value="13"></i><b>13</b></td>
<td>parameters of the postproc json</td>
</tr>
<tr>
<td><i class="conum" data-value="14"></i><b>14</b></td>
<td>parameters of the dgt jon</td>
</tr>
<tr>
<td><i class="conum" data-value="15"></i><b>15</b></td>
<td>parameters of the optimization problem : <code>Nmax</code>, <code>etol</code>. Specifically for the gradient descent we have to add : <code>l</code>, <code>t</code>, <code>a</code>, <code>b</code>, <code>c</code>.</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_algorithm"><a class="anchor" href="#_algorithm"></a>2. Algorithm</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Now that the data needed to solve a shape optimization problem has been described, let&#8217;s present the main points of the algorithm.</p>
</div>
<pre id="shapeopti" style="display:hidden;">
\begin{algorithm}
\caption{Geometric shape optimisation algorithm}
\hspace*{\algorithmicindent} \textbf{Input :} Parameters json file \\
\hspace*{\algorithmicindent} \textbf{Output :} Csv and paraview files for each iteration
\begin{algorithmic}
\FUNCTION{ShapeOpti}{}


\STATE \textbf{Initialization:}
\STATE $n=0$.
\STATE - Reading the json file containing the parameters.
\STATE - Solve the primal problem.
\STATE - Solve the dual problem.
\STATE - Solve the postprocessing problem.

\IF {NSGF}
\STATE - Solve the postprocessing of $\xi_J$ problem.
\STATE - Solve the $Dg^T$ problem.
\ENDIF

\STATE - Solve the expansion problem : $\theta_n$.

\WHILE{$\|\theta_n\|_{H^1}>\varepsilon_{tol}$ AND $n<N_{max}$}

\STATE - Deforming the mesh by applying $\theta_n$.

\IF {mesh quality $< q$}
\STATE - Remesh.
\ENDIF

\STATE - Solve the primal problem.
\STATE - Solve the dual problem.
\STATE - Solve the postprocessing problem.

\IF {NSGF}
\STATE - Solve the postprocessing of $\xi_J$ problem.
\STATE - Solve the $Dg^T$ problem.
\ENDIF

\STATE - Solve the expansion problem : $\theta_n$.

\STATE $n=n+1$.
\STATE - Save the results.


\ENDWHILE
\ENDFUNCTION
\end{algorithmic}
\end{algorithm}
</pre>
<div class="paragraph">
<p>For reasons of visibility, certain points have been omitted, such as the calculation of the Lagrange multiplier in the case of gradient descent, or certain coefficients in the case of null space gradient flow. The various results obtained are saved after each iteration in a csv file for all cost, volume and \(H^1\)-norm functions, etc. For fields and meshes, paraview files are also exported after each iteration.</p>
</div>
</div>
</div>
</article>
</div>
</main>
Expand Down
Loading

0 comments on commit bccf44b

Please sign in to comment.