Skip to content

Commit

Permalink
Add option to silence exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cbritopacheco committed Aug 9, 2023
1 parent 025e5f6 commit 94d8a12
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 49 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ option(RODIN_USE_SPQR "Use Rodin with SPQR support"
option(RODIN_USE_PARDISO "Use Rodin with Pardiso support" OFF)
option(RODIN_USE_APPLE_ACCELERATE "Use Rodin with Apple Accelerate support" OFF)
option(RODIN_SILENCE_WARNINGS "Silence warnings outputted by Rodin" OFF)
option(RODIN_SILENCE_EXCEPTIONS "Silence exceptions thrown by Rodin" ON)
option(RODIN_CODE_COVERAGE "Compile with code coverage flags" OFF)
option(RODIN_LTO "Compile with link time optimization" OFF)
option(RODIN_FEATURE_SUMMARY "Print Rodin feature summary" ON)
Expand Down
85 changes: 47 additions & 38 deletions examples/Misc/RS2023/L2_Grid_Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
plt.style.use("bmh")

conductivities = [2.0]
waveNumbers = range(1, 100)
waveNumbers = [ 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 80, 90 ]
angles = [ 0 ]


x_column = 'm'
y_column = 'epsilon'

latex_label = {
'm' : '$m$',
'epsilon' : '$\epsilon$',
'waveNumber' : '$k$'
'waveNumber' : '$k$',
'angle': '$\theta$'
}

file_label = {
'm' : 'Period',
'epsilon' : 'Epsilon',
'waveNumber' : 'Wavenumber'
'waveNumber' : 'Wavenumber',
'angle' : 'Angle',
}

if __name__ == '__main__':
Expand All @@ -34,45 +38,50 @@
df = pd.read_csv(args.filename)
print('Read dataset !')

for waveNumber in waveNumbers:
for conductivity in conductivities:
plt.figure()
print('Processing ', waveNumber)
sdf = df[
(df['conductivity'] > conductivity - 0.001) &
(df['conductivity'] < conductivity + 0.001) &
(df['waveNumber'] > waveNumber - 0.001) &
(df['waveNumber'] < waveNumber + 0.001)
]
for angle in angles:
for waveNumber in waveNumbers:
for conductivity in conductivities:
plt.figure()
print('Processing ', waveNumber)
sdf = df[
(df['conductivity'] > conductivity - 0.001) &
(df['conductivity'] < conductivity + 0.001) &
(df['waveNumber'] > waveNumber - 0.001) &
(df['waveNumber'] < waveNumber + 0.001) &
(df['angle'] > angle - 0.001) &
(df['angle'] < angle + 0.001)
]

thresh = sdf['error'].median()
sdf.loc[sdf['error'] > thresh, 'error'] = thresh
# thresh = sdf['error'].median()
# sdf.loc[sdf['error'] > thresh, 'error'] = thresh

plt.hexbin(
sdf.loc[:, x_column],
sdf.loc[:, y_column],
gridsize=45,
reduce_C_function=np.mean,
cmap='inferno',
C=sdf.loc[:, 'error'], edgecolors='face', linewidths=0.5)
plt.hexbin(
sdf.loc[:, x_column],
sdf.loc[:, y_column],
gridsize=45,
reduce_C_function=np.mean,
cmap='inferno',
C=sdf.loc[:, 'error'], edgecolors='face', linewidths=0.5)

# plt.contourf(
# sdf.loc[:, 'm'],
# sdf.loc[:, 'epsilon'],
# sdf.loc[:, 'error'])
plt.colorbar()
# plt.contourf(
# sdf.loc[:, 'm'],
# sdf.loc[:, 'epsilon'],
# sdf.loc[:, 'error'])
plt.colorbar()

plt.xlabel(latex_label[x_column])
plt.ylabel(latex_label[y_column])
plt.title(
'$|| u_\epsilon - u_0 ||_{L^2 (Q)} \
\ \mathrm{with} \ \gamma |_{B(x, e)} = %.2E$, k = %.2E' % (conductivity, waveNumber),
pad=20)
out=("%s_VS_%s_Gamma=%.2E_k=%.2E") % (
file_label[x_column], file_label[y_column], conductivity, waveNumber)
plt.savefig(out + '.svg')
plt.savefig(out + '.png')
# plt.show()
plt.xlabel(latex_label[x_column])
plt.ylabel(latex_label[y_column])
plt.title(
'$|| u_\epsilon - u_0 ||_{L^2 (Q)} \
\ \mathrm{with} \ \gamma |_{B(x, e)} = %.2E, \ k = %.2E, \
\ \\theta = %d^\circ $' % (conductivity, waveNumber, (180.0 / math.pi) * angle),
pad=20)
out=("%s_VS_%s_Gamma=%.2E_Wavenumber=%.2E_Angle=%.2E") % (
file_label[x_column], file_label[y_column], conductivity,
waveNumber, (180.0 / math.pi) * angle)
plt.savefig(out + '.svg')
plt.savefig(out + '.png')
# plt.show()



2 changes: 1 addition & 1 deletion src/Rodin/Alert/Alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Rodin::Alert
{
template <
class U,
class = decltype(std::declval<std::stringstream&>() << std::declval<const U&>())>
class = decltype(std::declval<std::ostream&>() << std::declval<const U&>())>
static std::true_type test(U*);

template <typename>
Expand Down
16 changes: 10 additions & 6 deletions src/Rodin/Alert/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* https://www.boost.org/LICENSE_1_0.txt)
*/
#include <iostream>

#include <rang.hpp>

#include "Rodin/Configure.h"

#include "Exception.h"

namespace Rodin::Alert
Expand All @@ -18,11 +19,14 @@ namespace Rodin::Alert

void Exception::raise() const
{
// std::cerr << rang::fg::red
// << "Error: "
// << rang::fg::reset
// << what()
// << std::endl;
#ifdef RODIN_SILENCE_EXCEPTIONS
#else
std::cerr << rang::fg::red
<< RODIN_ALERT_WARNING_PREFIX
<< rang::fg::reset
<< what()
<< std::endl;
#endif
throw *this;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Rodin/Alert/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#ifndef RODIN_ALERT_EXCEPTION_H
#define RODIN_ALERT_EXCEPTION_H

#define RODIN_ALERT_EXCEPTION_PREFIX "Error: "
#define RODIN_ALERT_EXCEPTION_PREFIX_LENGTH (sizeof(RODIN_ALERT_WARNING_PREFIX) - 1)

#include <exception>

#include "Alert.h"
Expand Down
8 changes: 4 additions & 4 deletions src/Rodin/Alert/Warning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ namespace Rodin::Alert
#ifdef RODIN_SILENCE_WARNINGS
#else
std::cerr << rang::fg::yellow
<< RODIN_ALERT_WARNING_PREFIX
<< rang::fg::reset
<< what()
<< std::endl;
<< RODIN_ALERT_WARNING_PREFIX
<< rang::fg::reset
<< what()
<< std::endl;
#endif
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/Rodin/Configure.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
*/
#cmakedefine RODIN_SILENCE_WARNINGS

/**
* @ingroup RodinDirectives
* @brief Indicates if Rodin exceptions are silenced.
*
* If defined, this directive will prevent Rodin from outputting the error
* messages. It does not prevent the exception from being thrown.
*/
#cmakedefine RODIN_SILENCE_EXCEPTIONS

/**
* @ingroup RodinDirectives
* @brief Indicates the Rodin resources directory.
Expand Down

0 comments on commit 94d8a12

Please sign in to comment.