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
example/step-7: Update indenting and modernize #6781
Conversation
examples/step-7/step-7.cc
Outdated
static const double width; | ||
static const unsigned int n_source_centers = 3; | ||
static const std::array<Point<dim>, n_source_centers> source_centers; | ||
static const double width; |
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.
Question: Shall we switch to std::array
here?
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.
I am in favor, but we have to explain why we can. In particular, we should use constexpr
then.
const auto center = cell->face(face_number)->center(); | ||
if ((std::fabs(center(0) - (-1)) < 1e-12) || | ||
(std::fabs(center(1) - (-1)) < 1e-12)) | ||
cell->face(face_number)->set_boundary_id(1); |
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.
Question: I like this idom of creating a const auto & ... = ...
because it creates easily readable code. Shall we keep this version?
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.
Updated to const auto center =
examples/step-7/step-7.cc
Outdated
static const Point<dim> source_centers[n_source_centers]; | ||
static const double width; | ||
static const unsigned int n_source_centers = 3; | ||
static const std::array<Point<dim>, n_source_centers> source_centers; |
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 might as well do std::array<Point<dim>,3>
here, initialize it with three elements, and later on when you need to query the size do source_centers.size()
(or just a range-based for loop over the elements of the array).
examples/step-7/step-7.cc
Outdated
const std::array<Point<1>, SolutionBase<1>::n_source_centers> | ||
SolutionBase<1>::source_centers = {Point<1>(-1.0 / 3.0), | ||
Point<1>(0.0), | ||
Point<1>(+1.0 / 3.0)}; |
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.
Could probably just brace initialize things here, unless of course you want to be explicit (which I never mind).
examples/step-7/step-7.cc
Outdated
fe_values.shape_grad(j, q_point) // | ||
+ // | ||
fe_values.shape_value(i, q_point) * // | ||
fe_values.shape_value(j, q_point)) * // |
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.
same as always
examples/step-7/step-7.cc
Outdated
cell_rhs(i) += (fe_values.shape_value(i, q_point) * | ||
rhs_values[q_point] * fe_values.JxW(q_point)); | ||
cell_rhs(i) += (fe_values.shape_value(i, q_point) * // | ||
rhs_values[q_point] * // |
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.
and here
examples/step-7/step-7.cc
Outdated
fe_face_values.JxW(q_point)); | ||
cell_rhs(i) += (neumann_value * // | ||
fe_face_values.shape_value(i, q_point) * // | ||
fe_face_values.JxW(q_point)); |
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.
and here
examples/step-7/step-7.cc
Outdated
1e-12)) | ||
cell->face(face_number)->set_boundary_id(1); | ||
{ | ||
const auto ¢er = cell->face(face_number)->center(); |
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.
no auto
reference here -- center()
returns an object, not a reference.
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.
also, maybe call it face_center
?
examples/step-7/step-7.cc
Outdated
@@ -1311,101 +1310,69 @@ int main() | |||
{ | |||
const unsigned int dim = 2; | |||
|
|||
try |
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.
I think we concluded to leave these in for the moment?
@tamiko -- ping? |
@tamiko -- ping?
*pong* Will update this PR later this week (addressing your comments) :-)
|
@tamiko -- ping again? |
@bangerth pong OK - Finally enough time to work on this again. @masterleinad, @bangerth, @drwells What is the latest consensus on the try-catch clause in main? |
I think we agreed to keep the status quo to make Windows happy (i.e., keep the try-catch in |
😢 Noooooooooooooooooooooooooooooooooooooooooooooooo... |
Its not the ugliest thing we have to do to maintain MSVC compatibility. |
I'd like to keep it too, if only so we can teach some C++. |
81900a5
to
ea2f681
Compare
@masterleinad @bangerth This is now updated. Please have a look |
@dealii/dealii ping 😺 |
examples/step-7/step-7.cc
Outdated
endc = | ||
triangulation.end(); | ||
for (; cell != endc; ++cell) | ||
for (const auto cell : triangulation.cell_iterators()) |
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.
Would you mind using const auto& cell
here?
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.
Well "cell" is an iterator and cell_iterators
and related return an iterator range. So using auto &cell
, or auto cell
doesn't make a difference here. I don't mind changing it to const auto &cell
but I guess @bangerth has some strong opinions on that matter. (He asked me to replace a const auto ¢er = ...
by const auto center = ...
because the right hand side returned a value not a refererence.)
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.
I see that we used const auto &cell
everywhere in the examples. So let me unify it.
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.
Yes, I really don't have much of an opinion in this context.
examples/step-7/step-7.cc
Outdated
SolutionBase<2>::source_centers[SolutionBase<2>::n_source_centers] = | ||
{Point<2>(-0.5, +0.5), Point<2>(-0.5, -0.5), Point<2>(+0.5, -0.5)}; | ||
const std::array<Point<2>, 3> SolutionBase<2>::source_centers = | ||
{Point<2>(-0.5, +0.5), Point<2>(-0.5, -0.5), Point<2>(+0.5, -0.5)}; |
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.
At other places, we usually omit Point<dim>
here, but I don't have a strong opinion about this.
b823699
to
ebfba63
Compare
@masterleinad I have updated this PR |
you need braces instead of the round brackets. |
ebfba63
to
286f4e9
Compare
@masterleinad I reverted back to the explicit initializer list. |
Still fine with me. |
/run-tests |
|
@masterleinad sigh What exact clang version is this AppleClang again? I do not get a warning with gcc-8, or clang-6. Anyway, double braces it is. |
Should be |
In reference to #6774