Skip to content

Commit

Permalink
Merge pull request #16488 from bangerth/point-parens
Browse files Browse the repository at this point in the history
Use p[index] instead of p(index) for class Point.
  • Loading branch information
blaisb committed Jan 18, 2024
2 parents 08160c0 + cbd918f commit 9c9a7d9
Show file tree
Hide file tree
Showing 81 changed files with 1,321 additions and 1,322 deletions.
2 changes: 1 addition & 1 deletion examples/step-12/step-12.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace Step12

for (unsigned int i = 0; i < values.size(); ++i)
{
if (points[i](0) < 0.5)
if (points[i][0] < 0.5)
values[i] = 1.;
else
values[i] = 0.;
Expand Down
2 changes: 1 addition & 1 deletion examples/step-12b/step-12b.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace Step12

for (unsigned int i = 0; i < values.size(); ++i)
{
if (points[i](0) < 0.5)
if (points[i][0] < 0.5)
values[i] = 1.;
else
values[i] = 0.;
Expand Down
20 changes: 10 additions & 10 deletions examples/step-13/step-13.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1224,9 +1224,9 @@ namespace Step13
{
(void)component;
AssertIndexRange(component, 1);
double q = p(0);
double q = p[0];
for (unsigned int i = 1; i < dim; ++i)
q += std::sin(10 * p(i) + 5 * p(0) * p(0));
q += std::sin(10 * p[i] + 5 * p[0] * p[0]);
const double exponential = std::exp(q);
return exponential;
}
Expand All @@ -1248,19 +1248,19 @@ namespace Step13
{
(void)component;
AssertIndexRange(component, 1);
double q = p(0);
double q = p[0];
for (unsigned int i = 1; i < dim; ++i)
q += std::sin(10 * p(i) + 5 * p(0) * p(0));
q += std::sin(10 * p[i] + 5 * p[0] * p[0]);
const double u = std::exp(q);
double t1 = 1, t2 = 0, t3 = 0;
for (unsigned int i = 1; i < dim; ++i)
{
t1 += std::cos(10 * p(i) + 5 * p(0) * p(0)) * 10 * p(0);
t2 += 10 * std::cos(10 * p(i) + 5 * p(0) * p(0)) -
100 * std::sin(10 * p(i) + 5 * p(0) * p(0)) * p(0) * p(0);
t3 += 100 * std::cos(10 * p(i) + 5 * p(0) * p(0)) *
std::cos(10 * p(i) + 5 * p(0) * p(0)) -
100 * std::sin(10 * p(i) + 5 * p(0) * p(0));
t1 += std::cos(10 * p[i] + 5 * p[0] * p[0]) * 10 * p[0];
t2 += 10 * std::cos(10 * p[i] + 5 * p[0] * p[0]) -
100 * std::sin(10 * p[i] + 5 * p[0] * p[0]) * p[0] * p[0];
t3 += 100 * std::cos(10 * p[i] + 5 * p[0] * p[0]) *
std::cos(10 * p[i] + 5 * p[0] * p[0]) -
100 * std::sin(10 * p[i] + 5 * p[0] * p[0]);
};
t1 = t1 * t1;

Expand Down
2 changes: 1 addition & 1 deletion examples/step-16b/step-16b.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace Step16
MeshWorker::IntegrationInfo<dim> &info) const
{
AssertDimension(dinfo.n_matrices(), 1);
const double coefficient = (dinfo.cell->center()(0) > 0.) ? .1 : 1.;
const double coefficient = (dinfo.cell->center()[0] > 0.) ? .1 : 1.;

LocalIntegrators::Laplace::cell_matrix(dinfo.matrix(0, false).matrix,
info.fe_values(0),
Expand Down
4 changes: 2 additions & 2 deletions examples/step-17/step-17.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ namespace Step17
Assert(dim >= 2, ExcInternalError());

Point<dim> point_1, point_2;
point_1(0) = 0.5;
point_2(0) = -0.5;
point_1[0] = 0.5;
point_2[0] = -0.5;

if (((p - point_1).norm_square() < 0.2 * 0.2) ||
((p - point_2).norm_square() < 0.2 * 0.2))
Expand Down
17 changes: 8 additions & 9 deletions examples/step-30/step-30.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace Step30

for (unsigned int i = 0; i < values.size(); ++i)
{
if (points[i](0) < 0.5)
if (points[i][0] < 0.5)
values[i] = 1.;
else
values[i] = 0.;
Expand Down Expand Up @@ -111,15 +111,15 @@ namespace Step30

for (unsigned int i = 0; i < points.size(); ++i)
{
if (points[i](0) > 0)
if (points[i][0] > 0)
{
values[i](0) = -points[i](1);
values[i](1) = points[i](0);
values[i][0] = -points[i][1];
values[i][1] = points[i][0];
}
else
{
values[i] = Point<dim>();
values[i](0) = -points[i](1);
values[i][0] = -points[i][1];
}
}
}
Expand Down Expand Up @@ -873,7 +873,7 @@ namespace Step30
double sum_of_average_jumps = 0.;
for (unsigned int i = 0; i < dim; ++i)
{
average_jumps[i] = jump(i) / area(i);
average_jumps[i] = jump[i] / area[i];
sum_of_average_jumps += average_jumps[i];
}

Expand Down Expand Up @@ -946,10 +946,9 @@ namespace Step30
{
// Create the rectangular domain.
Point<dim> p1, p2;
p1(0) = 0;
p1(0) = -1;
p1[0] = -1.;
for (unsigned int i = 0; i < dim; ++i)
p2(i) = 1.;
p2[i] = 1.;
// Adjust the number of cells in different directions to obtain
// completely isotropic cells for the original mesh.
std::vector<unsigned int> repetitions(dim, 1);
Expand Down
4 changes: 2 additions & 2 deletions examples/step-32/step-32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ namespace Step32

const double s = (r - R0) / h;
const double q =
(dim == 3) ? std::max(0.0, cos(numbers::PI * abs(p(2) / R1))) : 1.0;
const double phi = std::atan2(p(0), p(1));
(dim == 3) ? std::max(0.0, cos(numbers::PI * abs(p[2] / R1))) : 1.0;
const double phi = std::atan2(p[0], p[1]);
const double tau = s + 0.2 * s * (1 - s) * std::sin(6 * phi) * q;

return T0 * (1.0 - tau) + T1 * tau;
Expand Down
6 changes: 3 additions & 3 deletions examples/step-35/step-35.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ namespace Step35
{
const double Um = 1.5;
const double H = 4.1;
return 4. * Um * p(1) * (H - p(1)) / (H * H);
return 4. * Um * p[1] * (H - p[1]) / (H * H);
}
else
return 0.;
Expand Down Expand Up @@ -398,7 +398,7 @@ namespace Step35
{
(void)component;
AssertIndexRange(component, 1);
return 25. - p(0);
return 25. - p[0];
}

template <int dim>
Expand Down Expand Up @@ -1156,7 +1156,7 @@ namespace Step35
{
scratch.fe_val.get_function_values(u_star[d], scratch.u_star_tmp);
for (unsigned int q = 0; q < scratch.nqp; ++q)
scratch.u_star_local[q](d) = scratch.u_star_tmp[q];
scratch.u_star_local[q][d] = scratch.u_star_tmp[q];
}

for (unsigned int d = 0; d < dim; ++d)
Expand Down
42 changes: 21 additions & 21 deletions examples/step-38/step-38.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace Step38
template <>
double Solution<2>::value(const Point<2> &p, const unsigned int) const
{
return (-2. * p(0) * p(1));
return (-2. * p[0] * p[1]);
}


Expand All @@ -162,8 +162,8 @@ namespace Step38
const unsigned int) const
{
Tensor<1, 2> return_value;
return_value[0] = -2. * p(1) * (1 - 2. * p(0) * p(0));
return_value[1] = -2. * p(0) * (1 - 2. * p(1) * p(1));
return_value[0] = -2. * p[1] * (1 - 2. * p[0] * p[0]);
return_value[1] = -2. * p[0] * (1 - 2. * p[1] * p[1]);

return return_value;
}
Expand All @@ -172,8 +172,8 @@ namespace Step38
template <>
double Solution<3>::value(const Point<3> &p, const unsigned int) const
{
return (std::sin(numbers::PI * p(0)) * std::cos(numbers::PI * p(1)) *
exp(p(2)));
return (std::sin(numbers::PI * p[0]) * std::cos(numbers::PI * p[1]) *
exp(p[2]));
}


Expand All @@ -185,9 +185,9 @@ namespace Step38

Tensor<1, 3> return_value;

return_value[0] = PI * cos(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
return_value[1] = -PI * sin(PI * p(0)) * sin(PI * p(1)) * exp(p(2));
return_value[2] = sin(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
return_value[0] = PI * cos(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);
return_value[1] = -PI * sin(PI * p[0]) * sin(PI * p[1]) * exp(p[2]);
return_value[2] = sin(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);

return return_value;
}
Expand All @@ -206,7 +206,7 @@ namespace Step38
double RightHandSide<2>::value(const Point<2> &p,
const unsigned int /*component*/) const
{
return (-8. * p(0) * p(1));
return (-8. * p[0] * p[1]);
}


Expand All @@ -218,23 +218,23 @@ namespace Step38

Tensor<2, 3> hessian;

hessian[0][0] = -PI * PI * sin(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
hessian[1][1] = -PI * PI * sin(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
hessian[2][2] = sin(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
hessian[0][0] = -PI * PI * sin(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);
hessian[1][1] = -PI * PI * sin(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);
hessian[2][2] = sin(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);

hessian[0][1] = -PI * PI * cos(PI * p(0)) * sin(PI * p(1)) * exp(p(2));
hessian[1][0] = -PI * PI * cos(PI * p(0)) * sin(PI * p(1)) * exp(p(2));
hessian[0][1] = -PI * PI * cos(PI * p[0]) * sin(PI * p[1]) * exp(p[2]);
hessian[1][0] = -PI * PI * cos(PI * p[0]) * sin(PI * p[1]) * exp(p[2]);

hessian[0][2] = PI * cos(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
hessian[2][0] = PI * cos(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
hessian[0][2] = PI * cos(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);
hessian[2][0] = PI * cos(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);

hessian[1][2] = -PI * sin(PI * p(0)) * sin(PI * p(1)) * exp(p(2));
hessian[2][1] = -PI * sin(PI * p(0)) * sin(PI * p(1)) * exp(p(2));
hessian[1][2] = -PI * sin(PI * p[0]) * sin(PI * p[1]) * exp(p[2]);
hessian[2][1] = -PI * sin(PI * p[0]) * sin(PI * p[1]) * exp(p[2]);

Tensor<1, 3> gradient;
gradient[0] = PI * cos(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
gradient[1] = -PI * sin(PI * p(0)) * sin(PI * p(1)) * exp(p(2));
gradient[2] = sin(PI * p(0)) * cos(PI * p(1)) * exp(p(2));
gradient[0] = PI * cos(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);
gradient[1] = -PI * sin(PI * p[0]) * sin(PI * p[1]) * exp(p[2]);
gradient[2] = sin(PI * p[0]) * cos(PI * p[1]) * exp(p[2]);

Point<3> normal = p;
normal /= p.norm();
Expand Down
2 changes: 1 addition & 1 deletion examples/step-4/step-4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ double RightHandSide<dim>::value(const Point<dim> &p,
{
double return_value = 0.0;
for (unsigned int i = 0; i < dim; ++i)
return_value += 4.0 * std::pow(p(i), 4.0);
return_value += 4.0 * std::pow(p[i], 4.0);

return return_value;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/step-41/step-41.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ namespace Step41
(void)component;
Assert(component == 0, ExcIndexRange(component, 0, 1));

if (p(0) < -0.5)
if (p[0] < -0.5)
return -0.2;
else if (p(0) >= -0.5 && p(0) < 0.0)
else if (p[0] >= -0.5 && p[0] < 0.0)
return -0.4;
else if (p(0) >= 0.0 && p(0) < 0.5)
else if (p[0] >= 0.0 && p[0] < 0.5)
return -0.6;
else
return -0.8;
Expand Down
22 changes: 11 additions & 11 deletions examples/step-42/step-42.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ namespace Step42
const unsigned int component) const
{
if (component == 0)
return p(0);
return p[0];
else if (component == 1)
return p(1);
return p[1];
else if (component == 2)
{
if ((p(0) - 0.5) * (p(0) - 0.5) + (p(1) - 0.5) * (p(1) - 0.5) < 0.36)
return (-std::sqrt(0.36 - (p(0) - 0.5) * (p(0) - 0.5) -
(p(1) - 0.5) * (p(1) - 0.5)) +
if ((p[0] - 0.5) * (p[0] - 0.5) + (p[1] - 0.5) * (p[1] - 0.5) < 0.36)
return (-std::sqrt(0.36 - (p[0] - 0.5) * (p[0] - 0.5) -
(p[1] - 0.5) * (p[1] - 0.5)) +
z_surface + 0.59);
else
return 1000;
Expand Down Expand Up @@ -550,13 +550,13 @@ namespace Step42
const unsigned int component) const
{
if (component == 0)
return p(0);
return p[0];
if (component == 1)
return p(1);
return p[1];
else if (component == 2)
{
if (p(0) >= 0.0 && p(0) <= 1.0 && p(1) >= 0.0 && p(1) <= 1.0)
return z_surface + 0.999 - input_obstacle.get_value(p(0), p(1));
if (p[0] >= 0.0 && p[0] <= 1.0 && p[1] >= 0.0 && p[1] <= 1.0)
return z_surface + 0.999 - input_obstacle.get_value(p[0], p[1]);
}

Assert(false, ExcNotImplemented());
Expand Down Expand Up @@ -881,7 +881,7 @@ namespace Step42
// indicator one.
Point<3> rotate_half_sphere(const Point<3> &in)
{
return {in(2), in(1), -in(0)};
return {in[2], in[1], -in[0]};
}

template <int dim>
Expand Down Expand Up @@ -1267,7 +1267,7 @@ namespace Step42
obstacle->value(this_support_point, 2);
const double solution_here = solution(index_z);
const double undeformed_gap =
obstacle_value - this_support_point(2);
obstacle_value - this_support_point[2];

const double c = 100.0 * e_modulus;
if ((lambda(index_z) /
Expand Down
6 changes: 3 additions & 3 deletions examples/step-49/step-49.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ void grid_3()
for (const auto i : cell->vertex_indices())
{
Point<2> &v = cell->vertex(i);
if (std::abs(v(1) - 1.0) < 1e-5)
v(1) += 0.5;
if (std::abs(v[1] - 1.0) < 1e-5)
v[1] += 0.5;
}
}

Expand Down Expand Up @@ -315,7 +315,7 @@ struct Grid6Func

Point<2> operator()(const Point<2> &in) const
{
return {in(0), trans(in(1))};
return {in[0], trans(in[1])};
}
};

Expand Down
4 changes: 2 additions & 2 deletions examples/step-51/step-51.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1344,8 +1344,8 @@ namespace Step51
for (const auto &cell : triangulation.cell_iterators())
for (const auto &face : cell->face_iterators())
if (face->at_boundary())
if ((std::fabs(face->center()(0) - (-1)) < 1e-12) ||
(std::fabs(face->center()(1) - (-1)) < 1e-12))
if ((std::fabs(face->center()[0] - (-1)) < 1e-12) ||
(std::fabs(face->center()[1] - (-1)) < 1e-12))
face->set_boundary_id(1);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/step-52/step-52.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ namespace Step52
const double intensity = 10.;
const double frequency = numbers::PI / 10.;
const double b = 5.;
const double x = point(0);
const double x = point[0];

return intensity *
(frequency * std::cos(frequency * time) * (b * x - x * x) +
Expand Down
8 changes: 4 additions & 4 deletions examples/step-53/step-53.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ namespace Step53
{
const double b = std::sqrt(R * R * (1 - ellipticity * ellipticity));
const double ep = std::sqrt((R * R - b * b) / (b * b));
const double p = std::sqrt(x(0) * x(0) + x(1) * x(1));
const double th = std::atan2(R * x(2), b * p);
const double phi = std::atan2(x(1), x(0));
const double p = std::sqrt(x[0] * x[0] + x[1] * x[1]);
const double th = std::atan2(R * x[2], b * p);
const double phi = std::atan2(x[1], x[0]);
const double theta =
std::atan2(x(2) + ep * ep * b * Utilities::fixed_power<3>(std::sin(th)),
std::atan2(x[2] + ep * ep * b * Utilities::fixed_power<3>(std::sin(th)),
(p - (ellipticity * ellipticity * R *
Utilities::fixed_power<3>(std::cos(th)))));
const double R_bar =
Expand Down

0 comments on commit 9c9a7d9

Please sign in to comment.