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

Generalize DataOut::write_vtk for simplex mesh #10701

Merged
merged 1 commit into from
Aug 3, 2020

Conversation

peterrum
Copy link
Member

In the case of triangles and tetrahedrons, the input argument n_subdivisions in DataOut::build_patches() gets a new meaning: the cells are not subdivided. Instead, we switch between linear (5/22) and quadratic (10/24) VTK cell types. See also here (p. 9).

The proposed change enables:

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

#include <deal.II/fe/fe_system.h>
#include <deal.II/fe/mapping_isoparametric.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 <deal.II/simplex/fe_lib.h>
#include <deal.II/simplex/grid_generator.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 unsigned int n_components)
{
  Triangulation<dim, spacedim> tria;
  Simplex::GridGenerator::subdivided_hyper_cube(tria, 2);

  DoFHandler<dim> dof_handler(tria);

  dof_handler.distribute_dofs(fe);

  Vector<double> solution(dof_handler.n_dofs());

  MappingIsoparametric<dim> mapping(Simplex::FE_P<dim>(1));

  VectorTools::interpolate(mapping,
                           dof_handler,
                           RightHandSideFunction<dim>(n_components),
                           solution);

  DataOut<dim> data_out;

  data_out.attach_dof_handler(dof_handler);
  data_out.add_data_vector(solution, "solution");


  data_out.build_patches(mapping, /*1 or*/ 2);

  std::ofstream output("test.vtk");
  data_out.write_vtk(output);
}

int
main()
{
  {
    const unsigned int dim = 2;
    test<dim>(Simplex::FE_P<dim>(2) /*=degree*/, 1);
    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2 /*=degree*/), dim), dim);
    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2 /*=degree*/),
                            dim,
                            Simplex::FE_P<dim>(1 /*=degree*/),
                            1),
              dim + 1);
  }
  {
    const unsigned int dim = 3;
    test<dim>(Simplex::FE_P<dim>(2) /*=degree*/, 1);
    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2 /*=degree*/), dim), dim);
    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2 /*=degree*/),
                            dim,
                            Simplex::FE_P<dim>(1 /*=degree*/),
                            1),
              dim + 1);
  }
}

The code will not compile at the moment because it depends on features from the other PRs.

FYI @DanielPaukner

@agrayver
Copy link
Contributor

the input argument n_subdivisions in DataOut::build_patches() gets a new meaning: the cells are not subdivided

Depending on VtkFlags, the quads/hexes may not be subdivided, but are written as VTK high-order Lagrange cells (#6994 ).

I wonder if this should also be done for simplices as well? Then you have support for arbitrary order cells/elements and the logic of the class will remain in line with hex/quad.

I can help with the VTK part of the implementation if needed.

@peterrum
Copy link
Member Author

I can help with the VTK part of the implementation if needed.

That would be great and very much appreciated! My suggestion is that we get a first working simplex implementation in deal.II (with my current implementation and all the other PRs) and then based on that we can make additional improvementsl

@agrayver
Copy link
Contributor

No problem, I just wanted to bring this up and let you know.

@peterrum
Copy link
Member Author

@agrayver Thanks! I will!

@peterrum peterrum force-pushed the simplex_dataout_write_vtk branch 3 times, most recently from 189c262 to 9364a87 Compare July 27, 2020 19:12
@peterrum
Copy link
Member Author

I have rebased this branch. I will add a test once #10659 is merged. I need the mapping for creating the patches.

Copy link
Member

@kronbichler kronbichler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall, but I have a few comments (and wait for the promised tests).

@@ -851,6 +867,27 @@ namespace
"it."));
}

/**
* Write dim-dimensional cell with @p n_point vertices and first vertex at
* number start and further.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what 'further' means?

@@ -2371,6 +2432,26 @@ namespace DataOutBase

for (const auto &patch : patches)
{
// special treatment of simplices since they are not subdivided, s.t,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// special treatment of simplices since they are not subdivided, s.t,
// special treatment of simplices since they are not subdivided, such that

Comment on lines +2438 to +2450
if (patch.reference_cell_type != ReferenceCell::get_hypercube(dim))
{
Point<spacedim> node;

for (unsigned int point_no = 0; point_no < patch.data.n_cols();
++point_no)
{
for (unsigned int d = 0; d < spacedim; ++d)
node[d] =
patch.data(patch.data.size(0) - spacedim + d, point_no);

out.write_point(count++, node);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will that change once we support higher order simplex elements, i.e., is the if(...) continue code a temporary solution that waits for further code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I would like to keep on having the specialization since it also works (for mixed meshes) and older versions of Paraview.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the specialization for the quadratic version of those or the plain linear one? It is clear that we cannot use the tensor product variant below for simplices. But then my comment simply boils down to the question whether we can restructure the code and properly indent by if / else rather than if ... continue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@peterrum peterrum force-pushed the simplex_dataout_write_vtk branch 2 times, most recently from e3fd7e9 to 2311a9e Compare July 28, 2020 09:19
@peterrum
Copy link
Member Author

@kronbichler I have added the test and applied the suggestions!

@peterrum
Copy link
Member Author

/rebuild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants