Skip to content

Commit

Permalink
Merge pull request #3 from WISDEM/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ptrbortolotti authored Apr 7, 2022
2 parents e35e980 + 6f9c944 commit 6c5bc18
Show file tree
Hide file tree
Showing 9 changed files with 1,121 additions and 681 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,8 @@ dmypy.json
.pyre/
*.csv
*.fem
*.ans
*.ans

# Outputs
*.xlsx
*.sql
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ To run the code, follow these steps
2. In an anaconda environment, type

pip install pyfemm
conda install openmdao
conda install openmdao

The technical support of David Meeker, Ph.D., author of the Femm library is gratefully acknowledged
79 changes: 79 additions & 0 deletions examples/convergence_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import openmdao.api as om
import os
import matplotlib.pyplot as plt


class Convergence_Trends_Opt(om.ExplicitComponent):
"""
Deprecating this for now and using OptView from PyOptSparse instead.
"""

def initialize(self):

self.options.declare("opt_options")

def compute(self, inputs, outputs):

folder_output = self.options["opt_options"]["general"]["folder_output"]
print("Figures saved here: ", folder_output)
optimization_log = os.path.join(folder_output, self.options["opt_options"]["recorder"]["file_name"])

if os.path.exists(optimization_log):
cr = om.CaseReader(optimization_log)
cases = cr.get_cases()
rec_data = {}
design_vars = {}
responses = {}
iterations = []
for i, it_data in enumerate(cases):
iterations.append(i)

# Collect DVs and responses separately for DOE
for design_var in [it_data.get_design_vars()]:
for dv in design_var:
if i == 0:
design_vars[dv] = []
design_vars[dv].append(design_var[dv])

for response in [it_data.get_responses()]:
for resp in response:
if i == 0:
responses[resp] = []
responses[resp].append(response[resp])

# parameters = it_data.get_responses()
for parameters in [it_data.get_responses(), it_data.get_design_vars()]:
for j, param in enumerate(parameters.keys()):
if i == 0:
rec_data[param] = []
rec_data[param].append(parameters[param])

for param in rec_data.keys():
fig, ax = plt.subplots(1, 1, figsize=(5.3, 4))
ax.plot(iterations, rec_data[param])
ax.set(xlabel="Number of Iterations", ylabel=param)
fig_name = "Convergence_trend_" + param + ".png"
fig.savefig(os.path.join(folder_output, fig_name))
plt.close(fig)


class PlotRecorder(om.Group):
def initialize(self):
self.options.declare("opt_options")

def setup(self):
self.add_subsystem("conv_plots", Convergence_Trends_Opt(opt_options=self.options["opt_options"]))


mydir = os.path.dirname(os.path.realpath(__file__)) # get path to this file
output_folder_name = "test5"

opt_options = {}
opt_options["general"] = {}
opt_options["general"]["folder_output"] = os.path.join(mydir, "outputs", output_folder_name)
opt_options["recorder"] = {}
opt_options["recorder"]["file_name"] = "log.sql"

wt_opt = om.Problem(model=PlotRecorder(opt_options=opt_options))
wt_opt.setup(derivatives=False)
wt_opt.run_model()
Loading

0 comments on commit 6c5bc18

Please sign in to comment.