MappingCartesian<dim, spacedim>::InternalData::InternalData(
const Quadrature<dim> &q)
: cell_extents(numbers::signaling_nan<Tensor<1, dim>>())
+ , inverse_cell_extents(numbers::signaling_nan<Tensor<1, dim>>())
, volume_element(numbers::signaling_nan<double>())
, quadrature_points(q.get_points())
{}
{
return (Mapping<dim, spacedim>::InternalDataBase::memory_consumption() +
MemoryConsumption::memory_consumption(cell_extents) +
+ MemoryConsumption::memory_consumption(inverse_cell_extents) +
MemoryConsumption::memory_consumption(volume_element) +
MemoryConsumption::memory_consumption(quadrature_points));
}
const CellSimilarity::Similarity cell_similarity,
const InternalData &data) const
{
- // Compute start point and sizes
- // along axes. Strange vertex
- // numbering makes this complicated
- // again.
+ // Compute start point and sizes along axes. The vertices to be looked at
+ // are 1, 2, 4 compared to the base vertex 0.
if (cell_similarity != CellSimilarity::translation)
{
- const Point<dim> &start = cell->vertex(0);
- switch (dim)
+ const Point<dim> start = cell->vertex(0);
+ for (unsigned int d = 0; d < dim; ++d)
{
- case 1:
- data.cell_extents[0] = cell->vertex(1)[0] - start[0];
- break;
- case 2:
- data.cell_extents[0] = cell->vertex(1)[0] - start[0];
- data.cell_extents[1] = cell->vertex(2)[1] - start[1];
- break;
- case 3:
- data.cell_extents[0] = cell->vertex(1)[0] - start[0];
- data.cell_extents[1] = cell->vertex(2)[1] - start[1];
- data.cell_extents[2] = cell->vertex(4)[2] - start[2];
- break;
- default:
- DEAL_II_NOT_IMPLEMENTED();
+ const double cell_extent_d = cell->vertex(1 << d)[d] - start[d];
+ data.cell_extents[d] = cell_extent_d;
+ Assert(cell_extent_d != 0.,
+ ExcMessage("Cell does not appear to be Cartesian!"));
+ data.inverse_cell_extents[d] = 1. / cell_extent_d;
}
}
}
{
// let @p{start} be the origin of a local coordinate system. it is chosen
// as the (lower) left vertex
- const Point<dim> &start = cell->vertex(0);
+ const Point<dim> start = cell->vertex(0);
for (unsigned int i = 0; i < quadrature_points.size(); ++i)
{
{
output_data.inverse_jacobians[i] = Tensor<2, dim>();
for (unsigned int j = 0; j < dim; ++j)
- output_data.inverse_jacobians[i][j][j] = 1. / data.cell_extents[j];
+ output_data.inverse_jacobians[i][j][j] =
+ data.inverse_cell_extents[j];
}
}
const Tensor<1, dim> &ref_space_normal = quadrature.normal_vector(i);
for (unsigned int d = 0; d < dim; ++d)
{
- normal[d] = ref_space_normal[d] / data.cell_extents[d];
+ normal[d] = ref_space_normal[d] * data.inverse_cell_extents[d];
}
normal /= normal.norm();
output_data.normal_vectors[i] = normal;
for (unsigned int d = 0; d < dim; ++d)
{
det_jacobian *= data.cell_extents[d];
- invJTxNormal[d] = ref_space_normal[d] / data.cell_extents[d];
+ invJTxNormal[d] =
+ ref_space_normal[d] * data.inverse_cell_extents[d];
}
output_data.JxW_values[i] =
det_jacobian * invJTxNormal.norm() * quadrature.weight(i);
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d = 0; d < dim; ++d)
- output[i][d] = input[i][d] / data.cell_extents[d];
+ output[i][d] = input[i][d] * data.inverse_cell_extents[d];
return;
}
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d1 = 0; d1 < dim; ++d1)
for (unsigned int d2 = 0; d2 < dim; ++d2)
- output[i][d1][d2] = input[i][d1][d2] / data.cell_extents[d2];
+ output[i][d1][d2] =
+ input[i][d1][d2] * data.inverse_cell_extents[d2];
return;
}
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d1 = 0; d1 < dim; ++d1)
for (unsigned int d2 = 0; d2 < dim; ++d2)
- output[i][d1][d2] = input[i][d1][d2] / data.cell_extents[d2] /
- data.cell_extents[d1];
+ output[i][d1][d2] = input[i][d1][d2] *
+ data.inverse_cell_extents[d2] *
+ data.inverse_cell_extents[d1];
return;
}
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d1 = 0; d1 < dim; ++d1)
for (unsigned int d2 = 0; d2 < dim; ++d2)
- output[i][d1][d2] = input[i][d1][d2] * data.cell_extents[d2] /
- data.cell_extents[d1];
+ output[i][d1][d2] = input[i][d1][d2] * data.cell_extents[d2] *
+ data.inverse_cell_extents[d1];
return;
}
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d1 = 0; d1 < dim; ++d1)
for (unsigned int d2 = 0; d2 < dim; ++d2)
- output[i][d1][d2] = input[i][d1][d2] * data.cell_extents[d2] /
- data.cell_extents[d1] / data.volume_element;
+ output[i][d1][d2] = input[i][d1][d2] * data.cell_extents[d2] *
+ data.inverse_cell_extents[d1] /
+ data.volume_element;
return;
}
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d1 = 0; d1 < dim; ++d1)
for (unsigned int d2 = 0; d2 < dim; ++d2)
- output[i][d1][d2] = input[i][d1][d2] / data.cell_extents[d2];
+ output[i][d1][d2] =
+ input[i][d1][d2] * data.inverse_cell_extents[d2];
return;
}
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d1 = 0; d1 < dim; ++d1)
for (unsigned int d2 = 0; d2 < dim; ++d2)
- output[i][d1][d2] = input[i][d1][d2] / data.cell_extents[d2] /
- data.cell_extents[d1];
+ output[i][d1][d2] = input[i][d1][d2] *
+ data.inverse_cell_extents[d2] *
+ data.inverse_cell_extents[d1];
return;
}
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d1 = 0; d1 < dim; ++d1)
for (unsigned int d2 = 0; d2 < dim; ++d2)
- output[i][d1][d2] = input[i][d1][d2] * data.cell_extents[d2] /
- data.cell_extents[d1];
+ output[i][d1][d2] = input[i][d1][d2] * data.cell_extents[d2] *
+ data.inverse_cell_extents[d1];
return;
}
for (unsigned int i = 0; i < output.size(); ++i)
for (unsigned int d1 = 0; d1 < dim; ++d1)
for (unsigned int d2 = 0; d2 < dim; ++d2)
- output[i][d1][d2] = input[i][d1][d2] * data.cell_extents[d2] /
- data.cell_extents[d1] / data.volume_element;
+ output[i][d1][d2] = input[i][d1][d2] * data.cell_extents[d2] *
+ data.inverse_cell_extents[d1] /
+ data.volume_element;
return;
}
for (unsigned int j = 0; j < spacedim; ++j)
for (unsigned int k = 0; k < spacedim; ++k)
{
- output[q][i][j][k] = input[q][i][j][k] /
- data.cell_extents[j] /
- data.cell_extents[k];
+ output[q][i][j][k] = input[q][i][j][k] *
+ data.inverse_cell_extents[j] *
+ data.inverse_cell_extents[k];
}
return;
}
for (unsigned int j = 0; j < spacedim; ++j)
for (unsigned int k = 0; k < spacedim; ++k)
{
- output[q][i][j][k] =
- input[q][i][j][k] * data.cell_extents[i] /
- data.cell_extents[j] / data.cell_extents[k];
+ output[q][i][j][k] = input[q][i][j][k] *
+ data.cell_extents[i] *
+ data.inverse_cell_extents[j] *
+ data.inverse_cell_extents[k];
}
return;
}
for (unsigned int j = 0; j < spacedim; ++j)
for (unsigned int k = 0; k < spacedim; ++k)
{
- output[q][i][j][k] =
- input[q][i][j][k] / data.cell_extents[i] /
- data.cell_extents[j] / data.cell_extents[k];
+ output[q][i][j][k] = input[q][i][j][k] *
+ (data.inverse_cell_extents[i] *
+ data.inverse_cell_extents[j]) *
+ data.inverse_cell_extents[k];
}
return;
for (unsigned int k = 0; k < spacedim; ++k)
{
output[q][i][j][k] =
- input[q][i][j][k] * data.cell_extents[i] /
- data.volume_element / data.cell_extents[j] /
- data.cell_extents[k];
+ input[q][i][j][k] *
+ (data.cell_extents[i] / data.volume_element *
+ data.inverse_cell_extents[j]) *
+ data.inverse_cell_extents[k];
}
return;
const Point<dim> &p) const
{
Assert(is_cartesian(cell), ExcCellNotCartesian());
+ if (dim != spacedim)
+ DEAL_II_NOT_IMPLEMENTED();
- Tensor<1, dim> length;
- const Point<dim> start = cell->vertex(0);
- switch (dim)
- {
- case 1:
- length[0] = cell->vertex(1)[0] - start[0];
- break;
- case 2:
- length[0] = cell->vertex(1)[0] - start[0];
- length[1] = cell->vertex(2)[1] - start[1];
- break;
- case 3:
- length[0] = cell->vertex(1)[0] - start[0];
- length[1] = cell->vertex(2)[1] - start[1];
- length[2] = cell->vertex(4)[2] - start[2];
- break;
- default:
- DEAL_II_NOT_IMPLEMENTED();
- }
+ Point<dim> unit = cell->vertex(0);
- Point<dim> p_real = cell->vertex(0);
+ // Go through vertices with numbers 1, 2, 4
for (unsigned int d = 0; d < dim; ++d)
- p_real[d] += length[d] * p[d];
+ unit[d] += (cell->vertex(1 << d)[d] - unit[d]) * p[d];
- return p_real;
+ return unit;
}
if (dim != spacedim)
DEAL_II_NOT_IMPLEMENTED();
- const Point<dim> &start = cell->vertex(0);
- Point<dim> real = p;
- real -= start;
+ const Point<dim> start = cell->vertex(0);
+ Point<dim> real = p;
+
+ // Go through vertices with numbers 1, 2, 4
+ for (unsigned int d = 0; d < dim; ++d)
+ real[d] = (real[d] - start[d]) / (cell->vertex(1 << d)[d] - start[d]);
- switch (dim)
- {
- case 1:
- real[0] /= cell->vertex(1)[0] - start[0];
- break;
- case 2:
- real[0] /= cell->vertex(1)[0] - start[0];
- real[1] /= cell->vertex(2)[1] - start[1];
- break;
- case 3:
- real[0] /= cell->vertex(1)[0] - start[0];
- real[1] /= cell->vertex(2)[1] - start[1];
- real[2] /= cell->vertex(4)[2] - start[2];
- break;
- default:
- DEAL_II_NOT_IMPLEMENTED();
- }
return real;
}
+template <int dim, int spacedim>
+void
+MappingCartesian<dim, spacedim>::transform_points_real_to_unit_cell(
+ const typename Triangulation<dim, spacedim>::cell_iterator &cell,
+ const ArrayView<const Point<spacedim>> &real_points,
+ const ArrayView<Point<dim>> &unit_points) const
+{
+ Assert(is_cartesian(cell), ExcCellNotCartesian());
+ AssertDimension(real_points.size(), unit_points.size());
+
+ if (dim != spacedim)
+ DEAL_II_NOT_IMPLEMENTED();
+
+ const Point<dim> start = cell->vertex(0);
+
+ // Go through vertices with numbers 1, 2, 4
+ std::array<double, dim> inverse_lengths;
+ for (unsigned int d = 0; d < dim; ++d)
+ inverse_lengths[d] = 1. / (cell->vertex(1 << d)[d] - start[d]);
+
+ for (unsigned int i = 0; i < real_points.size(); ++i)
+ for (unsigned int d = 0; d < dim; ++d)
+ unit_points[i][d] = (real_points[i][d] - start[d]) * inverse_lengths[d];
+}
+
+
+
template <int dim, int spacedim>
std::unique_ptr<Mapping<dim, spacedim>>
MappingCartesian<dim, spacedim>::clone() const