PointsSpectrum.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 2001, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** Reliability module developed by:                                   **
00020 **   Terje Haukaas (haukaas@ce.berkeley.edu)                          **
00021 **   Armen Der Kiureghian (adk@ce.berkeley.edu)                       **
00022 **                                                                    **
00023 ** ****************************************************************** */
00024                                                                         
00025 // $Revision: 1.1 $
00026 // $Date: 2003/03/04 00:44:51 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/domain/spectrum/PointsSpectrum.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu)
00032 //
00033 
00034 #include <PointsSpectrum.h>
00035 #include <Spectrum.h>
00036 #include <Vector.h>
00037 #include <classTags.h>
00038 
00039 
00040 PointsSpectrum::PointsSpectrum(int tag, Vector freq, Vector ampl)
00041 :Spectrum(tag,SPECTRUM_points)
00042 {
00043         // Check that the frequency and the amplitude vectors have the same size
00044         int numPoints = freq.Size();
00045         if (numPoints != ampl.Size()) {
00046                 opserr << "Number of points to PointsSpectrum is not consistent!" << endln;
00047         }
00048 
00049         // Check that the frequencies are consequtive
00050         for (int i=1; i<freq.Size(); i++) {
00051                 if (freq(i-1)>freq(i)) {
00052                         opserr << "ERROR: The given Spectrum frequencies are not consequtive!" << endln;
00053                 }
00054         }
00055 
00056         frequencies = new Vector(freq);
00057         amplitudes = new Vector(ampl);
00058 
00059 }
00060 
00061 PointsSpectrum::~PointsSpectrum()
00062 {
00063         if (frequencies != 0) 
00064                 delete frequencies;
00065         if (amplitudes != 0)
00066                 delete frequencies;
00067 }
00068 
00069 void
00070 PointsSpectrum::Print(OPS_Stream &s, int flag)  
00071 {
00072 }
00073 
00074 
00075 double
00076 PointsSpectrum::getMinFrequency()
00077 {
00078         return (*frequencies)(0);
00079 }
00080 
00081 
00082 double
00083 PointsSpectrum::getMaxFrequency()
00084 {
00085         return (*frequencies)(frequencies->Size()-1);
00086 }
00087 
00088 
00089 double
00090 PointsSpectrum::getAmplitude(double frequency)
00091 {
00092         double result;
00093 
00094         if (frequency < (*frequencies)(0)  ||  frequency > (*frequencies)(frequencies->Size()-1) ) {
00095                 result = 0.0;
00096         }
00097         else {
00098                 double dy, dx, a, b;
00099                 for (int i=1; i<frequencies->Size(); i++) {
00100                         if (frequency > (*frequencies)(i-1) && frequency < (*frequencies)(i)) {
00101                                 dy = (*amplitudes)(i)  -  (*amplitudes)(i-1);
00102                                 dx = (*frequencies)(i)  -  (*frequencies)(i-1);
00103                                 a = dy/dx;
00104                                 b = (*amplitudes)(i-1);
00105                                 result = a * (frequency-(*frequencies)(i-1)) + b;
00106                         }
00107                 }
00108         }
00109 
00110         return result;
00111 }

Generated on Mon Oct 23 15:05:26 2006 for OpenSees by doxygen 1.5.0