00001
00002
00003
00004
00005
00006 #include "Albany_Networks.hpp"
00007
00008 void
00009 Albany::ReactorNetworkModel::
00010 evalModel(
00011 const Teuchos::Array<EpetraExt::ModelEvaluator::InArgs>& model_inargs,
00012 const Teuchos::Array<EpetraExt::ModelEvaluator::OutArgs>& model_outargs,
00013 const EpetraExt::ModelEvaluator::InArgs& network_inargs,
00014 const EpetraExt::ModelEvaluator::OutArgs& network_outargs,
00015 const Teuchos::Array<int>& n_p,
00016 const Teuchos::Array<int>& n_g,
00017 const Teuchos::Array< Teuchos::RCP<Epetra_Vector> >& p,
00018 const Teuchos::Array< Teuchos::RCP<Epetra_Vector> >& g,
00019 const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& dgdp,
00020 const Teuchos::Array<EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation>& dgdp_layout,
00021 const Teuchos::Array<EpetraExt::ModelEvaluator::OutArgs::sg_vector_t>& p_sg,
00022 const Teuchos::Array<EpetraExt::ModelEvaluator::OutArgs::sg_vector_t>& g_sg,
00023 const Teuchos::Array<Teuchos::RCP<Stokhos::EpetraMultiVectorOrthogPoly> >& dgdp_sg,
00024 const Teuchos::Array<EpetraExt::ModelEvaluator::EDerivativeMultiVectorOrientation>& dgdp_sg_layout) const
00025 {
00026
00027
00028 Teuchos::RCP<Epetra_Vector> f = network_outargs.get_f();
00029 if (f != Teuchos::null) {
00030
00031
00032 f->PutScalar(0.0);
00033 for (int i=0; i<n; i++) {
00034 (*f)[i] = (*g[0])[i+n] - (*g[1])[i];
00035 (*f)[i+n] = (*g[0])[i] - (*g[1])[i+n];
00036 (*f)[i+2*n] = (*p[0])[i+n] + (*p[1])[i];
00037 (*f)[i+3*n] = (*p[0])[i] + (*p[1])[i+n];
00038 }
00039
00040 }
00041
00042
00043 Teuchos::RCP<Epetra_Operator> W = network_outargs.get_W();
00044 if (W != Teuchos::null) {
00045
00046
00047 Teuchos::RCP<Epetra_CrsMatrix> W_crs =
00048 Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W, true);
00049 W_crs->PutScalar(0.0);
00050 int row, col;
00051 double val;
00052
00053
00054 for (int i=0; i<n; i++) {
00055 row = i;
00056
00057
00058 for (int j=0; j<n; j++) {
00059 col = j;
00060 val = (*dgdp[0])[j][i+n];
00061 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00062 }
00063
00064
00065 for (int j=0; j<n; j++) {
00066 col = n+j;
00067 val = (*dgdp[0])[j+n][i+n];
00068 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00069 }
00070
00071
00072 for (int j=0; j<n; j++) {
00073 col = 2*n+j;
00074 val = -(*dgdp[1])[j][i];
00075 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00076 }
00077
00078
00079 for (int j=0; j<n; j++) {
00080 col = 3*n+j;
00081 val = -(*dgdp[1])[j+n][i];
00082 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00083 }
00084
00085 }
00086
00087
00088 for (int i=0; i<n; i++) {
00089 row = n+i;
00090
00091
00092 for (int j=0; j<n; j++) {
00093 col = j;
00094 val = (*dgdp[0])[j][i];
00095 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00096 }
00097
00098
00099 for (int j=0; j<n; j++) {
00100 col = n+j;
00101 val = (*dgdp[0])[j+n][i];
00102 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00103 }
00104
00105
00106 for (int j=0; j<n; j++) {
00107 col = 2*n+j;
00108 val = -(*dgdp[1])[j][i+n];
00109 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00110 }
00111
00112
00113 for (int j=0; j<n; j++) {
00114 col = 3*n+j;
00115 val = -(*dgdp[1])[j+n][i+n];
00116 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00117 }
00118
00119 }
00120
00121
00122 for (int i=0; i<n; i++) {
00123 row = 2*n+i;
00124
00125
00126
00127
00128 col = n+i;
00129 val = 1.0;
00130 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00131
00132
00133 col = 2*n+i;
00134 val = 1.0;
00135 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00136
00137
00138 }
00139
00140
00141 for (int i=0; i<n; i++) {
00142 row = 3*n+i;
00143
00144
00145 col = 0+i;
00146 val = 1.0;
00147 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00148
00149
00150
00151
00152
00153
00154 col = 3*n+i;
00155 val = 1.0;
00156 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00157 }
00158
00159
00160 }
00161
00162
00163 if (network_outargs.supports(EpetraExt::ModelEvaluator::OUT_ARG_f_sg)) {
00164 EpetraExt::ModelEvaluator::OutArgs::sg_vector_t f_sg =
00165 network_outargs.get_f_sg();
00166 if (f_sg != Teuchos::null) {
00167
00168
00169 f_sg->init(0.0);
00170 for (int block=0; block<f_sg->size(); block++) {
00171 for (int i=0; i<n; i++) {
00172 (*f_sg)[block][i] = (*g_sg[0])[block][i+n] - (*g_sg[1])[block][i];
00173 (*f_sg)[block][i+n] = (*g_sg[0])[block][i] - (*g_sg[1])[block][i+n];
00174 (*f_sg)[block][i+2*n] = (*p_sg[0])[block][i+n] + (*p_sg[1])[block][i];
00175 (*f_sg)[block][i+3*n] = (*p_sg[0])[block][i] + (*p_sg[1])[block][i+n];
00176 }
00177 }
00178 }
00179 }
00180
00181
00182 if (network_outargs.supports(EpetraExt::ModelEvaluator::OUT_ARG_W_sg)) {
00183 EpetraExt::ModelEvaluator::OutArgs::sg_operator_t W_sg =
00184 network_outargs.get_W_sg();
00185 if (W_sg != Teuchos::null) {
00186
00187
00188 int row, col;
00189 double val;
00190 for (int block=0; block<W_sg->size(); block++) {
00191 Teuchos::RCP<Epetra_CrsMatrix> W_crs =
00192 Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(
00193 W_sg->getCoeffPtr(block), true);
00194
00195 W_crs->PutScalar(0.0);
00196
00197
00198 for (int i=0; i<n; i++) {
00199 row = i;
00200
00201
00202 for (int j=0; j<n; j++) {
00203 col = j;
00204 val = (*dgdp_sg[0])[block][j][i+n];
00205 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00206 }
00207
00208
00209 for (int j=0; j<n; j++) {
00210 col = n+j;
00211 val = (*dgdp_sg[0])[block][j+n][i+n];
00212 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00213 }
00214
00215
00216 for (int j=0; j<n; j++) {
00217 col = 2*n+j;
00218 val = -(*dgdp_sg[1])[block][j][i];
00219 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00220 }
00221
00222
00223 for (int j=0; j<n; j++) {
00224 col = 3*n+j;
00225 val = -(*dgdp_sg[1])[block][j+n][i];
00226 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00227 }
00228
00229 }
00230
00231
00232 for (int i=0; i<n; i++) {
00233 row = n+i;
00234
00235
00236 for (int j=0; j<n; j++) {
00237 col = j;
00238 val = (*dgdp_sg[0])[block][j][i];
00239 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00240 }
00241
00242
00243 for (int j=0; j<n; j++) {
00244 col = n+j;
00245 val = (*dgdp_sg[0])[block][j+n][i];
00246 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00247 }
00248
00249
00250 for (int j=0; j<n; j++) {
00251 col = 2*n+j;
00252 val = -(*dgdp_sg[1])[block][j][i+n];
00253 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00254 }
00255
00256
00257 for (int j=0; j<n; j++) {
00258 col = 3*n+j;
00259 val = -(*dgdp_sg[1])[block][j+n][i+n];
00260 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00261 }
00262
00263 }
00264
00265 }
00266
00267
00268 Teuchos::RCP<Epetra_CrsMatrix> W_crs =
00269 Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(
00270 W_sg->getCoeffPtr(0), true);
00271
00272
00273 for (int i=0; i<n; i++) {
00274 row = 2*n+i;
00275
00276
00277
00278
00279 col = n+i;
00280 val = 1.0;
00281 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00282
00283
00284 col = 2*n+i;
00285 val = 1.0;
00286 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00287
00288
00289 }
00290
00291
00292 for (int i=0; i<n; i++) {
00293 row = 3*n+i;
00294
00295
00296 col = 0+i;
00297 val = 1.0;
00298 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00299
00300
00301
00302
00303
00304
00305 col = 3*n+i;
00306 val = 1.0;
00307 W_crs->ReplaceGlobalValues(row, 1, &val, &col);
00308 }
00309
00310
00311 }
00312 }
00313 }
00314
00315