Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

reduced_nport.h

Go to the documentation of this file.
00001 // SuperMix version 1.0  C++ source file
00002 //
00003 // Copyright (c) 1999 California Institute of Technology.
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms for noncommercial
00007 // purposes are permitted provided that the above copyright notice and
00008 // this paragraph are duplicated in all such forms and that any
00009 // documentation and other materials related to such distribution and
00010 // use acknowledge that the software was developed by California
00011 // Institute of Technology. Redistribution and/or use in source or
00012 // binary forms is not permitted for any commercial purpose. Use of
00013 // this software does not include a permitted use of the Institute's
00014 // name or trademark for any purpose.
00015 //
00016 // DISCLAIMER:
00017 // THIS SOFTWARE AND/OR RELATED MATERIALS ARE PROVIDED "AS-IS" WITHOUT
00018 // WARRANTY OF ANY KIND INCLUDING ANY WARRANTIES OF PERFORMANCE OR
00019 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET
00020 // FORTH IN UCC 23212-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
00021 // LICENSED PRODUCT, HOWEVER USED.  IN NO EVENT SHALL CALTECH/JPL BE
00022 // LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING BUT NOT LIMITED TO
00023 // INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC
00024 // DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF
00025 // WHETHER CALTECH/JPL SHALL BE ADVISED, HAVE REASON TO KNOW, OR IN
00026 // FACT SHALL KNOW OF THE POSSIBILITY.  THE USER BEARS ALL RISK
00027 // RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND/OR RELATED
00028 // MATERIALS.
00029 //
00030 // **************************************************************
00031 // reduced_nport.h
00032 //
00033 // 10/11/00 FRR
00034 //
00035 // Here is an nport which acts like its parent nport with several ports
00036 // removed. If given an nport which models a circuit, this device simply
00037 // selects specified rows and columns from the parent's S matrix and
00038 // drops the rest. The new, smaller S matrix is returned, along with a
00039 // noise correlation matrix generated from the new S matrix using
00040 // sdata::passive_noise(). The result is a passive, sourceless nport.
00041 //
00042 // The parent nport can be specified in the constructor or with the
00043 // nport() member function.
00044 //
00045 // The ports from the parent which are to be included in the result are
00046 // specified in the constructor and/or with the add_port() member
00047 // function.
00048 //
00049 // Example:
00050 // -------
00051 // Suppose you have a circuit model for a 4-port object, but you only
00052 // need to consider ports 2 and 4 of the model, because the other two
00053 // ports are always terminated by the normalizing impedance device::Z0,
00054 // and you only are concerned with the waves at ports 2 and 4.
00055 //
00056 // circuit a;                // the 4-port model
00057 // reduced_nport b(a,2,4);   // b uses only a's ports 2 and 4
00058 //
00059 // sdata s = b.get_data();   // b calls a.get_data(), and then only keeps
00060 //                           // the data for ports 2 and 4, which it
00061 //                           // returns in the form of a 2-port sdata.
00062 //
00063 // This functionality is not included by supermix.h. You must
00064 // explicitly #include this header file.
00065 // 
00066 // **************************************************************
00067 
00068 #ifndef REDUCED_NPORT_H
00069 #define REDUCED_NPORT_H
00070 
00071 #include "nport.h"
00072 #include "matmath.h"
00073 #include <list>
00074 
00075 
00076 class reduced_nport : public nport
00077 {
00078 private:
00079   typedef list<int> array;
00080   array ports;
00081   int size_;
00082   nport *p;
00083 
00084   bool matrix_reduce(const Matrix & in)
00085     {
00086       if (size_ <= 0) return false;
00087       int min = in.minindex(), max = in.maxindex();
00088 
00089       int i, j;
00090       array::const_iterator ii, jj;
00091       for (i = 1, ii = ports.begin(); i <= size_; ++i) {
00092         int p1 = *(ii++);
00093         if(p1 < min || p1 > max) return false;
00094         data.S[i][i] = in[p1][p1];
00095         for (j = i+1, jj = ii; j <= size_; ++j, ++jj) {
00096           int p2 = *jj;
00097           data.S[i][j] = in[p1][p2];
00098           data.S[j][i] = in[p2][p1];
00099         }
00100       }
00101 
00102       return true;
00103     }
00104 
00105   void recalc() { recalc_S(); data.passive_noise(device::f, device::T); }
00106   void recalc_S()
00107     {
00108       if(!matrix_reduce(p->get_data_S().S))
00109         error::fatal("Couldn't reduce ports in reduced_nport.");
00110     }
00111 
00112 public:
00113 
00114   // The default constructor creates an uninitialized (size 0) instance.
00115   reduced_nport() : ports(), size_(0), p(0)
00116     { info.active = info.source = false; }
00117 
00118   // This constructor takes a parent nport and up to 4 ports to be assigned
00119   // to the reduced version (A port argument of 0 is ignored). The ports of
00120   // the result are numbered such that port 1 corresponds to the first port
00121   // argument, port 2 to the second, etc. If you need more than 4 ports,
00122   // make add_port() calls following construction to identify the additional
00123   // ports you need from the parent.
00124   reduced_nport(nport & ckt, int p1 = 0, int p2 = 0, int p3 = 0, int p4 = 0)
00125     : ports(), size_(), p(&ckt)
00126     {
00127       if (p1 != 0) add_port(p1);
00128       if (p2 != 0) add_port(p2);
00129       if (p3 != 0) add_port(p3);
00130       if (p4 != 0) add_port(p4);
00131       info.active = info.source = false;
00132     }
00133 
00134   // Here's how you specify or change the parent nport; it also clears any
00135   // previous port assignments, so you need to make add_port() calls after
00136   // calling this function. It returns a reference to its object.
00137   reduced_nport & nport(nport & ckt)
00138     {
00139       p = &ckt;
00140       size_ = 0;
00141       ports.erase(ports.begin(),ports.end());
00142       data.S.make_empty(); data.C.make_empty(); data.B.make_empty();
00143       return *this;
00144     } 
00145 
00146   // Here's how you add another port assignment. The argument is a port index
00147   // of the parent nport; the function returns the index of the reduced S
00148   // matrix to which this port will correspond. The first port assigned will
00149   // correspond to index 1, the next to index 2, etc.
00150   int add_port(int n)
00151     {
00152       ports.push_back(n);
00153       ++size_;
00154       data.resize(size_);
00155       return size_;
00156     }
00157 
00158   int size() { return size_;}
00159 
00160 };
00161 
00162 #endif /* REDUCED_NPORT_H */
00163 
00164 
00165 
00166 

Please direct comments and corrections to supermix@submm.caltech.edu
Go to the supermix home page
Generated by doxygen1.2.7