00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef CLIPPER_RESOL_FN
00046 #define CLIPPER_RESOL_FN
00047
00048 #include "hkl_data.h"
00049
00050 namespace clipper {
00051
00053
00066 class BasisFn_base
00067 {
00068 public:
00070 enum FNtype { GENERAL, LINEAR };
00071
00073 class Fderiv
00074 {
00075 public:
00076 ftype f;
00077 std::vector<ftype> df;
00078 Matrix<> df2;
00079 Fderiv() {}
00080 Fderiv(const int& np) : df(np,0.0), df2(np,np,0.0) {}
00081 };
00082
00084 BasisFn_base() {}
00086 BasisFn_base( const int& np ) : np_(np), result_(np) {}
00088 const int& num_params() const { return np_; }
00090 virtual ftype f( const HKL& hkl, const Cell& cell, const std::vector<ftype>& params ) const { return fderiv( hkl, cell, params ).f; }
00092 virtual const Fderiv& fderiv( const HKL& hkl, const Cell& cell, const std::vector<ftype>& params ) const = 0;
00094 virtual FNtype type() const;
00096 virtual int num_diagonals() const;
00097 protected:
00099 Fderiv& result() const { return result_; }
00100 virtual ~BasisFn_base() {}
00101
00102 private:
00103 int np_;
00104 mutable Fderiv result_;
00105 };
00106
00108
00114 class TargetFn_base
00115 {
00116 public:
00118 class Rderiv
00119 {
00120 public:
00121 ftype r;
00122 ftype dr;
00123 ftype dr2;
00124 };
00125
00127 enum FNtype { GENERAL, QUADRATIC };
00129
00130 virtual Rderiv rderiv( const HKL_info::HKL_reference_index& ih, const ftype& fh ) const = 0;
00132 virtual FNtype type() const { return GENERAL; }
00133 virtual ~TargetFn_base() {}
00134
00136 void debug( const HKL_info& hkl_info ) const;
00137 };
00138
00139
00141
00186 class ResolutionFn
00187 {
00188 public:
00190 ResolutionFn( const HKL_info& hkl_info, const BasisFn_base& basisfn, const TargetFn_base& targetfn, const std::vector<ftype>& params, const ftype damp = 0.0, const bool debug = false );
00192 inline ftype f( const HKL_info::HKL_reference_index& ih ) const { return basisfn_->f( ih.hkl(), cell_, params_ ); }
00194 const std::vector<ftype>& params() const;
00195
00197 void debug() const;
00198
00199 protected:
00200 const HKL_info* hkl_info_;
00201 const TargetFn_base* targetfn_;
00202 const BasisFn_base* basisfn_;
00203 std::vector<ftype> params_;
00204 Cell cell_;
00205
00207 void calc_derivs( const std::vector<ftype>& params, ftype& r, std::vector<ftype>& drdp, Matrix<>& drdp2 ) const;
00208
00210 ResolutionFn() {}
00211 };
00212
00213
00215
00234 class ResolutionFn_nonlinear: public ResolutionFn
00235 {
00236 public:
00238 ResolutionFn_nonlinear( const HKL_info& hkl_info, const BasisFn_base& basisfn, const TargetFn_base& targetfn, const std::vector<ftype>& params, const ftype damp = 0.0, const bool debug = false );
00239 };
00240
00241
00242 }
00243
00244 #endif