Skip to content

Commit

Permalink
DataOut: add wedge/pyramid test
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrum committed Oct 20, 2021
1 parent f6c58be commit c2f2736
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/deal.II/fe/fe_pyramid_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class FE_PyramidPoly : public dealii::FE_Poly<dim, spacedim>
FE_PyramidPoly(const unsigned int degree,
const internal::GenericDoFsPerObject & dpos,
const typename FiniteElementData<dim>::Conformity conformity);

/**
* @copydoc dealii::FiniteElement::convert_generalized_support_point_values_to_dof_values()
*/
virtual void
convert_generalized_support_point_values_to_dof_values(
const std::vector<Vector<double>> &support_point_values,
std::vector<double> & nodal_values) const override;
};

/**
Expand Down
8 changes: 8 additions & 0 deletions include/deal.II/fe/fe_wedge_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class FE_WedgePoly : public dealii::FE_Poly<dim, spacedim>
FE_WedgePoly(const unsigned int degree,
const internal::GenericDoFsPerObject & dpos,
const typename FiniteElementData<dim>::Conformity conformity);

/**
* @copydoc dealii::FiniteElement::convert_generalized_support_point_values_to_dof_values()
*/
virtual void
convert_generalized_support_point_values_to_dof_values(
const std::vector<Vector<double>> &support_point_values,
std::vector<double> & nodal_values) const override;
};

