-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from WISDEM/dev
Dev
- Loading branch information
Showing
9 changed files
with
1,121 additions
and
681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,4 +129,8 @@ dmypy.json | |
.pyre/ | ||
*.csv | ||
*.fem | ||
*.ans | ||
*.ans | ||
|
||
# Outputs | ||
*.xlsx | ||
*.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.