Skip to content

Commit

Permalink
1.4.6 release
Browse files Browse the repository at this point in the history
forgot to add the feature
  • Loading branch information
pjuangph committed Oct 20, 2022
1 parent 1d1d3eb commit 3b0b451
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
40 changes: 24 additions & 16 deletions docs/build/html/_modules/glennopt/base/optimizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,15 @@ <h1>Source code for glennopt.base.optimizer</h1><div class="highlight"><pre>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="p">[</span><span class="s1">&#39;POP</span><span class="si">{0:03d}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">pop_number</span><span class="p">)]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div>

<div class="viewcode-block" id="Optimizer.to_tecplot"><a class="viewcode-back" href="../../../modules/base.html#glennopt.base.optimizer.Optimizer.to_tecplot">[docs]</a> <span class="k">def</span> <span class="nf">to_tecplot</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Converts the dataframe to a tecplot file (.tec)</span>
<div class="viewcode-block" id="Optimizer.df_to_tecplot"><a class="viewcode-back" href="../../../modules/base.html#glennopt.base.optimizer.Optimizer.df_to_tecplot">[docs]</a> <span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">df_to_tecplot</span><span class="p">(</span><span class="n">df_dict</span><span class="p">:</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span><span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">],</span><span class="n">filename</span><span class="p">:</span><span class="nb">str</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Staticmethod to convert a normal pandas dataframe to tecplot file</span>

<span class="sd"> Args:</span>
<span class="sd"> df (Dict[str,pd.DataFrame]): For example {&#39;DOE&#39;: pd.DataFrame}</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
<span class="k">return</span>
<span class="n">firstKey</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="p">))</span>
<span class="n">firstPandas</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="p">[</span><span class="n">firstKey</span><span class="p">]</span>
<span class="n">firstKey</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="nb">iter</span><span class="p">(</span><span class="n">df_dict</span><span class="p">))</span>
<span class="n">firstPandas</span> <span class="o">=</span> <span class="n">df_dict</span><span class="p">[</span><span class="n">firstKey</span><span class="p">]</span>

<span class="c1"># header</span>
<span class="n">variables</span> <span class="o">=</span> <span class="p">[]</span>
Expand All @@ -761,17 +763,15 @@ <h1>Source code for glennopt.base.optimizer</h1><div class="highlight"><pre>
<span class="n">head</span> <span class="o">=</span> <span class="s1">&#39;VARIABLES = &#39;</span> <span class="o">+</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">variables</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>

<span class="c1"># zones</span>

<span class="n">zones</span> <span class="o">=</span> <span class="p">[]</span>

<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">df</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">df</span> <span class="ow">in</span> <span class="n">df_dict</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">iterrows</span><span class="p">():</span>
<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">df_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">iterrows</span><span class="p">():</span>
<span class="n">zone_str</span> <span class="o">=</span> <span class="s1">&#39;ZONE T = </span><span class="se">\&quot;</span><span class="si">{0}</span><span class="se">\&quot;\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">key</span><span class="o">+</span><span class="s2">&quot;_&quot;</span><span class="o">+</span><span class="n">df</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="s1">&#39;individual&#39;</span><span class="p">])</span>
<span class="n">data_str</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">i</span><span class="o">+=</span><span class="mi">1</span>
<span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
<span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">df_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
<span class="k">if</span> <span class="n">col</span><span class="o">==</span><span class="s1">&#39;population&#39;</span><span class="p">:</span>
<span class="k">if</span> <span class="n">row</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;DOE&quot;</span><span class="p">:</span>
<span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span>
Expand All @@ -790,16 +790,24 @@ <h1>Source code for glennopt.base.optimizer</h1><div class="highlight"><pre>
<span class="n">zones</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

<span class="c1"># write to .tec file</span>
<span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optimization_folder</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">))):</span>
<span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optimization_folder</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">))</span>

<span class="n">db_filename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optimization_folder</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="s1">&#39;database.tec&#39;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">db_filename</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="c1"># write headers</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">head</span><span class="p">)</span>
<span class="c1"># write zones</span>
<span class="k">for</span> <span class="n">zone</span> <span class="ow">in</span> <span class="n">zones</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span></div>

<div class="viewcode-block" id="Optimizer.to_tecplot"><a class="viewcode-back" href="../../../modules/base.html#glennopt.base.optimizer.Optimizer.to_tecplot">[docs]</a> <span class="k">def</span> <span class="nf">to_tecplot</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Converts the dataframe to a tecplot file (.tec)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
<span class="k">return</span>
<span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optimization_folder</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">))):</span>
<span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optimization_folder</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">))</span>

<span class="n">filename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optimization_folder</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="s1">&#39;database.tec&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">df_to_tecplot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pandas_cache</span><span class="p">,</span><span class="n">filename</span><span class="p">)</span></div>


<div class="viewcode-block" id="Optimizer.create_restart"><a class="viewcode-back" href="../../../modules/base.html#glennopt.base.optimizer.Optimizer.create_restart">[docs]</a> <span class="k">def</span> <span class="nf">create_restart</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Create a restart file containing all individuals of all populations</span>
Expand Down
2 changes: 2 additions & 0 deletions docs/build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ <h2 id="D">D</h2>
<li><a href="modules/helpers.html#glennopt.helpers.mutate.de_rand_1_bin">de_rand_1_bin() (in module glennopt.helpers.mutate)</a>
</li>
<li><a href="modules/helpers.html#glennopt.helpers.mutate.de_rand_1_bin_spawn">de_rand_1_bin_spawn() (in module glennopt.helpers.mutate)</a>
</li>
<li><a href="modules/base.html#glennopt.base.optimizer.Optimizer.df_to_tecplot">df_to_tecplot() (glennopt.base.optimizer.Optimizer static method)</a>
</li>
<li><a href="modules/helpers.html#glennopt.helpers.population_distance.distance">distance() (in module glennopt.helpers.population_distance)</a>
</li>
Expand Down
11 changes: 11 additions & 0 deletions docs/build/html/modules/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,17 @@ <h1>GlennOPT base classes<a class="headerlink" href="#glennopt-base-classes" tit
<dd><p>Create a restart file containing all individuals of all populations</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="glennopt.base.optimizer.Optimizer.df_to_tecplot">
<em class="property"><span class="pre">static</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">df_to_tecplot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">df_dict</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Dict</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">DataFrame</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/glennopt/base/optimizer.html#Optimizer.df_to_tecplot"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#glennopt.base.optimizer.Optimizer.df_to_tecplot" title="Permalink to this definition"></a></dt>
<dd><p>Staticmethod to convert a normal pandas dataframe to tecplot file</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>df</strong> (<em>Dict</em><em>[</em><em>str</em><em>,</em><em>pd.DataFrame</em><em>]</em>) – For example {‘DOE’: pd.DataFrame}</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="glennopt.base.optimizer.Optimizer.evaluate_population">
<span class="sig-name descname"><span class="pre">evaluate_population</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">individuals</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">List</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#glennopt.base.individual.Individual" title="glennopt.base.individual.Individual"><span class="pre">Individual</span></a><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">population_number</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/glennopt/base/optimizer.html#Optimizer.evaluate_population"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#glennopt.base.optimizer.Optimizer.evaluate_population" title="Permalink to this definition"></a></dt>
Expand Down
Binary file modified docs/build/html/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "GlennOPT"
version = "1.4.5"
version = "1.4.6"
description = "Multi and single objective optimization tool for cfd/computer simulations."
authors = ["Paht Juangphanich <[email protected]>"]

Expand Down

0 comments on commit 3b0b451

Please sign in to comment.