PMLInteractionForceField.cpp

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 :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 
00026 /***************************************************************************
00027  *                                                                         *
00028  *   This program is free software; you can redistribute it and/or modify  *
00029  *   it under the terms of the GNU General Public License as published by  *
00030  *   the Free Software Foundation; either version 2 of the License, or     *
00031  *   (at your option) any later version.                                   *
00032  *                                                                         *
00033  ***************************************************************************/
00034 
00035 #include "PMLInteractionForceField.h"
00036 
00037 #include "sofa/component/MechanicalObject.h"
00038 #include "sofa/component/forcefield/StiffSpringForceField.h"
00039 using namespace sofa::component::forcefield;
00040 
00041 #include <PhysicalModel.h>
00042 #include <MultiComponent.h>
00043 #include <CellProperties.h>
00044 
00045 
00046 namespace sofa
00047 {
00048 
00049 namespace filemanager
00050 {
00051 
00052 namespace pml
00053 {
00054 
00055 PMLInteractionForceField::PMLInteractionForceField(StructuralComponent* body, PMLBody* b1, PMLBody* b2, GNode * parent)
00056 {
00057     parentNode = parent;
00058 
00059     //get the parameters
00060     collisionsON = false;
00061     name = body->getProperties()->getName();
00062 
00063     body1 = b1;
00064     body2 = b2;
00065 
00066     ks = body->getProperties()->getDouble("stiffness");
00067     kd = body->getProperties()->getDouble("damping");
00068 
00069     //create the structure
00070     createForceField();
00071     createSprings(body);
00072 }
00073 
00074 PMLInteractionForceField::~PMLInteractionForceField()
00075 { 
00076     if(mmodel) delete mmodel; 
00077     if (Sforcefield) delete Sforcefield;
00078 }
00079 
00080 
00081 //create a TetrahedronFEMForceField
00082 void PMLInteractionForceField::createForceField()
00083 {
00084     Sforcefield = new StiffSpringForceField<Vec3Types>((MechanicalObject<Vec3Types>*)body1->getMechanicalState(), (MechanicalObject<Vec3Types>*)body2->getMechanicalState());
00085     parentNode->addObject(Sforcefield);
00086 }
00087 
00088 
00089 void PMLInteractionForceField::createSprings(StructuralComponent * body)
00090 {
00091     Vec3Types::VecCoord& P1 = *((MechanicalObject<Vec3Types>*)body1->getMechanicalState())->getX();
00092     Vec3Types::VecCoord& P2 = *((MechanicalObject<Vec3Types>*)body2->getMechanicalState())->getX();
00093     if (kd==0.0)kd=5.0;
00094     if (ks==0.0)ks=500.0;
00095     for (unsigned int i=0; i<body->getNumberOfCells() ; i++)
00096     {
00097         Cell * cell = body->getCell(i);
00098         if (cell->getType() == StructureProperties::LINE){
00099             unsigned int dof1 = body1->AtomsToDOFsIndexes[cell->getStructure(0)->getIndex()];
00100             unsigned int dof2 = body2->AtomsToDOFsIndexes[cell->getStructure(1)->getIndex()];
00101             Vec3Types::Deriv gap = P1[dof1] - P2[dof2];
00102             Sforcefield->addSpring(dof1, dof2, ks, kd, sqrt(dot(gap,gap)));
00103         }
00104     }
00105 }
00106 
00107 
00108 }
00109 }
00110 }

Generated on Sun Nov 23 03:56:14 2008 for Sofa by  doxygen 1.5.7.1