This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How do I use this compile_extension_module exactly

+1 vote

As first try I copied the code out of the file:

    code='''
    #ifndef __UBLAS_DUMMY_PRECONDITIONER_H
    #define __UBLAS_DUMMY_PRECONDITIONER_H
    #include "uBLASPreconditioner.h"
    namespace dolfin{
    /// This class provides a dummy (do nothing) preconditioner for the
    /// uBLAS Krylov solver.
    class uBLASDummyPreconditioner : public uBLASPreconditioner
    {
        public:
        /// Constructor
        uBLASDummyPreconditioner();
        /// Destructor
        ~uBLASDummyPreconditioner();
        /// Initialise preconditioner (dense matrix)
        void init(const uBLASMatrix<ublas_sparse_matrix>& A) {};
        /// Initialise preconditioner (virtual matrix)
        void init(const uBLASKrylovMatrix& A) {};
        /// Solve linear system Ax = b approximately
        void solve(uBLASVector& x, const uBLASVector& b) const;
    };
    }
    '''
    NoPreco=compile_extension_module(code,dolfin_module_import=["la"], additional_system_headers=["uBLASDummyPreconditioner.h"])

And the compiler answered:

File "C:\FEniCS\windkanal\Variablensatz_Windkanal.py", line 300, in Loese_v1
NoPreco=compile_extension_module(code,dolfin_module_import=["la"], additiona
l_system_headers=["uBLASDummyPreconditioner.h"])
File "C:\FEniCS\lib\site-packages\dolfin\compilemodules\jit.py", line 66, in m
pi_jit
return local_jit(*args, **kwargs)
File "C:\FEniCS\lib\site-packages\dolfin\compilemodules\compilemodule.py", lin
e 402, in compile_extension_module
raise ValueError, "Include the C++ code in the 'dolfin namspace', otherwise
SWIG cannot figure out the right PyDOLFIN types."
ValueError: Include the C++ code in the 'dolfin namspace', otherwise SWIG cannot
figure out the right PyDOLFIN types.

asked Aug 16, 2013 by Billy_Six FEniCS Novice (160 points)

Check my comment on original thread.

1 Answer

+1 vote

What version of DOLFIN do you use? For the development version this snippet should work:

from dolfin import *

code='''
#include "dolfin/la/uBLASPreconditioner.h"
#include "dolfin/la/uBLASLinearOperator.h"
#include "dolfin/la/uBLASVector.h"

namespace dolfin{
/// This class provides a dummy (do nothing) preconditioner for the
/// uBLAS Krylov solver.
class uBLASDummyPreconditioner : public uBLASPreconditioner
{
    public:
    /// Constructor
    uBLASDummyPreconditioner();
    /// Destructor
    ~uBLASDummyPreconditioner();
    /// Initialise preconditioner (dense matrix)
    void init(const uBLASMatrix<ublas_sparse_matrix>& A) {};
    /// Initialise preconditioner (virtual matrix)
    void init(const uBLASLinearOperator& A) {};
    /// Solve linear system Ax = b approximately
    void solve(uBLASVector& x, const uBLASVector& b) const;
};
}
'''

NoPreco=compile_extension_module(code)

Johan

answered Aug 16, 2013 by johanhake FEniCS Expert (22,480 points)

Johan, I believe this should somehow work as a workaround suggested here. Hence it applies to version 1.0.0.

I see. Then I am not sure what goes wrong. I do not have a 1.0.0 installation to debug on.

...