Commit dc742799 authored by Andreas Dedner's avatar Andreas Dedner

started on exporting the persistentcontainer - at the moment only .size is

available so not very usefull.
The provided test does demonstrate a segfault problem with uggrid
parent dbfd639c
Pipeline #20259 passed with stage
in 7 minutes and 24 seconds
// -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_PYTHON_GRID_PERSISTENTCONTAINER_HH
#define DUNE_PYTHON_GRID_PERSISTENTCONTAINER_HH
#include <array>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <dune/grid/utility/persistentcontainer.hh>
#include <dune/python/pybind11/pybind11.h>
#include <iostream>
namespace Dune
{
namespace Python
{
// registerPersistentContainer
// ---------------------------
template< class PersistentContainer, class... options >
inline static void registerPersistentContainer ( pybind11::handle scope, pybind11::class_< PersistentContainer, options... > cls )
{
typedef typename PersistentContainer::Grid Grid;
cls.def( pybind11::init( [] ( Grid &grid, int codim ) { return new PersistentContainer( grid, codim ); } ), pybind11::keep_alive< 1, 2 >() );
cls.def_property_readonly( "size", [] ( const PersistentContainer &self ) -> int {
return self.size();
},
R"doc(
return the size of the given persistent container
)doc" );
}
} // namespace Python
} // namespace Dune
#endif // #ifndef DUNE_PYTHON_GRID_PERSISTENTCONTAINER_HH
......@@ -11,6 +11,7 @@
#include <dune/grid/common/mcmgmapper.hh>
#include <dune/python/grid/capabilities.hh>
#include <dune/python/common/logger.hh>
#include <dune/python/pybind11/extensions.h>
#include <dune/python/pybind11/pybind11.h>
......
......@@ -183,6 +183,15 @@ def levelView(hgrid,level):
addAttr(module, module.GridView)
return hgrid._levelView(level)
pcGenerator = SimpleGenerator("PersistentContainer", "Dune::Python")
def persistentContainer(hgrid,codim,dimension):
includes = hgrid._includes + ["dune/python/grid/persistentcontainer.hh"]
typeName = "Dune::PersistentContainer<"+hgrid._typeName+", Dune::FieldVector<double,"+str(dimension)+">>"
moduleName = "persistentcontainer_" + hashIt(typeName)
module = pcGenerator.load(includes, typeName, moduleName)
return module.PersistentContainer(hgrid,codim)
generator = SimpleGenerator("HierarchicalGrid", "Dune::Python")
def module(includes, typeName, *args, **kwargs):
includes = includes + ["dune/python/grid/hierarchical.hh"]
......@@ -195,6 +204,7 @@ def module(includes, typeName, *args, **kwargs):
for d in range(module.LeafGrid.dimension+1):
dune.geometry.module(d)
setattr(module.HierarchicalGrid,"levelView",levelView)
setattr(module.HierarchicalGrid,"persistentContainer",persistentContainer)
return module
......
import dune.grid
import dune.alugrid
from dune.grid import cartesianDomain, gridFunction
domain = dune.grid.cartesianDomain([0,0,0],[2.5,2.5,2.5],[5,5,5])
print("testing ALUCubeGrid")
print("===================")
gridView = dune.alugrid.aluCubeGrid(domain)
pc0 = gridView.hierarchicalGrid.persistentContainer(0,1);
print("PC<0> created",pc0.size)
pc1 = gridView.hierarchicalGrid.persistentContainer(1,1);
print("PC<1> created",pc1.size)
print("testing UGGrid")
print("==============")
gridView = dune.grid.ugGrid(domain)
pc0 = gridView.hierarchicalGrid.persistentContainer(0,1);
print("PC<0> created",pc0.size)
pc1 = gridView.hierarchicalGrid.persistentContainer(1,1);
print("PC<1> created",pc1.size)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment