00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: PDEOperatorSum.hpp,v 1.6 2007/11/20 22:00:05 delpinux Exp $ 00019 00020 // Implement the sum of scalar PDE Operators 00021 00022 #ifndef PDE_OPERATOR_SUM_HPP 00023 #define PDE_OPERATOR_SUM_HPP 00024 00025 #include <vector> 00026 00027 #include <StreamCenter.hpp> 00028 00029 #include <PDEOperator.hpp> 00030 #include <ReferenceCounting.hpp> 00031 00040 class PDEOperatorSum 00041 { 00042 private: 00043 typedef 00044 std::vector<ConstReferenceCounting<PDEOperator> > 00045 OperatorList; 00048 OperatorList __operators; 00050 public: 00056 size_t numberOfOperators() const 00057 { 00058 return __operators.size(); 00059 } 00060 00068 ReferenceCounting<PDEOperatorSum> 00069 operator* (const ConstReferenceCounting<ScalarFunctionBase>& c) const 00070 { 00071 PDEOperatorSum* newPDEOperatorSum = new PDEOperatorSum(); 00072 newPDEOperatorSum->__operators.reserve(__operators.size()); 00073 00074 for (OperatorList::const_iterator i = __operators.begin(); 00075 i != __operators.end(); ++i) { 00076 newPDEOperatorSum->add((*(*i))*c); 00077 } 00078 00079 return newPDEOperatorSum; 00080 } 00081 00089 ConstReferenceCounting<PDEOperator> 00090 operator[](const size_t& i) const 00091 { 00092 ASSERT (i<__operators.size()); 00093 return (__operators[i]); 00094 } 00095 00103 const PDEOperatorSum& 00104 operator=(const PDEOperatorSum& pdeOperatorSum) 00105 { 00106 __operators.resize(pdeOperatorSum.__operators.size()); 00107 std::copy(pdeOperatorSum.__operators.begin(), 00108 pdeOperatorSum.__operators.end(), 00109 __operators.begin()); 00110 00111 return *this; 00112 } 00113 00122 friend std::ostream& 00123 operator << (std::ostream& os, const PDEOperatorSum& pdeOperatorSum) 00124 { 00125 if (pdeOperatorSum.__operators.size() > 0) { 00126 os << *(pdeOperatorSum.__operators[0]); 00127 for (size_t i=1; i<pdeOperatorSum.__operators.size(); ++i) 00128 os << '+' << *(pdeOperatorSum.__operators[i]); 00129 } else { 00130 os << 0; 00131 } 00132 00133 return os; 00134 } 00135 00141 void add(ConstReferenceCounting<PDEOperator> pdeOperator) 00142 { 00143 __operators.push_back(pdeOperator); 00144 } 00145 00150 PDEOperatorSum() 00151 { 00152 ; 00153 } 00154 00159 ~PDEOperatorSum() 00160 { 00161 ; 00162 } 00163 }; 00164 00165 #endif // PDE_OPERATOR_SUM_HPP
1.5.6