此**用於對兩個 xyz 座標檔案(即 c 0.0 0.1 0.2 這種形式的)進行線性插值。對於幾何構型優化問題,如果很難得到最優結構,則可以使用目標結構的兩個相鄰結構進行線性插值,從而得到最優結構的較好的初始猜測。
程式總共有三個**檔案組成。類的實現沒有寫成單獨的檔案。程式會輸出 geom_#.xyz 這樣一系列插值結構檔案。
---------- dispvec.h ----------
/*
* displacement vector definition
*/#ifndef displacement_vector_h
#define displacement_vector_h
#include #include #include class dispvec
dispvec(double x, double y, double z)
dispvec(const dispvec& rhs)
dispvec& operator=(const dispvec& rhs)
return *this;
}friend dispvec operator-(const dispvec& lhs, const dispvec& rhs)
friend dispvec operator+(const dispvec& lhs, const dispvec& rhs)
dispvec& operator+=(const dispvec& rhs)
dispvec& operator-=(const dispvec& rhs)
friend dispvec operator*(const double& lhs, const dispvec& rhs)
friend dispvec operator*(const dispvec& lhs, const double& rhs)
friend dispvec operator/(const dispvec& lhs, const double& rhs)
dispvec result;
result.x = lhs.x / rhs;
result.y = lhs.y / rhs;
result.z = lhs.z / rhs;
return result;
}friend std::istream& operator>>(std::istream& is, dispvec& rhs)
friend std::ostream& operator<<(std::ostream& os, const dispvec& rhs)
private:
double x;
double y;
double z;
};#endif
---------- atom.h ----------
/*
* atom definition
*/#ifndef atom_class_h
#define atom_class_h
#include #include #include "dispvec.h"
#include class atom
atom(const std::string& label, double x, double y, double z)
: label(label), coord(x, y, z) {}
atom(const std::string& label, const dispvec& coord)
: label(label), coord(coord) {}
dispvec computedispvec(const atom& rhs)
return (rhs.coord - coord);
}atom alongvec(const dispvec& rhs)
atom& movealongvec(const dispvec& rhs)
const std::string& label() const
friend std::istream& operator>>(std::istream& is, atom& rhs)
friend std::ostream& operator<<(std::ostream& os, const atom& rhs)
private:
std::string label;
dispvec coord;
};#endif
---------- main.cpp ----------
#include #include #include #include #include #include "atom.h"
#include "dispvec.h"
using namespace std;
int main(int argc, char** argv)
ifstream geomfile1(argv[1]);
ifstream geomfile2(argv[2]);
if(!geomfile1 || !geomfile2)
vectorgeom1;
vectorgeom2;
atom atom;
while(geomfile1 >> atom)
while(geomfile2 >> atom)
if(geom1.size() != geom2.size())
geomfile1.close();
geomfile2.close();
int numgeom = 0;
cout << "--> number of interpolated geoms: ";
cin >> numgeom;
if(numgeom < 1)
vectordispvecs;
vector::iterator it1 = geom1.begin();
vector::iterator it2 = geom2.begin();
while(it1 != geom1.end())
vector::iterator it3;
it1 = geom1.begin();
cout << "--> displacement vectors (each step):" << endl;
for(it3 = dispvecs.begin(); it3 != dispvecs.end(); ++it3)
cout << "--> reference geometry 1: " << argv[1] << endl;
cout << "--> reference geometry 2: " << argv[2] << endl;
ofstream geomout;
stringstream outname;
for(int ix = 0; ix != numgeom; ++ix)
geomout.close();
}cout << "--> " << numgeom << " file(s) generated! <--" << endl;
return 0;
}
對兩個整數進行加 減 乘 除
include int add int a,int b int sub int a,int b int mul int a,int b int div int a,int b void result int p int a,int b 使用函式的指標p作為result函式的形參 main int i...
c 對兩個Datatable的結構相同進行合併
c 對兩個datatable的結構相同進行合併 datatable db null datatable dt ds.tables 0 兩個datatable進行合併 db dt.copy datarow foundrows dt.select for int i 0 i foundrows.leng...
c 對兩個Datatable的結構相同進行合併
datatable db null datatable dt ds.tables 0 兩個datatable進行合併 db dt.copy datarow foundrows dt.select for inti 0 i foundrows.length i 兩個結構一樣的dt合併 datatabl...