-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix gradient in turbine example #38
Merged
Merged
Changes from 14 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
657e3b0
Clearer notation
jwallwork23 00b8d04
Label files with target under hessian-based approach
jwallwork23 96d6317
Label files with target under go approach
jwallwork23 068a7c5
Update and extend plotting for turbine case
jwallwork23 1281024
Setup tweaks
jwallwork23 8c55c2b
Outputs in debug mode
jwallwork23 2a05cf8
Add debug mode with Taylor test in turbine case
jwallwork23 d744a5d
Fix QoI expression to pass Taylor test
jwallwork23 b1d5f19
Use R-space rather than Constant
jwallwork23 3eec2ea
Notation tweak
jwallwork23 aea568a
Revise and extend QoI plotting
jwallwork23 bfe6e94
Don't use debug mode for Hessian-based
jwallwork23 c7a85af
Rename plot_qoi as plot_results
jwallwork23 915c882
Don't use .dat.data
jwallwork23 ac34caf
Function's val kwarg doesn't accept R-space Functions
jwallwork23 df4692e
Make use of Thetis' domain_constant
jwallwork23 7ab0657
Report when files can't be loaded
jwallwork23 75cb7e8
Drop unneccessary annotation
jwallwork23 a4f7dcf
Update plot recipe in Makefile
jwallwork23 2cfb6e7
Ensure both parts of cost function are negative
jwallwork23 eae8181
Convert turbine example to use discrete turbines
jwallwork23 3d107de
Attempt at scaling problem
jwallwork23 056ebbc
Raise error if lr goes to NaN
jwallwork23 3a9a318
Revisions to setup
jwallwork23 baf7fcc
Start optimisation at m=260
jwallwork23 95ed2d2
Fix regularisation term
jwallwork23 83683e1
Reset lr if BB formula gives negative or nan
jwallwork23 8ed8917
NaN-out invalid controls and powers; add warnings when doing so
jwallwork23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 was deleted.
Oops, something went wrong.
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,63 @@ | ||
import glob | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from thetis import create_directory | ||
|
||
create_directory("plots") | ||
|
||
data_dict = { | ||
"uniform": { | ||
"label": "Uniform meshing", | ||
}, | ||
"hessian": { | ||
"label": "Hessian-based", | ||
}, | ||
# "go": { | ||
# "label": "Goal-oriented", | ||
# }, | ||
} | ||
|
||
# Load data from files | ||
variables = ("nc", "J", "t", "m") | ||
for method, data in data_dict.items(): | ||
for variable in variables: | ||
data[variable] = [] | ||
for fname in glob.glob(f"data/{method}_*.log"): | ||
ext = "_".join(fname.split("_")[1:])[:-4] | ||
for variable in variables: | ||
try: | ||
value = np.load(f"data/{method}_progress_{variable}_{ext}.npy")[-1] | ||
except (FileNotFoundError, IndexError): | ||
continue | ||
if variable == "J": | ||
data[variable].append(-value / 1000) | ||
else: | ||
data[variable].append(value) | ||
|
||
metadata = { | ||
"J": {"label": "qoi", "name": r"Power output ($\mathrm{kW}$)"}, | ||
"nc": {"label": "elements", "name": "Number of mesh elements"}, | ||
"t": {"label": "time", "name": r"CPU time ($\mathrm{s}$)"}, | ||
"m": {"label": "control", "name": r"Control ($\mathrm{m}$)"}, | ||
} | ||
|
||
|
||
def plot(v1, v2): | ||
fig, axes = plt.subplots(figsize=(5, 3)) | ||
for data in data_dict.values(): | ||
axes.semilogx(data[v1], data[v2], "x", label=data["label"]) | ||
axes.set_xlabel(metadata[v1]["name"]) | ||
axes.set_ylabel(metadata[v2]["name"]) | ||
axes.grid(True, which="both") | ||
axes.legend() | ||
plt.tight_layout() | ||
fname = f"converged_{metadata[v2]['label']}_vs_{metadata[v1]['label']}" | ||
for ext in ("pdf", "jpg"): | ||
plt.savefig(f"plots/{fname}.{ext}") | ||
|
||
|
||
plot("nc", "J") | ||
plot("t", "J") | ||
plot("nc", "m") | ||
plot("t", "m") |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have changed all the other
Constant
terms to be in terms ofR space
except here and line 157. Just flagging with a comment in case this was unintentional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out. I've updated it to use Thetis' new
domain_constant
in df4692e.