// // block.h // // Copyright (C) 1996 Limit Point Systems, Inc. // // Author: Curtis Janssen // Maintainer: LPS // // This file is part of the SC Toolkit. // // The SC Toolkit is free software; you can redistribute it and/or modify // it under the terms of the GNU Library General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // // The SC Toolkit is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with the SC Toolkit; see the file COPYING.LIB. If not, write to // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // // The U.S. Government is granted a limited license as per AL 91-7. // #ifndef _math_scmat_block_h #define _math_scmat_block_h #ifdef __GNUC__ #pragma interface #endif #include namespace sc { class SCElementOp; class SCElementOp2; class SCElementOp3; /** SCMatrixBlock is the base clase for all types of blocks that comprise matrices and vectors. */ class SCMatrixBlock: public SavableState { public: int blocki, blockj; public: SCMatrixBlock(); SCMatrixBlock(StateIn&s); virtual ~SCMatrixBlock(); void save_data_state(StateOut&s); /** Return of copy of this. A runtime error will be generated for blocks that cannot do a deepcopy. These routines are only used internally in the matrix library. */ virtual SCMatrixBlock *deepcopy() const; /** Return a pointer to the block's data and the number of elements in the block. Some blocks cannot provide this information and a runtime error will be generated if these members are called. These routines are only used internally in the matrix library. */ virtual double *dat(); virtual int ndat() const; // These routines are obsolete. virtual void process(SCElementOp*) = 0; virtual void process(SCElementOp2*, SCMatrixBlock*) = 0; virtual void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*) = 0; }; class SCMatrixBlockListLink { private: void operator = (const SCMatrixBlockListLink&) {} // disallowed SCMatrixBlock* _block; SCMatrixBlockListLink* _next; public: SCMatrixBlockListLink(SCMatrixBlock*, SCMatrixBlockListLink* = 0); ~SCMatrixBlockListLink(); void block(SCMatrixBlock*); void next(SCMatrixBlockListLink* link) { _next = link; } SCMatrixBlock* block() { return _block; } SCMatrixBlockListLink* next() { return _next; } }; class SCMatrixBlockListIter { private: SCMatrixBlockListLink* link; public: SCMatrixBlockListIter(): link(0) {} SCMatrixBlockListIter(SCMatrixBlockListLink*l): link(l) {} int operator !=(const SCMatrixBlockListIter p) const { return link != p.link; } void operator ++() { link = link->next(); } void operator ++(int) { link = link->next(); } SCMatrixBlock* block() const { return link->block(); } }; class SCMatrixBlockList: public SavableState { private: SCMatrixBlockListLink* _begin; public: SCMatrixBlockList(); SCMatrixBlockList(StateIn&); ~SCMatrixBlockList(); void save_data_state(StateOut&); void insert(SCMatrixBlock*); void append(SCMatrixBlock*); SCMatrixBlockListIter begin() { return _begin; } SCMatrixBlockListIter end() { return 0; } SCMatrixBlockList *deepcopy(); }; /** The SCVectorSimpleBlock describes a piece of a vector. The following bit of code illustrates the data layout: fill(double *vector, SCVectorSimpleBlock &b) { int i,offset=0; for (i=b.istart; i>1) + b.jstart; for (int i=b.start; ii) offset += b.istart; else offset += i + b.jstart - b.jend; } } */ class SCMatrixLTriSubBlock: public SCMatrixBlock { public: SCMatrixLTriSubBlock(int is,int ie,int js,int je,double*data); SCMatrixLTriSubBlock(StateIn&); // does not delete the data member virtual ~SCMatrixLTriSubBlock(); // does not save the data member void save_data_state(StateOut&); int istart; int iend; int jstart; int jend; double* data; void process(SCElementOp*); void process(SCElementOp2*, SCMatrixBlock*); void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*); }; /** The SCMatrixDiagBlock describes a diagonal piece of a matrix. The following bit of code illustrates the data layout: fill(double **matrix, SCMatrixDiagBlock &b) { int i,j,offset=0; for (i=b.istart,j=b.jstart; i block_; int ready_; public: SCMatrixSimpleSubblockIter(Access, const Ref &b); void begin(); int ready(); void next(); SCMatrixBlock *block(); }; class SCMatrixListSubblockIter: public SCMatrixSubblockIter { protected: Ref list_; SCMatrixBlockListIter iter_; public: SCMatrixListSubblockIter(Access, const Ref &list); void begin(); int ready(); void next(); SCMatrixBlock *block(); }; class SCMatrixNullSubblockIter: public SCMatrixSubblockIter { public: SCMatrixNullSubblockIter(); SCMatrixNullSubblockIter(Access); void begin(); int ready(); void next(); SCMatrixBlock *block(); }; class SCMatrixCompositeSubblockIter: public SCMatrixSubblockIter { protected: int niters_; Ref *iters_; int iiter_; public: SCMatrixCompositeSubblockIter(Access, int niter); SCMatrixCompositeSubblockIter(Ref&, Ref&); ~SCMatrixCompositeSubblockIter(); void set_iter(int i, const Ref &); void begin(); int ready(); void next(); SCMatrixBlock *block(); int current_block() const { return iiter_; } }; class SCMatrixJointSubblockIter: public SCMatrixSubblockIter { protected: int niters_; Ref *iters_; public: SCMatrixJointSubblockIter(const Ref&, const Ref&, const Ref& = 0, const Ref& = 0, const Ref& = 0); ~SCMatrixJointSubblockIter(); void begin(); int ready(); void next(); SCMatrixBlock *block(); SCMatrixBlock *block(int i); }; } #endif // Local Variables: // mode: c++ // c-file-style: "CLJ" // End: