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

DataOut: add wedge/pyramid test #12851

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
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: 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