Clipper
derivs.h
00001 
00004 //C Copyright (C) 2000-2006 Kevin Cowtan and University of York
00005 //L
00006 //L  This library is free software and is distributed under the terms
00007 //L  and conditions of version 2.1 of the GNU Lesser General Public
00008 //L  Licence (LGPL) with the following additional clause:
00009 //L
00010 //L     `You may also combine or link a "work that uses the Library" to
00011 //L     produce a work containing portions of the Library, and distribute
00012 //L     that work under terms of your choice, provided that you give
00013 //L     prominent notice with each copy of the work that the specified
00014 //L     version of the Library is used in it, and that you include or
00015 //L     provide public access to the complete corresponding
00016 //L     machine-readable source code for the Library including whatever
00017 //L     changes were used in the work. (i.e. If you make changes to the
00018 //L     Library you must distribute those, but you do not need to
00019 //L     distribute source or object code to those portions of the work
00020 //L     not covered by this licence.)'
00021 //L
00022 //L  Note that this clause grants an additional right and does not impose
00023 //L  any additional restriction, and so does not affect compatibility
00024 //L  with the GNU General Public Licence (GPL). If you wish to negotiate
00025 //L  other terms, please contact the maintainer.
00026 //L
00027 //L  You can redistribute it and/or modify the library under the terms of
00028 //L  the GNU Lesser General Public License as published by the Free Software
00029 //L  Foundation; either version 2.1 of the License, or (at your option) any
00030 //L  later version.
00031 //L
00032 //L  This library is distributed in the hope that it will be useful, but
00033 //L  WITHOUT ANY WARRANTY; without even the implied warranty of
00034 //L  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00035 //L  Lesser General Public License for more details.
00036 //L
00037 //L  You should have received a copy of the CCP4 licence and/or GNU
00038 //L  Lesser General Public License along with this library; if not, write
00039 //L  to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
00040 //L  The GNU Lesser General Public can also be obtained by writing to the
00041 //L  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00042 //L  MA 02111-1307 USA
00043 
00044 
00045 #ifndef CLIPPER_DERIVS
00046 #define CLIPPER_DERIVS
00047 
00048 
00049 #include "coords.h"
00050 
00051 
00052 namespace clipper
00053 {
00054   template<class T> class Grad_orth;
00055   template<class T> class Grad_frac;
00056   template<class T> class Grad_map;
00057   template<class T> class Curv_orth;
00058   template<class T> class Curv_frac;
00059   template<class T> class Curv_map;
00060 
00061 
00063   template<class T> class Grad_orth : public Vec3<T>
00064   {
00065   public:
00066     Grad_orth() {}                 
00067     explicit Grad_orth( const Vec3<T>& v ) :
00068       Vec3<T>( v ) {}          
00069     Grad_orth( const T& dx, const T& dy, const T& dz ) :
00070       Vec3<T>( dx, dy, dz ) {} 
00071     const T& dx() const { return (*this)[0]; }  
00072     const T& dy() const { return (*this)[1]; }  
00073     const T& dz() const { return (*this)[2]; }  
00074 
00075     Grad_frac<T> grad_frac( const Cell& cell ) const;
00076     String format() const;  
00077   };
00078 
00079 
00081   template<class T> class Grad_frac : public Vec3<T>
00082   {
00083   public:
00084     Grad_frac() {}                 
00085     explicit Grad_frac( const Vec3<T>& v ) :
00086       Vec3<T>( v ) {}          
00087     Grad_frac( const T& du, const T& dv, const T& dw ) :
00088       Vec3<T>( du, dv, dw ) {} 
00089     const T& du() const { return (*this)[0]; }  
00090     const T& dv() const { return (*this)[1]; }  
00091     const T& dw() const { return (*this)[2]; }  
00092 
00093     Grad_orth<T> grad_orth( const Cell& cell ) const;
00095     Grad_map<T> grad_map( const Grid& g ) const;
00096     String format() const;  
00097   };
00098 
00099 
00101   template<class T> class Grad_map : public Vec3<T>
00102   {
00103   public:
00104     Grad_map() {}                 
00105     explicit Grad_map( const Vec3<T>& v ) :
00106       Vec3<T>( v ) {}          
00107     Grad_map( const T& du, const T& dv, const T& dw ) :
00108       Vec3<T>( du, dv, dw ) {} 
00109     const T& du() const { return (*this)[0]; }  
00110     const T& dv() const { return (*this)[1]; }  
00111     const T& dw() const { return (*this)[2]; }  
00112 
00113     Grad_frac<T> grad_frac( const Grid& g ) const;
00114     String format() const;  
00115   };
00116 
00117 
00119   template<class T> class Curv_orth : public Mat33<T>
00120   {
00121   public:
00122     Curv_orth() {}                 
00123     explicit Curv_orth( const Mat33<T>& m ) :
00124       Mat33<T>( m ) {}         
00125 
00126     Curv_frac<T> curv_frac( const Cell& cell ) const;
00127   };
00128 
00129 
00131   template<class T> class Curv_frac : public Mat33<T>
00132   {
00133   public:
00134     Curv_frac() {}                 
00135     explicit Curv_frac( const Mat33<T>& m ) :
00136       Mat33<T>( m ) {}         
00137 
00138     Curv_orth<T> curv_orth( const Cell& cell ) const;
00140     Curv_map<T> curv_map( const Grid& g ) const;
00141   };
00142 
00143 
00145   template<class T> class Curv_map : public Mat33<T>
00146   {
00147   public:
00148     Curv_map() {}                 
00149     explicit Curv_map( const Mat33<T>& m ) :
00150       Mat33<T>( m ) {}         
00151 
00152     Curv_frac<T> curv_frac( const Grid& g ) const;
00153   };
00154 
00155 
00156 
00157   // template implementations
00158 
00163   template<class T> String Grad_orth<T>::format() const
00164     { return "d/dx,d/dy,d/dz = ("+String(dx())+","+String(dy())+","+String(dz())+")"; }
00165 
00167   template<class T> inline Grad_frac<T> Grad_orth<T>::grad_frac( const Cell& cell ) const
00168     { return Grad_frac<T>( (*this) * Mat33<T>( cell.matrix_orth() ) ); }
00169 
00170 
00172   template<class T> String Grad_frac<T>::format() const
00173     { return "d/du,d/dv,d/dw = ("+String(du())+","+String(dv())+","+String(dw())+")"; }
00174 
00176   template<class T> inline Grad_orth<T> Grad_frac<T>::grad_orth( const Cell& cell ) const
00177     { return Grad_orth<T>( (*this) * Mat33<T>( cell.matrix_frac() ) ); }
00178 
00180   template<class T> inline Grad_map<T> Grad_frac<T>::grad_map( const Grid& g ) const
00181     { return Grad_map<T>( du()/g.nu(), dv()/g.nv(), dw()/g.nw() ); }
00182 
00183 
00185   template<class T> String Grad_map<T>::format() const
00186     { return "d/du,d/dv,d/dw = ("+String(du())+","+String(dv())+","+String(dw())+")"; }
00187 
00189   template<class T> inline Grad_frac<T> Grad_map<T>::grad_frac( const Grid& g ) const
00190     { return Grad_frac<T>( du()*g.nu(), dv()*g.nv(), dw()*g.nw() ); }
00191 
00192 
00194   template<class T> Curv_frac<T> Curv_orth<T>::curv_frac( const Cell& cell ) const
00195   {
00196     Mat33<T> m( cell.matrix_orth() );
00197     return Curv_frac<T>( m.transpose() * (*this) * m );
00198   }
00199 
00200 
00202   template<class T> Curv_orth<T> Curv_frac<T>::curv_orth( const Cell& cell ) const
00203   {
00204     Mat33<T> m( cell.matrix_frac() );
00205     return Curv_orth<T>( m.transpose() * (*this) * m );
00206   }
00207 
00209   template<class T> Curv_map<T> Curv_frac<T>::curv_map( const Grid& g ) const
00210   {
00211     Curv_map<T> c;
00212     c(0,0) = (*this)(0,0) / T(g.nu()*g.nu());
00213     c(0,1) = (*this)(0,1) / T(g.nu()*g.nv());
00214     c(0,2) = (*this)(0,2) / T(g.nu()*g.nw());
00215     c(1,0) = (*this)(1,0) / T(g.nv()*g.nu());
00216     c(1,1) = (*this)(1,1) / T(g.nv()*g.nv());
00217     c(1,2) = (*this)(1,2) / T(g.nv()*g.nw());
00218     c(2,0) = (*this)(2,0) / T(g.nw()*g.nu());
00219     c(2,1) = (*this)(2,1) / T(g.nw()*g.nv());
00220     c(2,2) = (*this)(2,2) / T(g.nw()*g.nw());
00221     return c;
00222   }
00223 
00224 
00226   template<class T> Curv_frac<T> Curv_map<T>::curv_frac( const Grid& g ) const
00227   {
00228     Curv_frac<T> c;
00229     c(0,0) = (*this)(0,0) * T(g.nu()*g.nu());
00230     c(0,1) = (*this)(0,1) * T(g.nu()*g.nv());
00231     c(0,2) = (*this)(0,2) * T(g.nu()*g.nw());
00232     c(1,0) = (*this)(1,0) * T(g.nv()*g.nu());
00233     c(1,1) = (*this)(1,1) * T(g.nv()*g.nv());
00234     c(1,2) = (*this)(1,2) * T(g.nv()*g.nw());
00235     c(2,0) = (*this)(2,0) * T(g.nw()*g.nu());
00236     c(2,1) = (*this)(2,1) * T(g.nw()*g.nv());
00237     c(2,2) = (*this)(2,2) * T(g.nw()*g.nw());
00238     return c;
00239   }
00240 
00241 
00242 } // namespace clipper
00243 
00244 #endif