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

Sort implementations of GridTools::cell_measure by dimension. #8296

Merged
merged 1 commit into from
May 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
118 changes: 59 additions & 59 deletions source/grid/grid_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,65 @@ namespace GridTools



template <>
double
cell_measure<2>(
const std::vector<Point<2>> &all_vertices,
const unsigned int (&vertex_indices)[GeometryInfo<2>::vertices_per_cell])
{
/*
Get the computation of the measure by this little Maple script. We
use the blinear mapping of the unit quad to the real quad. However,
every transformation mapping the unit faces to straight lines should
do.

Remember that the area of the quad is given by
\int_K 1 dx dy = \int_{\hat K} |det J| d(xi) d(eta)

# x and y are arrays holding the x- and y-values of the four vertices
# of this cell in real space.
x := array(0..3);
y := array(0..3);
z := array(0..3);
tphi[0] := (1-xi)*(1-eta):
tphi[1] := xi*(1-eta):
tphi[2] := (1-xi)*eta:
tphi[3] := xi*eta:
x_real := sum(x[s]*tphi[s], s=0..3):
y_real := sum(y[s]*tphi[s], s=0..3):
z_real := sum(z[s]*tphi[s], s=0..3):

Jxi := <diff(x_real,xi) | diff(y_real,xi) | diff(z_real,xi)>;
Jeta := <diff(x_real,eta)| diff(y_real,eta)| diff(z_real,eta)>;
with(VectorCalculus):
J := CrossProduct(Jxi, Jeta);
detJ := sqrt(J[1]^2 + J[2]^2 +J[3]^2);

# measure := evalf (Int (Int (detJ, xi=0..1, method = _NCrule ) ,
eta=0..1, method = _NCrule ) ): # readlib(C):

# C(measure, optimized);

additional optimizaton: divide by 2 only one time
*/

const double x[4] = {all_vertices[vertex_indices[0]](0),
all_vertices[vertex_indices[1]](0),
all_vertices[vertex_indices[2]](0),
all_vertices[vertex_indices[3]](0)};

const double y[4] = {all_vertices[vertex_indices[0]](1),
all_vertices[vertex_indices[1]](1),
all_vertices[vertex_indices[2]](1),
all_vertices[vertex_indices[3]](1)};

return (-x[1] * y[0] + x[1] * y[3] + y[0] * x[2] + x[0] * y[1] -
x[0] * y[2] - y[1] * x[3] - x[2] * y[3] + x[3] * y[2]) /
2;
}



template <>
double
cell_measure<3>(
Expand Down Expand Up @@ -356,65 +415,6 @@ namespace GridTools



template <>
double
cell_measure<2>(
const std::vector<Point<2>> &all_vertices,
const unsigned int (&vertex_indices)[GeometryInfo<2>::vertices_per_cell])
{
/*
Get the computation of the measure by this little Maple script. We
use the blinear mapping of the unit quad to the real quad. However,
every transformation mapping the unit faces to straight lines should
do.

Remember that the area of the quad is given by
\int_K 1 dx dy = \int_{\hat K} |det J| d(xi) d(eta)

# x and y are arrays holding the x- and y-values of the four vertices
# of this cell in real space.
x := array(0..3);
y := array(0..3);
z := array(0..3);
tphi[0] := (1-xi)*(1-eta):
tphi[1] := xi*(1-eta):
tphi[2] := (1-xi)*eta:
tphi[3] := xi*eta:
x_real := sum(x[s]*tphi[s], s=0..3):
y_real := sum(y[s]*tphi[s], s=0..3):
z_real := sum(z[s]*tphi[s], s=0..3):

Jxi := <diff(x_real,xi) | diff(y_real,xi) | diff(z_real,xi)>;
Jeta := <diff(x_real,eta)| diff(y_real,eta)| diff(z_real,eta)>;
with(VectorCalculus):
J := CrossProduct(Jxi, Jeta);
detJ := sqrt(J[1]^2 + J[2]^2 +J[3]^2);

# measure := evalf (Int (Int (detJ, xi=0..1, method = _NCrule ) ,
eta=0..1, method = _NCrule ) ): # readlib(C):

# C(measure, optimized);

additional optimizaton: divide by 2 only one time
*/

const double x[4] = {all_vertices[vertex_indices[0]](0),
all_vertices[vertex_indices[1]](0),
all_vertices[vertex_indices[2]](0),
all_vertices[vertex_indices[3]](0)};

const double y[4] = {all_vertices[vertex_indices[0]](1),
all_vertices[vertex_indices[1]](1),
all_vertices[vertex_indices[2]](1),
all_vertices[vertex_indices[3]](1)};

return (-x[1] * y[0] + x[1] * y[3] + y[0] * x[2] + x[0] * y[1] -
x[0] * y[2] - y[1] * x[3] - x[2] * y[3] + x[3] * y[2]) /
2;
}



template <int dim, int spacedim>
BoundingBox<spacedim>
compute_bounding_box(const Triangulation<dim, spacedim> &tria)
Expand Down