// @(#)root/matrix:$Id$
// Authors: Fons Rademakers, Eddy Offermann   Mar 2004

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

/*************************************************************************
 * Parts of this file are copied from the OOQP distribution and          *
 * are subject to the following license:                                 *
 *                                                                       *
 * COPYRIGHT 2001 UNIVERSITY OF CHICAGO                                  *
 *                                                                       *
 * The copyright holder hereby grants you royalty-free rights to use,    *
 * reproduce, prepare derivative works, and to redistribute this software*
 * to others, provided that any changes are clearly documented. This     *
 * software was authored by:                                             *
 *                                                                       *
 *   E. MICHAEL GERTZ      gertz@mcs.anl.gov                             *
 *   Mathematics and Computer Science Division                           *
 *   Argonne National Laboratory                                         *
 *   9700 S. Cass Avenue                                                 *
 *   Argonne, IL 60439-4844                                              *
 *                                                                       *
 *   STEPHEN J. WRIGHT     swright@cs.wisc.edu                           *
 *   Computer Sciences Department                                        *
 *   University of Wisconsin                                             *
 *   1210 West Dayton Street                                             *
 *   Madison, WI 53706   FAX: (608)262-9777                              *
 *                                                                       *
 * Any questions or comments may be directed to one of the authors.      *
 *                                                                       *
 * ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES OF   *
 * ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT, AND     *
 * OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A CONTRACT   *
 * WITH THE DEPARTMENT OF ENERGY.                                        *
 *************************************************************************/

#include "TQpProbDens.h"
#include "TMatrixD.h"

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TQpProbDens                                                          //
//                                                                      //
// dense matrix problem formulation                                     //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

ClassImp(TQpProbDens)

//______________________________________________________________________________
TQpProbDens::TQpProbDens(Int_t nx,Int_t my,Int_t mz) :
             TQpProbBase(nx,my,mz)
{
// Constructor

   // We do not want more constrains than variables
   R__ASSERT(nx-my-mz > 0);
}


//______________________________________________________________________________
TQpProbDens::TQpProbDens(const TQpProbDens &another) : TQpProbBase(another)
{
// Copy constructor

   *this = another;
}


//______________________________________________________________________________
TQpDataBase *TQpProbDens::MakeData(Double_t *c,
                                   Double_t *Q,
                                   Double_t *xlo,Bool_t   *ixlo,
                                   Double_t *xup,Bool_t   *ixup,
                                   Double_t *A,  Double_t *bA,
                                   Double_t *C,
                                   Double_t *clo,Bool_t   *iclo,
                                   Double_t *cup,Bool_t   *icup)
{
// Setup the data

   TVectorD    vc  ; vc  .Use(fNx,c);
   TMatrixDSym mQ  ; mQ  .Use(fNx,Q);
   TVectorD    vxlo; vxlo.Use(fNx,xlo);
   TVectorD    vxup; vxup.Use(fNx,xup);
   TMatrixD    mA  ;
   TVectorD    vbA ;
   if (fMy > 0) {
      mA  .Use(fMy,fNx,A);
      vbA .Use(fMy,bA);
   }
   TMatrixD    mC  ;
   TVectorD    vclo;
   TVectorD    vcup;
   if (fMz > 0) {
      mC  .Use(fMz,fNx,C);
      vclo.Use(fMz,clo);
      vcup.Use(fMz,cup);
   }

   TVectorD vixlo(fNx);
   TVectorD vixup(fNx);
   for (Int_t ix = 0; ix < fNx; ix++) {
      vixlo[ix] = (ixlo[ix]) ? 1.0 : 0.0;
      vixup[ix] = (ixup[ix]) ? 1.0 : 0.0;
   }

   TVectorD viclo(fMz);
   TVectorD vicup(fMz);
   for (Int_t ic = 0; ic < fMz; ic++) {
      viclo[ic] = (iclo[ic]) ? 1.0 : 0.0;
      vicup[ic] = (icup[ic]) ? 1.0 : 0.0;
   }

   TQpDataDens *data = new TQpDataDens(vc,mQ,vxlo,vixlo,vxup,vixup,mA,vbA,mC,vclo,
      viclo,vcup,vicup);

   return data;
}


