Changeset 24364


Ignore:
Timestamp:
11/19/19 21:26:05 (5 years ago)
Author:
Mathieu Morlighem
Message:

CHG: done with GEMB

Location:
issm/trunk-jpl/src/c/classes/Inputs2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/Inputs2/ArrayInput2.cpp

    r24360 r24364  
    1717
    1818        this->numberofelements_local = -1;
    19         this->N                      = -1;
     19        this->N                      = NULL;
    2020        this->values                 = NULL;
    2121
    2222}/*}}}*/
    23 ArrayInput2::ArrayInput2(int nbe_in,int N_in){/*{{{*/
     23ArrayInput2::ArrayInput2(int nbe_in){/*{{{*/
    2424
    2525        _assert_(nbe_in>0);
    2626        _assert_(nbe_in<1e11);
    2727        this->numberofelements_local = nbe_in;
    28         this->N                      = N_in;
    29         this->values                 = xNewZeroInit<IssmDouble>(this->numberofelements_local*this->N);
     28        this->N                      = xNewZeroInit<int>(this->numberofelements_local);
     29        this->values                 = xNewZeroInit<IssmDouble*>(this->numberofelements_local);
    3030
    3131}/*}}}*/
    3232ArrayInput2::~ArrayInput2(){/*{{{*/
    33         if(this->values) xDelete<IssmDouble>(this->values);
     33        if(this->values){
     34                for(int i=0;i<this->numberofelements_local;i++) if(this->values[i]) xDelete<IssmDouble>(this->values[i]);
     35                xDelete<IssmDouble>(this->values);
     36        }
     37        if(this->N) xDelete<int>(this->N);
    3438}
    3539/*}}}*/
     
    3842Input2* ArrayInput2::copy() {/*{{{*/
    3943
    40         ArrayInput2* output = new ArrayInput2(this->numberofelements_local,this->N);
    41         xMemCpy<IssmDouble>(output->values,this->values,this->numberofelements_local*this->N);
     44        ArrayInput2* output = new ArrayInput2(this->numberofelements_local);
     45
     46        output->N = xNew<int>(this->numberofelements_local);
     47        xMemCpy<int>(output->N,this->N,this->numberofelements_local);
     48
     49        output->values = xNew<IssmDouble*>(this->numberofelements_local);
     50        for(int i=0;i<this->numberofelements_local;i++){
     51                if(this->values[i]){
     52                        _assert_(this->N[i]>0);
     53                        output->values[i] = xNew<IssmDouble>(this->N[i]);
     54                        xMemCpy<IssmDouble>(output->values[i],this->values[i],this->N[i]);
     55                }
     56                else{
     57                        output->values[i] = NULL;
     58                }
     59        }
    4260
    4361        return output;
     
    4664void ArrayInput2::DeepEcho(void){/*{{{*/
    4765        _printf_("ArrayInput2 Echo:\n");
    48         _printf_("   Size:          "<<N<<"\n");
     66        ///_printf_("   Size:          "<<N<<"\n");
    4967        //printarray(this->values,this->M,this->N);
    5068        //_printf_(setw(15)<<"   ArrayInput2 "<<setw(25)<<left<<EnumToStringx(this->enum_type)<<" "<<(value?"true":"false") << "\n");
     
    6280        MARSHALLING_ENUM(ArrayInput2Enum);
    6381        MARSHALLING(this->numberofelements_local);
    64         MARSHALLING(this->N);
    65         if(this->numberofelements_local*this->N){
    66                 MARSHALLING_DYNAMIC(this->values,IssmDouble,this->numberofelements_local*this->N);
     82        if(this->numberofelements_local){
     83                MARSHALLING_DYNAMIC(this->N,int,this->numberofelements_local);
     84                for(int i=0;i<this->numberofelements_local;i++){
     85                        if(this->values[i]){
     86                                MARSHALLING_DYNAMIC(this->values[i],IssmDouble,this->N[i]);
     87                        }
     88                }
    6789        }
    68         else this->values = NULL;
     90        else{
     91                this->N      = NULL;
     92                this->values = NULL;
     93        }
    6994
    7095}
     
    79104
    80105        _assert_(this);
    81         _assert_(this->N==numindices);
    82         for(int i=0;i<numindices;i++) this->values[row*this->N+i] = values_in[i];
     106        _assert_(row>=0 && row<this->numberofelements_local);
     107
     108        if(this->N[row] != numindices){
     109                if(this->values[row]) xDelete<IssmDouble>(this->values[row]);
     110                this->values[row] = xNew<IssmDouble>(numindices);
     111        }
     112
     113        IssmDouble *el_values = this->values[row];
     114        for(int i=0;i<numindices;i++) el_values[i] = values_in[i];
     115
     116        this->N[row] = numindices;
    83117}
    84118/*}}}*/
     
    88122        _assert_(row>=0 && row<this->numberofelements_local);
    89123        if(pvalues){
    90                 IssmDouble* outvalues = xNew<IssmDouble>(this->N);
    91                 xMemCpy<IssmDouble>(outvalues,this->values,this->N);
     124                IssmDouble* outvalues = xNew<IssmDouble>(this->N[row]);
     125                xMemCpy<IssmDouble>(outvalues,this->values[row],this->N[row]);
    92126                *pvalues = outvalues;
    93127        }
    94128        if(pN){
    95                 *pN = this->N;
     129                *pN = this->N[row];
    96130        }
    97131}
  • issm/trunk-jpl/src/c/classes/Inputs2/ArrayInput2.h

    r24360 r24364  
    99        private:
    1010                int         numberofelements_local;
    11                 int         N;
    12                 IssmDouble* values;
     11                int*        N;
     12                IssmDouble** values;
    1313
    1414        public:
    1515                /*ArrayInput2 constructors, destructors: {{{*/
    1616                ArrayInput2();
    17                 ArrayInput2(int nbe_in,int N_in);
     17                ArrayInput2(int nbe_in);
    1818                ~ArrayInput2();
    1919                /*}}}*/
  • issm/trunk-jpl/src/c/classes/Inputs2/Inputs2.cpp

    r24360 r24364  
    554554
    555555        if(recreate){
    556                 this->inputs[id] = new ArrayInput2(this->numberofelements_local,numlayers);
     556                this->inputs[id] = new ArrayInput2(this->numberofelements_local);
    557557        }
    558558
Note: See TracChangeset for help on using the changeset viewer.