Skip to content
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

Merged
merged 9 commits into from Sep 20, 2018

Conversation

tamiko
Copy link
Member

@tamiko tamiko commented Jun 15, 2018

In reference to #6774

@tamiko tamiko mentioned this pull request Jun 15, 2018
61 tasks
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;
Copy link
Member Author

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?

Copy link
Member

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);
Copy link
Member Author

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?

Copy link
Member Author

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 =

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;
Copy link
Member

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).

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)};
Copy link
Member

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).

fe_values.shape_grad(j, q_point) //
+ //
fe_values.shape_value(i, q_point) * //
fe_values.shape_value(j, q_point)) * //
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as always

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] * //
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

1e-12))
cell->face(face_number)->set_boundary_id(1);
{
const auto &center = cell->face(face_number)->center();
Copy link
Member

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.

Copy link
Member

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?

@@ -1311,101 +1310,69 @@ int main()
{
const unsigned int dim = 2;

try
Copy link
Member

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?

@bangerth
Copy link
Member

bangerth commented Jul 5, 2018

@tamiko -- ping?

@tamiko
Copy link
Member Author

tamiko commented Jul 5, 2018 via email

@bangerth
Copy link
Member

@tamiko -- ping again?

@tamiko
Copy link
Member Author

tamiko commented Aug 31, 2018

@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?

@drwells
Copy link
Member

drwells commented Aug 31, 2018

I think we agreed to keep the status quo to make Windows happy (i.e., keep the try-catch in main).

@tamiko
Copy link
Member Author

tamiko commented Aug 31, 2018

😢 Noooooooooooooooooooooooooooooooooooooooooooooooo...

@drwells
Copy link
Member

drwells commented Aug 31, 2018

Its not the ugliest thing we have to do to maintain MSVC compatibility.

@bangerth
Copy link
Member

I'd like to keep it too, if only so we can teach some C++.

@tamiko
Copy link
Member Author

tamiko commented Sep 16, 2018

@masterleinad @bangerth This is now updated. Please have a look

@tamiko
Copy link
Member Author

tamiko commented Sep 19, 2018

@dealii/dealii ping 😺

endc =
triangulation.end();
for (; cell != endc; ++cell)
for (const auto cell : triangulation.cell_iterators())
Copy link
Member

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?

Copy link
Member Author

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 &center = ... by const auto center = ... because the right hand side returned a value not a refererence.)

Copy link
Member Author

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.

Copy link
Member

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.

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)};
Copy link
Member

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.

@tamiko
Copy link
Member Author

tamiko commented Sep 19, 2018

@masterleinad I have updated this PR

@masterleinad
Copy link
Member

masterleinad commented Sep 19, 2018

/home/bob/source/examples/step-7/step-7.cc:126:6: error: no viable conversion from 'double' to 'dealii::Point<1, double>'
    {(-1.0 / 3.0), (0.0), (+1.0 / 3.0)};

you need braces instead of the round brackets.

@tamiko
Copy link
Member Author

tamiko commented Sep 19, 2018

@masterleinad I reverted back to the explicit initializer list.

@masterleinad
Copy link
Member

Still fine with me.

@masterleinad
Copy link
Member

/run-tests

@masterleinad
Copy link
Member

/Users/cib-osx/auto-dealii-tjhei-osx/dealii/examples/step-7/step-7.cc:126:6: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
    {Point<1>(-1.0 / 3.0), Point<1>(0.0), Point<1>(+1.0 / 3.0)};
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     {                                                        }
/Users/cib-osx/auto-dealii-tjhei-osx/dealii/examples/step-7/step-7.cc:132:6: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
    {Point<2>(-0.5, +0.5), Point<2>(-0.5, -0.5), Point<2>(+0.5, -0.5)};
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     {                                                               }

@tamiko
Copy link
Member Author

tamiko commented Sep 20, 2018

@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.

@masterleinad
Copy link
Member

What exact clang version is this AppleClang again?

Should be llvm-3.9 or llvm-4.0.

@masterleinad masterleinad merged commit 4a2b8fd into dealii:master Sep 20, 2018
@masterleinad masterleinad deleted the update-step-7 branch September 20, 2018 07:55
@masterleinad masterleinad restored the update-step-7 branch September 20, 2018 07:56
@tamiko tamiko mentioned this pull request May 11, 2019
@tamiko tamiko deleted the update-step-7 branch August 7, 2019 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants