| [0b990d] | 1 | // | 
|---|
|  | 2 | // scextest.cc | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // Copyright (C) 1996 Limit Point Systems, Inc. | 
|---|
|  | 5 | // | 
|---|
|  | 6 | // Author: Curtis Janssen <cljanss@limitpt.com> | 
|---|
|  | 7 | // Maintainer: LPS | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // This file is part of the SC Toolkit. | 
|---|
|  | 10 | // | 
|---|
|  | 11 | // The SC Toolkit is free software; you can redistribute it and/or modify | 
|---|
|  | 12 | // it under the terms of the GNU Library General Public License as published by | 
|---|
|  | 13 | // the Free Software Foundation; either version 2, or (at your option) | 
|---|
|  | 14 | // any later version. | 
|---|
|  | 15 | // | 
|---|
|  | 16 | // The SC Toolkit is distributed in the hope that it will be useful, | 
|---|
|  | 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 19 | // GNU Library General Public License for more details. | 
|---|
|  | 20 | // | 
|---|
|  | 21 | // You should have received a copy of the GNU Library General Public License | 
|---|
|  | 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to | 
|---|
|  | 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
|  | 24 | // | 
|---|
|  | 25 | // The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
|  | 26 | // | 
|---|
|  | 27 |  | 
|---|
|  | 28 | #include <util/keyval/keyval.h> | 
|---|
|  | 29 | #include <util/state/stateio.h> | 
|---|
|  | 30 | #include <util/state/state_text.h> | 
|---|
|  | 31 | #include <math/scmat/local.h> | 
|---|
|  | 32 | #include <math/optimize/diis.h> | 
|---|
|  | 33 | #include <math/optimize/scextrap.h> | 
|---|
|  | 34 | #include <math/optimize/scextrapmat.h> | 
|---|
|  | 35 |  | 
|---|
|  | 36 | using namespace std; | 
|---|
|  | 37 | using namespace sc; | 
|---|
|  | 38 |  | 
|---|
|  | 39 | // Force linkages: | 
|---|
|  | 40 | #ifndef __PIC__ | 
|---|
|  | 41 | static ForceLink<DIIS> fl0; | 
|---|
|  | 42 | #endif | 
|---|
|  | 43 |  | 
|---|
|  | 44 | int | 
|---|
|  | 45 | main() | 
|---|
|  | 46 | { | 
|---|
|  | 47 | int i; | 
|---|
|  | 48 |  | 
|---|
|  | 49 | Ref<KeyVal> keyval = new ParsedKeyVal( SRCDIR "/scextest.in"); | 
|---|
|  | 50 |  | 
|---|
|  | 51 | Ref<SelfConsistentExtrapolation> extrap; | 
|---|
|  | 52 | extrap << keyval->describedclassvalue("scextrap"); | 
|---|
|  | 53 |  | 
|---|
|  | 54 | RefSCDimension dim = new SCDimension(3, "test_dim"); | 
|---|
|  | 55 | Ref<SCMatrixKit> kit = new LocalSCMatrixKit; | 
|---|
|  | 56 |  | 
|---|
|  | 57 | RefSymmSCMatrix datamat(dim,kit); | 
|---|
|  | 58 | datamat.assign(0.0); | 
|---|
|  | 59 | datamat->shift_diagonal(2.0); | 
|---|
|  | 60 |  | 
|---|
|  | 61 | RefDiagSCMatrix val(dim,kit); | 
|---|
|  | 62 | RefSCMatrix vec(dim,dim,kit); | 
|---|
|  | 63 |  | 
|---|
|  | 64 | // solve f(x) = x | 
|---|
|  | 65 |  | 
|---|
|  | 66 | i = 0; | 
|---|
|  | 67 | while (i < 100 && !extrap->converged()) { | 
|---|
|  | 68 | datamat.diagonalize(val,vec); | 
|---|
|  | 69 | for (int j=0; j<datamat.dim().n(); j++) { | 
|---|
|  | 70 | double v = val.get_element(j); | 
|---|
|  | 71 | val.set_element(j, sqrt(v)); | 
|---|
|  | 72 | } | 
|---|
|  | 73 | RefSymmSCMatrix newdatamat(dim,kit); | 
|---|
|  | 74 | newdatamat.assign(0.0); | 
|---|
|  | 75 | newdatamat.accumulate_transform(vec, val); | 
|---|
|  | 76 | RefSymmSCMatrix errormat = newdatamat - datamat; | 
|---|
|  | 77 |  | 
|---|
|  | 78 | datamat.assign(newdatamat); | 
|---|
|  | 79 | Ref<SCExtrapData> data = new SymmSCMatrixSCExtrapData(datamat); | 
|---|
|  | 80 | Ref<SCExtrapError> error = new SymmSCMatrixSCExtrapError(errormat); | 
|---|
|  | 81 |  | 
|---|
|  | 82 | ExEnv::out0() << "Iteration " << i << ":" << endl; | 
|---|
|  | 83 |  | 
|---|
|  | 84 | datamat.print("Datamat:"); | 
|---|
|  | 85 | errormat.print("Errormat:"); | 
|---|
|  | 86 |  | 
|---|
|  | 87 | extrap->extrapolate(data, error); | 
|---|
|  | 88 |  | 
|---|
|  | 89 | datamat.print("Extrap Datamat"); | 
|---|
|  | 90 |  | 
|---|
|  | 91 | i++; | 
|---|
|  | 92 | } | 
|---|
|  | 93 |  | 
|---|
|  | 94 | StateOutText s("scextest.ckpt"); | 
|---|
|  | 95 | SavableState::save_state(extrap.pointer(),s); | 
|---|
|  | 96 | s.close(); | 
|---|
|  | 97 |  | 
|---|
|  | 98 | StateInText si("scextest.ckpt"); | 
|---|
|  | 99 | Ref<SelfConsistentExtrapolation> e2; | 
|---|
|  | 100 | e2 << SavableState::restore_state(si); | 
|---|
|  | 101 |  | 
|---|
|  | 102 | si.close(); | 
|---|
|  | 103 |  | 
|---|
|  | 104 | return 0; | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 108 |  | 
|---|
|  | 109 | // Local Variables: | 
|---|
|  | 110 | // mode: c++ | 
|---|
|  | 111 | // c-file-style: "CLJ" | 
|---|
|  | 112 | // End: | 
|---|