File: _grid.cc

package info (click to toggle)
dune-grid 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,248 kB
  • sloc: cpp: 59,108; python: 1,437; perl: 191; makefile: 6; sh: 3
file content (90 lines) | stat: -rw-r--r-- 4,621 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:

#include <dune/grid/common/gridenums.hh>
#include <dune/grid/io/file/vtk/vtkwriter.hh>
#include <dune/grid/common/partitionset.hh>

#include <dune/python/grid/commops.hh>
#include <dune/python/grid/enums.hh>

#include <dune/python/pybind11/pybind11.h>

PYBIND11_MODULE( _grid, module )
{
  // enumeration types from dune-grid

  pybind11::enum_< Dune::PartitionType > partitionType( module, "PartitionType" );
  partitionType.value( "Interior", Dune::InteriorEntity );
  partitionType.value( "Border", Dune::BorderEntity );
  partitionType.value( "Overlap", Dune::OverlapEntity );
  partitionType.value( "Front", Dune::FrontEntity );
  partitionType.value( "Ghost", Dune::GhostEntity );

  pybind11::enum_< Dune::InterfaceType > interfaceType( module, "InterfaceType" );
  interfaceType.value( "InteriorBorder_InteriorBorder", Dune::InteriorBorder_InteriorBorder_Interface );
  interfaceType.value( "InteriorBorder_All", Dune::InteriorBorder_All_Interface );
  interfaceType.value( "Overlap_OverlapFront", Dune::Overlap_OverlapFront_Interface );
  interfaceType.value( "Overlap_All", Dune::Overlap_All_Interface );
  interfaceType.value( "All_All", Dune::All_All_Interface );

  auto addPartition = [](auto &module, auto partition, std::string name) {
    std::string className = name;
    className[0] = std::toupper(name[0]);
    pybind11::class_<decltype(partition)>(module, className.c_str());
    module.attr( name.c_str() ) = pybind11::cast( partition );
  };
  auto partitions = module.def_submodule("Partitions");
  addPartition(partitions, Dune::Partitions::interior, "interior");
  addPartition(partitions, Dune::Partitions::overlap, "overlap");
  addPartition(partitions, Dune::Partitions::ghost, "ghost");
  addPartition(partitions, Dune::Partitions::all, "all");
  addPartition(partitions, Dune::Partitions::interiorBorder, "interiorBorder");
  addPartition(partitions, Dune::Partitions::interiorBorderOverlap, "interiorBorderOverlap");
  addPartition(partitions, Dune::Partitions::interiorBorderOverlapFront, "interiorBorderOverlapFront");

  /*
  pybind11::enum_< Dune::PartitionIteratorType > partIterType( module, "PartitionIteratorType" );
  partIterType.value( "Interior", Dune::Interior_Partition );
  partIterType.value( "InteriorBorder", Dune::InteriorBorder_Partition );
  partIterType.value( "Overlap", Dune::Overlap_Partition );
  partIterType.value( "OverlapFront", Dune::OverlapFront_Partition );
  partIterType.value( "All", Dune::All_Partition );
  partIterType.value( "Ghost", Dune::Ghost_Partition );
  */

  pybind11::enum_< Dune::CommunicationDirection > communicationDirection( module, "CommunicationDirection" );
  communicationDirection.value( "Forward", Dune::ForwardCommunication );
  communicationDirection.value( "Backward", Dune::BackwardCommunication );

  pybind11::enum_< Dune::VTK::OutputType > vtkOutputType( module, "OutputType" );
  vtkOutputType.value( "ascii", Dune::VTK::OutputType::ascii );
  vtkOutputType.value( "base64", Dune::VTK::OutputType::base64 );
  vtkOutputType.value( "appendedraw", Dune::VTK::OutputType::appendedraw );
  vtkOutputType.value( "appendedbase64", Dune::VTK::OutputType::appendedbase64 );

  // enumeration types added by dune-python

  pybind11::enum_< Dune::Python::detail::CommOp > commOps( module, "CommOp" );
  commOps.value( "set", Dune::Python::detail::CommOp::set );
  commOps.value( "add", Dune::Python::detail::CommOp::add );

  pybind11::enum_< Dune::Python::Marker > marker( module, "Marker" );
  marker.value( "coarsen", Dune::Python::Marker::Coarsen );
  marker.value( "keep", Dune::Python::Marker::Keep );
  marker.value( "refine", Dune::Python::Marker::Refine );

  pybind11::enum_< Dune::Python::VTKDataType > vtkDataType( module, "DataType" );
  vtkDataType.value( "CellData", Dune::Python::VTKDataType::CellData );
  vtkDataType.value( "PointData", Dune::Python::VTKDataType::PointData );
  vtkDataType.value( "CellVector", Dune::Python::VTKDataType::CellVector );
  vtkDataType.value( "PointVector", Dune::Python::VTKDataType::PointVector );

  pybind11::enum_< Dune::Python::Reader > reader( module, "reader" );
  reader.value( "dgf", Dune::Python::Reader::dgf );
  reader.value( "dgfString", Dune::Python::Reader::dgfString );
  reader.value( "gmsh", Dune::Python::Reader::gmsh );
  reader.value( "structured", Dune::Python::Reader::structured );
}