MechanicalMapping.inl

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_CORE_COMPONENTMODEL_BEHAVIOR_MECHANICALMAPPING_INL
00028 #define SOFA_CORE_COMPONENTMODEL_BEHAVIOR_MECHANICALMAPPING_INL
00029 
00030 #include <sofa/core/Mapping.h>
00031 #include <sofa/core/Mapping.inl>
00032 #include <sofa/core/componentmodel/behavior/MechanicalMapping.h>
00033 #include <iostream>
00034 
00035 using std::cerr;
00036 using std::endl;
00037 
00038 namespace sofa
00039 {
00040 
00041 namespace core
00042 {
00043 
00044 namespace componentmodel
00045 {
00046 
00047 namespace behavior
00048 {
00049 
00050 template <class In, class Out>
00051 MechanicalMapping<In,Out>::MechanicalMapping(In* from, Out* to)
00052 : Mapping<In,Out>(from, to)
00053 , f_isMechanical( initData( &f_isMechanical, true, "isMechanical", "set to false if this mapping should only be used as a regular mapping instead of a mechanical mapping" ) )
00054 {
00055 }
00056     
00057 template <class In, class Out>
00058 MechanicalMapping<In,Out>::~MechanicalMapping()
00059 {
00060 }
00061 
00062 template <class In, class Out>
00063 BaseMechanicalState* MechanicalMapping<In,Out>::getMechFrom()
00064 {
00065     return this->fromModel;
00066 }
00067 
00068 template <class In, class Out>
00069 BaseMechanicalState* MechanicalMapping<In,Out>::getMechTo()
00070 {
00071     return this->toModel;
00072 }
00073 
00074 template <class In, class Out>
00075 bool MechanicalMapping<In,Out>::isMechanical()
00076 {
00077     return this->f_isMechanical.getValue();
00078 }
00079 
00080 template <class In, class Out>
00081 void MechanicalMapping<In,Out>::init()
00082 {
00083     this->updateMapping();
00084     propagateXfree();
00085 }
00086 
00087 template <class In, class Out>
00088 void MechanicalMapping<In,Out>::propagateX()
00089 {
00090     if (this->fromModel!=NULL && this->toModel->getX()!=NULL && this->fromModel->getX()!=NULL)
00091         apply(*this->toModel->getX(), *this->fromModel->getX());
00092 }
00093 
00094 template <class In, class Out>
00095 void MechanicalMapping<In,Out>::propagateV()
00096 {
00097     if (this->fromModel!=NULL && this->toModel->getV()!=NULL && this->fromModel->getV()!=NULL)
00098         applyJ(*this->toModel->getV(), *this->fromModel->getV());
00099 }
00100 
00101 template <class In, class Out>
00102 void MechanicalMapping<In,Out>::propagateDx()
00103 {
00104     if (this->fromModel!=NULL && this->toModel->getDx()!=NULL && this->fromModel->getDx()!=NULL)
00105         applyJ(*this->toModel->getDx(), *this->fromModel->getDx());
00106 }
00107 
00108 template <class In, class Out>
00109 void MechanicalMapping<In,Out>::propagateXfree()
00110 {
00111     if (this->fromModel!=NULL && this->toModel->getXfree()!=NULL && this->fromModel->getXfree()!=NULL)
00112         apply(*this->toModel->getXfree(), *this->fromModel->getXfree());
00113 }
00114 
00115 
00116 template <class In, class Out>
00117 void MechanicalMapping<In,Out>::accumulateForce()
00118 {
00119 /*    if( this->fromModel==NULL ) cerr<<"MechanicalMapping<In,Out>::accumulateForce, toModel is NULL"<<endl;
00120     else if( this->toModel==NULL ) cerr<<"MechanicalMapping<In,Out>::accumulateForce, toModel is NULL"<<endl;
00121     else cerr<<"MechanicalMapping<In,Out>::accumulateForce() OK"<<endl;*/
00122     if (this->fromModel!=NULL && this->toModel->getF()!=NULL && this->fromModel->getF()!=NULL)
00123         applyJT(*this->fromModel->getF(), *this->toModel->getF());
00124 }
00125 
00126 template <class In, class Out>
00127 void MechanicalMapping<In,Out>::accumulateDf()
00128 {
00129     if (this->fromModel!=NULL && this->toModel->getF()!=NULL && this->fromModel->getF()!=NULL)
00130         applyJT(*this->fromModel->getF(), *this->toModel->getF());
00131 }
00132 
00133 template <class In, class Out>
00134 void MechanicalMapping<In,Out>::accumulateConstraint()
00135 {
00136     if (this->fromModel!=NULL && this->toModel->getC()!=NULL && this->fromModel->getC()!=NULL)
00137     {
00138         applyJT(*this->fromModel->getC(), *this->toModel->getC());
00139 
00140         // Accumulate contacts indices through the MechanicalMapping
00141         std::vector<unsigned int>::iterator it = this->toModel->getConstraintId().begin();
00142         std::vector<unsigned int>::iterator itEnd = this->toModel->getConstraintId().end();
00143 
00144         while (it != itEnd)
00145         {
00146             this->fromModel->setConstraintId(*it);
00147             it++;
00148         }
00149     }
00150 }
00151 
00152 } // namespace behavior
00153 
00154 } // namespace componentmodel
00155 
00156 } // namespace core
00157 
00158 } // namespace sofa
00159 
00160 #endif

Generated on Sun Nov 23 02:29:00 2008 for Sofa by  doxygen 1.5.7.1