52 #include "Amesos_Klu.h"
95 const double GLp_pi = 3.14159265358979323846;
116 const char geomFileBase[],
117 const bool trace =
true,
118 const bool dumpAll =
false
225 GLpYUEpetraDataPool::GLpYUEpetraDataPool(
245 if( myfile && myfile[0] !=
'\0' ) {
251 ,len_x,len_y,local_nx,local_ny,2
253 #ifdef GLPYUEPETRA_DATAPOOL_DUMP_ALL_MESH
254 ,&*Teuchos::VerboseObjectBase::getDefaultOStream(),
true
268 int * qintvalues =
new int[standardmap.NumMyElements()];
269 double * qdvalues =
new double[standardmap.NumMyElements()];
270 standardmap.MyGlobalElements(qintvalues);
271 for (
int i = 0; i < standardmap.NumMyElements(); i++)
273 q_->ReplaceGlobalValues(standardmap.NumMyElements(), qintvalues, qdvalues);
274 q_->GlobalAssemble();
536 yoverlap->Import(*y, Importer,
Insert);
547 yoverlap->Import(*y, Importer,
Insert);
561 int nummystates = standardmap.NumMyElements();
562 int nummycontrols = bdryctrlmap.NumMyElements();
569 standardmap.MyGlobalElements(states.
Values());
570 bdryctrlmap.MyGlobalElements(controls.
Values());
571 for (
int i=0; i<nummystates; i++) {
572 KKTmapindx(i) = states(i);
573 KKTmapindx(nummystates+nummycontrols+i) = 2*numstates+states(i);
575 for (
int i=0; i<nummycontrols; i++) {
576 KKTmapindx(nummystates+i) = numstates+controls(i);
587 for (
int i=0; i<nummystates+nummycontrols; i++) {
596 for (
int i=0; i<nummystates; i++) {
598 values.
Resize(nummyentries);
599 indices.
Resize(nummyentries);
602 if (nummyentries > 0)
606 values.
Resize(nummyentries);
607 indices.
Resize(nummyentries);
610 if (nummyentries > 0)
615 for (
int i=0; i<nummystates; i++) {
617 values.
Resize(nummyentries);
618 indices.
Resize(nummyentries);
621 for (
int j=0; j<nummyentries; j++)
622 indices[j] = indices[j]+numstates;
623 if (nummyentries > 0)
633 for (
int i=0; i<nummystates; i++) {
635 values.
Resize(nummyentries);
636 indices.
Resize(nummyentries);
639 for (
int j=0; j<nummyentries; j++)
640 indices[j] = indices[j]+2*numstates;
641 if (nummyentries > 0)
645 values.
Resize(nummyentries);
646 indices.
Resize(nummyentries);
649 for (
int j=0; j<nummyentries; j++)
650 indices[j] = indices[j]+2*numstates;
651 if (nummyentries > 0)
656 for (
int i=0; i<nummystates; i++) {
658 values.
Resize(nummyentries);
659 indices.
Resize(nummyentries);
662 for (
int j=0; j<nummyentries; j++)
663 indices[j] = indices[j]+2*numstates;
665 if (nummyentries > 0)
670 std::cout <<
"Insertion of entries failed:\n";
671 std::cout << indices;
672 std::cout << nummyentries << std::endl;
673 std::cout <<
"at row: " << KKTmapindx.
Values()[i]+numstates << std::endl << std::endl;
697 for (
int i=0; i<
Nodes.
M(); i++) {
704 for (
int i=0; i<
Nodes.
M(); i++) {
711 for (
int i=0; i<
Nodes.
M(); i++) {
720 S1(0,0)= 1.0;
S1(0,1)=-1.0;
S1(0,2)= 0.0;
721 S1(1,0)=-1.0;
S1(1,1)= 1.0;
S1(1,2)= 0.0;
722 S1(2,0)= 0.0;
S1(2,1)= 0.0;
S1(2,2)= 0.0;
724 S2(0,0)= 2.0;
S2(0,1)=-1.0;
S2(0,2)=-1.0;
725 S2(1,0)=-1.0;
S2(1,1)= 0.0;
S2(1,2)= 1.0;
726 S2(2,0)=-1.0;
S2(2,1)= 1.0;
S2(2,2)= 0.0;
728 S3(0,0)= 1.0;
S3(0,1)= 0.0;
S3(0,2)=-1.0;
729 S3(1,0)= 0.0;
S3(1,1)= 0.0;
S3(1,2)= 0.0;
730 S3(2,0)=-1.0;
S3(2,1)= 0.0;
S3(2,2)= 1.0;
738 for (
int i=0; i<3; i++) {
739 for (
int j=0; j<3; j++) {
748 for (
int i=0; i<3; i++) {
749 for (
int j=0; j<3; j++) {
750 for (
int k=0; k<3; k++) {
760 for (
int i=0; i<3; i++) {
761 for (
int j=0; j<3; j++) {
762 for (
int k=0; k<3; k++) {
772 for (
int i=0; i<3; i++) {
773 for (
int j=0; j<3; j++) {
774 for (
int k=0; k<3; k++) {
785 os <<
"\n\nQuadrature nodes:";
786 os <<
"\n-----------------";
788 os <<
"\n\nQuadrature weights:";
789 os <<
"\n-------------------\n";
791 os <<
"\n\nNodal basis functions:";
792 os <<
"\n----------------------";
794 os <<
"\n\nIntegrals of combinations of partial derivatives:";
795 os <<
"\n-------------------------------------------------";
799 os <<
"\n\nIntegrals of basis functions:";
800 os <<
"\n-----------------------------\n";
802 os <<
"\n\nIntegrals of products N(i)*N(j):";
803 os <<
"\n--------------------------------\n";
805 os <<
"\n\nIntegrals of products N(i)*N(j)*N(k):";
806 os <<
"\n-------------------------------------\n";
808 os <<
"\n\nIntegrals of products N(i)*(dN(j)/dx1)*N(k):";
809 os <<
"\n--------------------------------------------\n";
811 os <<
"\n\nIntegrals of products N(i)*(dN(j)/dx2)*N(k):";
812 os <<
"\n--------------------------------------------\n";
829 double *first,
double *second)
831 for (
int i=0; i<product.
M(); i++) {
832 product[i] = first[i]*second[i];
838 double *first,
double *second,
double *third)
840 for (
int i=0; i<product.
M(); i++) {
841 product[i] = first[i]*second[i]*third[i];
905 #ifdef GLPAPP_SHOW_BOUNDARY_ASSEMBLY
907 out = Teuchos::VerboseObjectBase::getDefaultOStream();
909 *out <<
"\nEntering assemble_bdry(...) ...\n";
912 int numLocElems = t.
M();
913 int numLocEdges = e.
M();
922 for (
int j=0; j<numLocEdges; j++) {
923 BdryNode[j] = e(j,0);
924 BdryNode[j+numLocEdges] = e(j,1);
926 std::sort(BdryNode.
Values(), BdryNode.
Values()+2*numLocEdges);
927 lastindx = std::unique(BdryNode.
Values(), BdryNode.
Values()+2*numLocEdges);
928 const int numBdryNodes = lastindx - BdryNode.
Values();
929 BdryNode.
Resize(numBdryNodes);
935 lastindx = std::set_intersection(
940 const int numMyBdryNodes = lastindx - MyBdryNode.
Values();
941 MyBdryNode.
Resize(numMyBdryNodes);
946 Epetra_Map standardmap(-1, ipindx.
M(),
const_cast<int*
>(ipindx.
A()), indexBase, Comm);
947 Epetra_Map overlapmap(-1, pindx.
M(),
const_cast<int*
>(pindx.
A()), indexBase, Comm);
948 Epetra_Map mybdryctrlmap(-1, numMyBdryNodes, const_cast<int*>(MyBdryNode.
A()), indexBase, Comm);
953 #ifdef GLPAPP_SHOW_BOUNDARY_ASSEMBLY
954 *out <<
"\nstandardmap:\n";
956 *out <<
"\nmybdryctrlmap:\n";
969 const int numNodesPerEdge = 2;
979 for(
int i=0; i < numLocEdges; i++ ) {
982 global_id_0 = e(i,0),
983 global_id_1 = e(i,1),
984 local_id_0 = overlapmap.
LID(global_id_0),
985 local_id_1 = overlapmap.
LID(global_id_1);
987 epetra_nodes(0) = global_id_0;
988 epetra_nodes(1) = global_id_1;
991 x0 = pcoords(local_id_0,0),
992 y0 = pcoords(local_id_0,1),
993 x1 = pcoords(local_id_1,0),
994 y1 = pcoords(local_id_1,1);
996 const double l = sqrt(pow(x0-x1,2) + pow(y0-y1,2));
999 const double l_sixth = l * (1.0/6.0);
1000 Bt(0,0) = l_sixth * 2.0;
1001 Bt(0,1) = l_sixth * 1.0;
1002 Bt(1,0) = l_sixth * 1.0;
1003 Bt(1,1) = l_sixth * 2.0;
1005 #ifdef GLPAPP_SHOW_BOUNDARY_ASSEMBLY
1007 <<
"\nEdge global nodes = ("<<global_id_0<<
","<<global_id_1<<
"),"
1008 <<
" local nodes = ("<<local_id_0<<
","<<local_id_1<<
"),"
1009 <<
" (x0,y0)(x1,y1)=("<<x0<<
","<<y0<<
")("<<x1<<
","<<y1<<
"),"
1010 <<
" Bt = ["<<Bt(0,0)<<
","<<Bt(0,1)<<
";"<<Bt(1,0)<<
","<<Bt(1,1)<<
"]\n";
1015 if (err<0)
return(err);
1016 err = R->InsertGlobalValues(epetra_nodes,Bt,format);
1017 if (err<0)
return(err);
1036 if (err<0)
return(err);
1037 err = R->GlobalAssemble(mybdryctrlmap,mybdryctrlmap,
true);
1038 if (err<0)
return(err);
1040 if(B_out) *B_out = B;
1041 if(R_out) *R_out = R;
1043 #ifdef GLPAPP_SHOW_BOUNDARY_ASSEMBLY
1046 *out <<
"\nLeaving assemble_bdry(...) ...\n";
1116 RCP<Epetra_FECrsMatrix> &
A,
1117 RCP<Epetra_FECrsMatrix> & M,
1118 RCP<Epetra_FEVector> & b)
1121 int myPID = Comm.
MyPID();
1122 int numProcs = Comm.
NumProc();
1125 int numLocElems = t.
M();
1126 int numNodesPerElem = 3;
1130 Epetra_Map standardmap(-1, ipindx.
M(), (
int*)ipindx.
A(), indexBase, Comm);
1131 Epetra_Map overlapmap(-1, pindx.
M(), (
int*)pindx.
A(), indexBase, Comm);
1133 int* nodes =
new int[numNodesPerElem];
1134 int i=0, j=0, err=0;
1151 for (i=0; i< numNodesPerElem; i++) k(i)=1.0;
1153 for (i=0; i< numNodesPerElem; i++) { c(i,0)=0.0; c(i,1)=0.0; }
1155 for (i=0; i< numNodesPerElem; i++) r(i)=0.0;
1157 for (i=0; i< numNodesPerElem; i++) f(i)=0.0;
1161 sigma(0)=0.0; sigma(1)=0.0;
1162 for(i=0; i<numLocElems; i++) {
1163 nodes[0] = t(i,0); nodes[1] = t(i,1); nodes[2] = t(i,2);
1164 for (j=0; j<numNodesPerElem; j++) {
1166 vertices(j,0) = pcoords(overlapmap.LID(nodes[j]), 0);
1167 vertices(j,1) = pcoords(overlapmap.LID(nodes[j]), 1);
1169 f(j) = cos(
GLp_pi*vertices(j,0))*cos(
GLp_pi*vertices(j,1)) *
1172 lassembly(vertices, k, c, r, f, usr_par, At, bt);
1173 err = A->InsertGlobalValues(epetra_nodes, At, format);
1174 if (err<0)
return(err);
1175 err = b->SumIntoGlobalValues(epetra_nodes, bt);
1176 if (err<0)
return(err);
1184 for (i=0; i<e.
M(); i++) {
1186 neumann(j,0) = e(i,0); neumann(j,1) = e(i,1);
1190 neumann.Reshape(j,2);
1192 if (neumann.M() != 0) {
1205 N.
Shape(quadnodes.
M(),2);
1206 for (i=0; i<quadnodes.
M(); i++) {
1207 N(i,0) = 1.0 - quadnodes(i,0);
1208 N(i,1) = quadnodes(i,0);
1213 for (i=0; i<2; i++) {
1214 for (j=0; j<2; j++) {
1216 NN(i,j) = blas.
DOT(quadweights.
M(), quadweights.
A(), product.
A());
1223 for (i=0; i<neumann.M(); i++) {
1224 neumann_nodes(0) = neumann(i,0); neumann_nodes(1) = neumann(i,1);
1225 neumann_add(0) = pcoords(overlapmap.LID(neumann_nodes(0)),0)
1226 -pcoords(overlapmap.LID(neumann_nodes(1)),0);
1227 neumann_add(1) = pcoords(overlapmap.LID(neumann_nodes(0)),1)
1228 -pcoords(overlapmap.LID(neumann_nodes(1)),1);
1229 l = blas.
NRM2(neumann_add.
M(), neumann_add.
A());
1230 neumann_add.
Multiply(
'N',
'N', 1.0, NN, g, 0.0);
1231 neumann_add.
Scale(l);
1232 err = b->SumIntoGlobalValues(neumann_nodes, neumann_add);
1233 if (err<0)
return(err);
1240 for (i=0; i<e.
M(); i++) {
1242 robin(j,0) = e(i,0); robin(j,1) = e(i,1);
1248 if (robin.M() != 0) {
1262 N.
Shape(quadnodes.
M(),2);
1263 for (i=0; i<quadnodes.
M(); i++) {
1264 N(i,0) = 1.0 - quadnodes(i,0);
1265 N(i,1) = quadnodes(i,0);
1270 for (i=0; i<2; i++) {
1271 for (j=0; j<2; j++) {
1273 NN(i,j) = blas.
DOT(quadweights.
M(), quadweights.
A(), product.
A());
1280 for (i=0; i<2; i++) {
1281 for (j=0; j<2; j++) {
1282 for (
int k=0; k<2; k++) {
1284 NNN[k](i,j) = blas.
DOT(quadweights.
M(), quadweights.
A(),
1294 for (i=0; i<robin.M(); i++) {
1295 robin_nodes(0) = robin(i,0); robin_nodes(1) = robin(i,1);
1297 robin_b_add(0) = pcoords(overlapmap.LID(robin_nodes(0)),0)
1298 -pcoords(overlapmap.LID(robin_nodes(1)),0);
1299 robin_b_add(1) = pcoords(overlapmap.LID(robin_nodes(0)),1)
1300 -pcoords(overlapmap.LID(robin_nodes(1)),1);
1301 l = blas.
NRM2(robin_b_add.
M(), robin_b_add.
A());
1302 robin_b_add.
Multiply(
'N',
'N', 1.0, NN, g, 0.0);
1303 robin_b_add.
Scale(l);
1304 err = b->SumIntoGlobalValues(robin_nodes, robin_b_add);
1305 if (err<0)
return(err);
1307 NNN[0].
Scale(sigma(0)); NNN[1].
Scale(sigma(1));
1308 robin_A_add += NNN[0]; robin_A_add += NNN[1];
1309 robin_A_add.
Scale(l);
1310 err = A->InsertGlobalValues(robin_nodes, robin_A_add, format);
1311 if (err<0)
return(err);
1320 for (i=0; i<e.
M(); i++) {
1322 dirichlet(j,0) = e(i,0); dirichlet(j,1) = e(i,1);
1326 dirichlet.Reshape(j,2);
1337 for (i=0; i< numNodesPerElem; i++) k(i)=0.0;
1338 for (i=0; i< numNodesPerElem; i++) { c(i,0)=0.0; c(i,1)=0.0; }
1339 for (i=0; i< numNodesPerElem; i++) r(i)=1.0;
1340 for (i=0; i< numNodesPerElem; i++) f(i)=0.0;
1342 sigma(0)=0.0; sigma(1)=0.0;
1343 for(i=0; i<numLocElems; i++) {
1344 nodes[0] = t(i,0); nodes[1] = t(i,1); nodes[2] = t(i,2);
1345 for (j=0; j<numNodesPerElem; j++) {
1346 vertices(j,0) = pcoords(overlapmap.LID(nodes[j]), 0);
1347 vertices(j,1) = pcoords(overlapmap.LID(nodes[j]), 1);
1349 lassembly(vertices, k, c, r, f, usr_par, Mt, bt);
1350 err = M->InsertGlobalValues(epetra_nodes, Mt, format);
1351 if (err<0)
return(err);
1360 err = A->GlobalAssemble();
1361 if (err<0)
return(err);
1363 err = b->GlobalAssemble();
1364 if (err<0)
return(err);
1366 err = M->GlobalAssemble();
1367 if (err<0)
return(err);
1437 for(
int i=0; i<2; i++) {
1438 B(i,0) = vertices(1,i)-vertices(0,i);
1439 B(i,1) = vertices(2,i)-vertices(0,i);
1445 BtB.
Multiply(
'T',
'N', 1.0, B, B, 0.0);
1451 tmp = usr_par.
S1; tmp.
Scale(C(0,0));
1453 tmp = usr_par.
S2; tmp.
Scale(C(0,1));
1455 tmp = usr_par.
S3; tmp.
Scale(C(1,1));
1457 M1.
Scale( (k(0)*usr_par.
Nw(0) + k(1)*usr_par.
Nw(1) +
1458 k(2)*usr_par.
Nw(2)) * adB );
1461 tmp = usr_par.
NdNdx1Nw[0]; tmp.
Scale(b(0,0)*c(0,0)+b(0,1)*c(0,1));
1463 tmp = usr_par.
NdNdx1Nw[1]; tmp.
Scale(b(0,0)*c(1,0)+b(0,1)*c(1,1));
1465 tmp = usr_par.
NdNdx1Nw[2]; tmp.
Scale(b(0,0)*c(2,0)+b(0,1)*c(2,1));
1467 tmp = usr_par.
NdNdx2Nw[0]; tmp.
Scale(b(1,0)*c(0,0)+b(1,1)*c(0,1));
1469 tmp = usr_par.
NdNdx2Nw[1]; tmp.
Scale(b(1,0)*c(1,0)+b(1,1)*c(1,1));
1471 tmp = usr_par.
NdNdx2Nw[2]; tmp.
Scale(b(1,0)*c(2,0)+b(1,1)*c(2,1));
1512 lapack.
GETRF(dim, dim, inv.
A(), dim, ipiv.
A(), &info);
1513 lapack.
GETRI(dim, inv.
A(), dim, ipiv.
A(), work.
A(), &dim, &info);
1535 lapack.
GETRF(dim, dim, mymat.
A(), dim, ipiv.
A(), &info);
1538 for (
int i=0; i<dim; i++) {
1543 for (
int i=0; i<dim; i++) {
1544 if ((ipiv[i]-1) != i)
1548 det *= pow((
double)(-1.0),swaps);
1560 const char geomFileBase[],
1565 int MyPID = Comm.
MyPID();
1567 const int FileNameSize = 120;
1568 char FileName[FileNameSize];
1570 sprintf(FileName,
"%s.%03d", geomFileBase, MyPID);
1573 std::ifstream file_in(FileName);
1575 file_in.eof(), std::logic_error
1576 ,
"Error, the file \""<<FileName<<
"\" could not be opened for input!"
1581 fid = fopen(FileName,
"r");
1583 if(trace) printf(
"\nReading node info from %s ...\n", FileName);
1584 int numip = 0, numcp = 0;
1585 fscanf(fid,
"%d %d", &numip, &numcp);
1586 const int nump = numip + numcp;
1587 if(trace) printf(
"\nnumip = %d, numcp = %d, nump = %d\n", numip, numcp, nump );
1589 ipcoords.
Shape(numip, 2);
1591 pcoords.
Shape(nump, 2);
1592 for (
int i=0; i<numip; i++) {
1593 fscanf(fid,
"%d %lf %lf %*d",&ipindx(i),&ipcoords(i,0),&ipcoords(i,1));
1594 if(trace&&dumpAll) printf(
"%d %lf %lf\n",ipindx(i),ipcoords(i,0),ipcoords(i,1));
1595 pindx(i) = ipindx(i);
1596 pcoords(i,0) = ipcoords(i,0); pcoords(i,1) = ipcoords(i,1);
1598 for (
int i=numip; i<nump; i++) {
1599 fscanf(fid,
"%d %lf %lf %*d",&pindx(i),&pcoords(i,0),&pcoords(i,1));
1602 fscanf(fid,
"%*[^\n]");
1603 fscanf(fid,
"%*1[\n]");
1605 fscanf(fid,
"%*[^\n]");
1606 fscanf(fid,
"%*1[\n]");
1608 for (
int i=0; i<nump; i++) {
1609 fscanf(fid,
"%*[^\n]");
1610 fscanf(fid,
"%*1[\n]");
1613 if(trace) printf(
"\nReading element info from %s ...\n", FileName);
1615 fscanf(fid,
"%d", &numelems);
1616 if(trace) printf(
"\nnumelems = %d\n", numelems );
1617 t.
Shape(numelems,3);
1618 for (
int i=0; i<numelems; i++) {
1619 fscanf(fid,
"%d %d %d", &t(i,0), &t(i,1), &t(i,2));
1620 if(trace&&dumpAll) printf(
"%d %d %d\n", t(i,0), t(i,1), t(i,2));
1623 if(trace) printf(
"\nReading boundry edge info from %s ...\n", FileName);
1625 fscanf(fid,
"%d",&numedges);
1626 if(trace) printf(
"\nnumedges = %d\n", numedges );
1627 e.
Shape(numedges,3);
1628 for (
int i=0; i<numedges; i++) {
1629 fscanf(fid,
"%d %d %d", &e(i,0), &e(i,1), &e(i,2));
1630 if(trace&&dumpAll) printf(
"%d %d %d\n", e(i,0), e(i,1), e(i,2));
1634 if(trace) printf(
"Done reading mesh.\n");
1688 int myPID = Comm.
MyPID();
1689 int numProcs = Comm.
NumProc();
1691 int numLocNodes = pindx.
M();
1692 int numMyLocNodes = ipindx.
M();
1693 int numLocElems = t.
M();
1694 int numNodesPerElem = 3;
1698 Epetra_Map standardmap(-1, numMyLocNodes, (
int*)ipindx.
A(), indexBase, Comm);
1699 Epetra_Map overlapmap(-1, numLocNodes, (
int*)pindx.
A(), indexBase, Comm);
1703 int* nodes =
new int[numNodesPerElem];
1704 int i=0, j=0, err=0;
1710 int numQuadPts = Nodes.
M();
1715 N.
Shape(numQuadPts,3);
1716 for (
int i=0; i<numQuadPts; i++) {
1717 N(i,0) = 1.0 - Nodes(i,0) - Nodes(i,1);
1718 N(i,1) = Nodes(i,0);
1719 N(i,2) = Nodes(i,1);
1737 ly.
Size(numNodesPerElem);
1738 Nly.
Size(numQuadPts);
1739 ls.
Size(numNodesPerElem);
1740 Nls.
Size(numQuadPts);
1741 llambda.
Size(numNodesPerElem);
1742 Nllambda.
Size(numQuadPts);
1743 lgfctn.
Size(numQuadPts);
1744 lgfctnNi.
Size(numQuadPts);
1745 lgfctnNls.
Size(numQuadPts);
1746 lhessvec.
Size(numNodesPerElem);
1751 for(i=0; i<numLocElems; i++) {
1753 nodes[0] = t(i,0); nodes[1] = t(i,1); nodes[2] = t(i,2);
1754 for (j=0; j<numNodesPerElem; j++) {
1755 vertices(j,0) = pcoords(overlapmap.LID(nodes[j]), 0);
1756 vertices(j,1) = pcoords(overlapmap.LID(nodes[j]), 1);
1760 for(
int i=0; i<2; i++) {
1761 B(i,0) = vertices(1,i)-vertices(0,i);
1762 B(i,1) = vertices(2,i)-vertices(0,i);
1767 for (j=0; j<numNodesPerElem; j++) {
1768 ly(j) = (*((*y)(0)))[overlapmap.LID(nodes[j])];
1769 ls(j) = (*((*s)(0)))[overlapmap.LID(nodes[j])];
1770 llambda(j) = (*((*lambda)(0)))[overlapmap.LID(nodes[j])];
1773 Nly.
Multiply(
'N',
'N', 1.0, N, ly, 0.0);
1774 Nls.
Multiply(
'N',
'N', 1.0, N, ls, 0.0);
1775 Nllambda.
Multiply(
'N',
'N', 1.0, N, llambda, 0.0);
1778 for (
int i=0; i<numNodesPerElem; i++) {
1781 lhessvec(i) = adB*lgfctnNls.
Dot(Weights);
1784 err = hessvec->SumIntoGlobalValues(epetra_nodes, lhessvec);
1785 if (err<0)
return(err);
1790 err = hessvec->GlobalAssemble();
1791 if (err<0)
return(err);
1803 for (
int i=0; i<v.
M(); i++) {
1850 int myPID = Comm.
MyPID();
1851 int numProcs = Comm.
NumProc();
1853 int numLocNodes = pindx.
M();
1854 int numMyLocNodes = ipindx.
M();
1855 int numLocElems = t.
M();
1856 int numNodesPerElem = 3;
1860 Epetra_Map standardmap(-1, numMyLocNodes, (
int*)ipindx.
A(), indexBase, Comm);
1861 Epetra_Map overlapmap(-1, numLocNodes, (
int*)pindx.
A(), indexBase, Comm);
1866 int* nodes =
new int[numNodesPerElem];
1867 int i=0, j=0, err=0;
1873 int numQuadPts = Nodes.
M();
1878 N.
Shape(numQuadPts,3);
1879 for (
int i=0; i<numQuadPts; i++) {
1880 N(i,0) = 1.0 - Nodes(i,0) - Nodes(i,1);
1881 N(i,1) = Nodes(i,0);
1882 N(i,2) = Nodes(i,1);
1895 ly.Size(numNodesPerElem);
1896 Nly.
Size(numQuadPts);
1897 lgfctn.
Size(numQuadPts);
1898 lgfctnNiNj.
Size(numQuadPts);
1899 lGp.
Shape(numNodesPerElem, numNodesPerElem);
1904 for(i=0; i<numLocElems; i++) {
1906 nodes[0] = t(i,0); nodes[1] = t(i,1); nodes[2] = t(i,2);
1907 for (j=0; j<numNodesPerElem; j++) {
1908 vertices(j,0) = pcoords(overlapmap.LID(nodes[j]), 0);
1909 vertices(j,1) = pcoords(overlapmap.LID(nodes[j]), 1);
1913 for(
int i=0; i<2; i++) {
1914 B(i,0) = vertices(1,i)-vertices(0,i);
1915 B(i,1) = vertices(2,i)-vertices(0,i);
1920 for (j=0; j<numNodesPerElem; j++) {
1921 ly(j) = (*((*y)(0)))[overlapmap.LID(nodes[j])];
1924 Nly.
Multiply(
'N',
'N', 1.0, N, ly, 0.0);
1927 for (
int i=0; i<numNodesPerElem; i++) {
1928 for (
int j=0; j<numNodesPerElem; j++) {
1930 lGp(i,j) = adB*lgfctnNiNj.
Dot(Weights);
1935 if (err<0)
return(err);
1941 if (err<0)
return(err);
1953 for (
int i=0; i<v.
M(); i++) {
1954 gv(i) = 3.0*pow(v(i),2)-1.0;
2000 int myPID = Comm.
MyPID();
2001 int numProcs = Comm.
NumProc();
2003 int numLocNodes = pindx.
M();
2004 int numMyLocNodes = ipindx.
M();
2005 int numLocElems = t.
M();
2006 int numNodesPerElem = 3;
2010 Epetra_Map standardmap(-1, numMyLocNodes, (
int*)ipindx.
A(), indexBase, Comm);
2011 Epetra_Map overlapmap(-1, numLocNodes, (
int*)pindx.
A(), indexBase, Comm);
2015 int* nodes =
new int[numNodesPerElem];
2016 int i=0, j=0, err=0;
2022 int numQuadPts = Nodes.
M();
2027 N.
Shape(numQuadPts,3);
2028 for (
int i=0; i<numQuadPts; i++) {
2029 N(i,0) = 1.0 - Nodes(i,0) - Nodes(i,1);
2030 N(i,1) = Nodes(i,0);
2031 N(i,2) = Nodes(i,1);
2044 ly.
Size(numNodesPerElem);
2045 Nly.
Size(numQuadPts);
2046 lgfctn.
Size(numQuadPts);
2047 lgfctnNi.
Size(numQuadPts);
2048 lg.
Size(numNodesPerElem);
2053 for(i=0; i<numLocElems; i++) {
2055 nodes[0] = t(i,0); nodes[1] = t(i,1); nodes[2] = t(i,2);
2056 for (j=0; j<numNodesPerElem; j++) {
2057 vertices(j,0) = pcoords(overlapmap.LID(nodes[j]), 0);
2058 vertices(j,1) = pcoords(overlapmap.LID(nodes[j]), 1);
2062 for(
int i=0; i<2; i++) {
2063 B(i,0) = vertices(1,i)-vertices(0,i);
2064 B(i,1) = vertices(2,i)-vertices(0,i);
2069 for (j=0; j<numNodesPerElem; j++) {
2070 ly(j) = (*((*y)(0)))[overlapmap.LID(nodes[j])];
2073 Nly.
Multiply(
'N',
'N', 1.0, N, ly, 0.0);
2076 for (
int i=0; i<numNodesPerElem; i++) {
2078 lg(i) = adB*lgfctnNi.
Dot(Weights);
2081 err = g->SumIntoGlobalValues(epetra_nodes, lg);
2082 if (err<0)
return(err);
2087 err = g->GlobalAssemble();
2088 if (err<0)
return(err);
2101 for (
int i=0; i<v.
M(); i++) {
2102 gv(i) = pow(v(i),3)-v(i);
2136 std::cerr <<
"ERROR in "<< __FILE__ <<
", line " << __LINE__ << std::endl;
2137 std::cerr <<
"Function CrsMatrix2MATLAB accepts\n";
2138 std::cerr <<
"transformed matrices ONLY. Please call A.TransformToLoca()\n";
2139 std::cerr <<
"on your matrix A to that purpose.\n";
2140 std::cerr <<
"Now returning...\n";
2150 int NumGlobalNonzeros;
2158 if( IndexBase == 0 )
2160 else if ( IndexBase == 1)
2166 outfile <<
"A = spalloc(";
2167 outfile << NumGlobalRows <<
',' << NumGlobalRows;
2168 outfile <<
',' << NumGlobalNonzeros <<
");\n";
2171 for(
int Proc=0 ; Proc<NumProc ; ++Proc ) {
2173 if( MyPID == Proc ) {
2175 outfile <<
"\n\n% On proc " << Proc <<
": ";
2176 outfile << NumMyRows <<
" rows and ";
2180 for(
int MyRow=0 ; MyRow<NumMyRows ; ++MyRow ) {
2182 GlobalRow = A.
GRID(MyRow);
2185 double *Values =
new double[NumNzRow];
2186 int *Indices =
new int[NumNzRow];
2189 NumEntries, Values, Indices);
2191 for(
int j=0 ; j<NumEntries ; ++j ) {
2192 outfile <<
"A(" << GlobalRow + IndexBase
2193 <<
"," << A.
GCID(Indices[j]) + IndexBase
2194 <<
") = " << Values[j] <<
";\n";
2232 int MyPID = v.Comm().MyPID();
2233 int NumProc = v.Comm().NumProc();
2234 int MyLength = v.MyLength();
2235 int GlobalLength = v.GlobalLength();
2241 if( MyPID == 0 ) outfile <<
"v = zeros(" << GlobalLength <<
",1)\n";
2250 if( IndexBase == 0 )
2252 else if ( IndexBase == 1)
2255 for(
int Proc=0 ; Proc<NumProc ; ++Proc ) {
2257 if( MyPID == Proc ) {
2259 outfile <<
"% On proc " << Proc <<
": ";
2260 outfile << MyLength <<
" rows of ";
2261 outfile << GlobalLength <<
" elements\n";
2263 for( Row=0 ; Row<MyLength ; ++Row ) {
2264 outfile <<
"v(" << MyGlobalElements[Row] + IndexBase
2265 <<
") = " << v[Row] <<
";\n";
2300 int MyPID = v.Comm().MyPID();
2301 int NumProc = v.Comm().NumProc();
2309 if( MyPID == 0 ) outfile <<
"v = zeros(" << GlobalLength <<
",1)\n";
2318 if( IndexBase == 0 )
2320 else if ( IndexBase == 1)
2323 for(
int Proc=0 ; Proc<NumProc ; ++Proc ) {
2325 if( MyPID == Proc ) {
2327 outfile <<
"% On proc " << Proc <<
": ";
2328 outfile << MyLength <<
" rows of ";
2329 outfile << GlobalLength <<
" elements\n";
2331 for( Row=0 ; Row<MyLength ; ++Row ) {
2332 outfile <<
"v(" << MyGlobalElements[Row] + IndexBase
2333 <<
") = " << v[0][Row] <<
";\n";
2373 else if (order == 2) {
2375 nodes(0,0) = (1.0-1.0/sqrt(3.0))/2.0;
2376 nodes(1,0) = (1.0+1.0/sqrt(3.0))/2.0;
2381 else if (order == 3) {
2383 nodes(0,0) = (1.0-sqrt(3.0/5.0))/2.0;
2385 nodes(2,0) = (1.0+sqrt(3.0/5.0))/2.0;
2387 weights(0) = 5.0/18.0;
2388 weights(1) = 4.0/9.0;
2389 weights(2) = 5.0/18.0;
2392 std::cout <<
"Quadrature for dim = " << dim <<
" and order = ";
2393 std::cout << order <<
" not available.\n";
2398 else if (dim == 2) {
2405 nodes(0,0) = 1.0/3.0; nodes (0,1) = 1.0/3.0;
2409 else if (order == 2) {
2411 nodes(0,0) = 1.0/6.0; nodes (0,1) = 1.0/6.0;
2412 nodes(1,0) = 2.0/3.0; nodes (1,1) = 1.0/6.0;
2413 nodes(2,0) = 1.0/6.0; nodes (2,1) = 2.0/3.0;
2415 weights(0) = 1.0/6.0;
2416 weights(1) = 1.0/6.0;
2417 weights(2) = 1.0/6.0;
2419 else if (order == 3) {
2421 nodes(0,0) = 1.0/3.0; nodes (0,1) = 1.0/3.0;
2422 nodes(1,0) = 3.0/5.0; nodes (1,1) = 1.0/5.0;
2423 nodes(2,0) = 1.0/5.0; nodes (2,1) = 3.0/5.0;
2424 nodes(3,0) = 1.0/5.0; nodes (3,1) = 1.0/5.0;
2426 weights(0) = -9.0/32.0;
2427 weights(1) = 25.0/96.0;
2428 weights(2) = 25.0/96.0;
2429 weights(3) = 25.0/96.0;
2432 std::cout <<
"Quadrature for dim = " << dim <<
" and order = ";
2433 std::cout << order <<
" not available.\n";
2439 std::cout <<
"Quadrature for dim = " << dim <<
" not available.\n";
Teuchos::RCP< Epetra_FEVector > Ny_
Teuchos::RCP< Epetra_FECrsMatrix > getR()
int NumGlobalElements() const
Teuchos::RCP< Epetra_FEVector > getq()
Teuchos::RCP< const Epetra_Comm > commptr_
Teuchos::RCP< Epetra_FEVector > b_
Right-hand side of the PDE.
Teuchos::RCP< const Epetra_IntSerialDenseVector > getpindx()
double beta_
Regularization parameter.
void PrintVec(const Teuchos::RCP< const Epetra_Vector > &x)
Outputs the solution vector to files.
int Resize(int Length_in)
Epetra_SerialDenseMatrix NNw
int NumMyEntries(int Row) const
int Shape(int NumRows, int NumCols)
Teuchos::RCP< const Epetra_IntSerialDenseMatrix > gett()
void computeNpy(const Teuchos::RCP< const Epetra_MultiVector > &y)
Calls the function that computes the Jacobian of the nonlinear term.
Epetra_SerialDenseMatrix Nx2
int ExtractGlobalRowCopy(int_type Row, int Length, int &NumEntries, double *values, int_type *Indices) const
float NRM2(const int N, const float *X, const int INCX=1) const
Epetra_SerialDenseMatrix * NdNdx2Nw
Teuchos::RCP< Epetra_CrsMatrix > Augmat_
Augmented system matrix: [ I Jac* ] [Jac 0 ].
int MyGlobalElements(int *MyGlobalElementList) const
virtual void Print(std::ostream &os) const
int nonlinjac(const Epetra_Comm &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseMatrix &, const Teuchos::RCP< const Epetra_MultiVector > &, Teuchos::RCP< Epetra_FECrsMatrix > &)
int NumGlobalRows() const
Epetra_SerialDenseMatrix S3
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void computeNy(const Teuchos::RCP< const Epetra_MultiVector > &y)
Calls the function that computes the nonlinear term.
void gfctn(const Epetra_SerialDenseVector &, Epetra_SerialDenseVector &)
bool Vector2MATLAB(const Epetra_Vector &, std::ostream &)
Epetra_SerialDenseVector Weights
bool FEVector2MATLAB(const Epetra_FEVector &, std::ostream &)
int nonlinvec(const Epetra_Comm &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseMatrix &, const Teuchos::RCP< const Epetra_MultiVector > &, Teuchos::RCP< Epetra_FEVector > &)
Teuchos::RCP< Epetra_FECrsMatrix > A_
Volume stiffness matrix.
Epetra_SerialDenseMatrix S1
Teuchos::RCP< const Epetra_IntSerialDenseMatrix > gete()
int meshreader(const Epetra_Comm &, Epetra_IntSerialDenseVector &, Epetra_SerialDenseMatrix &, Epetra_IntSerialDenseVector &, Epetra_SerialDenseMatrix &, Epetra_IntSerialDenseMatrix &, Epetra_IntSerialDenseMatrix &, const char geomFileBase[], const bool trace=true, const bool dumpAll=false)
double determinant(const Epetra_SerialDenseMatrix &)
Provides the interface to generic abstract vector libraries.
void Print(std::ostream &os) const
bool IndicesAreLocal() const
virtual void Barrier() const =0
Teuchos::RCP< Epetra_FECrsMatrix > getNpy()
ostream & operator<<(ostream &os, const pair< Packet, Packet > &arg)
Transform to form the explicit transpose of a Epetra_RowMatrix.
Teuchos::RCP< Epetra_IntSerialDenseMatrix > t_
Elements (this includes all overlapping nodes).
void gpfctn(const Epetra_SerialDenseVector &v, Epetra_SerialDenseVector &gv)
Teuchos::RCP< Epetra_SerialDenseMatrix > pcoords_
Coordinates of all nodes in this subdomain.
virtual int MyPID() const =0
int FillComplete(bool OptimizeDataStorage=true)
int Resize(int Length_in)
int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
void GETRF(const int M, const int N, float *A, const int LDA, int *IPIV, int *INFO) const
Epetra_SerialDenseMatrix S2
virtual void Print(std::ostream &os) const
void rect2DMeshGenerator(const int numProc, const int procRank, const double len_x, const double len_y, const int local_nx, const int local_ny, const int bndy_marker, Epetra_IntSerialDenseVector *ipindx_out, Epetra_SerialDenseMatrix *ipcoords_out, Epetra_IntSerialDenseVector *pindx_out, Epetra_SerialDenseMatrix *pcoords_out, Epetra_IntSerialDenseMatrix *t_out, Epetra_IntSerialDenseMatrix *e_out, std::ostream *out, const bool dumpAll)
Generate a simple rectangular 2D triangular mesh that is only partitioned between processors in the y...
Epetra_SerialDenseMatrix * NdNdx1Nw
int NumMyElements() const
void Print(std::ostream &os) const
Teuchos::RCP< Epetra_FECrsMatrix > Npy_
Jacobian of the nonlinear term.
Teuchos::RCP< Epetra_FECrsMatrix > R_
Edge mass matrix.
void computeAugmat()
Assembles the augmented system (KKT-type) matrix.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Epetra_SerialDenseMatrix > getpcoords()
int assemble_bdry(const Epetra_Comm &Comm, const Epetra_IntSerialDenseVector &ipindx, const Epetra_SerialDenseMatrix &ipcoords, const Epetra_IntSerialDenseVector &pindx, const Epetra_SerialDenseMatrix &pcoords, const Epetra_IntSerialDenseMatrix &t, const Epetra_IntSerialDenseMatrix &e, Teuchos::RCP< Epetra_FECrsMatrix > *B, Teuchos::RCP< Epetra_FECrsMatrix > *R)
int assemblyFECrs(const Epetra_Comm &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseMatrix &, const Epetra_IntSerialDenseMatrix &, Teuchos::RCP< Epetra_FECrsMatrix > &, Teuchos::RCP< Epetra_FEVector > &)
int ExtractGlobalRowCopy(int GlobalRow, int Length, int &NumEntries, double *Values, int *Indices) const
T_To & dyn_cast(T_From &from)
Teuchos::RCP< Epetra_FECrsMatrix > B_
Control/state mass matrix.
void g2pfctn(const Epetra_SerialDenseVector &, Epetra_SerialDenseVector &)
virtual const Epetra_BlockMap & Map() const =0
int compproduct(Epetra_SerialDenseVector &, double *, double *)
Teuchos::RCP< Epetra_SerialDenseMatrix > ipcoords_
Coordinates of nodes that are unique to this subdomain.
int GlobalAssemble(bool callFillComplete=true, Epetra_CombineMode combineMode=Add, bool save_off_and_reuse_map_exporter=false)
int lassembly(const Epetra_SerialDenseMatrix &, const Epetra_SerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_SerialDenseVector &, const Epetra_SerialDenseVector &, const Usr_Par &, Epetra_SerialDenseMatrix &, Epetra_SerialDenseVector &)
Teuchos::RCP< const Epetra_IntSerialDenseVector > getipindx()
Teuchos::RCP< Epetra_FECrsMatrix > getH()
int NumGlobalNonzeros() const
Teuchos::RCP< const Epetra_SerialDenseMatrix > getipcoords()
void computeAll(const GenSQP::Vector &x)
Calls functions to compute nonlinear quantities and the augmented system matrix.
Teuchos::RCP< Epetra_FECrsMatrix > getB()
void GETRI(const int N, float *A, const int LDA, int *IPIV, float *WORK, const int *LWORK, int *INFO) const
int nonlinhessvec(const Epetra_Comm &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseMatrix &, const Teuchos::RCP< const Epetra_MultiVector > &, const Teuchos::RCP< const Epetra_MultiVector > &, const Teuchos::RCP< const Epetra_MultiVector > &, Teuchos::RCP< Epetra_FEVector > &)
Teuchos::RCP< Epetra_FEVector > q_
The desired state.
Teuchos::RCP< Epetra_FECrsMatrix > getA()
Epetra_SerialDenseMatrix Nodes
int Scale(double ScalarA)
Teuchos::RCP< Epetra_IntSerialDenseVector > pindx_
Global nodes (interior + shared, overlapping) in this subdomain.
virtual void Print(std::ostream &os) const
int Multiply(char TransA, char TransB, double ScalarAB, const Epetra_SerialDenseMatrix &A, const Epetra_SerialDenseMatrix &B, double ScalarThis)
virtual int NumProc() const =0
int GRID(int LRID_in) const
Teuchos::RCP< Epetra_CrsMatrix > getAugmat()
bool CrsMatrix2MATLAB(const Epetra_CrsMatrix &, std::ostream &)
Epetra_SerialDenseMatrix Nx1
const Epetra_Map & DomainMap() const
Epetra_SerialDenseVector Nw
Epetra_SerialDenseMatrix * NNNw
int solveAugsys(const Teuchos::RCP< const Epetra_MultiVector > &rhsy, const Teuchos::RCP< const Epetra_MultiVector > &rhsu, const Teuchos::RCP< const Epetra_MultiVector > &rhsp, const Teuchos::RCP< Epetra_MultiVector > &y, const Teuchos::RCP< Epetra_MultiVector > &u, const Teuchos::RCP< Epetra_MultiVector > &p, double tol)
Solves augmented system.
Teuchos::RCP< Epetra_FEVector > getNy()
int quadrature(const int, const int, Epetra_SerialDenseMatrix &, Epetra_SerialDenseVector &)
float DOT(const int N, const float *X, const float *Y, const int INCX=1, const int INCY=1) const
double Dot(const Epetra_SerialDenseVector &x) const
int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const
std::ostream & operator<<(std::ostream &, const Usr_Par &)
The GenSQP::Vector / (y,u) Epetra_MultiVector adapter class.
int Shape(int NumRows, int NumCols)
Teuchos::RCP< const Epetra_Comm > getCommPtr()
const Epetra_Comm & Comm() const
Epetra_SerialDenseMatrix N
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Teuchos::RCP< Epetra_FEVector > getb()
int assemble(const Epetra_Comm &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseVector &, const Epetra_SerialDenseMatrix &, const Epetra_IntSerialDenseMatrix &, const Epetra_IntSerialDenseMatrix &, Teuchos::RCP< Epetra_FECrsMatrix > &, Teuchos::RCP< Epetra_FECrsMatrix > &, Teuchos::RCP< Epetra_FEVector > &)
int GCID(int LCID_in) const
Teuchos::RCP< Epetra_IntSerialDenseMatrix > e_
Edges.
int inverse(const Epetra_SerialDenseMatrix &, Epetra_SerialDenseMatrix &)
Teuchos::RCP< Epetra_IntSerialDenseVector > ipindx_
Global nodes (interior, nonoverlapping) in this subdomain.
int NumMyNonzeros() const
Teuchos::RCP< Epetra_FECrsMatrix > H_
Volume mass matrix.