//______________________________________________________________________________
TQpDataBase *TQpProbDens::MakeData(TVectorD     &c,
                                   TMatrixDBase &Q_in,
                                   TVectorD     &xlo, TVectorD &ixlo,
                                   TVectorD     &xup, TVectorD &ixup,
                                   TMatrixDBase &A_in,TVectorD &bA,
                                   TMatrixDBase &C_in,
                                   TVectorD     &clo, TVectorD &iclo,
                                   TVectorD     &cup, TVectorD &icup)
{
// Setup the data

   TMatrixDSym &mQ = (TMatrixDSym &) Q_in;
   TMatrixD    &mA = (TMatrixD    &) A_in;
   TMatrixD    &mC = (TMatrixD    &) C_in;

   R__ASSERT(mQ.GetNrows() == fNx && mQ.GetNcols() == fNx);
   if (fMy > 0) R__ASSERT(mA.GetNrows() == fMy && mA.GetNcols() == fNx);
   else         R__ASSERT(mA.GetNrows() == fMy);
   if (fMz > 0) R__ASSERT(mC.GetNrows() == fMz && mC.GetNcols() == fNx);
   else         R__ASSERT(mC.GetNrows() == fMz);

   R__ASSERT(c.GetNrows()    == fNx);
   R__ASSERT(xlo.GetNrows()  == fNx);
   R__ASSERT(ixlo.GetNrows() == fNx);
   R__ASSERT(xup.GetNrows()  == fNx);
   R__ASSERT(ixup.GetNrows() == fNx);

   R__ASSERT(bA.GetNrows()   == fMy);
   R__ASSERT(clo.GetNrows()  == fMz);
   R__ASSERT(iclo.GetNrows() == fMz);
   R__ASSERT(cup.GetNrows()  == fMz);
   R__ASSERT(icup.GetNrows() == fMz);

   TQpDataDens *data = new TQpDataDens(c,mQ,xlo,ixlo,xup,ixup,mA,bA,mC,clo,iclo,cup,icup);

   return data;
}


//______________________________________________________________________________
TQpResidual* TQpProbDens::MakeResiduals(const TQpDataBase *data_in)
{
// Setup the residuals

   TQpDataDens *data = (TQpDataDens *) data_in;
   return new TQpResidual(fNx,fMy,fMz,data->fXloIndex,data->fXupIndex,data->fCloIndex,data->fCupIndex);
}


//______________________________________________________________________________
TQpVar* TQpProbDens::MakeVariables(const TQpDataBase *data_in)
{
// Setup the variables

   TQpDataDens *data = (TQpDataDens *) data_in;

   return new TQpVar(fNx,fMy,fMz,data->fXloIndex,data->fXupIndex,data->fCloIndex,data->fCupIndex);
}


//______________________________________________________________________________
TQpLinSolverBase* TQpProbDens::MakeLinSys(const TQpDataBase *data_in)
{
// Setup the linear solver

   TQpDataDens *data = (TQpDataDens *) data_in;
   return new TQpLinSolverDens(this,data);
}


//______________________________________________________________________________
void TQpProbDens::JoinRHS(TVectorD &rhs,TVectorD &rhs1_in,TVectorD &rhs2_in,TVectorD &rhs3_in)
{
// Assembles a single vector object from three given vectors .
//     rhs_out (output) final joined vector
//     rhs1_in (input) first part of rhs
//     rhs2_in (input) middle part of rhs
//     rhs3_in (input) last part of rhs .

   rhs.SetSub(0,rhs1_in);
   if (fMy > 0) rhs.SetSub(fNx,    rhs2_in);
   if (fMz > 0) rhs.SetSub(fNx+fMy,rhs3_in);
}


//______________________________________________________________________________
void TQpProbDens::SeparateVars(TVectorD &x_in,TVectorD &y_in,TVectorD &z_in,TVectorD &vars_in)
{
// Extracts three component vectors from a given aggregated vector.
//     vars_in  (input) aggregated vector
//     x_in (output) first part of vars
//     y_in (output) middle part of vars
//     z_in (output) last part of vars

   x_in = vars_in.GetSub(0,fNx-1);
   if (fMy > 0) y_in = vars_in.GetSub(fNx,    fNx+fMy-1);
   if (fMz > 0) z_in = vars_in.GetSub(fNx+fMy,fNx+fMy+fMz-1);
}


//______________________________________________________________________________
void TQpProbDens::MakeRandomData(TQpDataDens *&data,TQpVar *&soln,Int_t /*nnzQ*/,Int_t /*nnzA*/,Int_t /*nnzC*/)
{
// Create a random QP problem

   data = new TQpDataDens(fNx,fMy,fMz);
   soln = this->MakeVariables(data);
   data->DataRandom(soln->fX,soln->fY,soln->fZ,soln->fS);
}


