Skip to content

Commit

Permalink
Increase precision of convergence rate
Browse files Browse the repository at this point in the history
  • Loading branch information
cbegeman committed Jan 6, 2025
1 parent 5a60c8c commit 128a44c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions polaris/ocean/convergence/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def plot_convergence(self, variable_name, title, zidx):
convergence_failed = False
poly = np.polyfit(np.log10(refinement_array), np.log10(error_array), 1)
convergence = poly[0]
conv_round = np.round(convergence, 3)
conv_round = convergence

fit = refinement_array ** poly[0] * 10 ** poly[1]

Expand All @@ -239,7 +239,7 @@ def plot_convergence(self, variable_name, title, zidx):
ax.loglog(resolutions, order2, 'k', label='second order',
alpha=0.3)
ax.loglog(refinement_array, fit, 'k',
label=f'linear fit (order={conv_round})')
label=f'linear fit (order={convergence:1.3f})')
ax.loglog(refinement_array, error_array, 'o', label='numerical')

if self.baseline_dir is not None:
Expand All @@ -255,14 +255,14 @@ def plot_convergence(self, variable_name, title, zidx):
poly = np.polyfit(
np.log10(refinement_array), np.log10(error_array), 1)
base_convergence = poly[0]
conv_round = np.round(base_convergence, 3)
conv_round = base_convergence

fit = refinement_array ** poly[0] * 10 ** poly[1]
ax.loglog(refinement_array, error_array, 'o',
color='#ff7f0e', label='baseline')
ax.loglog(refinement_array, fit, color='#ff7f0e',
label=f'linear fit, baseline '
f'(order={conv_round})')
f'(order={base_convergence:1.3f})')
ax.set_xlabel(x_label)
ax.set_ylabel(f'{error_title}')
ax.set_title(f'Error Convergence of {title}')
Expand All @@ -273,11 +273,11 @@ def plot_convergence(self, variable_name, title, zidx):
plt.close()

logger.info(f'Order of convergence for {title}: '
f'{conv_round}')
f'{conv_round:1.3f}')

if conv_round < conv_thresh:
logger.error(f'Error: order of convergence for {title}\n'
f' {conv_round} < min tolerance '
f' {conv_round:1.3f} < min tolerance '
f'{conv_thresh}')
convergence_failed = True

Expand Down

0 comments on commit 128a44c

Please sign in to comment.