50 #include "Petra_Comm.h"
51 #include "Petra_Map.h"
52 #include "Petra_Time.h"
53 #include "Petra_RDP_MultiVector.h"
54 #include "Petra_RDP_Vector.h"
55 #include "Petra_RDP_CRS_Matrix.h"
56 #include "Trilinos_LinearProblem.h"
67 int main(
int argc,
char *argv[])
76 MPI_Init(&argc,&argv);
79 MPI_Comm_size(MPI_COMM_WORLD, &size);
80 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
91 Petra_Comm & Comm = *
new Petra_Comm( MPI_COMM_WORLD );
93 Petra_Comm & Comm = *
new Petra_Comm();
96 int MyPID = Comm.MyPID();
97 int NumProc = Comm.NumProc();
101 cout <<
"Usage: " << argv[0] <<
" number_of_elements" << endl;
104 int NumGlobalElements = atoi(argv[1])+1;
107 if (NumGlobalElements < NumProc) {
108 cout <<
"numGlobalBlocks = " << NumGlobalElements
109 <<
" cannot be < number of processors = " << NumProc << endl;
116 Petra_Map& StandardMap = *
new Petra_Map(NumGlobalElements, 0, Comm);
117 int NumMyElements = StandardMap.NumMyElements();
118 int * StandardMyGlobalElements =
new int[NumMyElements];
119 StandardMap.MyGlobalElements(StandardMyGlobalElements);
129 int OverlapNumMyElements;
132 OverlapNumMyElements = NumMyElements + 2;
133 if ((MyPID==0)||(MyPID==NumProc-1)) OverlapNumMyElements--;
135 if (MyPID==0) OverlapMinMyGID = StandardMap.MinMyGID();
136 else OverlapMinMyGID = StandardMap.MinMyGID()-1;
138 int * OverlapMyGlobalElements =
new int[OverlapNumMyElements];
140 for (i=0; i< OverlapNumMyElements; i++)
141 OverlapMyGlobalElements[i] = OverlapMinMyGID + i;
143 Petra_Map& OverlapMap = *
new Petra_Map(-1, OverlapNumMyElements,
144 OverlapMyGlobalElements, 0, Comm);
149 Petra_RDP_Vector& du = *
new Petra_RDP_Vector(StandardMap);
150 Petra_RDP_Vector& rhs = *
new Petra_RDP_Vector(StandardMap);
151 Petra_RDP_Vector& soln = *
new Petra_RDP_Vector(StandardMap);
152 Petra_RDP_CRS_Matrix&
A = *
new Petra_RDP_CRS_Matrix(
Copy, StandardMap, pS);
155 Petra_RDP_Vector& rhs1 = *
new Petra_RDP_Vector(OverlapMap);
156 Petra_RDP_Vector& u = *
new Petra_RDP_Vector(OverlapMap);
157 Petra_RDP_Vector& x = *
new Petra_RDP_Vector(OverlapMap);
158 Petra_RDP_CRS_Matrix& A1 = *
new Petra_RDP_CRS_Matrix(
Copy, OverlapMap, pO);
162 i=soln.PutScalar(1.0);
166 double *xx =
new double[2];
167 double *uu =
new double[2];
170 int *indicies =
new int[3];
171 double *RowValues =
new double[OverlapMap.NumGlobalElements()];
173 double residual, difference;
174 double relTol=1.0e-4;
175 double absTol=1.0e-9;
179 double dx=Length/((double) NumGlobalElements-1);
180 for (i=0; i < OverlapNumMyElements; i++) {
181 x[i]=dx*((double) OverlapMinMyGID+i);
186 for (
int NLS=0; NLS<2; NLS++) {
191 i=rhs1.PutScalar(0.0);
192 i=rhs.PutScalar(0.0);
195 for (
int ne=0; ne < OverlapNumMyElements-1; ne++) {
198 for(
int gp=0; gp < 3; gp++) {
206 for (i=0; i< 2; i++) {
207 rhs1[ne+i]+=basis.
wt*basis.
dx
208 *((1.0/(basis.
dx*basis.
dx))*basis.
duu*
214 for(j=0;j < 2; j++) {
217 row=OverlapMap.GID(ne+i);
218 column=OverlapMap.GID(ne+j);
219 ierr=A1.SumIntoGlobalValues(row, 1, &jac, &column);
222 ierr=A1.InsertGlobalValues(row, 1, &jac, &column);
234 Petra_Import & Importer = *
new Petra_Import(StandardMap, OverlapMap);
235 assert(rhs.Import(rhs1, Importer,
Insert)==0);
236 assert(A.Import(A1, Importer,
Insert)==0);
246 A.ReplaceGlobalValues(0, 1, &jac, &column);
249 A.ReplaceGlobalValues(0, 1, &jac, &column);
254 assert(A.FillComplete()==0);
272 ierr=rhs.Norm2(&residual);
273 ierr=du.Norm2(&difference);
274 if (MyPID==0) printf(
"\n***********************************************\n");
275 if (MyPID==0) printf(
"Iteration %d Residual L2=%e Update L2=%e\n"
276 ,NLS,residual,difference);
277 if (MyPID==0) printf(
"***********************************************\n");
278 if ((residual < absTol)&&(difference < relTol)) {
279 if (MyPID==0) printf(
"\n\nConvergence Achieved!!!!\n");
283 Trilinos_LinearProblem *Problem =
new Trilinos_LinearProblem(&A,&du,&rhs);
284 Problem->SetPDL(hard);
285 Problem->Iterate(400, 1.0e-8);
289 for (i=0;i<NumMyElements;i++) soln[i] -= du[i];
291 Petra_Import & Importer2 = *
new Petra_Import(OverlapMap, StandardMap);
292 assert(u.Import(soln, Importer2,
Insert)==0);
295 for (i=0;i<OverlapNumMyElements;i++)
296 printf(
"Proc=%d GID=%d u=%e soln=%e\n",MyPID,
297 OverlapMap.GID(i),u[i],soln[i]);
304 delete [] OverlapMyGlobalElements;
308 delete [] StandardMyGlobalElements;
void getBasis(int gp, double *x, double *u)
int main(int argc, char *argv[])