Chain::Chain(const Lead& lL, const std::string& T1, const Insulator& B, const std::string& T2, const Lead& lR) { lead.push_back(lL); lead.push_back(lR); barrier.push_back(B); couplingT.push_back( mat22(T1) ); couplingT.push_back( mat22(T2) ); _numBarrierAtom+=B.numAtom; // TODO }
void TestDim::index() { Dim sca; Dim row2(Dim::row_vec(2)); Dim row3(Dim::row_vec(3)); Dim col2(Dim::col_vec(2)); Dim col3(Dim::col_vec(3)); Dim mat22(Dim::matrix(2,2)); Dim mat32(Dim::matrix(3,2)); Dim mat23(Dim::matrix(2,3)); Dim mat33(Dim::matrix(3,3)); CPPUNIT_ASSERT (sca.index_dim(DoubleIndex::one_elt(sca,0,0))==sca); CPPUNIT_ASSERT (row3.index_dim(DoubleIndex::one_elt(row3,0,0))==sca); CPPUNIT_ASSERT (row3.index_dim(DoubleIndex::one_row(row3,0))==row3); CPPUNIT_ASSERT (row3.index_dim(DoubleIndex::cols(row3,0,1))==row2); CPPUNIT_ASSERT (col3.index_dim(DoubleIndex::one_elt(col3,0,0))==sca); CPPUNIT_ASSERT (col3.index_dim(DoubleIndex::one_col(col3,0))==col3); CPPUNIT_ASSERT (col3.index_dim(DoubleIndex::rows(col3,0,1))==col2); CPPUNIT_ASSERT (mat23.index_dim(DoubleIndex::one_elt(mat23,0,0))==sca); CPPUNIT_ASSERT (mat23.index_dim(DoubleIndex::one_row(mat23,0))==row3); CPPUNIT_ASSERT (mat23.index_dim(DoubleIndex::one_col(mat23,0))==col2); CPPUNIT_ASSERT (mat23.index_dim(DoubleIndex::cols(mat23,0,1))==mat22); CPPUNIT_ASSERT (mat23.index_dim(DoubleIndex::subrow(mat23,0,0,1))==row2); CPPUNIT_ASSERT (mat23.index_dim(DoubleIndex::all(mat23))==mat23); CPPUNIT_ASSERT (mat32.index_dim(DoubleIndex::subcol(mat32,0,1,0))==col2); CPPUNIT_ASSERT (mat33.index_dim(DoubleIndex::rows(mat33,0,1))==mat23); CPPUNIT_ASSERT (mat33.index_dim(DoubleIndex::cols(mat33,0,1))==mat32); }
mat22 mat22::rotate(float radian) { float cosr = cosf(radian); float sinr = sinf(radian); return mat22( cosr, -sinr, sinr, cosr); }
void TestDim::vec() { Dim sca; Dim row2(Dim::row_vec(2)); Dim row3(Dim::row_vec(3)); Dim col2(Dim::col_vec(2)); Dim col3(Dim::col_vec(3)); Dim mat22(Dim::matrix(2,2)); Dim mat32(Dim::matrix(3,2)); Dim mat23(Dim::matrix(2,3)); Dim mat33(Dim::matrix(3,3)); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(sca),true)==sca); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(sca),false)==sca); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(sca,sca),true)==row2); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(sca,sca),false)==col2); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(sca,sca,sca),true)==row3); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(sca,sca,sca),false)==col3); CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(sca,col2),true),DimException); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(sca,col2),false)==col3); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(sca,row2),true)==row3); CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(sca,row2),false),DimException); CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(sca,mat22),true),DimException); CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(sca,mat22),false),DimException); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(col2),true)==col2); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(col2),false)==col2); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(col2,col2),true)==mat22); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(col2,col2),false)==Dim::col_vec(4)); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(col2,col2,col2),true)==mat23); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(col2,col2,col2),false)==Dim::col_vec(6)); CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(col2,row2),true),DimException); CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(col2,row2),false),DimException); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(col2,mat22),true)==mat23); CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(col2,mat22),false),DimException); CPPUNIT_ASSERT (vec_dim(Array<const Dim>(col2,mat22,col2),true)==Dim::matrix(2,4)); }
Chain& Chain::operator<<(const std::string& obj) { couplingT.push_back( mat22(obj) ); return *this; }
mat22 mat22::flip_y() { return mat22( 1, 0, 0, -1); }
mat22 mat22::flip_x() { return mat22( -1, 0, 0, 1); }
mat22 mat22::mat22::scale(float sx, float sy) { return mat22( sx, 0, 0, sy); }
mat22 mat22::mat22::scale(float scaler) { return mat22( scaler, 0, 0, scaler); }
void TestDim::mul() { Dim sca; Dim row2(Dim::row_vec(2)); Dim row3(Dim::row_vec(3)); Dim col2(Dim::col_vec(2)); Dim col3(Dim::col_vec(3)); Dim mat22(Dim::matrix(2,2)); Dim mat32(Dim::matrix(3,2)); Dim mat23(Dim::matrix(2,3)); Dim mat33(Dim::matrix(3,3)); CPPUNIT_ASSERT (mul_dim(sca,sca)==sca); CPPUNIT_ASSERT (mul_dim(sca,row2)==row2); CPPUNIT_ASSERT (mul_dim(sca,row3)==row3); CPPUNIT_ASSERT (mul_dim(sca,col2)==col2); CPPUNIT_ASSERT (mul_dim(sca,col3)==col3); CPPUNIT_ASSERT (mul_dim(sca,mat22)==mat22); CPPUNIT_ASSERT (mul_dim(sca,mat23)==mat23); CPPUNIT_ASSERT (mul_dim(sca,mat32)==mat32); CPPUNIT_ASSERT (mul_dim(sca,mat33)==mat33); CPPUNIT_ASSERT_THROW(mul_dim(row2,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row2,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row2,row3),DimException); CPPUNIT_ASSERT (mul_dim(row2,col2)==sca); CPPUNIT_ASSERT_THROW(mul_dim(row2,col3),DimException); CPPUNIT_ASSERT (mul_dim(row2,mat22)==row2); CPPUNIT_ASSERT_THROW(mul_dim(row2,mat32),DimException); CPPUNIT_ASSERT (mul_dim(row2,mat23)==row3); CPPUNIT_ASSERT_THROW(mul_dim(row2,mat33),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row3,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row3,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row3,row3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row3,col2),DimException); CPPUNIT_ASSERT (mul_dim(row3,col3)==sca); CPPUNIT_ASSERT_THROW(mul_dim(row3,mat22),DimException); CPPUNIT_ASSERT (mul_dim(row3,mat32)==row2); CPPUNIT_ASSERT_THROW(mul_dim(row3,mat23),DimException); CPPUNIT_ASSERT (mul_dim(row3,mat33)==row3); CPPUNIT_ASSERT (mul_dim(col2,sca)==col2); CPPUNIT_ASSERT (mul_dim(col2,row2)==mat22); CPPUNIT_ASSERT (mul_dim(col2,row3)==mat23); CPPUNIT_ASSERT_THROW(mul_dim(col2,col2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,col3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,mat22),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,mat32),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,mat23),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,mat33),DimException); CPPUNIT_ASSERT (mul_dim(col3,sca)==col3); CPPUNIT_ASSERT (mul_dim(col3,row2)==mat32); CPPUNIT_ASSERT (mul_dim(col3,row3)==mat33); CPPUNIT_ASSERT_THROW(mul_dim(col3,col2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,col3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,mat22),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,mat32),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,mat23),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,mat33),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat22,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat22,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat22,row3),DimException); CPPUNIT_ASSERT (mul_dim(mat22,col2)==col2); CPPUNIT_ASSERT_THROW(mul_dim(mat22,col3),DimException); CPPUNIT_ASSERT (mul_dim(mat22,mat22)==mat22); CPPUNIT_ASSERT_THROW(mul_dim(mat22,mat32),DimException); CPPUNIT_ASSERT (mul_dim(mat22,mat23)==mat23); CPPUNIT_ASSERT_THROW(mul_dim(mat22,mat33),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat32,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat32,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat32,row3),DimException); CPPUNIT_ASSERT (mul_dim(mat32,col2)==col3); CPPUNIT_ASSERT_THROW(mul_dim(mat32,col3),DimException); CPPUNIT_ASSERT (mul_dim(mat32,mat22)==mat32); CPPUNIT_ASSERT_THROW(mul_dim(mat32,mat32),DimException); CPPUNIT_ASSERT (mul_dim(mat32,mat23)==mat33); CPPUNIT_ASSERT_THROW(mul_dim(mat32,mat33),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat23,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat23,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat23,row3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat23,col2),DimException); CPPUNIT_ASSERT (mul_dim(mat23,col3)==col2); CPPUNIT_ASSERT_THROW(mul_dim(mat23,mat22),DimException); CPPUNIT_ASSERT (mul_dim(mat23,mat32)==mat22); CPPUNIT_ASSERT_THROW(mul_dim(mat23,mat23),DimException); CPPUNIT_ASSERT (mul_dim(mat23,mat33)==mat23); CPPUNIT_ASSERT_THROW(mul_dim(mat33,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat33,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat33,row3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat33,col2),DimException); CPPUNIT_ASSERT (mul_dim(mat33,col3)==col3); CPPUNIT_ASSERT_THROW(mul_dim(mat33,mat22),DimException); CPPUNIT_ASSERT (mul_dim(mat33,mat32)==mat32); CPPUNIT_ASSERT_THROW(mul_dim(mat33,mat23),DimException); CPPUNIT_ASSERT (mul_dim(mat33,mat33)==mat33); }