Molmodel

RiboseMobilizer.h

Go to the documentation of this file.
00001 /* -------------------------------------------------------------------------- *
00002  *                      SimTK Core: SimTK Simbody(tm)                         *
00003  * -------------------------------------------------------------------------- *
00004  * This is part of the SimTK Core biosimulation toolkit originating from      *
00005  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00006  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00007  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00008  *                                                                            *
00009  * Portions copyright (c) 2008 Stanford University and the Authors.           *
00010  * Authors: Christopher Bruns                                                 *
00011  * Contributors: Ajay Seth                                                    *
00012  *                                                                            *
00013  * Permission is hereby granted, free of charge, to any person obtaining a    *
00014  * copy of this software and associated documentation files (the "Software"), *
00015  * to deal in the Software without restriction, including without limitation  *
00016  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00017  * and/or sell copies of the Software, and to permit persons to whom the      *
00018  * Software is furnished to do so, subject to the following conditions:       *
00019  *                                                                            *
00020  * The above copyright notice and this permission notice shall be included in *
00021  * all copies or substantial portions of the Software.                        *
00022  *                                                                            *
00023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00024  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00025  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00026  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00027  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00028  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00029  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00030  * -------------------------------------------------------------------------- */
00031 
00032 #ifndef SimTK_RIBOSE_MOBILIZER_H_
00033 #define SimTK_RIBOSE_MOBILIZER_H_
00034 
00035 #include "SimTKsimbody.h"
00036 #include "molmodel/internal/common.h"
00037 #include "molmodel/internal/units.h"
00038 #include <cmath>
00039 
00040 namespace SimTK {
00041 
00043 class ZeroFunction : public Function::Constant {
00044 public:
00045     ZeroFunction() : Function::Constant(0, 0) {}
00046 };
00047 
00049 class SimTK_MOLMODEL_EXPORT SinusoidFunction : public Function {
00050 private:
00051     Angle amplitude;
00052     Angle phase;
00053 public:
00054 
00055     //Default constructor
00056     SinusoidFunction()
00057         : amplitude(1.0), phase(0.0*Deg2Rad) {}
00058     
00059     //Convenience constructor to specify the slope and Y-intercept of the linear r
00060     SinusoidFunction(Angle amp, Angle phi)
00061     : amplitude(amp), phase(phi) {}
00062     
00063     Real calcValue(const Vector& x) const{
00064         return amplitude*std::sin(x[0] - phase);
00065     }
00066     
00067     Real calcDerivative(const Array_<int>& derivComponents, const Vector& x) const{
00068         Real deriv = 0;
00069     
00070         assert(1 == x.size());
00071         
00072         // Derivatives 1, 5, 9, 13, ... are cos()
00073         if      ( 1 == (derivComponents.size() % 4) ){
00074             deriv = amplitude*std::cos(x[0] - phase);
00075         }
00076         // Derivatives 2, 6, 10, 14, ... are -sin()
00077         else if ( 2 == (derivComponents.size() % 4) ){
00078             deriv = -amplitude*std::sin(x[0] - phase);
00079         }
00080         // Derivatives 3, 7, 11, 15, ... are -cos()
00081         else if ( 3 == (derivComponents.size() % 4) ){
00082             deriv = -amplitude*std::cos(x[0] - phase);
00083         }
00084         // Derivatives 0, 4, 8, 12, ... are sin()
00085         else if ( 0 == (derivComponents.size() % 4) ){
00086             deriv = amplitude*std::sin(x[0] - phase);
00087         }
00088         else assert(false);
00089         
00090         return deriv;
00091     }
00092     
00093     int getArgumentSize() const{
00094         return 1;
00095     }
00096     
00097     int getMaxDerivativeOrder() const{
00098         return 1000;
00099     }
00100 };
00101     
00102 class SimTK_MOLMODEL_EXPORT PseudorotationMobilizer : public MobilizedBody::FunctionBased
00103 {
00104 public:
00105     PseudorotationMobilizer(
00106             MobilizedBody& parent,
00107             const Transform& inbFrame,
00108             const Body& body,
00109             const Transform& outbFrame,
00110             Angle amplitude,
00111             Angle phase
00112             )
00113     : MobilizedBody::FunctionBased(
00114             parent,
00115             inbFrame,
00116             body,
00117             outbFrame,
00118             1,
00119             createFunctions(amplitude, phase),
00120             createCoordIndices() // TODO ask Ajay
00121             )
00122     {}  
00123     
00124 private:
00125     
00126     static std::vector< const Function* > createFunctions(Angle amplitude, Angle phase);
00127     static std::vector< std::vector<int> > createCoordIndices();    
00128     
00129 };
00130 
00131 
00132 class SimTK_MOLMODEL_EXPORT RiboseNu3Mobilizer : public PseudorotationMobilizer
00133 {
00134 public:
00135     RiboseNu3Mobilizer(
00136             MobilizedBody& parent,
00137             const Transform& inbFrame,
00138             const Body& body,
00139             const Transform& outbFrame)
00140     : PseudorotationMobilizer(
00141             parent,
00142             inbFrame,
00143             body,
00144             outbFrame,
00145             36.4*Deg2Rad,
00146             124.8*Deg2Rad)
00147     {}
00148             
00149 };
00150 
00151 } // namespace SimTK
00152 
00153 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines