Triang_trunc.h

00001 /*  _________________________________________________________________________
00002  *
00003  *  UTILIB: A utility library for developing portable C++ codes.
00004  *  Copyright (c) 2001, Sandia National Laboratories.
00005  *  This software is distributed under the GNU Lesser General Public License.
00006  *  For more information, see the README file in the top UTILIB directory.
00007  *  _________________________________________________________________________
00008  */
00009 
00010 //
00011 // Triang_trunc.h - generates a triangular truncated distribution
00012 //
00013 // Triang_trunc.h adapted by B. D. Schimel from Uniform.h
00014 // Uniform.h adapted from GNU code by Dirk Grunwald.
00015 //
00016 
00017 #ifndef _Triang_trunc_h
00018 #define _Triang_trunc_h
00019 
00020 #include "Triangular.h"
00021 
00022 
00023 
00024 class Triang_trunc: public Triangular {
00025 
00026     double sig(double deltab, double dist);
00027 
00028 public:
00029 
00030     Triang_trunc(RNG *gen=(RNG*)NULL, double low=0.0, double high=1.0);
00031     void set_base(double deltab, double lwr, double upr, double x);
00032 };
00033 
00034 inline Triang_trunc::Triang_trunc(RNG *gen, double low, double high)
00035 :Triangular(gen,low,high)
00036 {
00037 }
00038 
00039 inline void Triang_trunc::set_base(double deltab, double lwr, double upr, 
00040                                                                 double x)
00041 {
00042   double dist,temp;
00043 
00044   //cutoff factors
00045   dist = x-lwr;
00046   sigma_lwr = sig(deltab,dist);
00047   dist = upr-x;
00048   sigma_upr = sig(deltab,dist);
00049 
00050   //probability of stepping toward the lower bound
00051   temp=sigma_lwr-0.5*sigma_lwr*sigma_lwr;
00052   prob_lwr=temp/(temp+sigma_upr-0.5*sigma_upr*sigma_upr);
00053 
00054 }
00055 
00056 inline double Triang_trunc::sig(double deltab, double dist)
00057 {
00058   double sigma;
00059 
00060   //cutoff factor sigma
00061   if(dist < 0.0)
00062     sigma=0.0;
00063   else if(dist < deltab )
00064     sigma=dist/deltab;
00065   else
00066     sigma=1.0;
00067 
00068 
00069   return(sigma);
00070 
00071 }
00072 
00073 #endif