メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

FEGrid.cc

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
00024 #pragma implementation
00025 #endif
00026 
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030 
00031 #include <iostream>
00032 
00033 #include "FEGrid.h"
00034 #include "lo-error.h"
00035 
00036 // error handling
00037 
00038 void
00039 FEGrid::error (const char* msg) const
00040 {
00041   (*current_liboctave_error_handler) ("fatal FEGrid error: %s", msg);
00042 }
00043 
00044 void
00045 FEGrid::nel_error (void) const
00046 {
00047   error ("number of elements less than 1");
00048 }
00049 
00050 // Constructors
00051 
00052 FEGrid::FEGrid (int nel, double width)
00053 {
00054   if (nel < 1)
00055     {
00056       nel_error ();
00057       return;
00058     }
00059 
00060   elem.resize (nel+1);
00061 
00062   for (int i = 0; i <= nel; i++)
00063     elem.elem (i) = i * width;
00064 }
00065 
00066 FEGrid::FEGrid (int nel, double l, double r)
00067 {
00068   if (nel < 1)
00069     {
00070       nel_error ();
00071       return;
00072     }
00073 
00074   elem.resize (nel+1);
00075 
00076   double width = (r - l) / nel;
00077 
00078   for (int i = 0; i <= nel; i++)
00079     elem.elem (i) = i * width + l;
00080 
00081   check_grid ();
00082 }
00083 
00084 int
00085 FEGrid::element (double x) const
00086 {
00087   if (! in_bounds (x))
00088     {
00089       error ("value not within grid boundaries");
00090       return -1;
00091     }
00092 
00093   int nel = elem.capacity () - 1;
00094   for (int i = 1; i <= nel; i++)
00095     {
00096       if (x >= elem.elem (i-1) && x <= elem.elem (i))
00097         return i;
00098     }
00099   return -1;
00100        
00101 }
00102 
00103 void
00104 FEGrid::check_grid (void) const
00105 {
00106   int nel = elem.capacity () - 1;
00107   if (nel < 1)
00108     {
00109       nel_error ();
00110       return;
00111     }
00112 
00113   for (int i = 1; i <= nel; i++)
00114     {
00115       if (elem.elem (i-1) > elem.elem (i))
00116         {
00117           error ("element boundaries not in ascending order");
00118           return;
00119         }
00120 
00121       if (elem.elem (i-1) == elem.elem (i))
00122         {
00123           error ("zero width element");
00124           return;
00125         }
00126     }
00127 }
00128 
00129 std::ostream&
00130 operator << (std::ostream& s, const FEGrid& g)
00131 {
00132   s << g.element_boundaries ();
00133   return s;
00134 }
00135 
00136 /*
00137 ;;; Local Variables: ***
00138 ;;; mode: C++ ***
00139 ;;; End: ***
00140 */

Wed Dec 29 11:51:34 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送