00001 /* 00002 * ******** fete: From ENDF To ENDL ********* 00003 * 00004 * Copyright (c) 2006, The Regents of the University of California. 00005 * All rights reserved. 00006 * 00007 * Produced at the Lawrence Livermore National Laboratory. 00008 * Written by David A. Brown, Gerry Hedstrom, Tony Hill 00009 * 00010 * This file is part of fete v1.0 (UCRL-CODE-218718) 00011 * 00012 * Please read the COPYING file for "Our Notice and GNU General 00013 * Public License" in the root of this software distribution. 00014 * 00015 * This program is free software; you can redistribute it and/or modify 00016 * it under the terms of the GNU General Public License (as published by 00017 * the Free Software Foundation) version 2, dated June 1991. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms 00022 * and conditions of the GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU General Public License along 00025 * with this program; if not, write to the Free Software Foundation, Inc., 00026 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00027 * 00028 * $Revision: 1867 $ 00029 * $Date: 2006-05-15 10:19:04 -0700 (Mon, 15 May 2006) $ 00030 * $Author: dbrown $ 00031 * $Id: list_1d.hpp 1867 2006-05-15 17:19:04Z dbrown $ 00032 * 00033 * ******** fete: From ENDF To ENDL ********* 00034 */ 00035 00036 // header for the classes used in making lists 00037 #ifndef ONE_D_LIST_CLASS 00038 #define ONE_D_LIST_CLASS 00039 00040 #include <iostream> 00041 #include <iomanip> 00042 #include <fstream> 00043 #include <cmath> 00044 #include <list> 00045 #include <utility> 00046 #include <vector> 00047 #include <string> 00048 00049 using namespace std; 00050 00051 // ------------------------ class dd_link --------------- 00052 //!The basic link holds a pair of doubles 00053 class dd_link 00054 { 00055 public: 00056 double x; 00057 double y; 00058 00059 //!Default inline constructor is zero. 00060 inline dd_link( ) 00061 { 00062 x = 0.0; 00063 y = 0.0; 00064 } 00065 //!Inline copy constructor 00066 inline dd_link(double xx, double yy) 00067 { 00068 x = xx; 00069 y = yy; 00070 } 00071 00072 //!Inline default desctructor is blank. 00073 inline ~dd_link() {} 00074 00075 //!Common name used to access the X value of this link. 00076 inline double& E_in() 00077 { 00078 return x; 00079 } 00080 //!Common name used to access the X value of this link. 00081 inline double& E_out() 00082 { 00083 return x; 00084 } 00085 //!Common name used to access the X value of this link. 00086 inline double& mu() 00087 { 00088 return x; 00089 } 00090 00091 //!Common name used to access the Y value of this link. 00092 inline double& Prob() 00093 { 00094 return y; 00095 } 00096 00097 //!Common name used to access the Y value of this link. 00098 inline double& x_sec() 00099 { 00100 return y; 00101 } 00102 00103 //!Equality testing. 00104 inline bool operator==(const dd_link& other) const 00105 { 00106 return ( x == other.x && y == other.y ); 00107 } 00108 00109 }; 00110 00111 // ************************************** 00112 // Here is the principal linked list 00113 // ************************************** 00114 00115 // ----------------------- class dd_list ------------------- 00116 //!List of dd_links. 00117 class dd_list : public list< dd_link > 00118 { 00119 private: 00120 00121 public: 00122 //! A label for the list. 00123 double tag; 00124 00125 double min_E_out; // needed to recover from scaling to unit base 00126 double max_E_out; 00127 00128 //! Energy at which the interpolation type changes 00129 vector<int> NBT; 00130 00131 // the interpolation types 00132 // 1: histogram 00133 // 2: linear-linear 00134 // 3: y linear in log(x) 00135 // 4: log(y) linear in x 00136 // 5: log-log 00137 // 6: special for charged particle cross sections (see 0.19) 00138 // 11-15: corresponding points (see 0.20) 00139 // 21-25: unit base (see 0.20) 00140 //! Interpolation type used. 00141 vector<int> INT; 00142 00143 //!Default constructor 00144 dd_list(): tag(0.0), min_E_out(0.0), max_E_out(20.0), INT(0), NBT(0) {} 00145 00146 //!Common name used to access the label for this list. 00147 inline double& E_in() 00148 { 00149 return tag; 00150 } 00151 00152 //! To scale the energies in the list to make 0 <= E' <= 1 00153 void unit_base(); 00154 00155 //! To expand the energies from unit base to min_E_out <= E' <= max_E_out 00156 void rescale(); 00157 00158 //! Method for printing this list. 00159 void print(); 00160 00161 //! Copy one list into another 00162 void copy( dd_list& list_2 ); 00163 00164 //! Adds one list to another, with interpolation. 00165 dd_list& operator+=(dd_list& list_2); 00166 00167 //! Add list_2 as discrete lines (for gammas). Here, tol measures the sameness of the energies 00168 dd_list& line_sum( dd_list& list_2, double tol ); 00169 00170 //! If two adjacent lines have the same frequency, this routine adds their intensities. 00171 void join_lines( ); 00172 00173 //! Scales the Y value of this list. 00174 dd_list& operator*=(double X); 00175 00176 //! Multiplies the Y values by the Y values in a second list. 00177 dd_list& operator*=(dd_list& list_2); 00178 00179 //! Divides the Y values in one list by the values in another. 00180 dd_list& operator/=(dd_list& list_2); 00181 00182 //! Tests if data actually needs jump widening 00183 bool needs_widening( ); 00184 00185 //! Shift duplicate x-values in the list. 00186 void widen_jumps( double cluster_min=1e-11 ); 00187 00188 //! Utility code used by widen_jumps 00189 void widen_cluster( dd_list::iterator cluster_start, 00190 dd_list::iterator cluster_end, int cluster_size, 00191 double jump_width, double cluster_min ); 00192 00193 //! Thin the list to within global tolerance (tol_1d). 00194 void thinit(); 00195 00196 //! Insert into the list NP data pairs from inFile. 00197 void read_data( ifstream& inFile, int NP, double x_factor, 00198 double y_factor); 00199 00200 //! Find the link with the next larger x-value 00201 dd_list::iterator find_next( double X ); 00202 00203 //! Find the y-value corresponding to this x using lin-lin interpolation. 00204 double evaluate( double X ); 00205 00206 //! Chops off values above the maximum ENDL energy 00207 void chop( double max_E ); 00208 00209 //! Writes the 2-column data to an ENDL file, e.g., cross sections 00210 void write_endl( int I ); 00211 00212 //! This function performs Interp_Type interpolation between two dd_links. 00213 double interp( double E, dd_link& left_link, 00214 dd_link& right_link, int Interp_Type ); 00215 00216 //! This function performs histogram interpolation between two dd_links. 00217 double hist_interp( double E, dd_link& left_link, 00218 dd_link& right_link ); 00219 00220 //! This function performs lin-lin interpolation between two dd_links. 00221 double linlin_interp( double E, dd_link& left_link, 00222 dd_link& right_link ); 00223 00224 //! This function performs lin-log interpolation between two dd_links. 00225 double linlog_interp( double E, dd_link& left_link, 00226 dd_link& right_link ); 00227 00228 //! This function performs log-lin interpolation between two dd_links. 00229 double loglin_interp( double E, dd_link& left_link, 00230 dd_link& right_link ); 00231 00232 //! This function performs log-log interpolation between two dd_links. 00233 double loglog_interp( double E, dd_link& left_link, 00234 dd_link& right_link ); 00235 00236 //find a root of func(x, alpha) = target 00237 //between BB and CC. 00238 //! Return the root with accuracy of tol + 4*tol*|root| 00239 double zeroin(double (*func)(double, double), 00240 double target, 00241 dd_link& BB, 00242 dd_link& CC, 00243 double alpha, 00244 double tol); 00245 00246 //! Checks the accuracy of linear interpolation. 00247 // Ignore values below the noise. 00248 bool check_interp(dd_list::iterator left_link, dd_list::iterator mid_link, 00249 dd_list::iterator right_link, double tol, double noise); 00250 00251 //! Expand the list to permit linear-linear interpolation. 00252 //! Max_E is the maximum energy for histogram data. 00253 void expand_interp( double Max_E); 00254 00255 //! This version is used for gammas, in which LEP is the interpolation type 00256 //! Max_E is the maximum energy for histogram data. 00257 void expand_interp( int LEP, double Max_E ); 00258 00259 //! Expand histogram data to linear-linear between the two cosecutive links. 00260 void Hist_2_LinLin(dd_list::iterator left_link, double Max_E); 00261 00262 //! Expand histogram data to linear-linear between the two links. 00263 void Hist_2_LinLin(dd_list::iterator first_link, 00264 dd_list::iterator last_link, double Max_E ); 00265 00266 //! Expand the log-log data to linear-linear between the two consecutive links. 00267 void LogLog_2_LinLin(dd_list::iterator left_link); 00268 00269 //! Expand the log-log data to linear-linear between the two links. 00270 void LogLog_2_LinLin(dd_list::iterator first_link,iterator last_link); 00271 00272 //! This function expands log-log data to linear-linear for an entire link list. 00273 void LogLog_2_LinLin( ); 00274 00275 //! Appends to E_in_list the incident energies in this list 00276 void collect_E_in( list< double >& E_in_list ); 00277 00278 // Used by the fill_in_lists routine 00279 void pad_head( double E0 ); 00280 00281 // Used by the fill_in_lists routine 00282 void pad_tail( double E0 ); 00283 00284 // Deletes links with duplicate x values 00285 void unique( ); 00286 00287 // make sure that there are links for each energy in E_in_list 00288 void fill_with( list< double >& E_in_list ); 00289 }; 00290 00291 // -------------------- fill_in_lists --------------- 00292 //! This routine fills in to ensure that the x-values in both lists are the same. 00293 void fill_in_lists( dd_list& list_1, dd_list& list_2 ); 00294 #endif