evolution_std.C

00001 /*
00002  *  Methods of template class Evolution_std
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_std.C,v 1.8 2005/01/11 12:48:46 f_limousin Exp $
00030  * $Log: evolution_std.C,v $
00031  * Revision 1.8  2005/01/11 12:48:46  f_limousin
00032  * Implement the function operator=(const Evolution_std<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:34  e_gourgoulhon
00061  * Added an assert in method update.
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  * $Header: /cvsroot/Lorene/C++/Include/Template/evolution_std.C,v 1.8 2005/01/11 12:48:46 f_limousin Exp $
00069  *
00070  */
00071 
00072 // C++ headers
00073 #include "headcpp.h" 
00074 
00075 // C headers
00076 #include <stdlib.h>
00077 #include <assert.h>
00078 
00079 
00080 
00081                     //-------------------------//
00082                     //      Constructors       //
00083                     //-------------------------//
00084 
00085                     
00086 template<typename TyT> 
00087 Evolution_std<TyT>::Evolution_std(const TyT& initial_value, int nstored, 
00088                                   int initial_j, double initial_time) 
00089       : Evolution<TyT>(initial_value, initial_j, initial_time, nstored)
00090 { }                    
00091                                         
00092 
00093 template<typename TyT> 
00094 Evolution_std<TyT>::Evolution_std(int nstored) 
00095       : Evolution<TyT>(nstored)
00096 { }                    
00097                                         
00098 
00099 template<typename TyT> 
00100 Evolution_std<TyT>::Evolution_std(const Evolution_std<TyT>& evo)
00101       : Evolution<TyT>(evo)
00102 { }
00103 
00104 
00105                     
00106                     
00107                     //-----------------------//
00108                     //      Destructor       //
00109                     //-----------------------//
00110 
00111                     
00112 template<typename TyT> 
00113 Evolution_std<TyT>::~Evolution_std(){ }
00114 
00115                     
00116                     
00117                     //-----------------------//
00118                     //      Mutators         //
00119                     //-----------------------//
00120 
00121                     
00122 template<typename TyT> 
00123 void Evolution_std<TyT>::operator=(const Evolution_std<TyT>& evo) {
00124 
00125     size = evo.size ;
00126     pos_jtop = evo.pos_jtop ;
00127  
00128     for (int j=0; j<size; j++) {
00129         step[j] = evo.step[j] ; 
00130     }
00131     
00132     for (int j=0; j<size; j++) {
00133         the_time[j] = evo.the_time[j] ; 
00134     }
00135     
00136 
00137     for (int j=0; j<size; j++) {
00138         if (val[j] != 0x0) {
00139         delete val[j] ;
00140         val[j] = 0x0 ;
00141     }
00142     }
00143 
00144     for (int j=0; j<size; j++) {
00145         if (evo.val[j] != 0x0) {        
00146             val[j] = new TyT( *(evo.val[j]) ) ; 
00147         }
00148         else {
00149             val[j] = 0x0 ; 
00150         }
00151     }
00152 }
00153 
00154 template<typename TyT> 
00155 void Evolution_std<TyT>::operator=(const Evolution<TyT>& ) {
00156 
00157     cerr << "void Evolution_std<TyT>::operator= : not implemented yet ! \n" ; 
00158     abort() ; 
00159  
00160 }
00161 
00162 
00163                     
00164 template<typename TyT> 
00165 void Evolution_std<TyT>::update(const TyT& new_value, int j, double time_j) {
00166 
00167 
00168     if (is_known(j)) {   // Case of a time step already stored
00169                          //-----------------------------------
00170         int pos = position(j) ; 
00171         assert( fabs(the_time[pos] - time_j) < 1.e-14 ) ;   
00172         assert( val[pos] != &new_value ) ; // to avoid self assignment
00173         delete val[pos] ; 
00174         val[pos] = new TyT(new_value) ; 
00175     }
00176     else {              // Storage of a new time step
00177                         //---------------------------
00178 
00179         if ( (pos_jtop != -1) && (j < step[pos_jtop]) ) {
00180             cerr << 
00181                 "Evolution_std<TyT>::update : the time step j = "
00182                 << j << " must be in the future\n" 
00183                 << "  of the last stored time step (" <<  step[pos_jtop] << ") !"
00184                 << endl ; 
00185             abort() ; 
00186         }
00187           
00188         pos_jtop++ ; 
00189             
00190         if (pos_jtop == size) {  // re-organization of arrays step, the_time 
00191                                 // and val is necessary
00192     
00193             if ( val[0] != 0x0 ) delete val[0] ; 
00194 
00195             for (int i=0; i<size-1; i++) {
00196                 step[i] = step[i+1] ; 
00197                 the_time[i] = the_time[i+1] ; 
00198                 val[i] = val[i+1] ; 
00199             }
00200         
00201             pos_jtop-- ;        // pos_jtop = size-1
00202         
00203         }
00204         else {
00205             assert( pos_jtop < size ) ; 
00206             assert( val[pos_jtop] == 0x0 ) ; 
00207         }
00208     
00209         step[pos_jtop] = j ;
00210         the_time[pos_jtop] = time_j ; 
00211         val[pos_jtop] = new TyT( new_value ) ; 
00212     }
00213 
00214 }                   
00215                     
00216 
00217                     

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