ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
shared1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <admodel.h>
00008 
00009 #  if defined(USE_SHARE_FLAGS)
00010 /*
00011   static int integer(const index_type& it)
00012   {
00013     return it.integer();
00014   }
00015 */
00016 
00017   int param_init_d3array::shared_size_count(void)
00018   {
00019     if (share_flags->get_current_phase() != current_phase)
00020     {
00021       share_flags->get_inv_matrix_shared(current_phase);
00022     }
00023     i3_array & bmap = share_flags->get_bmap();
00024     int  mmin=bmap.indexmin();
00025     int  mmax=bmap.indexmax();
00026     int nv=0;
00027     for (int i=mmin;i<=mmax;i++)
00028     {
00029       nv+=::size_count((*this)(bmap(i,1,1),bmap(i,1,2)));
00030     }
00031     return nv;
00032   }
00033 
00034   void param_init_d3array::shared_set_value_inv
00035     (const dvector& _x,const int& _ii)
00036   {
00037     ADUNCONST(int,ii)
00038     ADUNCONST(dvector,x)
00039     index_type& it=*(share_flags->get_invflags());
00040     //int mmin=share_flags->invflags->indexmin();
00041     //int mmax=share_flags->invflags->indexmax();
00042     int mmin=it.indexmin();
00043     int mmax=it.indexmax();
00044     int i;
00045     for (i=mmin;i<=mmax;i++)
00046     {
00047       int k1=it(i)(1).integer();
00048       int k2=it(i)(2).integer();
00049       const dvar_vector & v=(*this)(k1,k2);
00050       int kmin=v.indexmin();
00051       int kmax=v.indexmax();
00052       for (int k=kmin;k<=kmax;k++)
00053       {
00054         x(ii++)=::value(v(k));
00055       }
00056     }
00057   }
00058 
00059   void param_init_d3array::shared_set_value(const dvar_vector& _x,
00060     const int& _ii,const dvariable& pen)
00061   {
00062     ADUNCONST(int,ii)
00063     ADUNCONST(dvar_vector,x)
00064     i3_array & bmap = share_flags->get_bmap();
00065     int  mmin=bmap.indexmin();
00066     int  mmax=bmap.indexmax();
00067     for (int i=mmin;i<=mmax;i++)
00068     {
00069       int  jmin=bmap(i).indexmin();
00070       int  jmax=bmap(i).indexmax();
00071 
00072       int ii1 = 0;
00073       for (int j=jmin;j<=jmax;j++)
00074       {
00075         dvar_vector& v=(*this)(bmap(i,j,1),bmap(i,j,2));
00076 
00077         int kmin=v.indexmin();
00078         int kmax=v.indexmax();
00079 
00080         ii1=ii;
00081         for (int k=kmin;k<=kmax;k++)
00082         {
00083           v(k)=x(ii1++);
00084         }
00085       }
00086       ii=ii1;
00087     }
00088   }
00089 
00090   void param_init_d3array::setshare
00091     (const index_type& sf,const index_type& af)
00092   {
00093     share_flags = new shareinfo(sf,af);
00094     int idim1= share_flags->get_shareflags()->dimension();
00095     share_flags->get_dimension()=idim1;
00096     int idim2= share_flags->get_activeflags()->dimension();
00097     switch (idim1)
00098     {
00099     case 1:
00100       share_flags->get_inv_vector_shared(current_phase);
00101       break;
00102     case 2:
00103       {
00104         cout << idim1 << " " << idim2 << endl;
00105          // check rationality
00106         int mmin1= share_flags->get_shareflags()->indexmin();
00107         int mmax1= share_flags->get_shareflags()->indexmax();
00108         int mmin2= share_flags->get_activeflags()->indexmin();
00109         int mmax2= share_flags->get_activeflags()->indexmax();
00110         int mmin=indexmin();
00111         int mmax=indexmax();
00112         if (mmin1 != mmin || mmax1 != mmax ||
00113           mmin2 != mmin || mmax2 != mmax)
00114         {
00115           cerr << "sanity error" << endl;
00116           ad_exit(1);
00117         }
00118         share_flags->get_inv_matrix_shared(current_phase);
00119       }
00120       break;
00121     default:
00122       cerr << "Error" << endl;
00123       ad_exit(1);
00124     }
00125   }
00126 #  endif