dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #12214
Re: A minimal c++ Function test and some bugs
On Tue, Feb 17, 2009 at 03:59:51PM +0000, A Navaei wrote:
> 2009/2/17 A Navaei <axnavaei@xxxxxxxxxxxxxx>:
> > The following minimal test for Function in c++ reveals some bugs. I
> > guess this example can help me with dealing with the current issues of
> > ImageFunction.
> >
> > (1) interpolate.py does not work when a Function is created in c++ and
> > wrapped (see comment [2]). It seems that the bug is originated from
> > the copy constructor (see comment [3])
> >
> > (2) In order to perform the interpolation, why is it necessary to
> > create another Function and then copy it?
> >
> > (3) Signature checkes seem not working properly (see comment [1]). The
> > signature-based assignments are error-prone anyway, why the
> > object-oriented approach is not used?
> >
> >
> I'm adding another issue:
>
> (4) Sub-classing Function and calling the sub-class interpolate()
> function does not call eval().
Which interpolate() function? There are 4 different.
--
Anders
> Code is attached.
>
>
> -Ali
> #include <dolfin/function/Function.h>
> #include <dolfin/function/FunctionSpace.h>
> #include <dolfin/mesh/Mesh.h>
> #include <dolfin/fem/FiniteElement.h>
> #include <dolfin/fem/DofMap.h>
> #include <dolfin/mesh/UnitSquare.h>
>
> #include <boost/shared_ptr.hpp>
>
> using namespace dolfin;
>
> int msize[2];
>
> class MyFunction : public Function
> {
> public:
> MyFunction(const FunctionSpace& V) : Function(V) {};
>
> void eval(double* values, const double* x) const
> {
> int i = int((msize[0] - 1) * x[0]);
> int j = int((msize[1] - 1) * x[1]);
> int index = i + (msize[0] * j);
> std::cout << "\tEvaluating [" << i << ", " << j << "](" << index << ")" << std::endl;
> }
> };
>
> int main()
> {
> typedef boost::shared_ptr< const Mesh > MeshConstPointerType;
> typedef boost::shared_ptr< const FiniteElement > ElementConstPointerType;
> typedef boost::shared_ptr< const DofMap > DofMapConstPointerType;
>
> std::cout << "- Creating mesh...";
> msize[0] = 10; msize[1] = 10;
> UnitSquare mesh(msize[0] - 1, msize[1] - 1);
> std::cout << "done." << std::endl;
>
> std::string elemSig("FiniteElement('Lagrange', 'triangle', 1)");
> // std::string elemSig("dummy"); // [1] This gives segmentation fault.
> std::string dofSig("FFC dof map for FiniteElement('Lagrange', 'triangle', 1)");
>
> std::cout << "- Creating FunctionSpace...";
> FunctionSpace V(MeshConstPointerType(&mesh, NoDeleter<const dolfin::Mesh>()),
> ElementConstPointerType(new dolfin::FiniteElement(elemSig)),
> DofMapConstPointerType(new dolfin::DofMap(dofSig, mesh)));
> std::cout << "done." << std::endl;
>
> std::cout << "- Creating Function...";
> MyFunction v(V);
> std::cout << "done." << std::endl;
>
> /*
> // [2] This gives segmentation fault.
> std::cout << "- Interpolating as interpolate.py...";
> Function Pv(v); // [3] The copy ctor doesn't work.
> v.interpolate(Pv.vector(), v.function_space());
> std::cout << "done." << std::endl;
> */
> // [4] This seems to work fine.
> std::cout << "- Interpolating...";
> v.interpolate(v.vector(), v.function_space());
> std::cout << "done." << std::endl;
> };
>
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev
Attachment:
signature.asc
Description: Digital signature
Follow ups
References