//______________________________________________________________________________
TQpProbDens &TQpProbDens::operator=(const TQpProbDens &source)
{
// Assignment operator

   if (this != &source) {
      TQpProbBase::operator=(source);
   }
   return *this;
}
 TQpProbDens.cxx:1
 TQpProbDens.cxx:2
 TQpProbDens.cxx:3
 TQpProbDens.cxx:4
 TQpProbDens.cxx:5
 TQpProbDens.cxx:6
 TQpProbDens.cxx:7
 TQpProbDens.cxx:8
 TQpProbDens.cxx:9
 TQpProbDens.cxx:10
 TQpProbDens.cxx:11
 TQpProbDens.cxx:12
 TQpProbDens.cxx:13
 TQpProbDens.cxx:14
 TQpProbDens.cxx:15
 TQpProbDens.cxx:16
 TQpProbDens.cxx:17
 TQpProbDens.cxx:18
 TQpProbDens.cxx:19
 TQpProbDens.cxx:20
 TQpProbDens.cxx:21
 TQpProbDens.cxx:22
 TQpProbDens.cxx:23
 TQpProbDens.cxx:24
 TQpProbDens.cxx:25
 TQpProbDens.cxx:26
 TQpProbDens.cxx:27
 TQpProbDens.cxx:28
 TQpProbDens.cxx:29
 TQpProbDens.cxx:30
 TQpProbDens.cxx:31
 TQpProbDens.cxx:32
 TQpProbDens.cxx:33
 TQpProbDens.cxx:34
 TQpProbDens.cxx:35
 TQpProbDens.cxx:36
 TQpProbDens.cxx:37
 TQpProbDens.cxx:38
 TQpProbDens.cxx:39
 TQpProbDens.cxx:40
 TQpProbDens.cxx:41
 TQpProbDens.cxx:42
 TQpProbDens.cxx:43
 TQpProbDens.cxx:44
 TQpProbDens.cxx:45
 TQpProbDens.cxx:46
 TQpProbDens.cxx:47
 TQpProbDens.cxx:48
 TQpProbDens.cxx:49
 TQpProbDens.cxx:50
 TQpProbDens.cxx:51
 TQpProbDens.cxx:52
 TQpProbDens.cxx:53
 TQpProbDens.cxx:54
 TQpProbDens.cxx:55
 TQpProbDens.cxx:56
 TQpProbDens.cxx:57
 TQpProbDens.cxx:58
 TQpProbDens.cxx:59
 TQpProbDens.cxx:60
 TQpProbDens.cxx:61
 TQpProbDens.cxx:62
 TQpProbDens.cxx:63
 TQpProbDens.cxx:64
 TQpProbDens.cxx:65
 TQpProbDens.cxx:66
 TQpProbDens.cxx:67
 TQpProbDens.cxx:68
 TQpProbDens.cxx:69
 TQpProbDens.cxx:70
 TQpProbDens.cxx:71
 TQpProbDens.cxx:72
 TQpProbDens.cxx:73
 TQpProbDens.cxx:74
 TQpProbDens.cxx:75
 TQpProbDens.cxx:76
 TQpProbDens.cxx:77
 TQpProbDens.cxx:78
 TQpProbDens.cxx:79
 TQpProbDens.cxx:80
 TQpProbDens.cxx:81
 TQpProbDens.cxx:82
 TQpProbDens.cxx:83
 TQpProbDens.cxx:84
 TQpProbDens.cxx:85
 TQpProbDens.cxx:86
 TQpProbDens.cxx:87
 TQpProbDens.cxx:88
 TQpProbDens.cxx:89
 TQpProbDens.cxx:90
 TQpProbDens.cxx:91
 TQpProbDens.cxx:92
 TQpProbDens.cxx:93
 TQpProbDens.cxx:94
 TQpProbDens.cxx:95
 TQpProbDens.cxx:96
 TQpProbDens.cxx:97
 TQpProbDens.cxx:98
 TQpProbDens.cxx:99
 TQpProbDens.cxx:100
 TQpProbDens.cxx:101
 TQpProbDens.cxx:102
 TQpProbDens.cxx:103
 TQpProbDens.cxx:104
 TQpProbDens.cxx:105
 TQpProbDens.cxx:106
 TQpProbDens.cxx:107
 TQpProbDens.cxx:108
 TQpProbDens.cxx:109
 TQpProbDens.cxx:110
 TQpProbDens.cxx:111
 TQpProbDens.cxx:112
 TQpProbDens.cxx:113
 TQpProbDens.cxx:114
 TQpProbDens.cxx:115
 TQpProbDens.cxx:116
 TQpProbDens.cxx:117
 TQpProbDens.cxx:118
 TQpProbDens.cxx:119
 TQpProbDens.cxx:120
 TQpProbDens.cxx:121
 TQpProbDens.cxx:122
 TQpProbDens.cxx:123
 TQpProbDens.cxx:124
 TQpProbDens.cxx:125
 TQpProbDens.cxx:126
 TQpProbDens.cxx:127
 TQpProbDens.cxx:128
 TQpProbDens.cxx:129
 TQpProbDens.cxx:130
 TQpProbDens.cxx:131
 TQpProbDens.cxx:132
 TQpProbDens.cxx:133
 TQpProbDens.cxx:134
 TQpProbDens.cxx:135
 TQpProbDens.cxx:136
 TQpProbDens.cxx:137
 TQpProbDens.cxx:138
 TQpProbDens.cxx:139
 TQpProbDens.cxx:140
 TQpProbDens.cxx:141
 TQpProbDens.cxx:142
 TQpProbDens.cxx:143
 TQpProbDens.cxx:144
 TQpProbDens.cxx:145
 TQpProbDens.cxx:146
 TQpProbDens.cxx:147
 TQpProbDens.cxx:148
 TQpProbDens.cxx:149
 TQpProbDens.cxx:150
 TQpProbDens.cxx:151
 TQpProbDens.cxx:152
 TQpProbDens.cxx:153
 TQpProbDens.cxx:154
 TQpProbDens.cxx:155
 TQpProbDens.cxx:156
 TQpProbDens.cxx:157
 TQpProbDens.cxx:158
 TQpProbDens.cxx:159
 TQpProbDens.cxx:160
 TQpProbDens.cxx:161
 TQpProbDens.cxx:162
 TQpProbDens.cxx:163
 TQpProbDens.cxx:164
 TQpProbDens.cxx:165
 TQpProbDens.cxx:166
 TQpProbDens.cxx:167
 TQpProbDens.cxx:168
 TQpProbDens.cxx:169
 TQpProbDens.cxx:170
 TQpProbDens.cxx:171
 TQpProbDens.cxx:172
 TQpProbDens.cxx:173
 TQpProbDens.cxx:174
 TQpProbDens.cxx:175
 TQpProbDens.cxx:176
 TQpProbDens.cxx:177
 TQpProbDens.cxx:178
 TQpProbDens.cxx:179
 TQpProbDens.cxx:180
 TQpProbDens.cxx:181
 TQpProbDens.cxx:182
 TQpProbDens.cxx:183
 TQpProbDens.cxx:184
 TQpProbDens.cxx:185
 TQpProbDens.cxx:186
 TQpProbDens.cxx:187
 TQpProbDens.cxx:188
 TQpProbDens.cxx:189
 TQpProbDens.cxx:190
 TQpProbDens.cxx:191
 TQpProbDens.cxx:192
 TQpProbDens.cxx:193
 TQpProbDens.cxx:194
 TQpProbDens.cxx:195
 TQpProbDens.cxx:196
 TQpProbDens.cxx:197
 TQpProbDens.cxx:198
 TQpProbDens.cxx:199
 TQpProbDens.cxx:200
 TQpProbDens.cxx:201
 TQpProbDens.cxx:202
 TQpProbDens.cxx:203
 TQpProbDens.cxx:204
 TQpProbDens.cxx:205
 TQpProbDens.cxx:206
 TQpProbDens.cxx:207
 TQpProbDens.cxx:208
 TQpProbDens.cxx:209
 TQpProbDens.cxx:210
 TQpProbDens.cxx:211
 TQpProbDens.cxx:212
 TQpProbDens.cxx:213
 TQpProbDens.cxx:214
 TQpProbDens.cxx:215
 TQpProbDens.cxx:216
 TQpProbDens.cxx:217
 TQpProbDens.cxx:218
 TQpProbDens.cxx:219
 TQpProbDens.cxx:220
 TQpProbDens.cxx:221
 TQpProbDens.cxx:222
 TQpProbDens.cxx:223
 TQpProbDens.cxx:224
 TQpProbDens.cxx:225
 TQpProbDens.cxx:226
 TQpProbDens.cxx:227
 TQpProbDens.cxx:228
 TQpProbDens.cxx:229
 TQpProbDens.cxx:230
 TQpProbDens.cxx:231
 TQpProbDens.cxx:232
 TQpProbDens.cxx:233
 TQpProbDens.cxx:234
 TQpProbDens.cxx:235
 TQpProbDens.cxx:236
 TQpProbDens.cxx:237
 TQpProbDens.cxx:238
 TQpProbDens.cxx:239
 TQpProbDens.cxx:240
 TQpProbDens.cxx:241
 TQpProbDens.cxx:242
 TQpProbDens.cxx:243
 TQpProbDens.cxx:244
 TQpProbDens.cxx:245
 TQpProbDens.cxx:246
 TQpProbDens.cxx:247
 TQpProbDens.cxx:248
 TQpProbDens.cxx:249