/**
Expand Down
22 changes: 22 additions & 0 deletions source/fe/fe_pyramid_p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ FE_PyramidPoly<dim, spacedim>::FE_PyramidPoly(



template <int dim, int spacedim>
void
FE_PyramidPoly<dim, spacedim>::
convert_generalized_support_point_values_to_dof_values(
const std::vector<Vector<double>> &support_point_values,
std::vector<double> & nodal_values) const
{
AssertDimension(support_point_values.size(),
this->get_unit_support_points().size());
AssertDimension(support_point_values.size(), nodal_values.size());
AssertDimension(this->dofs_per_cell, nodal_values.size());

for (unsigned int i = 0; i < this->dofs_per_cell; ++i)
{
AssertDimension(support_point_values[i].size(), 1);

nodal_values[i] = support_point_values[i](0);
}
}



template <int dim, int spacedim>
FE_PyramidP<dim, spacedim>::FE_PyramidP(const unsigned int degree)
: FE_PyramidPoly<dim, spacedim>(degree,
Expand Down
22 changes: 22 additions & 0 deletions source/fe/fe_wedge_p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ FE_WedgePoly<dim, spacedim>::FE_WedgePoly(



template <int dim, int spacedim>
void
FE_WedgePoly<dim, spacedim>::
convert_generalized_support_point_values_to_dof_values(
const std::vector<Vector<double>> &support_point_values,
std::vector<double> & nodal_values) const
{
AssertDimension(support_point_values.size(),
this->get_unit_support_points().size());
AssertDimension(support_point_values.size(), nodal_values.size());
AssertDimension(this->dofs_per_cell, nodal_values.size());

for (unsigned int i = 0; i < this->dofs_per_cell; ++i)
{
AssertDimension(support_point_values[i].size(), 1);

nodal_values[i] = support_point_values[i](0);
}
}



template <int dim, int spacedim>
FE_WedgeP<dim, spacedim>::FE_WedgeP(const unsigned int degree)
: FE_WedgePoly<dim, spacedim>(degree,
Expand Down
118 changes: 118 additions & 0 deletions tests/simplex/data_out_write_vtk_04.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2021 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 DataOut::write_vtk() for wedge and pyramid meshes.

#include <deal.II/base/quadrature_lib.h>

#include <deal.II/dofs/dof_handler.h>

#include <deal.II/fe/fe_pyramid_p.h>
#include <deal.II/fe/fe_simplex_p.h>
#include <deal.II/fe/fe_simplex_p_bubbles.h>
#include <deal.II/fe/fe_system.h>
#include <deal.II/fe/fe_wedge_p.h>
#include <deal.II/fe/mapping_fe.h>

#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/grid_in.h>
#include <deal.II/grid/grid_out.h>
#include <deal.II/grid/tria.h>

#include <deal.II/numerics/data_out.h>
#include <deal.II/numerics/vector_tools.h>

#include "../tests.h"

#include "simplex_grids.h"

using namespace dealii;

template <int dim>
class RightHandSideFunction : public Function<dim>
{
public:
RightHandSideFunction(const unsigned int n_components)
: Function<dim>(n_components)
{}

virtual double
value(const Point<dim> &p, const unsigned int component = 0) const
{
return p[component % dim] * p[component % dim];
}
};

template <int dim, int spacedim = dim>
void
test(const FiniteElement<dim, spacedim> & fe,
const std::function<void(Triangulation<dim, spacedim> &)> &fu)
{
Triangulation<dim, spacedim> tria;
fu(tria);

DoFHandler<dim> dof_handler(tria);
dof_handler.distribute_dofs(fe);

Vector<double> solution(dof_handler.n_dofs());
VectorTools::interpolate(dof_handler,
RightHandSideFunction<dim>(fe.n_components()),
solution);

static unsigned int counter = 0;

for (unsigned int i = 0; i <= 1; ++i)
{
DataOut<dim> data_out;

if (i == 0)
{
data_out.attach_dof_handler(dof_handler);
data_out.add_data_vector(solution, "solution");
}
else
{
data_out.attach_triangulation(tria);
}

data_out.build_patches();

#if 0
std::ofstream output("test." + std::to_string(dim) + "." +
std::to_string(counter++) + ".vtk");
data_out.write_vtk(output);
#else
data_out.write_vtk(deallog.get_file_stream());
#endif
}
}

int
main()
{
initlog();

// test wedges
test<3, 3>(FE_WedgeP<3>(1), [](auto &tria) {
GridGenerator::subdivided_hyper_cube_with_wedges(tria, 1);
});

// test pyramids
test<3, 3>(FE_PyramidP<3>(1), [](auto &tria) {
GridGenerator::subdivided_hyper_cube_with_pyramids(tria, 1);
});
}
155 changes: 155 additions & 0 deletions tests/simplex/data_out_write_vtk_04.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@

# vtk DataFile Version 3.0
#This file was generated
ASCII
DATASET UNSTRUCTURED_GRID

POINTS 12 double
0.00000 0.00000 0.00000
1.00000 0.00000 0.00000
0.00000 1.00000 0.00000
0.00000 0.00000 1.00000
1.00000 0.00000 1.00000
0.00000 1.00000 1.00000
1.00000 1.00000 0.00000
0.00000 1.00000 0.00000
1.00000 0.00000 0.00000
1.00000 1.00000 1.00000
0.00000 1.00000 1.00000
1.00000 0.00000 1.00000

CELLS 2 14
6 0 1 2 3 4 5
6 6 7 8 9 10 11

CELL_TYPES 2
13 13
POINT_DATA 12
SCALARS solution double 1
LOOKUP_TABLE default
0.00000 1.00000 0.00000 0.00000 1.00000 0.00000 1.00000 0.00000 1.00000 1.00000 0.00000 1.00000
# vtk DataFile Version 3.0
#This file was generated
ASCII
DATASET UNSTRUCTURED_GRID

POINTS 12 double
0.00000 0.00000 0.00000
1.00000 0.00000 0.00000
0.00000 1.00000 0.00000
0.00000 0.00000 1.00000
1.00000 0.00000 1.00000
0.00000 1.00000 1.00000
1.00000 1.00000 0.00000
0.00000 1.00000 0.00000
1.00000 0.00000 0.00000
1.00000 1.00000 1.00000
0.00000 1.00000 1.00000
1.00000 0.00000 1.00000

CELLS 2 14
6 0 1 2 3 4 5
6 6 7 8 9 10 11

CELL_TYPES 2
13 13
POINT_DATA 12
# vtk DataFile Version 3.0
#This file was generated
ASCII
DATASET UNSTRUCTURED_GRID

POINTS 30 double
0.00000 0.00000 0.00000
0.00000 1.00000 0.00000
0.00000 1.00000 1.00000
0.00000 0.00000 1.00000
0.500000 0.500000 0.500000
0.00000 1.00000 0.00000
1.00000 1.00000 0.00000
1.00000 1.00000 1.00000
0.00000 1.00000 1.00000
0.500000 0.500000 0.500000
0.00000 1.00000 1.00000
1.00000 1.00000 1.00000
1.00000 0.00000 1.00000
0.00000 0.00000 1.00000
0.500000 0.500000 0.500000
1.00000 0.00000 0.00000
1.00000 0.00000 1.00000
1.00000 1.00000 1.00000
1.00000 1.00000 0.00000
0.500000 0.500000 0.500000
0.00000 0.00000 0.00000
1.00000 0.00000 0.00000
1.00000 1.00000 0.00000
0.00000 1.00000 0.00000
0.500000 0.500000 0.500000
0.00000 0.00000 0.00000
0.00000 0.00000 1.00000
1.00000 0.00000 1.00000
1.00000 0.00000 0.00000
0.500000 0.500000 0.500000

CELLS 6 36
5 0 1 2 3 4
5 5 6 7 8 9
5 10 11 12 13 14
5 15 16 17 18 19
5 20 21 22 23 24
5 25 26 27 28 29

CELL_TYPES 6
14 14 14 14 14 14
POINT_DATA 30
SCALARS solution double 1
LOOKUP_TABLE default
0.00000 0.00000 0.00000 0.00000 0.250000 0.00000 1.00000 1.00000 0.00000 0.250000 0.00000 1.00000 1.00000 0.00000 0.250000 1.00000 1.00000 1.00000 1.00000 0.250000 0.00000 1.00000 1.00000 0.00000 0.250000 0.00000 0.00000 1.00000 1.00000 0.250000
# vtk DataFile Version 3.0
#This file was generated
ASCII
DATASET UNSTRUCTURED_GRID

POINTS 30 double
0.00000 0.00000 0.00000
0.00000 1.00000 0.00000
0.00000 1.00000 1.00000
0.00000 0.00000 1.00000
0.500000 0.500000 0.500000
0.00000 1.00000 0.00000
1.00000 1.00000 0.00000
1.00000 1.00000 1.00000
0.00000 1.00000 1.00000
0.500000 0.500000 0.500000
0.00000 1.00000 1.00000
1.00000 1.00000 1.00000
1.00000 0.00000 1.00000
0.00000 0.00000 1.00000
0.500000 0.500000 0.500000
1.00000 0.00000 0.00000
1.00000 0.00000 1.00000
1.00000 1.00000 1.00000
1.00000 1.00000 0.00000
0.500000 0.500000 0.500000
0.00000 0.00000 0.00000
1.00000 0.00000 0.00000
1.00000 1.00000 0.00000
0.00000 1.00000 0.00000
0.500000 0.500000 0.500000
0.00000 0.00000 0.00000
0.00000 0.00000 1.00000
1.00000 0.00000 1.00000
1.00000 0.00000 0.00000
0.500000 0.500000 0.500000

CELLS 6 36
5 0 1 2 3 4
5 5 6 7 8 9
5 10 11 12 13 14
5 15 16 17 18 19
5 20 21 22 23 24
5 25 26 27 28 29

CELL_TYPES 6
14 14 14 14 14 14
POINT_DATA 30

0 comments on commit c2f2736

Please sign in to comment.