PMLMappedBody.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  *                                                                         *
00029  *   This program is free software; you can redistribute it and/or modify  *
00030  *   it under the terms of the GNU General Public License as published by  *
00031  *   the Free Software Foundation; either version 2 of the License, or     *
00032  *   (at your option) any later version.                                   *
00033  *                                                                         *
00034  ***************************************************************************/
00035 
00036 #include "PMLMappedBody.h"
00037 
00038 #include "sofa/component/MechanicalObject.h"
00039 #include "sofa/component/mapping/BarycentricMapping.h"
00040 using namespace sofa::component::mapping;
00041 using namespace sofa::component;
00042 
00043 #include <PhysicalModel.h>
00044 #include <MultiComponent.h>
00045 #include <CellProperties.h>
00046 #include <PMLTransform.h>
00047 
00048 namespace sofa
00049 {
00050 
00051 namespace filemanager
00052 {
00053 
00054 namespace pml
00055 {
00056 
00057 PMLMappedBody::PMLMappedBody(StructuralComponent* body, PMLBody* fromBody, GNode * parent)
00058 {
00059     parentNode = parent;
00060     bodyRef = fromBody;
00061 
00062     solverName = body->getProperties()->getString("solver");
00063 
00064     //create the structure
00065     createMechanicalState(body);
00066     createSolver();
00067 }
00068 
00069 
00070 PMLMappedBody::~PMLMappedBody()
00071 {
00072     if(mapping) delete mapping; 
00073 }
00074 
00075 
00076 Vector3 PMLMappedBody::getDOF(unsigned int index)
00077 {
00078     return (*((MechanicalState<Vec3Types>*)mmodel)->getX())[index];
00079 }
00080 
00081 
00082 //creation of the mechanical model
00083 //each pml atom constituing the body correspond to a DOF
00084 void PMLMappedBody::createMechanicalState(StructuralComponent* body)
00085 {
00086     mmodel = new MechanicalObject<Vec3Types>;
00087     StructuralComponent* atoms = body->getAtoms();
00088     mmodel->resize(atoms->getNumberOfStructures());
00089     Atom* pAtom;
00090 
00091     SReal pos[3];
00092     for (unsigned int i(0) ; i<atoms->getNumberOfStructures() ; i++) {
00093         pAtom = (Atom*) (atoms->getStructure(i));
00094         pAtom->getPosition(pos);
00095         AtomsToDOFsIndexes.insert(std::pair <unsigned int, unsigned int>(pAtom->getIndex(),i));
00096         (*((MechanicalState<Vec3Types>*)mmodel)->getX())[i] = Vector3(pos[0],pos[1],pos[2]);
00097     }
00098 
00099     //creation of the mapping
00100     mapping = new BarycentricMapping< MechanicalMapping<MechanicalState<Vec3Types>, MechanicalState<Vec3Types> > >((MechanicalState<Vec3Types>*)bodyRef->getMechanicalState(),(MechanicalState<Vec3Types>*) mmodel);
00101 
00102     parentNode->addObject(mmodel);
00103     parentNode->addObject(mapping);
00104 
00105 }
00106 
00107 
00108 }
00109 }
00110 }

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