double
TriaAccessor<structdim, dim, spacedim>::diameter() const
{
- switch (structdim)
+ switch (this->reference_cell_type())
{
- case 1:
+ case ReferenceCell::Type::Line:
return (this->vertex(1) - this->vertex(0)).norm();
- case 2:
+ case ReferenceCell::Type::Tri:
+ return std::max(std::max((this->vertex(1) - this->vertex(0)).norm(),
+ (this->vertex(2) - this->vertex(1)).norm()),
+ (this->vertex(2) - this->vertex(0)).norm());
+ case ReferenceCell::Type::Quad:
return std::max((this->vertex(3) - this->vertex(0)).norm(),
(this->vertex(2) - this->vertex(1)).norm());
- case 3:
+ case ReferenceCell::Type::Tet:
+ return std::max(
+ std::max(std::max((this->vertex(1) - this->vertex(0)).norm(),
+ (this->vertex(2) - this->vertex(0)).norm()),
+ std::max((this->vertex(2) - this->vertex(1)).norm(),
+ (this->vertex(3) - this->vertex(0)).norm())),
+ std::max((this->vertex(3) - this->vertex(1)).norm(),
+ (this->vertex(3) - this->vertex(2)).norm()));
+ case ReferenceCell::Type::Hex:
return std::max(std::max((this->vertex(7) - this->vertex(0)).norm(),
(this->vertex(6) - this->vertex(1)).norm()),
std::max((this->vertex(2) - this->vertex(5)).norm(),
cell_measure<2>(const std::vector<Point<2>> & all_vertices,
const ArrayView<const unsigned int> &vertex_indices)
{
+ if (vertex_indices.size() == 3) // triangle
+ {
+ const double x[3] = {all_vertices[vertex_indices[0]](0),
+ all_vertices[vertex_indices[1]](0),
+ all_vertices[vertex_indices[2]](0)};
+
+ const double y[3] = {all_vertices[vertex_indices[0]](1),
+ all_vertices[vertex_indices[1]](1),
+ all_vertices[vertex_indices[2]](1)};
+
+ return 0.5 * std::abs((x[0] - x[2]) * (y[1] - y[0]) -
+ (x[0] - x[1]) * (y[2] - y[0]));
+ }
+
AssertDimension(vertex_indices.size(), GeometryInfo<2>::vertices_per_cell);
/*
cell_measure<3>(const std::vector<Point<3>> & all_vertices,
const ArrayView<const unsigned int> &vertex_indices)
{
+ if (vertex_indices.size() == 4) // tetrahedron
+ {
+ const auto &a = all_vertices[vertex_indices[0]];
+ const auto &b = all_vertices[vertex_indices[1]];
+ const auto &c = all_vertices[vertex_indices[2]];
+ const auto &d = all_vertices[vertex_indices[3]];
+
+ return (1.0 / 6.0) * std::abs((a - d) * cross_product_3d(b - d, c - d));
+ }
+
AssertDimension(vertex_indices.size(), GeometryInfo<3>::vertices_per_cell);
// note that this is the
// cell_measure based on the new
vertex_indices[i] = accessor.vertex_index(i);
return GridTools::cell_measure<2>(
- accessor.get_triangulation().get_vertices(), vertex_indices);
+ accessor.get_triangulation().get_vertices(),
+ ArrayView<unsigned int>(vertex_indices, accessor.n_vertices()));
}
vertex_indices[i] = accessor.vertex_index(i);
return GridTools::cell_measure<3>(
- accessor.get_triangulation().get_vertices(), vertex_indices);
+ accessor.get_triangulation().get_vertices(),
+ ArrayView<unsigned int>(vertex_indices, accessor.n_vertices()));
}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Test TriaAccessor::measure() and TriaAccessor::diameter().
+
+#include <deal.II/grid/tria.h>
+
+#include "../tests.h"
+
+template <int dim, int spacedim>
+void
+process(const std::vector<Point<spacedim>> &vertices,
+ const std::vector<CellData<dim>> & cells)
+{
+ Triangulation<dim, spacedim> tria;
+ tria.create_triangulation(vertices, cells, SubCellData());
+
+ deallog << "dim=" << dim << " spacedim=" << spacedim << ":" << std::endl;
+ for (const auto &cell : tria.active_cell_iterators())
+ {
+ deallog << "measure: " << cell->measure() << std::endl;
+ deallog << "diameter: " << cell->diameter() << std::endl;
+ }
+ deallog << std::endl;
+}
+
+template <int dim>
+void
+test()
+{
+ Assert(false, ExcNotImplemented());
+}
+
+template <>
+void
+test<2>()
+{
+ const int dim = 2;
+ const int spacedim = 2;
+
+ std::vector<Point<spacedim>> vertices;
+ vertices.emplace_back(0, 0);
+ vertices.emplace_back(1, 0);
+ vertices.emplace_back(0, 1);
+
+ std::vector<CellData<dim>> cells;
+ CellData<dim> cell;
+ cell.vertices = {0, 1, 2};
+ cells.push_back(cell);
+
+ process(vertices, cells);
+}
+
+template <>
+void
+test<3>()
+{
+ const int dim = 3;
+ const int spacedim = 3;
+
+ std::vector<Point<spacedim>> vertices;
+ vertices.emplace_back(0, 0, 0);
+ vertices.emplace_back(1, 0, 0);
+ vertices.emplace_back(0, 1, 0);
+ vertices.emplace_back(0, 0, 1);
+
+ std::vector<CellData<dim>> cells;
+ CellData<dim> cell;
+ cell.vertices = {0, 1, 2, 3};
+ cells.push_back(cell);
+
+ process(vertices, cells);
+}
+
+int
+main()
+{
+ initlog();
+
+ test<2>();
+ test<3>();
+}
--- /dev/null
+
+DEAL::dim=2 spacedim=2:
+DEAL::measure: 0.500000
+DEAL::diameter: 1.41421
+DEAL::
+DEAL::dim=3 spacedim=3:
+DEAL::measure: 0.166667
+DEAL::diameter: 1.41421
+DEAL::