Re: [deal.II] Re: Binding Step-6 class with Boost.Python gives an compilation error: "use of deleted function"

2020-06-14 Thread Wolfgang Bangerth

On 6/14/20 7:09 PM, Oleg Kmechak wrote:

 Solver(Model *model):
 dof_handler(triangulation)
 {
 model = model;


Oleg,
I have not tried too carefully to look at what you're doing, but this line 
doesn't look right. It is equivalent to

  this->model = this->model;
which I don't think is what you want to do.

I should not that we occasionally use the following style in constructors:

 Solver (Model *model)
 :  model (model)
 { ... }

which is initializing this->model with the given argument 'model'. But that 
only works in the initializer list of a class.


You are correct that the error messages you see result from the fact that 
somewhere in the Python interfaces, it is trying to create a copy 
operator/constructor for the Model class, but that that doesn't exist because 
the copy operations for Triangulation and DoFHandler are not allowed. That has 
nothing to do with the issue above.


Best
 W.

--

Wolfgang Bangerth  email: bange...@colostate.edu
   www: http://www.math.colostate.edu/~bangerth/

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/36b4fbb9-9b0a-9ff6-850e-2ba967ceca52%40colostate.edu.


[deal.II] Re: Binding Step-6 class with Boost.Python gives an compilation error: "use of deleted function"

2020-06-14 Thread Oleg Kmechak
Looks like I got solution.

Problem is that Boost.Python is trying to construct some assignment 
operator (operator=). While it is trying to do this, its traping do deleted 
methods of DoFHandler and Triangulation. 
Solution(or workaround in my case) is to use option boost::noncopyable:
class_("Solver"
, init(args("model")))
boost::copyable:
also it looks like there 
 is 
possibility to overload asignment operator, but I didn't tryied it and it 
looks tricky.

Best, 
Oleg Kmechak 

On Monday, 15 June 2020 02:34:49 UTC+2, Oleg Kmechak wrote:
>
> Hello All, 
>
> I am trying to port C++ program to Python using Boost.Python. Have done 
> already a lot of work with porting of classes(mostly based on std) and it 
> works as expected. 
> But currently strugling with the last one class to port(class Solver), 
> which is almost the same as step-6. 
>
> Some code(link to repo 
> 
> ):
>
> ```cpp
> class Solver
> {
> public:
> //Solver():
> //dof_handler(triangulation),
> //fe(3), 
> //quadrature_formula(3),
> //face_quadrature_formula(3)
> //{}
>
> ///Solver constructor
> Solver(Model *model):
> dof_handler(triangulation)
> { 
> model = model;
>
> //fixme
> //fe = FE_Q{model->solver_params.quadrature_degree};
>
> //quadrature_formula = 
> QGauss{model->solver_params.quadrature_degree};
>
> //face_quadrature_formula = QGauss 1>{model->solver_params.quadrature_degree};
> };
> 
> ~Solver(){clear();}
>
> void OpenMesh(const string fileName = "river.msh");
> void run();
> void output_results(const string file_name) const;
> vector integrate(const Model& mdl, const Point&
>  point, const double angle);
>
> ///Clear Solver object.
> void clear()
> {
>   dof_handler.clear();
>   triangulation.clear();
>   hanging_node_constraints.clear();
>   system_matrix.clear();
>   solution.reinit(0);
> }
> private:
> Model *model = NULL;
>
> Triangulation triangulation;
> DoFHandler dof_handler;
>
> FE_Q fe = FE_Q{3};
> QGauss quadrature_formula = QGauss{3};
> QGauss face_quadrature_formula = QGauss{3};
> 
> AffineConstraints hanging_node_constraints;
>
> SparsityPattern sparsity_pattern;
> SparseMatrix system_matrix;
>
> Vector solution;
> Vector system_rhs;
>
> ConvergenceTable convergence_table;
>
> void setup_system();
> void assemble_system();
> void solve();
> void refine_grid();
> };
> } // namespace River
> ```
>
> BoostPython part:
>
> ```cpp
> class_("Solver", init(args("model")))
> .def("OpenMesh", ::Solver::OpenMesh)
> .def("run", ::Solver::run)
> .def("output_results", ::Solver::output_results)
> .def("integrate", ::Solver::integrate)
> .def("clear", ::Solver::clear)
> ;
>
>
>
>
> And it gives next error, but I nowhere use copy constructor of 
> *DoFHandler* nor *Triangulation*:
>
> [ 98%] Building CXX object source/CMakeFiles/riversimPY.dir/pythonapi.cpp.o
>
> In file included from 
> /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
>  from /usr/include/boost/python/object/value_holder.hpp:47,
>  from 
> /usr/include/boost/python/object/class_metadata.hpp:14,
>  from /usr/include/boost/python/class.hpp:23,
>  from /usr/include/boost/python.hpp:18,
>  from 
> /mnt/c/users/ofcra/dev/riversim/source/pythonapi.cpp:1:
> /usr/include/boost/python/object/value_holder.hpp: In instantiation of 
> ‘boost::python::objects::value_holder::value_holder(PyObject*, A0) 
> [with A0 = boost::reference_wrapper; Value = 
> River::Solver; PyObject = _object]’:
> /usr/include/boost/python/object/make_instance.hpp:72:16:   required from 
> ‘static Holder* boost::python::objects::make_instance Holder>::construct(void*, PyObject*, boost::reference_wrapper) 
> [with T = River::Solver; Holder = 
> boost::python::objects::value_holder; PyObject = _object]’
> /usr/include/boost/python/object/make_instance.hpp:46:31:   required from 
> ‘static PyObject* boost::python::objects::make_instance_impl Derived>::execute(Arg&) [with Arg = const boost::reference_wrapper River::Solver>; T = River::Solver; Holder = 
> boost::python::objects::value_holder; Derived = 
> boost::python::objects::make_instance 

[deal.II] Binding Step-6 class with Boost.Python gives an compilation error: "use of deleted function"

2020-06-14 Thread Oleg Kmechak
Hello All, 

I am trying to port C++ program to Python using Boost.Python. Have done 
already a lot of work with porting of classes(mostly based on std) and it 
works as expected. 
But currently strugling with the last one class to port(class Solver), 
which is almost the same as step-6. 

Some code(link to repo 

):

```cpp
class Solver
{
public:
//Solver():
//dof_handler(triangulation),
//fe(3), 
//quadrature_formula(3),
//face_quadrature_formula(3)
//{}

///Solver constructor
Solver(Model *model):
dof_handler(triangulation)
{ 
model = model;

//fixme
//fe = FE_Q{model->solver_params.quadrature_degree};
//quadrature_formula = 
QGauss{model->solver_params.quadrature_degree};
//face_quadrature_formula = QGauss{model->solver_params.quadrature_degree};
};

~Solver(){clear();}

void OpenMesh(const string fileName = "river.msh");
void run();
void output_results(const string file_name) const;
vector integrate(const Model& mdl, const Point& point, 
const double angle);

///Clear Solver object.
void clear()
{
  dof_handler.clear();
  triangulation.clear();
  hanging_node_constraints.clear();
  system_matrix.clear();
  solution.reinit(0);
}
private:
Model *model = NULL;

Triangulation triangulation;
DoFHandler dof_handler;

FE_Q fe = FE_Q{3};
QGauss quadrature_formula = QGauss{3};
QGauss face_quadrature_formula = QGauss{3};

AffineConstraints hanging_node_constraints;

SparsityPattern sparsity_pattern;
SparseMatrix system_matrix;

Vector solution;
Vector system_rhs;

ConvergenceTable convergence_table;

void setup_system();
void assemble_system();
void solve();
void refine_grid();
};
} // namespace River
```

BoostPython part:

```cpp
class_("Solver", init(args("model")))
.def("OpenMesh", ::Solver::OpenMesh)
.def("run", ::Solver::run)
.def("output_results", ::Solver::output_results)
.def("integrate", ::Solver::integrate)
.def("clear", ::Solver::clear)
;




