mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-10-24 22:57:42 -05:00
Add Python gas-water simulator and refactor to template base class
Extend the Python blackoil simulator to support two-phase gas-water simulations by extracting common functionality into a template base class and implementing proper module separation. - Extract PyBaseSimulator<TypeTag> template base class containing all common simulator functionality (20+ methods including advance, run, step, property access, and MPI handling) - Add PyGasWaterSimulator for two-phase gas-water simulations using FlowGasWaterProblem TypeTag with oil phase disabled - Split Python modules to avoid ODR violations: - BlackOil.so for PyBlackOilSimulator (FlowProblemTPFA) - GasWater.so for PyGasWaterSimulator (FlowGasWaterProblem) - Implement proper template instantiation control with explicit instantiations per module - Eliminate ~400 lines of code duplication between simulators - Clean inheritance hierarchy: derived classes contain only constructors - Type-safe specialization through OPM's TypeTag property system - Separate docstring generation for each simulator type - Independent build targets with shared infrastructure - Update CMakeLists.txt to support multiple pybind11 modules - Add docstrings_gw_simulators.json for gas-water simulator documentation - Remove centralized Pybind11Exporter.cpp in favor of distributed exports - Implement proper build dependencies and custom targets This establishes a scalable foundation for extending OPM's Python bindings to support additional simulator types (thermal, polymer, solvent) while maintaining type safety and avoiding symbol conflicts. Files changed: 21 files, 915 insertions, 428 deletions
This commit is contained in:
1 parent
4ca1699c78
commit
32dd09c78f
18 files changed
+906
-420
No files matched your search
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"PyGasWaterSimulator":{
|
||||
"type": "class",
|
||||
"signature": "opm.simulators.GasWaterSimulator",
|
||||
"doc": "The GasWaterSimulator class to run simulations using a given Deck."
|
||||
},
|
||||
"PyGasWaterSimulator_filename_constructor": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.__init__(deck_filename: str, args: list[str] = []) -> GasWaterSimulator",
|
||||
"doc": "Constructor using a deck file name.\n\n:param deck_filename: The file name of the deck to be used for the simulation.\n:type deck_filename: str\n:param args: Simulator options.\n:type args: list[str]\n:return: The GasWaterSimulator.\n:type return: GasWaterSimulator"
|
||||
},
|
||||
"PyGasWaterSimulator_objects_constructor": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.__init__(deck: Deck, state: EclipseState, schedule: Schedule, summary_config: SummaryConfig, args: list[str] = []) -> GasWaterSimulator",
|
||||
"doc": "Constructor using Deck, EclipseState, Schedule, and SummaryConfig objects.\n\n:param deck: Deck object.\n:type deck: Deck\n:param state: EclipseState object.\n:type state: EclipseState\n:param schedule: Schedule object.\n:type schedule: Schedule\n:param summary_config: SummaryConfig object.\n:type summary_config: SummaryConfig\n:param args: Simulator options.\n:type args: list[str]\n:return: The GasWaterSimulator.\n:type return: GasWaterSimulator"
|
||||
},
|
||||
"advance": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.advance(report_step: int) -> None",
|
||||
"doc": "Advances the simulation to a specific report step.\n\n:param report_step: Target report step to advance to.\n:type report_step: int"
|
||||
},
|
||||
"checkSimulationFinished": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.check_simulation_finished() -> bool",
|
||||
"doc": "Checks if the simulation has finished.\n\n:return: True if the simulation is finished, False otherwise.\n:type return: bool"
|
||||
},
|
||||
"currentStep": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.current_step() -> int",
|
||||
"doc": "Gets the current simulation step.\n\n:return: The current step number."
|
||||
},
|
||||
"getCellVolumes": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.get_cell_volumes() -> NDArray[float]",
|
||||
"doc": "Retrieves the cell volumes of the simulation grid.\n\n:return: An array of cell volumes.\n:type return: NDArray[float]"
|
||||
},
|
||||
"getDT": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.get_dt() -> float",
|
||||
"doc": "Gets the timestep size of the last completed step.\n\n:return: Timestep size in days.\n:type return: float"
|
||||
},
|
||||
"getFluidStateVariable": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.get_fluid_state_variable(name: str) -> NDArray[float]",
|
||||
"doc": "Retrieves a fluid state variable for the simulation grid.\n\n:param name: The name of the variable. Valid names are 'pw' (pressure water), 'pg' (pressure gas), 'po' (pressure oil), 'rho_w' (density water), 'rho_g' (density gas), 'rho_o' (density oil)'Rs' (soultion gas-oil ratio), 'Rv' (volatile gas-oil ratio), 'Sw' (water saturation), 'Sg' (gas saturation), 'So' (oil saturation), and 'T' (temperature).\n:type name: str\n\n:return: An array of fluid state variables.\n:type return: NDArray[float]"
|
||||
},
|
||||
"getPorosity": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.get_porosity() -> NDArray[float]",
|
||||
"doc": "Retrieves the porosity values of the simulation grid.\n\n:return: An array of porosity values.\n:type return: numpy.ndarray"
|
||||
},
|
||||
"getPrimaryVarMeaning": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.get_primary_var_meaning(variable: str) -> NDArray[int]",
|
||||
"doc": "Retrieves the primary variable meaning of the simulation grid.\n\n:param variable: The name of the variable. Valid names are 'pressure', 'water', 'gas', and 'brine'.\n:type variable: str\n\n:return: An array of primary variable meanings. See ``get_primary_variable_meaning_map()`` for more information.\n:type return: NDArray[int]"
|
||||
},
|
||||
"getPrimaryVarMeaningMap": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.get_primary_var_meaning_map(variable: str) -> dict[str, int]",
|
||||
"doc": "Retrieves the primary variable meaning map for each primary variable.\n\n:param variable: The name of the variable. Valid names are 'pressure', 'water', 'gas', and 'brine'.\n:type variable: str\n\n:return: A dictionary of primary variable meanings. The keys are the primary variable meanings and the values are the corresponding integer codes. The integer codes are used to represent the primary variable meanings in the simulation grid. For variable name 'pressure', the valid keys are: 'Po', 'Pg', and 'Pw', for variable name 'water', the valid keys are: 'Sw', 'Rvw', 'Rsw', and 'Disabled', for variable name 'gas', the valid keys are: 'Sg', 'Rs', 'Rv', and 'Disabled', for variable name 'brine', the valid keys are: 'Cs', 'Sp', and 'Disabled'.\n:type return: dict[str, int]"
|
||||
},
|
||||
"getPrimaryVariable": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.get_primary_variable(variable: str) -> NDArray[float]",
|
||||
"doc": "Retrieves the primary variable's values for the simulation grid.\n\n:param variable: The name of the variable. Valid names are 'pressure', 'water', 'gas', and 'brine'.\n:type variable: str\n\n:return: An array of primary variable values. See ``get_primary_variable_meaning()`` for more information.\n:type return: NDArray[float]"
|
||||
},
|
||||
"run": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.run() -> int",
|
||||
"doc": "Runs the simulation to completion with the provided deck file or previously set deck.\n\n:return: EXIT_SUCCESS if the simulation completes successfully."
|
||||
},
|
||||
"setPorosity": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.set_porosity(array: NDArray[float]) -> None",
|
||||
"doc": "Sets the porosity values for the simulation grid.\n\n:param array: An array of porosity values to be set.\n:type array: NDArray[float]"
|
||||
},
|
||||
"setPrimaryVariable": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.set_primary_variable(variable: str, value: NDArray[float]) -> None",
|
||||
"doc": "Sets the primary variable's values for the simulation grid.\n\n:param variable: The name of the variable. Valid names are 'pressure', 'water', 'gas', and 'brine'.\n:type variable: str\n:param value: An array of primary variable values to be set. See ``get_primary_variable()`` for more information.\n:type value: NDArray[float]"
|
||||
},
|
||||
"setupMpi": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.mpi_init(init: bool, finalize: bool) -> None",
|
||||
"doc": "Sets MPI up for parallel simulation. This method should be called before any other method.\n\n:param init: Whether to call ``MPI_Init()`` or not.\n:param finalize: Whether to call ``MPI_Finalize()```when the simulator object goes out of scope.\n\n:return: None"
|
||||
},
|
||||
"step": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.step() -> int",
|
||||
"doc": "Executes the next simulation report step.\n\n:return: Result of the simulation step."
|
||||
},
|
||||
"stepCleanup": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.step_cleanup() -> int",
|
||||
"doc": "Performs cleanup after the last simulation step.\n\n:return: EXIT_SUCCESS if cleanup is successful."
|
||||
},
|
||||
"stepInit": {
|
||||
"signature": "opm.simulators.GasWaterSimulator.step_init() -> int",
|
||||
"doc": "Initializes the simulation before taking the first report step. This method should be called before the first call to ``step()``\n\n:return: EXIT_SUCCESS if the initialization is successful."
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@
|
||||
"doc": "The BlackOilSimulator class to run simulations using a given Deck."
|
||||
},
|
||||
"PyBlackOilSimulator_filename_constructor": {
|
||||
"signature": "opm.simulators.BlackOilSimulator.__init__(deck_filename: str) -> BlackOilSimulator",
|
||||
"doc": "Constructor using a deck file name.\n\n:param deck_filename: The file name of the deck to be used for the simulation.\n:type deck_filename: str\n:return: The BlackOilSimulator.\n:type return: BlackOilSimulator"
|
||||
"signature": "opm.simulators.BlackOilSimulator.__init__(deck_filename: str, args: list[str] = []) -> BlackOilSimulator",
|
||||
"doc": "Constructor using a deck file name.\n\n:param deck_filename: The file name of the deck to be used for the simulation.\n:type deck_filename: str\n:param args: Simulator options.\n:type args: list[str]\n:return: The BlackOilSimulator.\n:type return: BlackOilSimulator"
|
||||
},
|
||||
"PyBlackOilSimulator_objects_constructor": {
|
||||
"signature": "opm.simulators.BlackOilSimulator.__init__(deck: Deck, state: EclipseState, schedule: Schedule, summary_config: SummaryConfig) -> BlackOilSimulator",
|
||||
"doc": "Constructor using Deck, EclipseState, Schedule, and SummaryConfig objects.\n\n:param deck: Deck object.\n:type deck: Deck\n:param state: EclipseState object.\n:type state: EclipseState\n:param schedule: Schedule object.\n:type schedule: Schedule\n:param summary_config: SummaryConfig object.\n:type summary_config: SummaryConfig\n:return: The BlackOilSimulator.\n:type return: BlackOilSimulator"
|
||||
"signature": "opm.simulators.BlackOilSimulator.__init__(deck: Deck, state: EclipseState, schedule: Schedule, summary_config: SummaryConfig, args: list[str] = []) -> BlackOilSimulator",
|
||||
"doc": "Constructor using Deck, EclipseState, Schedule, and SummaryConfig objects.\n\n:param deck: Deck object.\n:type deck: Deck\n:param state: EclipseState object.\n:type state: EclipseState\n:param schedule: Schedule object.\n:type schedule: Schedule\n:param summary_config: SummaryConfig object.\n:type summary_config: SummaryConfig\n:param args: Simulator options.\n:type args: list[str]\n:return: The BlackOilSimulator.\n:type return: BlackOilSimulator"
|
||||
},
|
||||
"advance": {
|
||||
"signature": "opm.simulators.BlackOilSimulator.advance(report_step: int) -> None",
|
||||
|
||||
@@ -9,4 +9,5 @@
|
||||
# where FoamSimulator and PurePythonUtils does not currently exists,
|
||||
# but could be possible future extensions..
|
||||
#
|
||||
from .simulators import BlackOilSimulator
|
||||
from .BlackOil import BlackOilSimulator
|
||||
from .GasWater import GasWaterSimulator
|
||||
+6
-1
@@ -33,7 +33,12 @@ setup(
|
||||
'opm',
|
||||
'opm.simulators'
|
||||
],
|
||||
package_data={'opm' : ['$<TARGET_FILE_NAME:simulators>']},
|
||||
package_data={
|
||||
'opm': [
|
||||
'$<TARGET_FILE_NAME:BlackOil>',
|
||||
'$<TARGET_FILE_NAME:GasWater>'
|
||||
]
|
||||
},
|
||||
include_package_data=True,
|
||||
# SPDX license expression to replace deprecated license classifier usage.
|
||||
license='GPL-3.0-or-later',
|
||||
|
||||
@@ -3,6 +3,8 @@ set(PYTHON_OPM_SIMULATORS_PACKAGE_PATH ${PROJECT_BINARY_DIR}/python/opm/simulato
|
||||
# Set the path to the input docstrings.json file and the output .hpp file
|
||||
set(PYTHON_DOCSTRINGS_FILE "${PROJECT_SOURCE_DIR}/python/docstrings_simulators.json")
|
||||
set(PYTHON_DOCSTRINGS_GENERATED_HPP "${PROJECT_BINARY_DIR}/python/PyBlackOilSimulatorDoc.hpp")
|
||||
set(PYTHON_GW_DOCSTRINGS_FILE "${PROJECT_SOURCE_DIR}/python/docstrings_gw_simulators.json")
|
||||
set(PYTHON_GW_DOCSTRINGS_GENERATED_HPP "${PROJECT_BINARY_DIR}/python/PyGasWaterSimulatorDoc.hpp")
|
||||
# Note: If the new find_package(Python3) is used in the top level CMakeLists.txt, the variable
|
||||
# ${PYTHON_EXECUTABLE} is set there to ${Python3_EXECUTABLE}
|
||||
#
|
||||
@@ -20,6 +22,14 @@ add_custom_command(
|
||||
DEPENDS ${PYTHON_DOCSTRINGS_FILE}
|
||||
COMMENT "Generating PyBlackOilSimulatorDoc.hpp from JSON file"
|
||||
)
|
||||
add_custom_command(
|
||||
OUTPUT ${PYTHON_GW_DOCSTRINGS_GENERATED_HPP}
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_SOURCE_DIR}
|
||||
${PYTHON_EXECUTABLE} ${PYTHON_GENERATE_DOCSTRINGS_PY}
|
||||
${PYTHON_GW_DOCSTRINGS_FILE} ${PYTHON_GW_DOCSTRINGS_GENERATED_HPP} PYGASWATERSIMULATORDOC_HPP "Opm::Pybind::DocStrings"
|
||||
DEPENDS ${PYTHON_GW_DOCSTRINGS_FILE}
|
||||
COMMENT "Generating PyGasWaterSimulatorDoc.hpp from JSON file"
|
||||
)
|
||||
# NOTE: The variable ${PYBIND11_SYSTEM} is set in python/CMakeLists.txt
|
||||
# to the value "SYSTEM" or unset, depending on the current version of Pybind11.
|
||||
# The value is then forwarded to target_include_directories(), see
|
||||
@@ -27,21 +37,66 @@ add_custom_command(
|
||||
# https://cmake.org/cmake/help/latest/command/target_include_directories.html
|
||||
# https://pybind11.readthedocs.io/en/stable/compiling.html
|
||||
#
|
||||
pybind11_add_module(simulators ${PYBIND11_SYSTEM}
|
||||
pybind11_add_module(BlackOil ${PYBIND11_SYSTEM}
|
||||
$<TARGET_OBJECTS:moduleVersion>
|
||||
Pybind11Exporter.cpp
|
||||
PyBlackOilSimulator.cpp
|
||||
${PYTHON_DOCSTRINGS_GENERATED_HPP} # Include the generated .hpp as a source file
|
||||
)
|
||||
|
||||
pybind11_add_module(GasWater ${PYBIND11_SYSTEM}
|
||||
$<TARGET_OBJECTS:moduleVersion>
|
||||
PyGasWaterSimulator.cpp
|
||||
${PYTHON_GW_DOCSTRINGS_GENERATED_HPP} # Include the generated .hpp as a source file
|
||||
)
|
||||
|
||||
set_target_properties( simulators PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYTHON_OPM_SIMULATORS_PACKAGE_PATH} )
|
||||
find_file(PYTHON_INSTALL_PY install.py
|
||||
PATHS ${opm-common_DIR} ${opm-common_PYTHON_COMMON_DIR}
|
||||
PATH_SUFFIXES python NO_DEFAULT_PATH REQUIRED)
|
||||
|
||||
target_link_libraries( simulators PRIVATE opmsimulators )
|
||||
# Add the binary (build) directory to the include directories for the target
|
||||
# NOTE: instead of using file( COPY ...) which copies the files at configure time (not at build time)
|
||||
# we should add copying of the files at build time such that running "make" or "make all" will
|
||||
# update the files if they have been modified. We use the install.py script in opm-common, see also
|
||||
# CMakeLists.txt in opm-common
|
||||
add_custom_target(copy_python ALL
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${PYTHON_INSTALL_PY}"
|
||||
${PROJECT_SOURCE_DIR}/python/opm ${PROJECT_BINARY_DIR}/python 0
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${PYTHON_INSTALL_PY}"
|
||||
${PROJECT_SOURCE_DIR}/python/test ${PROJECT_BINARY_DIR}/python 0
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${PYTHON_INSTALL_PY}"
|
||||
${PROJECT_SOURCE_DIR}/python/test_data ${PROJECT_BINARY_DIR}/python 0
|
||||
)
|
||||
|
||||
# Add the build directory where the generated hpp file will be
|
||||
# to the include directories for the target
|
||||
target_include_directories(simulators PRIVATE ${PROJECT_BINARY_DIR}/python)
|
||||
foreach(target_name IN ITEMS BlackOil GasWater)
|
||||
set_target_properties(
|
||||
${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYTHON_OPM_SIMULATORS_PACKAGE_PATH}
|
||||
)
|
||||
target_link_libraries( ${target_name} PRIVATE opmsimulators )
|
||||
# Add the binary (build) directory to the include directories for the target
|
||||
|
||||
# Add the build directory where the generated hpp file will be
|
||||
# to the include directories for the target
|
||||
target_include_directories(${target_name} PRIVATE ${PROJECT_BINARY_DIR}/python)
|
||||
add_dependencies(${target_name} copy_python)
|
||||
|
||||
# Since the installation of Python code is nonstandard it is protected by an
|
||||
# extra cmake switch, OPM_INSTALL_PYTHON. If you prefer you can still invoke
|
||||
# setup.py install manually - optionally with the generated script
|
||||
# setup-install.sh - and completely bypass cmake in the installation phase.
|
||||
if (OPM_INSTALL_PYTHON)
|
||||
include(PyInstallPrefix) # from opm-common
|
||||
install(
|
||||
TARGETS ${target_name}
|
||||
DESTINATION ${DEST_PREFIX}${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX}/opm
|
||||
)
|
||||
install(
|
||||
CODE "execute_process(
|
||||
COMMAND ${PYTHON_EXECUTABLE}
|
||||
${PYTHON_INSTALL_PY}
|
||||
${PROJECT_BINARY_DIR}/python/opm
|
||||
${DEST_PREFIX}${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX} 1)"
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "
|
||||
import site, sys
|
||||
@@ -74,30 +129,12 @@ if(OPM_ENABLE_PYTHON_TESTS)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
find_file(PYTHON_INSTALL_PY install.py
|
||||
PATHS ${opm-common_DIR} ${opm-common_PYTHON_COMMON_DIR}
|
||||
PATH_SUFFIXES python NO_DEFAULT_PATH REQUIRED)
|
||||
|
||||
# NOTE: instead of using file( COPY ...) which copies the files at configure time (not at build time)
|
||||
# we should add copying of the files at build time such that running "make" or "make all" will
|
||||
# update the files if they have been modified. We use the install.py script in opm-common, see also
|
||||
# CMakeLists.txt in opm-common
|
||||
add_custom_target(copy_python ALL
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${PYTHON_INSTALL_PY}"
|
||||
${PROJECT_SOURCE_DIR}/python/opm ${PROJECT_BINARY_DIR}/python 0
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${PYTHON_INSTALL_PY}"
|
||||
${PROJECT_SOURCE_DIR}/python/test ${PROJECT_BINARY_DIR}/python 0
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${PYTHON_INSTALL_PY}"
|
||||
${PROJECT_SOURCE_DIR}/python/test_data ${PROJECT_BINARY_DIR}/python 0
|
||||
)
|
||||
|
||||
file(COPY ${PROJECT_SOURCE_DIR}/python/opm/CMakeLists.txt DESTINATION ${PROJECT_BINARY_DIR}/python)
|
||||
file(COPY ${PROJECT_SOURCE_DIR}/python/requirements.txt DESTINATION ${PROJECT_BINARY_DIR}/python)
|
||||
file(COPY ${PROJECT_SOURCE_DIR}/python/README.md DESTINATION ${PROJECT_BINARY_DIR}/python)
|
||||
file(COPY ${PROJECT_SOURCE_DIR}/python/MANIFEST.in DESTINATION ${PROJECT_BINARY_DIR}/python)
|
||||
file(COPY ${PROJECT_SOURCE_DIR}/python/pyproject.toml DESTINATION ${PROJECT_BINARY_DIR}/python)
|
||||
|
||||
|
||||
set(opm-simulators_PYTHON_PACKAGE_VERSION ${OPM_PYTHON_PACKAGE_VERSION_TAG})
|
||||
|
||||
# Generate versioned setup.py
|
||||
@@ -106,19 +143,4 @@ configure_file(${PROJECT_SOURCE_DIR}/python/setup.py.in
|
||||
file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/python/setup.py
|
||||
INPUT ${PROJECT_BINARY_DIR}/python/setup.py.tmp)
|
||||
|
||||
add_dependencies(simulators copy_python)
|
||||
|
||||
# Since the installation of Python code is nonstandard it is protected by an
|
||||
# extra cmake switch, OPM_INSTALL_PYTHON. If you prefer you can still invoke
|
||||
# setup.py install manually - optionally with the generated script
|
||||
# setup-install.sh - and completely bypass cmake in the installation phase.
|
||||
if (OPM_INSTALL_PYTHON)
|
||||
include(PyInstallPrefix) # from opm-common
|
||||
install(TARGETS simulators DESTINATION ${DEST_PREFIX}${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX}/opm)
|
||||
install(
|
||||
CODE "execute_process(
|
||||
COMMAND ${PYTHON_EXECUTABLE}
|
||||
${PYTHON_INSTALL_PY}
|
||||
${PROJECT_BINARY_DIR}/python/opm
|
||||
${DEST_PREFIX}${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX} 1)")
|
||||
endif()
|
||||
@@ -18,13 +18,6 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <opm/input/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/input/eclipse/Schedule/Schedule.hpp>
|
||||
#include <opm/input/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
|
||||
#include <opm/simulators/flow/FlowMain.hpp>
|
||||
//#include <opm/simulators/flow/python/PyFluidState.hpp>
|
||||
#include <opm/simulators/flow/python/PyMaterialState.hpp>
|
||||
#include <opm/simulators/flow/python/PyBlackOilSimulator.hpp>
|
||||
// NOTE: This file will be generated at compile time and placed in the build directory
|
||||
// See python/generate_docstring_hpp.py, and python/simulators/CMakeLists.txt for details
|
||||
@@ -34,267 +27,41 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
// NOTE: We need the below explicit instantiations or else the symbols
|
||||
// will not be available in the shared library and we will get
|
||||
// undefined symbol errors when trying to import the module in Python.
|
||||
namespace Opm::Pybind {
|
||||
|
||||
template class PyBaseSimulator<Opm::Properties::TTag::FlowProblemTPFA>;
|
||||
|
||||
} // namespace Opm::Pybind
|
||||
|
||||
namespace Opm {
|
||||
|
||||
std::unique_ptr<FlowMain<Properties::TTag::FlowProblemTPFA>>
|
||||
flowBlackoilTpfaMainInit(int argc, char** argv, bool outputCout, bool outputFiles)
|
||||
{
|
||||
// we always want to use the default locale, and thus spare us the trouble
|
||||
// with incorrect locale settings.
|
||||
resetLocale();
|
||||
template class PyMain<Opm::Properties::TTag::FlowProblemTPFA>;
|
||||
template std::unique_ptr<FlowMain<Opm::Properties::TTag::FlowProblemTPFA>>
|
||||
flowMainInit<Opm::Properties::TTag::FlowProblemTPFA>(
|
||||
int argc, char** argv, bool outputCout, bool outputFiles);
|
||||
|
||||
return std::make_unique<FlowMain<Properties::TTag::FlowProblemTPFA>>(
|
||||
argc, argv, outputCout, outputFiles);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Opm
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace Opm::Pybind {
|
||||
PyBlackOilSimulator::PyBlackOilSimulator(const std::string& deck_filename,
|
||||
const std::vector<std::string>& args)
|
||||
: deck_filename_{deck_filename}
|
||||
, args_{args}
|
||||
{
|
||||
}
|
||||
|
||||
PyBlackOilSimulator::PyBlackOilSimulator(
|
||||
std::shared_ptr<Opm::Deck> deck,
|
||||
std::shared_ptr<Opm::EclipseState> state,
|
||||
std::shared_ptr<Opm::Schedule> schedule,
|
||||
std::shared_ptr<Opm::SummaryConfig> summary_config
|
||||
)
|
||||
: deck_{std::move(deck)}
|
||||
, eclipse_state_{std::move(state)}
|
||||
, schedule_{std::move(schedule)}
|
||||
, summary_config_{std::move(summary_config)}
|
||||
{
|
||||
}
|
||||
|
||||
// Public methods alphabetically sorted
|
||||
// ------------------------------------
|
||||
|
||||
void PyBlackOilSimulator::advance(int report_step)
|
||||
{
|
||||
while (currentStep() < report_step) {
|
||||
step();
|
||||
}
|
||||
}
|
||||
|
||||
bool PyBlackOilSimulator::checkSimulationFinished()
|
||||
{
|
||||
return getFlowMain().getSimTimer()->done();
|
||||
}
|
||||
|
||||
// This returns the report step number that will be executed next time step()
|
||||
// is called.
|
||||
int PyBlackOilSimulator::currentStep()
|
||||
{
|
||||
return getFlowMain().getSimTimer()->currentStepNum();
|
||||
// NOTE: this->simulator_->episodeIndex() would also return the current
|
||||
// report step number, but this number is always delayed by 1 step relative
|
||||
// to this->flow_main_->getSimTimer()->currentStepNum()
|
||||
// See details in runStep() in file SimulatorFullyImplicitBlackoilEbos.hpp
|
||||
}
|
||||
|
||||
py::array_t<double> PyBlackOilSimulator::getCellVolumes() {
|
||||
auto vector = getMaterialState().getCellVolumes();
|
||||
return py::array(vector.size(), vector.data());
|
||||
}
|
||||
|
||||
double PyBlackOilSimulator::getDT() {
|
||||
return getFlowMain().getPreviousReportStepSize();
|
||||
}
|
||||
|
||||
py::array_t<double> PyBlackOilSimulator::getPorosity()
|
||||
{
|
||||
auto vector = getMaterialState().getPorosity();
|
||||
return py::array(vector.size(), vector.data());
|
||||
}
|
||||
|
||||
py::array_t<double>
|
||||
PyBlackOilSimulator::
|
||||
getFluidStateVariable(const std::string &name) const
|
||||
{
|
||||
auto vector = getFluidState().getFluidStateVariable(name);
|
||||
return py::array(vector.size(), vector.data());
|
||||
}
|
||||
|
||||
py::array_t<double>
|
||||
PyBlackOilSimulator::
|
||||
getPrimaryVariable(const std::string &variable) const
|
||||
{
|
||||
auto vector = getFluidState().getPrimaryVariable(variable);
|
||||
return py::array(vector.size(), vector.data());
|
||||
}
|
||||
|
||||
py::array_t<int>
|
||||
PyBlackOilSimulator::
|
||||
getPrimaryVarMeaning(const std::string &variable) const
|
||||
{
|
||||
auto vector = getFluidState().getPrimaryVarMeaning(variable);
|
||||
return py::array(vector.size(), vector.data());
|
||||
}
|
||||
|
||||
std::map<std::string, int>
|
||||
PyBlackOilSimulator::
|
||||
getPrimaryVarMeaningMap(const std::string &variable) const
|
||||
{
|
||||
|
||||
return getFluidState().getPrimaryVarMeaningMap(variable);
|
||||
}
|
||||
|
||||
int PyBlackOilSimulator::run()
|
||||
{
|
||||
auto main_object = Opm::Main( this->deck_filename_ );
|
||||
return main_object.runStatic<Opm::Properties::TTag::FlowProblemTPFA>();
|
||||
}
|
||||
|
||||
void PyBlackOilSimulator::setPorosity( py::array_t<double,
|
||||
py::array::c_style | py::array::forcecast> array)
|
||||
{
|
||||
std::size_t size_ = array.size();
|
||||
const double *poro = array.data();
|
||||
getMaterialState().setPorosity(poro, size_);
|
||||
}
|
||||
|
||||
void
|
||||
PyBlackOilSimulator::
|
||||
setPrimaryVariable(
|
||||
const std::string &variable,
|
||||
py::array_t<double,
|
||||
py::array::c_style | py::array::forcecast> array
|
||||
)
|
||||
{
|
||||
std::size_t size_ = array.size();
|
||||
const double *data = array.data();
|
||||
getFluidState().setPrimaryVariable(variable, data, size_);
|
||||
}
|
||||
|
||||
void PyBlackOilSimulator::setupMpi(bool mpi_init, bool mpi_finalize)
|
||||
{
|
||||
if (this->has_run_init_) {
|
||||
throw std::logic_error("mpi_init() called after step_init()");
|
||||
}
|
||||
this->mpi_init_ = mpi_init;
|
||||
this->mpi_finalize_ = mpi_finalize;
|
||||
}
|
||||
|
||||
int PyBlackOilSimulator::step()
|
||||
{
|
||||
if (!this->has_run_init_) {
|
||||
throw std::logic_error("step() called before step_init()");
|
||||
}
|
||||
if (this->has_run_cleanup_) {
|
||||
throw std::logic_error("step() called after step_cleanup()");
|
||||
}
|
||||
if(checkSimulationFinished()) {
|
||||
throw std::logic_error("step() called, but simulation is done");
|
||||
}
|
||||
//if (this->debug_)
|
||||
// this->mainEbos_->getSimTimer()->report(std::cout);
|
||||
auto result = getFlowMain().executeStep();
|
||||
return result;
|
||||
}
|
||||
|
||||
int PyBlackOilSimulator::stepCleanup()
|
||||
{
|
||||
this->has_run_cleanup_ = true;
|
||||
return getFlowMain().executeStepsCleanup();
|
||||
}
|
||||
|
||||
int PyBlackOilSimulator::stepInit()
|
||||
{
|
||||
|
||||
if (this->has_run_init_) {
|
||||
// Running step_init() multiple times is not implemented yet,
|
||||
if (this->has_run_cleanup_) {
|
||||
throw std::logic_error("step_init() called again");
|
||||
}
|
||||
else {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
if (this->deck_) {
|
||||
this->main_ = std::make_unique<Opm::PyMain>(
|
||||
this->deck_->getDataFile(),
|
||||
this->eclipse_state_,
|
||||
this->schedule_,
|
||||
this->summary_config_,
|
||||
this->mpi_init_,
|
||||
this->mpi_finalize_
|
||||
);
|
||||
}
|
||||
else {
|
||||
this->main_ = std::make_unique<Opm::PyMain>(
|
||||
this->deck_filename_,
|
||||
this->mpi_init_,
|
||||
this->mpi_finalize_
|
||||
);
|
||||
}
|
||||
this->main_->setArguments(args_);
|
||||
int exit_code = EXIT_SUCCESS;
|
||||
this->flow_main_ = this->main_->initFlowBlackoil(exit_code);
|
||||
if (this->flow_main_) {
|
||||
int result = this->flow_main_->executeInitStep();
|
||||
this->has_run_init_ = true;
|
||||
this->simulator_ = this->flow_main_->getSimulatorPtr();
|
||||
this->fluid_state_ = std::make_unique<PyFluidState<TypeTag>>(this->simulator_);
|
||||
this->material_state_ = std::make_unique<PyMaterialState<TypeTag>>(this->simulator_);
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return exit_code;
|
||||
}
|
||||
}
|
||||
|
||||
// Private methods alphabetically sorted
|
||||
// ------------------------------------
|
||||
|
||||
Opm::FlowMain<typename Opm::Pybind::PyBlackOilSimulator::TypeTag>&
|
||||
PyBlackOilSimulator::getFlowMain() const
|
||||
{
|
||||
if (this->flow_main_) {
|
||||
return *this->flow_main_;
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("BlackOilSimulator not initialized: "
|
||||
"Cannot get reference to FlowMain object" );
|
||||
}
|
||||
}
|
||||
|
||||
PyFluidState<typename PyBlackOilSimulator::TypeTag>&
|
||||
PyBlackOilSimulator::
|
||||
getFluidState() const
|
||||
{
|
||||
if (this->fluid_state_) {
|
||||
return *this->fluid_state_;
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("BlackOilSimulator not initialized: "
|
||||
"Cannot get reference to FlowMainEbos object" );
|
||||
}
|
||||
}
|
||||
|
||||
PyMaterialState<typename PyBlackOilSimulator::TypeTag>&
|
||||
PyBlackOilSimulator::getMaterialState() const
|
||||
{
|
||||
if (this->material_state_) {
|
||||
return *this->material_state_;
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("BlackOilSimulator not initialized: "
|
||||
"Cannot get reference to FlowMain object" );
|
||||
}
|
||||
}
|
||||
|
||||
// Exported functions
|
||||
// Exported functions x
|
||||
void export_PyBlackOilSimulator(py::module& m)
|
||||
{
|
||||
using namespace Opm::Pybind::DocStrings;
|
||||
|
||||
py::class_<PyBlackOilSimulator>(m, "BlackOilSimulator")
|
||||
using TypeTag = Opm::Properties::TTag::FlowProblemTPFA;
|
||||
py::class_<PyBaseSimulator<TypeTag>>(
|
||||
m,
|
||||
"_BaseSimulatorBO",
|
||||
py::module_local()
|
||||
);
|
||||
py::class_<PyBlackOilSimulator, PyBaseSimulator<TypeTag> >(m, "BlackOilSimulator")
|
||||
.def(py::init<const std::string&,
|
||||
const std::vector<std::string>&>(),
|
||||
PyBlackOilSimulator_filename_constructor_docstring,
|
||||
@@ -303,31 +70,39 @@ void export_PyBlackOilSimulator(py::module& m)
|
||||
std::shared_ptr<Opm::Deck>,
|
||||
std::shared_ptr<Opm::EclipseState>,
|
||||
std::shared_ptr<Opm::Schedule>,
|
||||
std::shared_ptr<Opm::SummaryConfig>>(),
|
||||
PyBlackOilSimulator_objects_constructor_docstring)
|
||||
.def("advance", &PyBlackOilSimulator::advance, advance_docstring, py::arg("report_step"))
|
||||
.def("check_simulation_finished", &PyBlackOilSimulator::checkSimulationFinished,
|
||||
std::shared_ptr<Opm::SummaryConfig>,
|
||||
const std::vector<std::string>&>(),
|
||||
PyBlackOilSimulator_objects_constructor_docstring,
|
||||
py::arg("Deck"), py::arg("EclipseState"), py::arg("Schedule"), py::arg("SummaryConfig"),
|
||||
py::arg("args") = std::vector<std::string>{})
|
||||
.def("advance", &PyBaseSimulator<TypeTag>::advance, advance_docstring, py::arg("report_step"))
|
||||
.def("check_simulation_finished", &PyBaseSimulator<TypeTag>::checkSimulationFinished,
|
||||
checkSimulationFinished_docstring)
|
||||
.def("current_step", &PyBlackOilSimulator::currentStep, currentStep_docstring)
|
||||
.def("get_cell_volumes", &PyBlackOilSimulator::getCellVolumes, getCellVolumes_docstring)
|
||||
.def("get_dt", &PyBlackOilSimulator::getDT, getDT_docstring)
|
||||
.def("get_fluidstate_variable", &PyBlackOilSimulator::getFluidStateVariable,
|
||||
.def("current_step", &PyBaseSimulator<TypeTag>::currentStep, currentStep_docstring)
|
||||
.def("get_cell_volumes", &PyBaseSimulator<TypeTag>::getCellVolumes, getCellVolumes_docstring)
|
||||
.def("get_dt", &PyBaseSimulator<TypeTag>::getDT, getDT_docstring)
|
||||
.def("get_fluidstate_variable", &PyBaseSimulator<TypeTag>::getFluidStateVariable,
|
||||
py::return_value_policy::copy, getFluidStateVariable_docstring, py::arg("name"))
|
||||
.def("get_porosity", &PyBlackOilSimulator::getPorosity, getPorosity_docstring)
|
||||
.def("get_primary_variable_meaning", &PyBlackOilSimulator::getPrimaryVarMeaning,
|
||||
.def("get_porosity", &PyBaseSimulator<TypeTag>::getPorosity, getPorosity_docstring)
|
||||
.def("get_primary_variable_meaning", &PyBaseSimulator<TypeTag>::getPrimaryVarMeaning,
|
||||
py::return_value_policy::copy, getPrimaryVarMeaning_docstring, py::arg("variable"))
|
||||
.def("get_primary_variable_meaning_map", &PyBlackOilSimulator::getPrimaryVarMeaningMap,
|
||||
.def("get_primary_variable_meaning_map", &PyBaseSimulator<TypeTag>::getPrimaryVarMeaningMap,
|
||||
py::return_value_policy::copy, getPrimaryVarMeaningMap_docstring, py::arg("variable"))
|
||||
.def("get_primary_variable", &PyBlackOilSimulator::getPrimaryVariable,
|
||||
.def("get_primary_variable", &PyBaseSimulator<TypeTag>::getPrimaryVariable,
|
||||
py::return_value_policy::copy, getPrimaryVariable_docstring, py::arg("variable"))
|
||||
.def("run", &PyBlackOilSimulator::run, run_docstring)
|
||||
.def("set_porosity", &PyBlackOilSimulator::setPorosity, setPorosity_docstring, py::arg("array"))
|
||||
.def("set_primary_variable", &PyBlackOilSimulator::setPrimaryVariable,
|
||||
.def("run", &PyBaseSimulator<TypeTag>::run, run_docstring)
|
||||
.def("set_porosity", &PyBaseSimulator<TypeTag>::setPorosity, setPorosity_docstring, py::arg("array"))
|
||||
.def("set_primary_variable", &PyBaseSimulator<TypeTag>::setPrimaryVariable,
|
||||
py::arg("variable"), setPrimaryVariable_docstring, py::arg("value"))
|
||||
.def("setup_mpi", &PyBlackOilSimulator::setupMpi, setupMpi_docstring, py::arg("init"), py::arg("finalize"))
|
||||
.def("step", &PyBlackOilSimulator::step, step_docstring)
|
||||
.def("step_cleanup", &PyBlackOilSimulator::stepCleanup, stepCleanup_docstring)
|
||||
.def("step_init", &PyBlackOilSimulator::stepInit, stepInit_docstring);
|
||||
.def("setup_mpi", &PyBaseSimulator<TypeTag>::setupMpi, setupMpi_docstring, py::arg("init"), py::arg("finalize"))
|
||||
.def("step", &PyBaseSimulator<TypeTag>::step, step_docstring)
|
||||
.def("step_cleanup", &PyBaseSimulator<TypeTag>::stepCleanup, stepCleanup_docstring)
|
||||
.def("step_init", &PyBaseSimulator<TypeTag>::stepInit, stepInit_docstring);
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(BlackOil, m)
|
||||
{
|
||||
export_PyBlackOilSimulator(m);
|
||||
}
|
||||
|
||||
} // namespace Opm::Pybind
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
Copyright 2020 Equinor ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <opm/simulators/flow/python/PyGasWaterSimulator.hpp>
|
||||
// NOTE: This file will be generated at compile time and placed in the build directory
|
||||
// See python/generate_docstring_hpp.py, and python/simulators/CMakeLists.txt for details
|
||||
#include <PyGasWaterSimulatorDoc.hpp>
|
||||
// NOTE: EXIT_SUCCESS, EXIT_FAILURE is defined in cstdlib
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace Opm {
|
||||
namespace Properties {
|
||||
|
||||
//! The indices required by the model
|
||||
template<class TypeTag>
|
||||
struct Indices<TypeTag, TTag::FlowGasWaterProblem>
|
||||
{
|
||||
private:
|
||||
// it is unfortunately not possible to simply use 'TypeTag' here because this leads
|
||||
// to cyclic definitions of some properties. if this happens the compiler error
|
||||
// messages unfortunately are *really* confusing and not really helpful.
|
||||
using BaseTypeTag = TTag::FlowProblem;
|
||||
using FluidSystem = GetPropType<BaseTypeTag, Properties::FluidSystem>;
|
||||
|
||||
public:
|
||||
using type = BlackOilTwoPhaseIndices<getPropValue<TypeTag, Properties::EnableSolvent>(),
|
||||
getPropValue<TypeTag, Properties::EnableExtbo>(),
|
||||
getPropValue<TypeTag, Properties::EnablePolymer>(),
|
||||
getPropValue<TypeTag, Properties::EnableEnergy>(),
|
||||
getPropValue<TypeTag, Properties::EnableFoam>(),
|
||||
getPropValue<TypeTag, Properties::EnableBrine>(),
|
||||
/*PVOffset=*/0,
|
||||
/*disabledCompIdx=*/FluidSystem::oilCompIdx,
|
||||
getPropValue<TypeTag, Properties::EnableMICP>()>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: We need the below explicit instantiations or else the symbols
|
||||
// will not be available in the shared library and we will get
|
||||
// undefined symbol errors when trying to import the module in Python.
|
||||
namespace Opm::Pybind {
|
||||
|
||||
template class PyBaseSimulator<Opm::Properties::TTag::FlowGasWaterProblem>;
|
||||
|
||||
} // namespace Opm::Pybind
|
||||
|
||||
namespace Opm {
|
||||
|
||||
template class PyMain<Opm::Properties::TTag::FlowGasWaterProblem>;
|
||||
template std::unique_ptr<FlowMain<Opm::Properties::TTag::FlowGasWaterProblem>>
|
||||
flowMainInit<Opm::Properties::TTag::FlowGasWaterProblem>(
|
||||
int argc, char** argv, bool outputCout, bool outputFiles);
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace Opm::Pybind {
|
||||
|
||||
// Exported functions
|
||||
void export_PyGasWaterSimulator(py::module& m)
|
||||
{
|
||||
using namespace Opm::Pybind::DocStrings;
|
||||
using TypeTag = Opm::Properties::TTag::FlowGasWaterProblem;
|
||||
|
||||
py::class_<PyBaseSimulator<TypeTag>>(
|
||||
m,
|
||||
"_BaseSimulatorGW",
|
||||
py::module_local()
|
||||
);
|
||||
py::class_<PyGasWaterSimulator, PyBaseSimulator<TypeTag> >(m, "GasWaterSimulator")
|
||||
.def(py::init<const std::string&,
|
||||
const std::vector<std::string>&>(),
|
||||
PyGasWaterSimulator_filename_constructor_docstring,
|
||||
py::arg("filename"), py::arg("args") = std::vector<std::string>{})
|
||||
.def(py::init<
|
||||
std::shared_ptr<Opm::Deck>,
|
||||
std::shared_ptr<Opm::EclipseState>,
|
||||
std::shared_ptr<Opm::Schedule>,
|
||||
std::shared_ptr<Opm::SummaryConfig>,
|
||||
const std::vector<std::string>&>(),
|
||||
PyGasWaterSimulator_objects_constructor_docstring,
|
||||
py::arg("Deck"), py::arg("EclipseState"), py::arg("Schedule"), py::arg("SummaryConfig"),
|
||||
py::arg("args") = std::vector<std::string>{})
|
||||
.def("advance", &PyBaseSimulator<TypeTag>::advance, advance_docstring, py::arg("report_step"))
|
||||
.def("check_simulation_finished", &PyBaseSimulator<TypeTag>::checkSimulationFinished,
|
||||
checkSimulationFinished_docstring)
|
||||
.def("current_step", &PyBaseSimulator<TypeTag>::currentStep, currentStep_docstring)
|
||||
.def("get_cell_volumes", &PyBaseSimulator<TypeTag>::getCellVolumes, getCellVolumes_docstring)
|
||||
.def("get_dt", &PyBaseSimulator<TypeTag>::getDT, getDT_docstring)
|
||||
.def("get_fluidstate_variable", &PyBaseSimulator<TypeTag>::getFluidStateVariable,
|
||||
py::return_value_policy::copy, getFluidStateVariable_docstring, py::arg("name"))
|
||||
.def("get_porosity", &PyBaseSimulator<TypeTag>::getPorosity, getPorosity_docstring)
|
||||
.def("get_primary_variable_meaning", &PyBaseSimulator<TypeTag>::getPrimaryVarMeaning,
|
||||
py::return_value_policy::copy, getPrimaryVarMeaning_docstring, py::arg("variable"))
|
||||
.def("get_primary_variable_meaning_map", &PyBaseSimulator<TypeTag>::getPrimaryVarMeaningMap,
|
||||
py::return_value_policy::copy, getPrimaryVarMeaningMap_docstring, py::arg("variable"))
|
||||
.def("get_primary_variable", &PyBaseSimulator<TypeTag>::getPrimaryVariable,
|
||||
py::return_value_policy::copy, getPrimaryVariable_docstring, py::arg("variable"))
|
||||
.def("run", &PyBaseSimulator<TypeTag>::run, run_docstring)
|
||||
.def("set_porosity", &PyBaseSimulator<TypeTag>::setPorosity, setPorosity_docstring, py::arg("array"))
|
||||
.def("set_primary_variable", &PyBaseSimulator<TypeTag>::setPrimaryVariable,
|
||||
py::arg("variable"), setPrimaryVariable_docstring, py::arg("value"))
|
||||
.def("setup_mpi", &PyBaseSimulator<TypeTag>::setupMpi, setupMpi_docstring, py::arg("init"), py::arg("finalize"))
|
||||
.def("step", &PyBaseSimulator<TypeTag>::step, step_docstring)
|
||||
.def("step_cleanup", &PyBaseSimulator<TypeTag>::stepCleanup, stepCleanup_docstring)
|
||||
.def("step_init", &PyBaseSimulator<TypeTag>::stepInit, stepInit_docstring);
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(GasWater, m)
|
||||
{
|
||||
export_PyGasWaterSimulator(m);
|
||||
}
|
||||
|
||||
} // namespace Opm::Pybind
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
Copyright 2013, 2014, 2015 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2014 Dr. Blatt - HPC-Simulation-Software & Services
|
||||
Copyright 2015 IRIS AS
|
||||
Copyright 2014 STATOIL ASA.
|
||||
Copyright 2023 Inria
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef OPM_PYMAIN_HEADER_INCLUDED
|
||||
#define OPM_PYMAIN_HEADER_INCLUDED
|
||||
|
||||
#include <opm/simulators/flow/FlowMain.hpp>
|
||||
#include <opm/simulators/flow/Main.hpp>
|
||||
#include <opm/simulators/flow/TTagFlowProblemTPFA.hpp>
|
||||
|
||||
#include <flow/flow_blackoil.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
// ----------------- Python Main class -----------------
|
||||
// Adds a python-only initialization method
|
||||
class PyMain : public Main
|
||||
{
|
||||
public:
|
||||
using FlowMainType = FlowMain<Properties::TTag::FlowProblemTPFA>;
|
||||
|
||||
using Main::Main;
|
||||
|
||||
void setArguments(const std::vector<std::string>& args)
|
||||
{
|
||||
if (args.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We have the two arguments previously setup (binary name and input
|
||||
// case name) by the main class plus whichever args are in the
|
||||
// parameter that was passed from the python side.
|
||||
this->argc_ = 2 + args.size();
|
||||
|
||||
// Setup our vector of char*'s
|
||||
argv_python_.resize(2 + args.size());
|
||||
argv_python_[0] = argv_[0];
|
||||
argv_python_[1] = argv_[1];
|
||||
for (std::size_t i = 0; i < args.size(); ++i) {
|
||||
argv_python_[i+2] = const_cast<char*>(args[i].c_str());
|
||||
}
|
||||
|
||||
// Finally set the main class' argv pointer to the combined
|
||||
// parameter list.
|
||||
this->argv_ = argv_python_.data();
|
||||
}
|
||||
|
||||
// To be called from the Python interface code. Only do the
|
||||
// initialization and then return a pointer to the FlowMain object that
|
||||
// can later be accessed directly from the Python interface to
|
||||
// e.g. advance the simulator one report step
|
||||
std::unique_ptr<FlowMainType> initFlowBlackoil(int& exitCode)
|
||||
{
|
||||
exitCode = EXIT_SUCCESS;
|
||||
|
||||
if (this->initialize_<Properties::TTag::FlowEarlyBird>(exitCode, true)) {
|
||||
// TODO: check that this deck really represents a blackoil
|
||||
// case. E.g. check that number of phases == 3
|
||||
this->setupVanguard();
|
||||
|
||||
return flowBlackoilTpfaMainInit
|
||||
(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
|
||||
// NOTE: exitCode was set by initialize_() above;
|
||||
return {}; // nullptr
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<char*> argv_python_{};
|
||||
};
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
#endif // OPM_PYMAIN_HEADER_INCLUDED
|
||||
@@ -1,11 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <opm/simulators/flow/python/Pybind11Exporter.hpp>
|
||||
|
||||
void Opm::Pybind::export_all(py::module& m) {
|
||||
export_PyBlackOilSimulator(m);
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(simulators, m)
|
||||
{
|
||||
Opm::Pybind::export_all(m);
|
||||
}
|
||||
Reference in new issue
Block a user