Skip to content
Snippets Groups Projects
Commit e7236d8a authored by dedner's avatar dedner
Browse files

improved the runtime configuration check for the python package

parent 0fd4b07b
No related branches found
No related tags found
No related merge requests found
from ._grids import *
registry = dict()
registry["grid"] = {
"ALU" : aluGrid,
"ALUConform" : aluConformGrid,
"ALUCube" : aluCubeGrid,
"ALUSimplex" : aluSimplexGrid,
}
registry["grid"] = grid_registry
......@@ -4,66 +4,70 @@ import sys
import logging
logger = logging.getLogger(__name__)
import dune.common.checkconfiguration as checkconfiguration
def aluGrid(constructor, dimgrid=None, dimworld=None, elementType=None, **parameters):
from dune.grid.grid_generator import module, getDimgrid
if not dimgrid:
dimgrid = getDimgrid(constructor)
try:
checkconfiguration.preprocessorTest([ ("#if HAVE_DUNE_ALUGRID","ALUGrid is not available") ])
except checkconfiguration.ConfigurationError as err:
if logger.getEffectiveLevel() == logging.DEBUG:
raise
else:
print("configuration error while creating an ALUGrid, exiting...")
sys.exit(-1)
try:
checkconfiguration.have("HAVE_DUNE_ALUGRID")
except checkconfiguration.ConfigurationError as err:
if logger.getEffectiveLevel() == logging.DEBUG:
raise
else:
print("configuration error while creating an ALUGrid, exiting...")
sys.exit(-1)
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 <= dimworld and dimworld <= 3):
raise KeyError("Parameter error in ALUGrid with dimworld=" + str(dimworld) + ": dimworld has to be either 2 or 3")
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 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::ALUGrid< " + str(dimgrid) + ", " + str(dimworld) + ", " + elementType + ", " + refinement + " >"
includes = ["dune/alugrid/grid.hh", "dune/alugrid/dgf.hh"]
gridModule = module(includes, typeName)
return gridModule.LeafGrid(gridModule.reader(constructor))
def aluConformGrid(constructor, dimgrid=None, dimworld=None, **parameters):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::simplex", refinement="Dune::conforming")
def aluCubeGrid(constructor, dimgrid=None, dimworld=None, **parameters):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::cube", refinement="Dune::nonconforming")
def aluSimplexGrid(constructor, dimgrid=None, dimworld=None):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::simplex", refinement="Dune::nonconforming")
from dune.common.checkconfiguration import have, preprocessorTest, ConfigurationError
try:
have("HAVE_DUNE_ALUGRID")
def aluGrid(constructor, dimgrid=None, dimworld=None, elementType=None, **parameters):
from dune.grid.grid_generator import module, getDimgrid
if not dimgrid:
dimgrid = getDimgrid(constructor)
try:
preprocessorTest([ ("#if HAVE_DUNE_ALUGRID","ALUGrid is not available") ])
except checkconfiguration.ConfigurationError as err:
if logger.getEffectiveLevel() == logging.DEBUG:
raise
else:
print("configuration error while creating an ALUGrid, exiting...")
sys.exit(-1)
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 <= dimworld and dimworld <= 3):
raise KeyError("Parameter error in ALUGrid with dimworld=" + str(dimworld) + ": dimworld has to be either 2 or 3")
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 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::ALUGrid< " + str(dimgrid) + ", " + str(dimworld) + ", " + elementType + ", " + refinement + " >"
includes = ["dune/alugrid/grid.hh", "dune/alugrid/dgf.hh"]
gridModule = module(includes, typeName)
return gridModule.LeafGrid(gridModule.reader(constructor))
def aluConformGrid(constructor, dimgrid=None, dimworld=None, **parameters):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::simplex", refinement="Dune::conforming")
def aluCubeGrid(constructor, dimgrid=None, dimworld=None, **parameters):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::cube", refinement="Dune::nonconforming")
def aluSimplexGrid(constructor, dimgrid=None, dimworld=None):
return aluGrid(constructor, dimgrid, dimworld, elementType="Dune::simplex", refinement="Dune::nonconforming")
grid_registry = {
"ALU" : aluGrid,
"ALUConform" : aluConformGrid,
"ALUCube" : aluCubeGrid,
"ALUSimplex" : aluSimplexGrid,
}
except ConfigurationError:
grid_registry = {}
pass
if __name__ == "__main__":
import doctest
......
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