And it gives next error, but I nowhere use copy constructor of *DoFHandler* 
nor *Triangulation*:

[ 98%] Building CXX object source/CMakeFiles/riversimPY.dir/pythonapi.cpp.o

In file included from 
/usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
 from /usr/include/boost/python/object/value_holder.hpp:47,
 from 
/usr/include/boost/python/object/class_metadata.hpp:14,
 from /usr/include/boost/python/class.hpp:23,
 from /usr/include/boost/python.hpp:18,
 from 
/mnt/c/users/ofcra/dev/riversim/source/pythonapi.cpp:1:
/usr/include/boost/python/object/value_holder.hpp: In instantiation of 
‘boost::python::objects::value_holder::value_holder(PyObject*, A0) 
[with A0 = boost::reference_wrapper; Value = 
River::Solver; PyObject = _object]’:
/usr/include/boost/python/object/make_instance.hpp:72:16:   required from 
‘static Holder* boost::python::objects::make_instance::construct(void*, PyObject*, boost::reference_wrapper) 
[with T = River::Solver; Holder = 
boost::python::objects::value_holder; PyObject = _object]’
/usr/include/boost/python/object/make_instance.hpp:46:31:   required from 
‘static PyObject* boost::python::objects::make_instance_impl::execute(Arg&) [with Arg = const boost::reference_wrapper; T = River::Solver; Holder = 
boost::python::objects::value_holder; Derived = 
boost::python::objects::make_instance >; PyObject = _object]’
/usr/include/boost/python/object/class_wrapper.hpp:29:37:   required from 
‘static PyObject* boost::python::objects::class_cref_wrapper::convert(const Src&) [with Src = River::Solver; MakeInstance 
= boost::python::objects::make_instance >; PyObject = _object]’
/usr/include/boost/python/converter/as_to_python_function.hpp:27:61:  
 required from ‘static PyObject* 
boost::python::converter::as_to_python_function::convert(const 
void*) [with T = River::Solver; ToPython = 
boost::python::objects::class_cref_wrapper > >; PyObject = 
_object]’
/usr/include/boost/python/to_python_converter.hpp:83:9:   [ skipping 2 
instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/boost/python/object/class_metadata.hpp:227:55:   required from 
‘static void boost::python::objects::class_metadata::register_aux2(T2*, Callback) [with T2 = River::Solver; Callback =