Access to the content of a ChVectorDynamicD with pyChrono

33 views
Skip to first unread message

Nicolas CORTES

unread,
Jun 23, 2023, 5:44:26 AM6/23/23
to ProjectChrono
Hello,
I am using ChElementBeamIGA and I wish to see the Knot sequence.
I obtained a ChVectorDynamicD with the command :
knots = element.GetKnotSquence()
but I do not manage to print its content...

I tried to get it with :
- knots[0]
- knots.GetVectData(0)
- knots.GetVect()

However, each of my tentatives sold with a core dumped. The exact error is :

eigen-3.4.0/Eigen/src/Core/DenseCoeffsBase.h:367: Eigen::internal::traits<Derived>::Scalar &Eigen::DenseCoeffsBase<Derived, 1>::operator()(long, long) [with Derived = Eigen::Matrix<double, -1, 1, 0, -1, 1>]: Assertion `row >= 0 && row < rows() && col >= 0 && col < cols()' failed.
Aborted (core dumped)


Is this the correct way to access the content of a ChVectorDynamicD or is there an other way ?

Thank you in advance for your help,

Nicolas

Nicolas CORTES

unread,
Jun 28, 2023, 10:03:07 AM6/28/23
to ProjectChrono
I manage to solve my problem by replacing 1 into 0 in the file chrono_swig/interface/core/ChMatrix.i in line 127, 130, 139 and 145.
From (*$self)(i, 1) to (*$self)(i, 0)

%extend chrono::ChVectorDynamic<double>{
        public:
            double __getitem__(int i) {
                return (*$self)(i,0);
                }
            void __setitem__(int i, double v) {
                (*$self)(i, 0) = v;
                }

            const int Size() {
                const int r = $self->rows();
                return r;
                }
            void GetVectorData(double* p, int len) {
                for (int i = 0; i < len; i++){
                    p[i] =  (double)(*$self)(i, 0);
                        }
                }
            void SetVect(int numel, double* q){
                ($self)->resize(numel);
                for (int i = 0; i < numel; i++){
                    (*$self)(i, 0) = q[i];
                        }
                }
        };

Radu Serban

unread,
Jun 29, 2023, 3:40:12 PM6/29/23
to ProjectChrono

Nicolas,  could you please submit a pull request with this fix?

Thanks,
Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/c1b64a90-0d67-408d-94d0-5ca2538daae0n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages