// ------------------------------------------------------------------------------- // Copyright (c) 2012, Junggon Kim // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ------------------------------------------------------------------------------- //================================================================================ // GConstraint: base class for constraints // // junggon@gmail.com //================================================================================ #ifndef _GEAR_CONSTRAINT_ #define _GEAR_CONSTRAINT_ #include #include "gelement.h" #include "gcoordinate.h" #include "liegroup.h" #include "rmatrix3j.h" //============================================================= // GConstraint //============================================================= class GConstraint: public GElementWithCoordinates { public: int constrNum; // the number of constraints RMatrix C; // C = C(q,t) where q = pCoordinates[]->q, size(C) = (m,1) RMatrix J; // J = dC/dq, size(J) = (m,n) RMatrix dJdt; // dJdt = dJ/dt, size(dJdt) = (m,n) // where m = constrNum, n = size(pCoordinates) // (note) In general, pCoordinates is a part of system coordinates. public: GConstraint(); virtual ~GConstraint() {} int getNumConstraints() { return constrNum; } virtual void update_C() = 0; virtual void update_J() = 0; virtual void update_dJdt() = 0; // get C RMatrix& get_C() { return C; } void get_C(gReal *re) { matSet(re, C.GetPtr(), constrNum); } const gReal* getPtr_C() { return C.GetPtr(); } // get J or its column(s) RMatrix& get_J() { return J; } RMatrix get_J(int i) { if ( i>=0 && i indices) { RMatrix re(constrNum,(int)indices.size()); get_J(re.GetPtr(), indices); return re; } RMatrix get_J(std::vector pcoords) { RMatrix re(constrNum,(int)pcoords.size()); get_J(re.GetPtr(), pcoords); return re; } void get_J(gReal *re) { matSet(re, J.GetPtr(), constrNum*getNumCoordinates()); } void get_J(gReal *re, int i) { if ( i>=0 && i indices) { for (int i=0; i<(int)indices.size(); i++) { get_J(&re[constrNum*i], indices[i]); } } void get_J(gReal *re, std::vector pcoords) { for (int i=0; i<(int)pcoords.size(); i++) { get_J(&re[constrNum*i], pcoords[i]); } } gReal* getPtr_J() { return J.GetPtr(); } gReal* getPtr_J(int i) { if ( i>=0 && i=0 && i indices) { RMatrix re(constrNum,(int)indices.size()); get_dJdt(re.GetPtr(), indices); return re; } RMatrix get_dJdt(std::vector pcoords) { RMatrix re(constrNum,(int)pcoords.size()); get_dJdt(re.GetPtr(), pcoords); return re; } void get_dJdt(gReal *re) { matSet(re, dJdt.GetPtr(), constrNum*getNumCoordinates()); } void get_dJdt(gReal *re, int i) { if ( i>=0 && i indices) { for (int i=0; i<(int)indices.size(); i++) { get_dJdt(&re[constrNum*i], indices[i]); } } void get_dJdt(gReal *re, std::vector pcoords) { for (int i=0; i<(int)pcoords.size(); i++) { get_dJdt(&re[constrNum*i], pcoords[i]); } } gReal* getPtr_dJdt() { return dJdt.GetPtr(); } gReal* getPtr_dJdt(int i) { if ( i>=0 && i