Skip to content
Snippets Groups Projects
Commit b668aaef authored by Robert K's avatar Robert K
Browse files

[feature][Python] Python bindings for some of the metagrids.

parent 524f7b2e
No related branches found
No related tags found
1 merge request!1Update to 2.8
......@@ -30,4 +30,9 @@ add_subdirectory(cmake/modules)
add_subdirectory(doc)
add_subdirectory(dune)
# if Python bindings are enabled, include necessary sub directories.
if( DUNE_ENABLE_PYTHONBINDINGS )
add_subdirectory("python")
endif()
finalize_dune_project(GENERATE_CONFIG_H_CMAKE)
#include <dune/grid/spheregrid/grid.hh>
#include <dune/grid/spheregrid/dgfparser.hh>
......@@ -48,13 +48,9 @@ namespace Dune
{
//! type of the SphereGrid entity
typedef typename Grid::template Codim< codim >::Entity Entity;
//! type of the SphereGrid entity pointer
typedef typename Grid::template Codim< codim >::EntityPointer EntityPointer;
//! type of the host entity
typedef typename HostGrid::template Codim< codim >::Entity HostEntity;
//! type of the host entity pointer
typedef typename HostGrid::template Codim< codim >::EntityPointer HostEntityPointer;
};
//! type of the SphereGrid leaf intersection
......
......@@ -14,7 +14,7 @@ namespace Dune
typedef FieldVector< ctype, 3 > DomainVector;
typedef FieldVector< ctype, 3 > RangeVector;
DefaultMapToSphere ( ctype radius = 0.5 ) : radius_( radius ) {}
DefaultMapToSphere ( ctype radius = 1.0 ) : radius_( radius ) {}
RangeVector operator() ( const DomainVector &x ) const
{
......
......@@ -21,6 +21,7 @@ endforeach(_executable ${TESTS})
dune_add_test(NAME test-spheregrid SOURCES test-spheregrid.cc CMAKE_GUARD dune-alugrid_FOUND)
set_property(TARGET test-spheregrid APPEND PROPERTY COMPILE_DEFINITIONS "GRIDDIM=2" "WORLDDIM=3" "ALUGRID_SIMPLEX")
#add_directory_test_target(test_target)
# add_dependencies(${test_target} ${TESTS})
......
......@@ -10,7 +10,9 @@
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/spheregrid.hh>
#include <dune/grid/io/file/dgfparser/dgfwriter.hh>
#include <dune/grid/io/file/vtk/vtkwriter.hh>
#if HAVE_DUNE_ALUGRID
// use overloaded test because intersection test fails for manifold
......@@ -77,12 +79,23 @@ try {
if( argc > 1 )
filename = argv[1];
GridPtr< HostGrid > hostGrid( filename );
GridPtr< HostGrid > hostPtr( filename );
HostGrid& hostGrid = *hostPtr;
hostGrid.globalRefine( 4 );
{
Dune :: VTKWriter< HostGrid :: LeafGridView> vtkWriter(hostGrid.leafGridView());
vtkWriter.write( "orgshpere.vtu" );
}
typedef SphereGrid< HostGrid > Grid;
GridPtr< Grid > gridPtr ( filename );
Grid& grid = *gridPtr;
SphereGrid< HostGrid > grid( *hostGrid, 0.5 );
//grid.loadBalance();
/*
{
std::cout << "Check serial grid" << std::endl;
checkSerial(grid,
......@@ -98,6 +111,12 @@ try {
if (myrank == 0) std::cout << "Check non-conform grid" << std::endl;
checkParallel(grid,0,2, display );
}
*/
{
Dune :: VTKWriter< typename Grid :: LeafGridView> vtkWriter(grid.leafGridView());
vtkWriter.write( "shpere" );
}
return 0;
}
......
add_subdirectory(dune)
configure_file(setup.py.in setup.py)
add_subdirectory(alugrid)
add_python_targets(dune
__init__
)
__import__('pkg_resources').declare_namespace(__name__)
add_python_targets(metagrid
__init__
_grids
)
from ._grids import *
registry = dict()
registry["grid"] = grid_registry
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
import logging
logger = logging.getLogger(__name__)
from dune.common.checkconfiguration import assertHave, ConfigurationError
try:
assertHave("HAVE_DUNE_METAGRID")
def sphereGrid(constructor, dimgrid=2, dimworld=3, elementType=simplex, comm=None, serial=False, **parameters):
from dune.grid.grid_generator import module, getDimgrid
if not dimgrid:
dimgrid = getDimgrid(constructor)
if dimworld is None:
dimworld = dimgrid
if elementType is None:
elementType = parameters.pop("type")
refinement = parameters["refinement"]
if refinement == "conforming":
refinement="Dune::conforming"
elif refinement == "nonconforming":
refinement="Dune::nonconforming"
if not (2 <= dimgrid and dimgrid <= dimworld):
raise KeyError("Parameter error in ALUGrid with dimgrid=" + str(dimgrid) + ": dimgrid has to be either 2 or 3")
if not (2 <= dimworld and dimworld <= 3):
raise KeyError("Parameter error in ALUGrid with dimworld=" + str(dimworld) + ": dimworld has to be either 2 or 3")
if refinement=="Dune::conforming" and elementType=="Dune::cube":
raise KeyError("Parameter error in ALUGrid with refinement=" + refinement + " and type=" + elementType + ": conforming refinement is only available with simplex element type")
typeName = "Dune::SphereGrid< " + hostGrid + " >"
includes = ["dune/alugrid/grid.hh", "dune/alugrid/dgf.hh",
"dune/grid/spheregrid/grid.hh", "dune/grid/spheregrid/dgfparser.hh"]
gridModule = module(includes, typeName)
if comm is not None:
raise Exception("Passing communicator to grid construction is not yet implemented in Python bindings of dune-grid")
return gridModule.LeafGrid(gridModule.reader(constructor, comm))
else:
return gridModule.LeafGrid(gridModule.reader(constructor))
def aluConformGrid(constructor, dimgrid=None, dimworld=None, comm=None, serial=False, **parameters):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::simplex", refinement="Dune::conforming", comm=comm, serial=serial)
def aluCubeGrid(constructor, dimgrid=None, dimworld=None, comm=None, serial=False, **parameters):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::cube", refinement="Dune::nonconforming", comm=comm, serial=serial)
def aluSimplexGrid(constructor, dimgrid=None, dimworld=None, comm=None, serial=False, **parameters):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::simplex", refinement="Dune::nonconforming", comm=comm, serial=serial)
grid_registry = {
"ALU" : aluGrid,
"ALUConform" : aluConformGrid,
"ALUCube" : aluCubeGrid,
"ALUSimplex" : aluSimplexGrid,
}
except ConfigurationError:
grid_registry = {}
pass
if __name__ == "__main__":
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS)
from setuptools import setup, find_packages
pkg = [m for m in "${ProjectPythonRequires}".split(' ') if "dune" not in m]
setup(name="${ProjectName}",
namespace_packages=['dune'],
description="${ProjectDescription}",
version="${ProjectVersionString}",
author="${ProjectAuthor}",
author_email="${ProjectMaintainerEmail}",
packages = find_packages(),
zip_safe = 0,
package_data = {'': ['*.so']},
install_requires = pkg
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment