evolution_full.C

00001 /*
00002  *  Methods of template class Evolution_full
00003  *
00004  *    (see file evolution.h for documentation).
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2004  Eric Gourgoulhon & Jerome Novak
00010  *
00011  *   This file is part of LORENE.
00012  *
00013  *   LORENE is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License version 2
00015  *   as published by the Free Software Foundation.
00016  *
00017  *   LORENE is distributed in the hope that it will be useful,
00018  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *   GNU General Public License for more details.
00021  *
00022  *   You should have received a copy of the GNU General Public License
00023  *   along with LORENE; if not, write to the Free Software
00024  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 /*
00029  * $Id: evolution_full.C,v 1.8 2005/01/11 12:46:16 f_limousin Exp $
00030  * $Log: evolution_full.C,v $
00031  * Revision 1.8  2005/01/11 12:46:16  f_limousin
00032  * Implement the function operator=(const Evolution_full<TyT>& ).
00033  *
00034  * Revision 1.7  2004/05/31 09:06:12  e_gourgoulhon
00035  * Added protection against self-assignement in method update.
00036  *
00037  * Revision 1.6  2004/03/26 13:31:09  j_novak
00038  * Definition of the macro UNDEF_STEP for non-defined time-steps.
00039  * Changes in the way the time derivative is calculated.
00040  *
00041  * Revision 1.5  2004/03/26 08:22:13  e_gourgoulhon
00042  * *** Full reorganization of class Evolution ***
00043  * Introduction of the notion of absoluteuniversal time steps,
00044  * stored in the new array 'step'.
00045  * The new function position(int j) makes a correspondence
00046  * between a universal time step j and the position in the
00047  * arrays step, the_time and val.
00048  * Only method update is now virtual.
00049  * Methods operator[], position, is_known, downdate belong to
00050  * the base class.
00051  *
00052  * Revision 1.4  2004/03/23 14:50:41  e_gourgoulhon
00053  * Added methods is_updated, downdate, get_jlast, get_size,
00054  * as well as constructors without any initial value.
00055  * Formatted documentation for Doxygen.
00056  *
00057  * Revision 1.3  2004/02/17 22:13:34  e_gourgoulhon
00058  * Suppressed declaration of global char[] evolution_C = ...
00059  *
00060  * Revision 1.2  2004/02/16 12:37:01  e_gourgoulhon
00061  * Method update: initialization of extended part of arrays val and the_time.
00062  *
00063  * Revision 1.1  2004/02/15 21:55:33  e_gourgoulhon
00064  * Introduced derived classes Evolution_full and Evolution_std.
00065  * Evolution is now an abstract base class.
00066  *
00067  *
00068  *
00069  * $Header: /cvsroot/Lorene/C++/Include/Template/evolution_full.C,v 1.8 2005/01/11 12:46:16 f_limousin Exp $
00070  *
00071  */
00072 
00073 // C++ headers
00074 #include "headcpp.h" 
00075 
00076 // C headers
00077 #include <stdlib.h>
00078 #include <assert.h>
00079 
00080 
00081 
00082                     //-------------------------//
00083                     //      Constructors       //
00084                     //-------------------------//
00085 
00086                     
00087 template<typename TyT> 
00088 Evolution_full<TyT>::Evolution_full(const TyT& initial_value, int initial_j,
00089                             double initial_time, int fact_resize_i)
00090       : Evolution<TyT>(initial_value, initial_j, initial_time, 100), 
00091         fact_resize(fact_resize_i) 
00092 { }    
00093                        
00094                                         
00095 template<typename TyT> 
00096 Evolution_full<TyT>::Evolution_full(int fact_resize_i)
00097       : Evolution<TyT>(100), 
00098         fact_resize(fact_resize_i) 
00099 { }    
00100                                         
00101 
00102 template<typename TyT> 
00103 Evolution_full<TyT>::Evolution_full(const Evolution_full<TyT>& evo)
00104       : Evolution<TyT>(evo), 
00105         fact_resize(evo.fact_resize) 
00106 { }
00107 
00108                     
00109                     
00110                     //-----------------------//
00111                     //      Destructor       //
00112                     //-----------------------//
00113 
00114                     
00115 template<typename TyT> 
00116 Evolution_full<TyT>::~Evolution_full(){ }
00117                     
00118                     
00119                     //-----------------------//
00120                     //      Mutators         //
00121                     //-----------------------//
00122 
00123                     
00124 template<typename TyT> 
00125 void Evolution_full<TyT>::operator=(const Evolution_full<TyT>& evo) {
00126 
00127     size = evo.size ;
00128     pos_jtop = evo.pos_jtop ;
00129  
00130     for (int j=0; j<size; j++) {
00131         step[j] = evo.step[j] ; 
00132     }
00133     
00134     for (int j=0; j<size; j++) {
00135         the_time[j] = evo.the_time[j] ; 
00136     }
00137     
00138 
00139     for (int j=0; j<size; j++) {
00140         if (val[j] != 0x0) {
00141         delete val[j] ;
00142         val[j] = 0x0 ;
00143     }
00144     }
00145 
00146     for (int j=0; j<size; j++) {
00147         if (evo.val[j] != 0x0) {        
00148             val[j] = new TyT( *(evo.val[j]) ) ; 
00149         }
00150         else {
00151             val[j] = 0x0 ; 
00152         }
00153     }
00154 
00155     fact_resize = evo.fact_resize ; 
00156 }
00157 
00158 template<typename TyT> 
00159 void Evolution_full<TyT>::operator=(const Evolution<TyT>& ) {
00160 
00161     cerr << "void Evolution_full<TyT>::operator= : not implemented yet ! \n" ; 
00162     abort() ; 
00163 
00164 }
00165 
00166 
00167                     
00168 template<typename TyT> 
00169 void Evolution_full<TyT>::update(const TyT& new_value, int j, 
00170                                  double time_j) {
00171 
00172     
00173     if (is_known(j)) {   // Case of a time step already stored
00174                          //-----------------------------------
00175         int pos = position(j) ; 
00176         assert( fabs(the_time[pos] - time_j) < 1.e-14 ) ;   
00177         assert( val[pos] != &new_value ) ; // to avoid self assignment
00178         delete val[pos] ; 
00179         val[pos] = new TyT(new_value) ; 
00180     }
00181     else {              // Storage of a new time step
00182                         //---------------------------
00183         if ( (pos_jtop != -1) && (j < step[pos_jtop]) ) {
00184             cerr << 
00185                 "Evolution_full<TyT>::update : the time step j = "
00186                 << j << " must be in the future\n" 
00187                 << "  of the last stored time step (" <<  step[pos_jtop] << ") !"
00188                 << endl ; 
00189             abort() ; 
00190         }
00191           
00192         pos_jtop++ ; 
00193             
00194         if (pos_jtop == size) {  // re-organization of arrays step, the_time 
00195                                 // and val is necessary
00196     
00197             int size_new = fact_resize * size ; 
00198 
00199             int* step_new = new int[size_new] ;
00200             for (int i=0; i<size; i++) {
00201                 step_new[i] = step[i] ; 
00202             }
00203             for (int i=size; i<size_new; i++) {
00204                 step_new[i] = UNDEF_STEP ; 
00205             }
00206             
00207             double* the_time_new = new double[size_new] ;
00208             for (int i=0; i<size; i++) {
00209                 the_time_new[i] = the_time[i] ; 
00210             }
00211             for (int i=size; i<size_new; i++) {
00212                 the_time_new[i] = -1e20 ; 
00213             }
00214             
00215             TyT** val_new = new TyT*[size_new] ; 
00216             for (int i=0; i<size; i++) {
00217                 val_new[i] = val[i] ; 
00218             }
00219             for (int i=size; i<size_new; i++) {
00220                 val_new[i] = 0x0 ; 
00221             }
00222             
00223             size = size_new ;
00224             delete [] step ; 
00225             step = step_new ;  
00226             delete [] the_time ; 
00227             the_time = the_time_new ; 
00228             delete [] val ; 
00229             val = val_new ;  
00230             
00231         }
00232         else {
00233             assert( pos_jtop < size ) ; 
00234             assert( val[pos_jtop] == 0x0 ) ; 
00235         }
00236     
00237         step[pos_jtop] = j ;
00238         the_time[pos_jtop] = time_j ; 
00239         val[pos_jtop] = new TyT( new_value ) ; 
00240     }
00241 }                   
00242                     
00243 
00244 
00245 
00246 

Generated on Tue Feb 7 01:35:17 2012 for LORENE by  doxygen 1.4.6