mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Return vectors by value
Return vectors by value instead of unique pointers to arrays.
This commit is contained in:
parent
55aab60549
commit
757c67f284
@ -48,13 +48,10 @@ namespace Opm::Pybind
|
|||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
PyFluidState(Simulator *ebos_simulator);
|
PyFluidState(Simulator *ebos_simulator);
|
||||||
std::unique_ptr<double []> getFluidStateVariable(
|
std::vector<double> getFluidStateVariable(const std::string &name) const;
|
||||||
const std::string &name, std::size_t *size ) const;
|
std::vector<int> getPrimaryVarMeaning(const std::string &variable) const;
|
||||||
std::unique_ptr<int []> getPrimaryVarMeaning(
|
|
||||||
const std::string &variable, std::size_t *size) const;
|
|
||||||
std::map<std::string, int> getPrimaryVarMeaningMap(const std::string &variable) const;
|
std::map<std::string, int> getPrimaryVarMeaningMap(const std::string &variable) const;
|
||||||
std::unique_ptr<double []> getPrimaryVariable(
|
std::vector<double> getPrimaryVariable(const std::string &idx_name) const;
|
||||||
const std::string &idx_name, std::size_t *size ) const;
|
|
||||||
void setPrimaryVariable(const std::string &idx_name, const double *data, std::size_t size);
|
void setPrimaryVariable(const std::string &idx_name, const double *data, std::size_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -31,14 +31,14 @@ PyFluidState(Simulator* ebos_simulator) : ebos_simulator_(ebos_simulator)
|
|||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
|
|
||||||
template <class TypeTag>
|
template <class TypeTag>
|
||||||
std::unique_ptr<int []>
|
std::vector<int>
|
||||||
PyFluidState<TypeTag>::
|
PyFluidState<TypeTag>::
|
||||||
getPrimaryVarMeaning(const std::string &variable, std::size_t *size) const {
|
getPrimaryVarMeaning(const std::string &variable) const {
|
||||||
Model &model = this->ebos_simulator_->model();
|
Model &model = this->ebos_simulator_->model();
|
||||||
auto &sol = model.solution(/*timeIdx*/0);
|
auto &sol = model.solution(/*timeIdx*/0);
|
||||||
*size = model.numGridDof();
|
auto size = model.numGridDof();
|
||||||
auto array = std::make_unique<int []>(*size);
|
std::vector<int> array(size);
|
||||||
for (unsigned dof_idx = 0; dof_idx < *size; ++dof_idx) {
|
for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
|
||||||
auto primary_vars = sol[dof_idx];
|
auto primary_vars = sol[dof_idx];
|
||||||
array[dof_idx] = getVariableMeaning_(primary_vars, variable);
|
array[dof_idx] = getVariableMeaning_(primary_vars, variable);
|
||||||
}
|
}
|
||||||
@ -106,20 +106,20 @@ getPrimaryVarMeaningMap(const std::string &variable) const
|
|||||||
kr_g = Gas relperm,
|
kr_g = Gas relperm,
|
||||||
*/
|
*/
|
||||||
template <class TypeTag>
|
template <class TypeTag>
|
||||||
std::unique_ptr<double []>
|
std::vector<double>
|
||||||
PyFluidState<TypeTag>::
|
PyFluidState<TypeTag>::
|
||||||
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 ElementIterator = typename GridView::template Codim<0>::Iterator;
|
||||||
using Element = typename GridView::template Codim<0>::Entity;
|
using Element = typename GridView::template Codim<0>::Entity;
|
||||||
|
|
||||||
Model &model = this->ebos_simulator_->model();
|
Model &model = this->ebos_simulator_->model();
|
||||||
*size = model.numGridDof();
|
auto size = model.numGridDof();
|
||||||
|
std::vector<double> array(size);
|
||||||
const auto& grid_view = this->ebos_simulator_->vanguard().gridView();
|
const auto& grid_view = this->ebos_simulator_->vanguard().gridView();
|
||||||
/* NOTE: grid_view.size(0) should give the same value as
|
/* NOTE: grid_view.size(0) should give the same value as
|
||||||
* model.numGridDof()
|
* model.numGridDof()
|
||||||
*/
|
*/
|
||||||
auto array = std::make_unique<double []>(*size);
|
|
||||||
ElementContext elem_ctx(*this->ebos_simulator_);
|
ElementContext elem_ctx(*this->ebos_simulator_);
|
||||||
ElementIterator elem_itr = grid_view.template begin</*codim=*/0>();
|
ElementIterator elem_itr = grid_view.template begin</*codim=*/0>();
|
||||||
const ElementIterator& elem_end_itr = grid_view.template end</*codim=*/0>();
|
const ElementIterator& elem_end_itr = grid_view.template end</*codim=*/0>();
|
||||||
@ -128,7 +128,7 @@ getFluidStateVariable(const std::string &name, std::size_t *size ) const
|
|||||||
const Element& elem = *elem_itr;
|
const Element& elem = *elem_itr;
|
||||||
elem_ctx.updatePrimaryStencil(elem);
|
elem_ctx.updatePrimaryStencil(elem);
|
||||||
elem_ctx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
|
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& int_quants = elem_ctx.intensiveQuantities(dof_idx, /*timeIdx=*/0);
|
||||||
const auto& fs = int_quants.fluidState();
|
const auto& fs = int_quants.fluidState();
|
||||||
unsigned global_dof_idx = elem_ctx.globalSpaceIndex(dof_idx, /*timeIdx=*/0);
|
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 <class TypeTag>
|
template <class TypeTag>
|
||||||
std::unique_ptr<double []>
|
std::vector<double>
|
||||||
PyFluidState<TypeTag>::
|
PyFluidState<TypeTag>::
|
||||||
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);
|
std::size_t primary_var_idx = getPrimaryVarIndex_(idx_name);
|
||||||
Model &model = this->ebos_simulator_->model();
|
Model &model = this->ebos_simulator_->model();
|
||||||
auto &sol = model.solution(/*timeIdx*/0);
|
auto &sol = model.solution(/*timeIdx*/0);
|
||||||
*size = model.numGridDof();
|
auto size = model.numGridDof();
|
||||||
auto array = std::make_unique<double []>(*size);
|
std::vector<double> array(size);
|
||||||
for (unsigned dof_idx = 0; dof_idx < *size; ++dof_idx) {
|
for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
|
||||||
auto primary_vars = sol[dof_idx];
|
auto primary_vars = sol[dof_idx];
|
||||||
array[dof_idx] = primary_vars[primary_var_idx];
|
array[dof_idx] = primary_vars[primary_var_idx];
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,8 @@ namespace Opm::Pybind
|
|||||||
PyMaterialState(Simulator *ebos_simulator)
|
PyMaterialState(Simulator *ebos_simulator)
|
||||||
: ebos_simulator_(ebos_simulator) { }
|
: ebos_simulator_(ebos_simulator) { }
|
||||||
|
|
||||||
std::unique_ptr<double []> getCellVolumes( std::size_t *size);
|
std::vector<double> getCellVolumes();
|
||||||
std::unique_ptr<double []> getPorosity( std::size_t *size);
|
std::vector<double> getPorosity();
|
||||||
void setPorosity(const double *poro, std::size_t size);
|
void setPorosity(const double *poro, std::size_t size);
|
||||||
private:
|
private:
|
||||||
Simulator *ebos_simulator_;
|
Simulator *ebos_simulator_;
|
||||||
|
@ -22,29 +22,29 @@
|
|||||||
namespace Opm::Pybind {
|
namespace Opm::Pybind {
|
||||||
|
|
||||||
template <class TypeTag>
|
template <class TypeTag>
|
||||||
std::unique_ptr<double []>
|
std::vector<double>
|
||||||
PyMaterialState<TypeTag>::
|
PyMaterialState<TypeTag>::
|
||||||
getCellVolumes( std::size_t *size)
|
getCellVolumes()
|
||||||
{
|
{
|
||||||
Model &model = this->ebos_simulator_->model();
|
Model &model = this->ebos_simulator_->model();
|
||||||
*size = model.numGridDof();
|
auto size = model.numGridDof();
|
||||||
auto array = std::make_unique<double []>(*size);
|
std::vector<double> array(size);
|
||||||
for (unsigned dof_idx = 0; dof_idx < *size; ++dof_idx) {
|
for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
|
||||||
array[dof_idx] = model.dofTotalVolume(dof_idx);
|
array[dof_idx] = model.dofTotalVolume(dof_idx);
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class TypeTag>
|
template <class TypeTag>
|
||||||
std::unique_ptr<double []>
|
std::vector<double>
|
||||||
PyMaterialState<TypeTag>::
|
PyMaterialState<TypeTag>::
|
||||||
getPorosity( std::size_t *size)
|
getPorosity()
|
||||||
{
|
{
|
||||||
Problem &problem = this->ebos_simulator_->problem();
|
Problem &problem = this->ebos_simulator_->problem();
|
||||||
Model &model = this->ebos_simulator_->model();
|
Model &model = this->ebos_simulator_->model();
|
||||||
*size = model.numGridDof();
|
auto size = model.numGridDof();
|
||||||
auto array = std::make_unique<double []>(*size);
|
std::vector<double> array(size);
|
||||||
for (unsigned dof_idx = 0; dof_idx < *size; ++dof_idx) {
|
for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
|
||||||
array[dof_idx] = problem.referencePorosity(dof_idx, /*timeIdx*/0);
|
array[dof_idx] = problem.referencePorosity(dof_idx, /*timeIdx*/0);
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
|
@ -95,9 +95,8 @@ int PyBlackOilSimulator::currentStep()
|
|||||||
}
|
}
|
||||||
|
|
||||||
py::array_t<double> PyBlackOilSimulator::getCellVolumes() {
|
py::array_t<double> PyBlackOilSimulator::getCellVolumes() {
|
||||||
std::size_t len;
|
auto vector = getMaterialState().getCellVolumes();
|
||||||
auto array = getMaterialState().getCellVolumes(&len);
|
return py::array(vector.size(), vector.data());
|
||||||
return py::array(len, array.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double PyBlackOilSimulator::getDT() {
|
double PyBlackOilSimulator::getDT() {
|
||||||
@ -106,36 +105,32 @@ double PyBlackOilSimulator::getDT() {
|
|||||||
|
|
||||||
py::array_t<double> PyBlackOilSimulator::getPorosity()
|
py::array_t<double> PyBlackOilSimulator::getPorosity()
|
||||||
{
|
{
|
||||||
std::size_t len;
|
auto vector = getMaterialState().getPorosity();
|
||||||
auto array = getMaterialState().getPorosity(&len);
|
return py::array(vector.size(), vector.data());
|
||||||
return py::array(len, array.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
py::array_t<double>
|
py::array_t<double>
|
||||||
PyBlackOilSimulator::
|
PyBlackOilSimulator::
|
||||||
getFluidStateVariable(const std::string &name) const
|
getFluidStateVariable(const std::string &name) const
|
||||||
{
|
{
|
||||||
std::size_t len;
|
auto vector = getFluidState().getFluidStateVariable(name);
|
||||||
auto array = getFluidState().getFluidStateVariable(name, &len);
|
return py::array(vector.size(), vector.data());
|
||||||
return py::array(len, array.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
py::array_t<double>
|
py::array_t<double>
|
||||||
PyBlackOilSimulator::
|
PyBlackOilSimulator::
|
||||||
getPrimaryVariable(const std::string &variable) const
|
getPrimaryVariable(const std::string &variable) const
|
||||||
{
|
{
|
||||||
std::size_t len;
|
auto vector = getFluidState().getPrimaryVariable(variable);
|
||||||
auto array = getFluidState().getPrimaryVariable(variable, &len);
|
return py::array(vector.size(), vector.data());
|
||||||
return py::array(len, array.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
py::array_t<int>
|
py::array_t<int>
|
||||||
PyBlackOilSimulator::
|
PyBlackOilSimulator::
|
||||||
getPrimaryVarMeaning(const std::string &variable) const
|
getPrimaryVarMeaning(const std::string &variable) const
|
||||||
{
|
{
|
||||||
std::size_t len;
|
auto vector = getFluidState().getPrimaryVarMeaning(variable);
|
||||||
auto array = getFluidState().getPrimaryVarMeaning(variable, &len);
|
return py::array(vector.size(), vector.data());
|
||||||
return py::array(len, array.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, int>
|
std::map<std::string, int>
|
||||||
|
Loading…
Reference in New Issue
Block a user