Commit f02456d3 authored by Andreas Dedner's avatar Andreas Dedner

[!126] fixed a bug in the venv detection that failed with python3's venv

Merge branch 'bugfix/venv-issue' into 'master'

ref:staging/dune-python Also:

-   sort and make the header files unique in the generated cc files - this
    fixs avoid long header lists
-   added better subfigure treatment to plot command
-   fixed a few warning

See merge request [!126]

  [!126]: gitlab.dune-project.org/staging/dune-python/merge_requests/126
parents 8a67e439 6ad10e5e
Pipeline #18468 failed with stage
in 6 minutes and 41 seconds
......@@ -70,7 +70,7 @@ namespace Dune
{
const int dimWorld = Grid::dimensionworld;
for( std::size_t i = 0; i < info.shape[ 0 ]; ++i )
for( int i = 0; i < info.shape[ 0 ]; ++i )
{
const std::size_t offset = i * (info.strides[ 0 ] / sizeof( T ));
FieldVector< typename Grid::ctype, dimWorld > x;
......@@ -133,7 +133,7 @@ namespace Dune
{
const int dimGrid = Grid::dimension;
const std::size_t numVertices = ReferenceElements< typename Grid::ctype, dimGrid >::general( type ).size( dimGrid );
const int numVertices = ReferenceElements< typename Grid::ctype, dimGrid >::general( type ).size( dimGrid );
if( (info.ndim != 2) || (info.shape[ 1 ] != numVertices) )
{
std::ostringstream msg;
......@@ -146,10 +146,10 @@ namespace Dune
}
std::vector< unsigned int > vertices( numVertices );
for( std::size_t i = 0; i < info.shape[ 0 ]; ++i )
for( int i = 0; i < info.shape[ 0 ]; ++i )
{
const std::size_t offset = i * (info.strides[ 0 ] / sizeof( T ));
for( std::size_t j = 0; j < numVertices; ++j )
for( int j = 0; j < numVertices; ++j )
vertices[ j ] = static_cast< T * >( info.ptr )[ offset + j * (info.strides[ 1 ] / sizeof( T )) ];
factory.insertElement( type, vertices );
}
......
......@@ -411,7 +411,7 @@ namespace Dune
throw pybind11::value_error( "Argument 'entity' is not a valid entity for this grid." );
}, "entity"_a,
R"doc(
Check whether an entity is contained in this grid
Check whether an entity is contained in the grid instance
Args:
entity: entity to check
......
......@@ -448,7 +448,6 @@ def get_default_build_args():
return None
def build_module(builddir, build_args=None):
if build_args is None:
build_args = get_default_build_args()
......@@ -463,6 +462,17 @@ def build_module(builddir, build_args=None):
raise RuntimeError(buffer_to_str(stderr))
return buffer_to_str(stdout)
def inVEnv():
# If sys.real_prefix exists, this is a virtualenv set up with the virtualenv package
real_prefix = hasattr(sys, 'real_prefix')
if real_prefix:
return 1
# If a virtualenv is set up with pyvenv, we check for equality of base_prefix and prefix
if hasattr(sys, 'base_prefix'):
return (sys.prefix != sys.base_prefix)
# If none of the above conditions triggered, this is probably no virtualenv interpreter
return 0
def get_dune_py_dir():
try:
......@@ -473,12 +483,9 @@ def get_dune_py_dir():
pass
# test if in virtual env
try:
realPath = sys.real_prefix
if inVEnv():
virtualEnvPath = sys.prefix
return os.path.join(virtualEnvPath, '.cache', 'dune-py')
except AttributeError:
pass
# generate in home directory
try:
......
......@@ -58,6 +58,7 @@ def load(functionName, includes, *args):
signature = functionName + "( " + ", ".join(argTypes) + " )"
moduleName = "algorithm_" + hashIt(signature) + "_" + hashIt(source)
includes = sorted(set(includes))
source += "".join(["#include <" + i + ">\n" for i in includes])
source += "\n"
source += '#include <dune/python/common/typeregistry.hh>\n'
......
......@@ -118,6 +118,8 @@ class SimpleGenerator(object):
includes = includes[0]
else:
allIncludes = includes
allIncludes = sorted(set(allIncludes))
includes = sorted(set(includes))
source = self.pre(allIncludes, typeName[0], moduleName, defines, preamble)
for nr, (tn, a, o, b, d) in enumerate( zip(typeName, args, options, bufferProtocol, dynamicAttr) ):
source += self.main(nr, includes, tn, *a, options=o, bufferProtocol=b, dynamicAttr=d)
......
......@@ -30,6 +30,13 @@ def plotGrid(grid, gridLines="black", figure=None,
if figure is None:
figure = pyplot.figure(figsize=figsize)
else:
try:
subPlot = figure[1]
figure = figure[0]
pyplot.subplot(subPlot)
except:
pass
_plotGrid(figure, grid, gridLines=gridLines)
......@@ -87,7 +94,9 @@ def _plotData(fig, grid, solution, level=0, gridLines="black",
levels = linspace(clim[0], clim[1], 256, endpoint=True)
pyplot.tricontourf(triangulation, data, cmap=cmap, levels=levels, extend="both")
if colorbar:
if colorbar is not None and colorbar:
if isinstance(colorbar,bool):
colorbar="vertical"
# having extend not 'both' does not seem to work (needs fixing)...
if clim[0] > minData and clim[1] < maxData:
extend = 'both'
......@@ -99,7 +108,7 @@ def _plotData(fig, grid, solution, level=0, gridLines="black",
extend = 'neither'
v = linspace(clim[0], clim[1], 10, endpoint=True)
norm = matplotlib.colors.Normalize(vmin=clim[0], vmax=clim[1])
cbar = pyplot.colorbar(orientation="vertical",shrink=1.0,
cbar = pyplot.colorbar(orientation=colorbar,shrink=1.0,
extend=extend, norm=norm, ticks=v)
cbar.ax.tick_params(labelsize=18)
else:
......@@ -129,7 +138,9 @@ def _plotData(fig, grid, solution, level=0, gridLines="black",
vert.append(q)
coll = PolyCollection(vert, array=data, edgecolor=gridLines, linewidth=0.5, zorder=2, cmap=cmap)
pyplot.gca().add_collection(coll)
if colorbar:
if colorbar is not None or colorbar:
if isinstance(colorbar,bool):
colorbar="vertical"
# having extend not 'both' does not seem to work (needs fixing)...
if clim[0] > minData and clim[1] < maxData:
extend = 'both'
......@@ -141,7 +152,7 @@ def _plotData(fig, grid, solution, level=0, gridLines="black",
extend = 'neither'
v = linspace(clim[0], clim[1], 10, endpoint=True)
norm = matplotlib.colors.Normalize(vmin=clim[0], vmax=clim[1])
cbar = pyplot.colorbar(coll, orientation="vertical",shrink=1.0,
cbar = pyplot.colorbar(coll, orientation=colorbar,shrink=1.0,
extend=extend, norm=norm, ticks=v)
cbar.ax.tick_params(labelsize=18)
......@@ -171,6 +182,12 @@ def plotPointData(solution, level=0, gridLines="black",
figure = pyplot.figure(figsize=figsize)
show = True
else:
try:
subPlot = figure[1]
figure = figure[0]
pyplot.subplot(subPlot)
except:
pass
show = False
_plotData(figure,grid,solution,level,gridLines,None,
vectors,nofVectors,xlim,ylim,clim,cmap,
......
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