#include "Didasko_ConfigDefs.h"
#if defined(HAVE_DIDASKO_EPETRA)
#include "Epetra_ConfigDefs.h"
#ifdef HAVE_MPI
#include "mpi.h"
#include "Epetra_MpiComm.h"
#else
#include "Epetra_SerialComm.h"
#endif
#include "Epetra_Map.h"
#include "Epetra_Vector.h"
#include "Epetra_CrsMatrix.h"
#include "Epetra_Import.h"
#include "Epetra_SerialDenseMatrix.h"
void compute_loc_matrix( double *x_triangle, double *y_triangle,
int find( const int list[], const int length, const int index);
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
#else
#endif
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(0);
}
int NumMyElements = 0;
int NumMyExternalElements = 0;
int NumMyTotalElements = 0;
int FE_NumMyElements = 0;
int * MyGlobalElements = 0;
cout << MyPID << endl;
switch( MyPID ) {
case 0:
NumMyElements = 3;
NumMyExternalElements = 2;
NumMyTotalElements = NumMyElements + NumMyExternalElements;
FE_NumMyElements = 3;
MyGlobalElements = new int[NumMyTotalElements];
MyGlobalElements[0] = 0;
MyGlobalElements[1] = 4;
MyGlobalElements[2] = 3;
MyGlobalElements[3] = 1;
MyGlobalElements[4] = 5;
break;
case 1:
NumMyElements = 3;
NumMyExternalElements = 2;
NumMyTotalElements = NumMyElements + NumMyExternalElements;
FE_NumMyElements = 3;
MyGlobalElements = new int[NumMyTotalElements];
MyGlobalElements[0] = 1;
MyGlobalElements[1] = 2;
MyGlobalElements[2] = 5;
MyGlobalElements[3] = 0;
MyGlobalElements[4] = 4;
break;
}
Epetra_Map Map(-1,NumMyElements,MyGlobalElements,0,Comm);
switch( MyPID ) {
case 0:
T.
Shape(3,FE_NumMyElements);
CoordX_noExt[0] = 0.0;
CoordX_noExt[1] = 1.0;
CoordX_noExt[2] = 0.0;
CoordY_noExt[0] = 0.0;
CoordY_noExt[1] = 1.0;
CoordY_noExt[2] = 1.0;
T(0,0) = 0; T(0,1) = 4; T(0,2) = 3;
T(1,0) = 0; T(1,1) = 1; T(1,2) = 4;
T(2,0) = 4; T(2,1) = 1; T(2,2) = 5;
break;
case 1:
T.
Shape(3,FE_NumMyElements);
CoordX_noExt[0] = 1.0;
CoordX_noExt[1] = 2.0;
CoordX_noExt[2] = 2.0;
CoordY_noExt[0] = 0.0;
CoordY_noExt[1] = 0.0;
CoordY_noExt[2] = 1.0;
T(0,0) = 0; T(0,1) = 1; T(0,2) = 4;
T(1,0) = 1; T(1,1) = 5; T(1,2) = 4;
T(2,0) = 1; T(2,1) = 2; T(2,2) = 5;
break;
}
MyGlobalElements, 0, Comm);
CoordX.Import(CoordX_noExt,Importer,Insert);
CoordY.Import(CoordY_noExt,Importer,Insert);
const int MaxNnzRow = 5;
int Element, MyRow, GlobalRow, GlobalCol, i, j, k;
Struct.
Shape(NumMyElements,MaxNnzRow);
for( i=0 ; i<NumMyElements ; ++i )
for( j=0 ; j<MaxNnzRow ; ++j )
Struct(i,j) = -1;
for( Element=0 ; Element<FE_NumMyElements ; ++Element ) {
for( i=0 ; i<3 ; ++i ) {
GlobalRow = T(Element,i);
MyRow = A.LRID(GlobalRow);
if( MyRow != -1 ) {
for( j=0 ; j<3 ; ++j ) {
GlobalCol = T(Element,j);
for( k=0 ; k<MaxNnzRow ; ++k ) {
if( Struct(MyRow,k) == GlobalCol ||
Struct(MyRow,k) == -1 ) break;
}
if( Struct(MyRow,k) == -1 ) {
Struct(MyRow,k) = GlobalCol;
} else if( Struct(MyRow,k) != GlobalCol ) {
cerr << "ERROR: not enough space for element "
<< GlobalRow << "," << GlobalCol << endl;
return( 0 );
}
}
}
}
}
int * Indices = new int [MaxNnzRow];
double * Values = new double [MaxNnzRow];
for( i=0 ; i<MaxNnzRow ; ++i ) Values[i] = 0.0;
for( int Row=0 ; Row<NumMyElements ; ++Row ) {
int Length = 0;
for( int j=0 ; j<MaxNnzRow ; ++j ) {
if( Struct(Row,j) == -1 ) break;
Indices[Length] = Struct(Row,j);
Length++;
}
GlobalRow = MyGlobalElements[Row];
A.InsertGlobalValues(GlobalRow, Length, Values, Indices);
}
for( int Element=0 ; Element<FE_NumMyElements ; ++Element ) {
for( int i=0 ; i<3 ; ++i ) {
int global = T(Element,i);
int local = find(MyGlobalElements,NumMyTotalElements,
global);
if( global == -1 ) {
cerr << "ERROR\n";
return( EXIT_FAILURE );
}
T(Element,i) = local;
}
}
for( int Element=0 ; Element<FE_NumMyElements ; ++Element ) {
int GlobalRow;
int MyRow;
int GlobalCol;
double x_triangle[3];
double y_triangle[3];
for( int i=0 ; i<3 ; ++i ) {
MyRow = T(Element,i);
y_triangle[i] = CoordX[MyRow];
x_triangle[i] = CoordY[MyRow];
}
compute_loc_matrix( x_triangle, y_triangle,Ke );
for( int i=0 ; i<3 ; ++i ) {
MyRow = T(Element,i);
if( MyRow < NumMyElements ) {
for( int j=0 ; j<3 ; ++j ) {
GlobalRow = MyGlobalElements[MyRow];
GlobalCol = MyGlobalElements[T(Element,j)];
A.SumIntoGlobalValues(GlobalRow,1,&(Ke(i,j)),&GlobalCol);
}
}
}
}
A.FillComplete();
delete[] MyGlobalElements;
delete[] Indices;
delete[] Values;
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return( EXIT_SUCCESS );
}
int find( const int list[], const int length, const int index)
{
int pos=-1;
for( int i=0 ; i<length ; ++i )
if( list[i] == index ) {
pos = i;
break;
}
return pos;
}
void compute_loc_matrix( double *x_triangle, double *y_triangle,
{
int ii, jj;
double det_J;
double xa, ya, xb, yb, xc, yc;
xa = x_triangle[0];
xb = x_triangle[1];
xc = x_triangle[2];
ya = y_triangle[0];
yb = y_triangle[1];
yc = y_triangle[2];
Ke(0,0) = (yc-yb)*(yc-yb) + (xc-xb)*(xc-xb);
Ke(0,1) = (yc-yb)*(ya-yc) + (xc-xb)*(xa-xc);
Ke(0,2) = (yb-ya)*(yc-yb) + (xb-xa)*(xc-xb);
Ke(1,0) = (yc-yb)*(ya-yc) + (xc-xb)*(xa-xc);
Ke(1,1) = (yc-ya)*(yc-ya) + (xc-xa)*(xc-xa);
Ke(1,2) = (ya-yc)*(yb-ya) + (xa-xc)*(xb-xa);
Ke(2,0) = (yb-ya)*(yc-yb) + (xb-xa)*(xc-xb);
Ke(2,1) = (ya-yc)*(yb-ya) + (xa-xc)*(xb-xa);
Ke(2,2) = (yb-ya)*(yb-ya) + (xb-xa)*(xb-xa);
det_J = (xb-xa)*(yc-ya)-(xc-xa)*(yb-ya);
det_J = 2*det_J;
if( det_J<0 ) det_J *=-1;
for (ii = 0; ii < 3; ii++) {
for (jj = 0; jj < 3; jj++) {
Ke(ii,jj) = Ke(ii,jj) / det_J;
}
}
return;
}
#else
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
puts("Please configure Didasko with:\n"
"--enable-epetra");
return 0;
}
#endif