mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-10-24 22:57:42 -05:00
Python wrapper of single phase (water) simulator
This commit is contained in:
1 parent
fafa4d8a19
commit
d0c08c4382
9 files changed
+332
-2
No files matched your search
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"PyOnePhaseSimulator":{
|
||||
"type": "class",
|
||||
"signature": "opm.simulators.OnePhaseSimulator",
|
||||
"doc": "The OnePhaseSimulator class to run simulations using a given Deck."
|
||||
},
|
||||
"PyOnePhaseSimulator_filename_constructor": {
|
||||
"signature": "opm.simulators.OnePhaseSimulator.__init__(deck_filename: str, args: list[str] = []) -> OnePhaseSimulator",
|
||||
"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 OnePhaseSimulator.\n:type return: OnePhaseSimulator"
|
||||
},
|
||||
"PyOnePhaseSimulator_objects_constructor": {
|
||||
"signature": "opm.simulators.OnePhaseSimulator.__init__(deck: Deck, state: EclipseState, schedule: Schedule, summary_config: SummaryConfig, args: list[str] = []) -> OnePhaseSimulator",
|
||||
"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 OnePhaseSimulator.\n:type return: OnePhaseSimulator"
|
||||
},
|
||||
"advance": {
|
||||
"signature": "opm.simulators.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.current_step() -> int",
|
||||
"doc": "Gets the current simulation step.\n\n:return: The current step number."
|
||||
},
|
||||
"getCellVolumes": {
|
||||
"signature": "opm.simulators.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.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.OnePhaseSimulator.step() -> int",
|
||||
"doc": "Executes the next simulation report step.\n\n:return: Result of the simulation step."
|
||||
},
|
||||
"stepCleanup": {
|
||||
"signature": "opm.simulators.OnePhaseSimulator.step_cleanup() -> int",
|
||||
"doc": "Performs cleanup after the last simulation step.\n\n:return: EXIT_SUCCESS if cleanup is successful."
|
||||
},
|
||||
"stepInit": {
|
||||
"signature": "opm.simulators.OnePhaseSimulator.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."
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,4 @@
|
||||
#
|
||||
from .BlackOil import BlackOilSimulator
|
||||
from .GasWater import GasWaterSimulator
|
||||
from .OnePhase import OnePhaseSimulator
|
||||
+2
-1
@@ -36,7 +36,8 @@ setup(
|
||||
package_data={
|
||||
'opm': [
|
||||
'$<TARGET_FILE_NAME:BlackOil>',
|
||||
'$<TARGET_FILE_NAME:GasWater>'
|
||||
'$<TARGET_FILE_NAME:GasWater>',
|
||||
'$<TARGET_FILE_NAME:OnePhase>',
|
||||
]
|
||||
},
|
||||
include_package_data=True,
|
||||
|
||||
@@ -4,6 +4,8 @@ set(PYTHON_OPM_SIMULATORS_PACKAGE_PATH ${PROJECT_BINARY_DIR}/python/opm/simulato
|
||||
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_GENERATED_HPP "${PROJECT_BINARY_DIR}/python/PyGasWaterSimulatorDoc.hpp")
|
||||
set(PYTHON_OP_DOCSTRINGS_FILE "${PROJECT_SOURCE_DIR}/python/docstrings_op_simulators.json")
|
||||
set(PYTHON_OP_DOCSTRINGS_GENERATED_HPP "${PROJECT_BINARY_DIR}/python/PyOnePhaseSimulatorDoc.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}
|
||||
#
|
||||
@@ -29,6 +31,14 @@ add_custom_command(
|
||||
DEPENDS ${PYTHON_DOCSTRINGS_FILE}
|
||||
COMMENT "Generating PyGasWaterSimulatorDoc.hpp from JSON file"
|
||||
)
|
||||
add_custom_command(
|
||||
OUTPUT ${PYTHON_OP_DOCSTRINGS_GENERATED_HPP}
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_SOURCE_DIR}
|
||||
${PYTHON_EXECUTABLE} ${PYTHON_GENERATE_DOCSTRINGS_PY}
|
||||
${PYTHON_OP_DOCSTRINGS_FILE} ${PYTHON_OP_DOCSTRINGS_GENERATED_HPP} PYONEPHASESIMULATORDOC_HPP "Opm::Pybind::DocStrings"
|
||||
DEPENDS ${PYTHON_OP_DOCSTRINGS_FILE}
|
||||
COMMENT "Generating PyOnePhaseSimulatorDoc.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
|
||||
@@ -48,6 +58,12 @@ pybind11_add_module(GasWater ${PYBIND11_SYSTEM}
|
||||
${PYTHON_GW_DOCSTRINGS_GENERATED_HPP} # Include the generated .hpp as a source file
|
||||
)
|
||||
|
||||
pybind11_add_module(OnePhase ${PYBIND11_SYSTEM}
|
||||
$<TARGET_OBJECTS:moduleVersion>
|
||||
PyOnePhaseSimulator.cpp
|
||||
${PYTHON_OP_DOCSTRINGS_GENERATED_HPP} # Include the generated .hpp as a source file
|
||||
)
|
||||
|
||||
# Create a convenience target to build all Python simulator modules
|
||||
add_custom_target(python_simulator_modules
|
||||
DEPENDS BlackOil GasWater
|
||||
@@ -71,7 +87,7 @@ add_custom_target(copy_python ALL
|
||||
${PROJECT_SOURCE_DIR}/python/test_data ${PROJECT_BINARY_DIR}/python 0
|
||||
)
|
||||
|
||||
foreach(target_name IN ITEMS BlackOil GasWater)
|
||||
foreach(target_name IN ITEMS BlackOil GasWater OnePhase)
|
||||
set_target_properties(
|
||||
${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYTHON_OPM_SIMULATORS_PACKAGE_PATH}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
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/models/blackoil/blackoilonephaseindices.hh>
|
||||
#include <opm/simulators/flow/python/PyOnePhaseSimulator.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 <PyOnePhaseSimulatorDoc.hpp>
|
||||
// NOTE: EXIT_SUCCESS, EXIT_FAILURE is defined in cstdlib
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace Opm::Properties {
|
||||
|
||||
//! The indices required by the model
|
||||
template<class TypeTag>
|
||||
struct Indices<TypeTag, TTag::FlowOnePhaseProblem>
|
||||
{
|
||||
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 = BlackOilOnePhaseIndices<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,
|
||||
/*enabledCompIdx=*/FluidSystem::waterCompIdx,
|
||||
getPropValue<TypeTag, Properties::EnableMICP>()>;
|
||||
}; // struct Indices
|
||||
|
||||
} // namespace Opm::Properties
|
||||
|
||||
// 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::FlowOnePhaseProblem>;
|
||||
|
||||
} // namespace Opm::Pybind
|
||||
|
||||
// Define main function
|
||||
namespace Opm {
|
||||
|
||||
template class PyMain<Opm::Properties::TTag::FlowOnePhaseProblem>;
|
||||
template std::unique_ptr<FlowMain<Opm::Properties::TTag::FlowOnePhaseProblem>>
|
||||
flowMainInit<Opm::Properties::TTag::FlowOnePhaseProblem>(
|
||||
int argc, char** argv, bool outputCout, bool outputFiles);
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace Opm::Pybind {
|
||||
|
||||
// Exported functions
|
||||
void export_PyOnePhaseSimulator(py::module& m)
|
||||
{
|
||||
using namespace Opm::Pybind::DocStrings;
|
||||
using TypeTag = Opm::Properties::TTag::FlowOnePhaseProblem;
|
||||
|
||||
py::class_<PyBaseSimulator<TypeTag>>(
|
||||
m,
|
||||
"_BaseSimulatorOP",
|
||||
py::module_local()
|
||||
);
|
||||
py::class_<PyOnePhaseSimulator, PyBaseSimulator<TypeTag> >(m, "OnePhaseSimulator")
|
||||
.def(py::init<const std::string&,
|
||||
const std::vector<std::string>&>(),
|
||||
PyOnePhaseSimulator_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>&>(),
|
||||
PyOnePhaseSimulator_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(OnePhase, m)
|
||||
{
|
||||
export_PyOnePhaseSimulator(m);
|
||||
}
|
||||
|
||||
} // namespace Opm::Pybind
|
||||
Reference in new issue
Block a user