diff --git a/opm/simulators/flow/python/PyFluidState.hpp b/opm/simulators/flow/python/PyFluidState.hpp index b76d859ff..6df866b42 100644 --- a/opm/simulators/flow/python/PyFluidState.hpp +++ b/opm/simulators/flow/python/PyFluidState.hpp @@ -48,13 +48,10 @@ namespace Opm::Pybind }; public: PyFluidState(Simulator *ebos_simulator); - std::unique_ptr getFluidStateVariable( - const std::string &name, std::size_t *size ) const; - std::unique_ptr getPrimaryVarMeaning( - const std::string &variable, std::size_t *size) const; + std::vector getFluidStateVariable(const std::string &name) const; + std::vector getPrimaryVarMeaning(const std::string &variable) const; std::map getPrimaryVarMeaningMap(const std::string &variable) const; - std::unique_ptr getPrimaryVariable( - const std::string &idx_name, std::size_t *size ) const; + std::vector getPrimaryVariable(const std::string &idx_name) const; void setPrimaryVariable(const std::string &idx_name, const double *data, std::size_t size); private: diff --git a/opm/simulators/flow/python/PyFluidState_impl.hpp b/opm/simulators/flow/python/PyFluidState_impl.hpp index 94d328025..6079f798d 100644 --- a/opm/simulators/flow/python/PyFluidState_impl.hpp +++ b/opm/simulators/flow/python/PyFluidState_impl.hpp @@ -31,14 +31,14 @@ PyFluidState(Simulator* ebos_simulator) : ebos_simulator_(ebos_simulator) // ------------------------------------ template -std::unique_ptr +std::vector PyFluidState:: -getPrimaryVarMeaning(const std::string &variable, std::size_t *size) const { +getPrimaryVarMeaning(const std::string &variable) const { Model &model = this->ebos_simulator_->model(); auto &sol = model.solution(/*timeIdx*/0); - *size = model.numGridDof(); - auto array = std::make_unique(*size); - for (unsigned dof_idx = 0; dof_idx < *size; ++dof_idx) { + auto size = model.numGridDof(); + std::vector array(size); + for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) { auto primary_vars = sol[dof_idx]; array[dof_idx] = getVariableMeaning_(primary_vars, variable); } @@ -106,20 +106,20 @@ getPrimaryVarMeaningMap(const std::string &variable) const kr_g = Gas relperm, */ template -std::unique_ptr +std::vector PyFluidState:: -getFluidStateVariable(const std::string &name, std::size_t *size ) const +getFluidStateVariable(const std::string &name) const { using ElementIterator = typename GridView::template Codim<0>::Iterator; using Element = typename GridView::template Codim<0>::Entity; Model &model = this->ebos_simulator_->model(); - *size = model.numGridDof(); + auto size = model.numGridDof(); + std::vector array(size); const auto& grid_view = this->ebos_simulator_->vanguard().gridView(); /* NOTE: grid_view.size(0) should give the same value as * model.numGridDof() */ - auto array = std::make_unique(*size); ElementContext elem_ctx(*this->ebos_simulator_); ElementIterator elem_itr = grid_view.template begin(); const ElementIterator& elem_end_itr = grid_view.template end(); @@ -128,7 +128,7 @@ getFluidStateVariable(const std::string &name, std::size_t *size ) const const Element& elem = *elem_itr; elem_ctx.updatePrimaryStencil(elem); elem_ctx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); - for (unsigned dof_idx = 0;dof_idx < elem_ctx.numPrimaryDof(/*timeIdx=*/0); ++dof_idx) { + for (unsigned dof_idx = 0; dof_idx < elem_ctx.numPrimaryDof(/*timeIdx=*/0); ++dof_idx) { const auto& int_quants = elem_ctx.intensiveQuantities(dof_idx, /*timeIdx=*/0); const auto& fs = int_quants.fluidState(); unsigned global_dof_idx = elem_ctx.globalSpaceIndex(dof_idx, /*timeIdx=*/0); @@ -139,16 +139,16 @@ getFluidStateVariable(const std::string &name, std::size_t *size ) const } template -std::unique_ptr +std::vector PyFluidState:: -getPrimaryVariable(const std::string &idx_name, std::size_t *size ) const +getPrimaryVariable(const std::string &idx_name) const { std::size_t primary_var_idx = getPrimaryVarIndex_(idx_name); Model &model = this->ebos_simulator_->model(); auto &sol = model.solution(/*timeIdx*/0); - *size = model.numGridDof(); - auto array = std::make_unique(*size); - for (unsigned dof_idx = 0; dof_idx < *size; ++dof_idx) { + auto size = model.numGridDof(); + std::vector array(size); + for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) { auto primary_vars = sol[dof_idx]; array[dof_idx] = primary_vars[primary_var_idx]; } diff --git a/opm/simulators/flow/python/PyMaterialState.hpp b/opm/simulators/flow/python/PyMaterialState.hpp index d1bf20ad3..86831d0a3 100644 --- a/opm/simulators/flow/python/PyMaterialState.hpp +++ b/opm/simulators/flow/python/PyMaterialState.hpp @@ -45,8 +45,8 @@ namespace Opm::Pybind PyMaterialState(Simulator *ebos_simulator) : ebos_simulator_(ebos_simulator) { } - std::unique_ptr getCellVolumes( std::size_t *size); - std::unique_ptr getPorosity( std::size_t *size); + std::vector getCellVolumes(); + std::vector getPorosity(); void setPorosity(const double *poro, std::size_t size); private: Simulator *ebos_simulator_; diff --git a/opm/simulators/flow/python/PyMaterialState_impl.hpp b/opm/simulators/flow/python/PyMaterialState_impl.hpp index e8d07be53..2181b49ef 100644 --- a/opm/simulators/flow/python/PyMaterialState_impl.hpp +++ b/opm/simulators/flow/python/PyMaterialState_impl.hpp @@ -22,29 +22,29 @@ namespace Opm::Pybind { template -std::unique_ptr +std::vector PyMaterialState:: -getCellVolumes( std::size_t *size) +getCellVolumes() { Model &model = this->ebos_simulator_->model(); - *size = model.numGridDof(); - auto array = std::make_unique(*size); - for (unsigned dof_idx = 0; dof_idx < *size; ++dof_idx) { + auto size = model.numGridDof(); + std::vector array(size); + for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) { array[dof_idx] = model.dofTotalVolume(dof_idx); } return array; } template -std::unique_ptr +std::vector PyMaterialState:: -getPorosity( std::size_t *size) +getPorosity() { Problem &problem = this->ebos_simulator_->problem(); Model &model = this->ebos_simulator_->model(); - *size = model.numGridDof(); - auto array = std::make_unique(*size); - for (unsigned dof_idx = 0; dof_idx < *size; ++dof_idx) { + auto size = model.numGridDof(); + std::vector array(size); + for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) { array[dof_idx] = problem.referencePorosity(dof_idx, /*timeIdx*/0); } return array; diff --git a/python/simulators/PyBlackOilSimulator.cpp b/python/simulators/PyBlackOilSimulator.cpp index b70b16dfc..afb7165fb 100644 --- a/python/simulators/PyBlackOilSimulator.cpp +++ b/python/simulators/PyBlackOilSimulator.cpp @@ -95,9 +95,8 @@ int PyBlackOilSimulator::currentStep() } py::array_t PyBlackOilSimulator::getCellVolumes() { - std::size_t len; - auto array = getMaterialState().getCellVolumes(&len); - return py::array(len, array.get()); + auto vector = getMaterialState().getCellVolumes(); + return py::array(vector.size(), vector.data()); } double PyBlackOilSimulator::getDT() { @@ -106,36 +105,32 @@ double PyBlackOilSimulator::getDT() { py::array_t PyBlackOilSimulator::getPorosity() { - std::size_t len; - auto array = getMaterialState().getPorosity(&len); - return py::array(len, array.get()); + auto vector = getMaterialState().getPorosity(); + return py::array(vector.size(), vector.data()); } py::array_t PyBlackOilSimulator:: getFluidStateVariable(const std::string &name) const { - std::size_t len; - auto array = getFluidState().getFluidStateVariable(name, &len); - return py::array(len, array.get()); + auto vector = getFluidState().getFluidStateVariable(name); + return py::array(vector.size(), vector.data()); } py::array_t PyBlackOilSimulator:: getPrimaryVariable(const std::string &variable) const { - std::size_t len; - auto array = getFluidState().getPrimaryVariable(variable, &len); - return py::array(len, array.get()); + auto vector = getFluidState().getPrimaryVariable(variable); + return py::array(vector.size(), vector.data()); } py::array_t PyBlackOilSimulator:: getPrimaryVarMeaning(const std::string &variable) const { - std::size_t len; - auto array = getFluidState().getPrimaryVarMeaning(variable, &len); - return py::array(len, array.get()); + auto vector = getFluidState().getPrimaryVarMeaning(variable); + return py::array(vector.size(), vector.data()); } std::map