Пример #1
0
// Constructor - creates the Epetra objects (maps and vectors)
Interface::Interface(int numGlobalElements, Epetra_Comm& comm, double xmin_,
                     double xmax_) :
  NumGlobalElements(numGlobalElements),
  NumMyElements(0),  // gets set after map creation
  MyPID(comm.MyPID()),
  NumProc(comm.NumProc()),
  xmin(xmin_),
  xmax(xmax_),
  factor(1.0),
  Comm(&comm),
  StandardMap(0),
  OverlapMap(0),
  Importer(0),
  rhs(0),
  Graph(0)
{

  // Construct a Source Map that puts approximately the same
  // Number of equations on each processor in uniform global ordering
  StandardMap = new Epetra_Map(NumGlobalElements, 0, *Comm);

  // Get the number of elements owned by this processor
  NumMyElements = StandardMap->NumMyElements();

  // Construct an overlaped map for the finite element fill *************
  // For single processor jobs, the overlap and standard map are the same
  if (NumProc == 1) {
    OverlapMap = new Epetra_Map(*StandardMap);
  } else {

    int OverlapNumMyElements;
    int OverlapMinMyGID;
    OverlapNumMyElements = NumMyElements + 2;
    if ((MyPID == 0) || (MyPID == NumProc - 1))
      OverlapNumMyElements --;

    if (MyPID==0)
      OverlapMinMyGID = StandardMap->MinMyGID();
    else
      OverlapMinMyGID = StandardMap->MinMyGID() - 1;

    int* OverlapMyGlobalElements = new int[OverlapNumMyElements];

    for (int i = 0; i < OverlapNumMyElements; i ++)
      OverlapMyGlobalElements[i] = OverlapMinMyGID + i;

    OverlapMap = new Epetra_Map(-1, OverlapNumMyElements,
                OverlapMyGlobalElements, 0, *Comm);

    delete [] OverlapMyGlobalElements;

  } // End Overlap map construction *************************************

  // Construct Linear Objects
  Importer = new Epetra_Import(*OverlapMap, *StandardMap);
  initialSolution = Teuchos::rcp(new Epetra_Vector(*StandardMap));

  // Assign non-zero entries in the graph
  createGraph();

  // Construct a matrix
  jacobian = Teuchos::rcp(new Epetra_CrsMatrix (Copy, *Graph));

  // Clean-up
  jacobian->FillComplete();

  // Create the nodal coordinates
  xptr = Teuchos::rcp(new Epetra_Vector(*StandardMap));
  double Length = xmax - xmin;
  double dx = Length/((double) NumGlobalElements-1);
  for (int i=0; i < NumMyElements; i++) {
    (*xptr)[i] = xmin + dx*((double) StandardMap->MinMyGID()+i);
  }

  initializeSoln();

}
Пример #2
0
// Constructor - creates the Epetra objects (maps and vectors) 
Brusselator::Brusselator(int numGlobalNodes, Epetra_Comm& comm,
                         OverlapType OType_) :
  xmin(0.0),
  xmax(1.0),
  Comm(&comm),
  overlapType(OType_),
  NumGlobalNodes(numGlobalNodes),
  ColumnToOverlapImporter(0),
  AA(0),
  A(0),
  alpha(0.6),
  beta(2.0)
{

  // Commonly used variables
  int i;
  MyPID = Comm->MyPID();      // Process ID
  NumProc = Comm->NumProc();  // Total number of processes

  // Here we assume a 2-species Brusselator model, ie 2 dofs per node
  // Note that this needs to be echoed in thew anonymous enum for NUMSPECIES.
  NumSpecies = 2;
  NumGlobalUnknowns = NumSpecies * NumGlobalNodes;

  // Construct a Source Map that puts approximately the same 
  // number of equations on each processor 

  // Begin by distributing nodes fairly equally
  StandardNodeMap = new Epetra_Map(NumGlobalNodes, 0, *Comm);

  // Get the number of nodes owned by this processor
  NumMyNodes = StandardNodeMap->NumMyElements();

  // Construct an overlap node map for the finite element fill
  // For single processor jobs, the overlap and standard maps are the same
  if (NumProc == 1) 
    OverlapNodeMap = new Epetra_Map(*StandardNodeMap);
  else {

    if( overlapType == ELEMENTS ) {

      int OverlapNumMyNodes;
      int OverlapMinMyNodeGID;

      OverlapNumMyNodes = NumMyNodes + 2;
      if ((MyPID == 0) || (MyPID == NumProc - 1))
        OverlapNumMyNodes --;

      if (MyPID==0)
        OverlapMinMyNodeGID = StandardNodeMap->MinMyGID();
      else
        OverlapMinMyNodeGID = StandardNodeMap->MinMyGID() - 1;

      int* OverlapMyGlobalNodes = new int[OverlapNumMyNodes];

      for (i = 0; i < OverlapNumMyNodes; i ++)
        OverlapMyGlobalNodes[i] = OverlapMinMyNodeGID + i;

      OverlapNodeMap = new Epetra_Map(-1, OverlapNumMyNodes, 
                                OverlapMyGlobalNodes, 0, *Comm);

      delete [] OverlapMyGlobalNodes;
    }

    else { // overlapType == NODES

      // Here we distribute elements such that nodes are ghosted, i.e. no 
      // overlapping elements but instead overlapping nodes
      int OverlapNumMyNodes;
      int OverlapMinMyNodeGID;
  
      OverlapNumMyNodes = NumMyNodes + 1;
      if ( MyPID == NumProc - 1 ) 
        OverlapNumMyNodes --;
      
      OverlapMinMyNodeGID = StandardNodeMap->MinMyGID();
      
      int* OverlapMyGlobalNodes = new int[OverlapNumMyNodes];
      
        for (i = 0; i < OverlapNumMyNodes; i ++) 
        OverlapMyGlobalNodes[i] = OverlapMinMyNodeGID + i;
      
      OverlapNodeMap = new Epetra_Map(-1, OverlapNumMyNodes, 
  			    OverlapMyGlobalNodes, 0, *Comm);

      delete [] OverlapMyGlobalNodes;
    }
  } // End Overlap node map construction ********************************

  // Now create the unknowns maps from the node maps
  NumMyUnknowns = NumSpecies * NumMyNodes;
  int* StandardMyGlobalUnknowns = new int[NumMyUnknowns];
  for (int k=0; k<NumSpecies; k++) 
    for (i=0; i<NumMyNodes; i++)

      // For now, we employ an interleave of unknowns

      StandardMyGlobalUnknowns[ NumSpecies * i + k ] = 
               NumSpecies * StandardNodeMap->GID(i) + k;

  StandardMap = new Epetra_Map(-1, NumMyUnknowns, StandardMyGlobalUnknowns,
                                 0, *Comm);
  delete [] StandardMyGlobalUnknowns;

  assert(StandardMap->NumGlobalElements() == NumGlobalUnknowns);

  if (NumProc == 1) {
    OverlapMap = new Epetra_Map(*StandardMap);
  } 
  else {
    int OverlapNumMyNodes = OverlapNodeMap->NumMyElements();
    int OverlapNumMyUnknowns = NumSpecies * OverlapNumMyNodes;
    int* OverlapMyGlobalUnknowns = new int[OverlapNumMyUnknowns];
    for (int k=0; k<NumSpecies; k++) 
      for (i=0; i<OverlapNumMyNodes; i++)
        OverlapMyGlobalUnknowns[ NumSpecies * i + k ] = 
                 NumSpecies * OverlapNodeMap->GID(i) + k;

    OverlapMap = new Epetra_Map(-1, OverlapNumMyUnknowns, 
                                OverlapMyGlobalUnknowns, 0, *Comm);
    delete [] OverlapMyGlobalUnknowns;

  } // End Overlap unknowns map construction ***************************


#ifdef DEBUG_MAPS
  // Output to check progress so far
  printf("[%d] NumSpecies, NumMyNodes, NumGlobalNodes, NumMyUnknowns, NumGlobalUnknowns :\n %d\t%d\t%d\t%d\n",
    MyPID,NumSpecies, NumMyNodes, NumGlobalNodes, NumMyUnknowns, NumGlobalUnknowns);

  Comm->Barrier();
  Comm->Barrier();
  Comm->Barrier();
  printf("[%d] StandardNodeMap :\n", MyPID);
  Comm->Barrier();
  cout << *StandardNodeMap << endl;
  Comm->Barrier();
  printf("[%d] OverlapNodeMap :\n", MyPID);
  Comm->Barrier();
  cout << *OverlapNodeMap << endl;
  Comm->Barrier();
  printf("[%d] StandardMap :\n", MyPID);
  Comm->Barrier();
  cout << *StandardMap << endl;
  Comm->Barrier();
  printf("[%d] StandardMap :\n", MyPID);
  Comm->Barrier();
  cout << *OverlapMap << endl;
  Comm->Barrier();
#endif

  // Construct Linear Objects  
  Importer = new Epetra_Import(*OverlapMap, *StandardMap);
  nodeImporter = new Epetra_Import(*OverlapNodeMap, *StandardNodeMap);
  initialSolution = new Epetra_Vector(*StandardMap);
  solnDot = new Epetra_Vector(*StandardMap);
  AA = new Epetra_CrsGraph(Copy, *StandardMap, 0);

  // Allocate the memory for a matrix dynamically (i.e. the graph is dynamic).
  if( overlapType == NODES )
    generateGraphUsingNodes(*AA);
  else
    generateGraphUsingElements(*AA);

#ifdef DEBUG_GRAPH
  AA->Print(cout);
#endif
#ifdef DEBUG_IMPORTER
  Importer->Print(cout);
#endif

  // Create the Importer needed for FD coloring using element overlap
  // as well as the problem Jacobian matrix which may or may not be used
  // depending on the choice of Jacobian operator
  if( overlapType == ELEMENTS ) {
    ColumnToOverlapImporter = new Epetra_Import(AA->ColMap(),*OverlapMap);
    A = new Epetra_CrsMatrix (Copy, *AA);
    A->FillComplete();
  }

  // Create the nodal coordinates
  xptr = new Epetra_Vector(*StandardNodeMap);
  double Length= xmax - xmin;
  dx=Length/((double) NumGlobalNodes-1);
  for (i=0; i < NumMyNodes; i++) {
    (*xptr)[i]=xmin + dx*((double) StandardNodeMap->MinMyGID()+i);
  }

  initializeSoln();

}
Пример #3
0
// Constructor - creates the Epetra objects (maps and vectors) 
PelletTransport::PelletTransport( int NumGlobalElementsUO2_  , double xminUO2_  , double xmaxUO2_  ,
                                  int NumGlobalElementsHe_   , double xminHe_   , double xmaxHe_   ,
                                  int NumGlobalElementsClad_ , double xminClad_ , double xmaxClad_ ,
                                  Epetra_Comm& Comm_, bool restart_ ) :
  NumGlobalElementsUO2(NumGlobalElementsUO2_),
  NumGlobalElementsHe(NumGlobalElementsHe_),
  NumGlobalElementsClad(NumGlobalElementsClad_),
  xminUO2(xminUO2_),
  xmaxUO2(xmaxUO2_),
  xminHe(xminHe_),
  xmaxHe(xmaxHe_),
  xminClad(xminClad_),
  xmaxClad(xmaxClad_),
  dt(1.0e+10),
  restart(restart_),
  Comm(&Comm_)
{

  NumGlobalNodes = NumGlobalElementsUO2 + NumGlobalElementsHe + NumGlobalElementsClad + 1;

  MyPID = Comm->MyPID();      // Process ID
  NumProc = Comm->NumProc();  // Total number of processes

  // Here we assume a 2-species PelletTransport model, ie 2 dofs per node
  // Note that this needs to be echoed in thew anonymous enum for NUMSPECIES.
  NumSpecies = 2;
  NumGlobalUnknowns = NumSpecies * NumGlobalNodes;

  // Construct a Source Map that puts approximately the same 
  // number of equations on each processor 

  // Begin by distributing nodes fairly equally
  StandardNodeMap = new Epetra_Map(NumGlobalNodes, 0, *Comm);

  // Get the number of nodes owned by this processor
  NumMyNodes = StandardNodeMap->NumMyElements();

  // Construct an overlap node map for the finite element fill
  // For single processor jobs, the overlap and standard maps are the same
  if (NumProc == 1) 
    OverlapNodeMap = new Epetra_Map(*StandardNodeMap);
  else 
  {
    // Distribute elements such that nodes are ghosted
    int OverlapNumMyNodes;
    int OverlapMinMyNodeGID;

    OverlapNumMyNodes = NumMyNodes + 1;
    if ( MyPID == NumProc - 1 ) 
      OverlapNumMyNodes --;
    
    OverlapMinMyNodeGID = StandardNodeMap->MinMyGID();
    
    int* OverlapMyGlobalNodes = new int[OverlapNumMyNodes];
    
    for( int i = 0; i < OverlapNumMyNodes; ++i ) 
      OverlapMyGlobalNodes[i] = OverlapMinMyNodeGID + i;
    
    OverlapNodeMap = new Epetra_Map(-1, OverlapNumMyNodes, 
                          OverlapMyGlobalNodes, 0, *Comm);

    delete [] OverlapMyGlobalNodes;

  } // End Overlap node map construction ********************************

  // Now create the unknowns maps from the node maps
  NumMyUnknowns = NumSpecies * NumMyNodes;
  int* StandardMyGlobalUnknowns = new int[NumMyUnknowns];
  for( int k = 0; k < NumSpecies; ++k )
    for( int i = 0; i < NumMyNodes; ++i )
    {
      // For now, we employ an interleave of unknowns
      StandardMyGlobalUnknowns[ NumSpecies * i + k ] = NumSpecies * StandardNodeMap->GID(i) + k;
    }

  StandardMap = new Epetra_Map(-1, NumMyUnknowns, StandardMyGlobalUnknowns, 0, *Comm);
  delete [] StandardMyGlobalUnknowns;

  assert(StandardMap->NumGlobalElements() == NumGlobalUnknowns);

  if (NumProc == 1) 
    OverlapMap = new Epetra_Map(*StandardMap);
  else 
  {
    int OverlapNumMyNodes = OverlapNodeMap->NumMyElements();
    int OverlapNumMyUnknowns = NumSpecies * OverlapNumMyNodes;
    int* OverlapMyGlobalUnknowns = new int[OverlapNumMyUnknowns];
    for (int k=0; k<NumSpecies; k++) 
      for( int i = 0; i < OverlapNumMyNodes; ++i )
        OverlapMyGlobalUnknowns[ NumSpecies * i + k ] = NumSpecies * OverlapNodeMap->GID(i) + k;

    OverlapMap = new Epetra_Map(-1, OverlapNumMyUnknowns, OverlapMyGlobalUnknowns, 0, *Comm);
    delete [] OverlapMyGlobalUnknowns;

  } // End Overlap unknowns map construction ***************************


#ifdef DEBUG_MAPS
  // Output to check progress so far
  printf("[%d] NumSpecies, NumMyNodes, NumGlobalNodes, NumMyUnknowns, NumGlobalUnknowns :\n %d\t%d\t%d\t%d\n",
    MyPID,NumSpecies, NumMyNodes, NumGlobalNodes, NumMyUnknowns, NumGlobalUnknowns);

  Comm->Barrier();
  Comm->Barrier();
  Comm->Barrier();
  printf("[%d] StandardNodeMap :\n", MyPID);
  Comm->Barrier();
  cout << *StandardNodeMap << endl;
  Comm->Barrier();
  printf("[%d] OverlapNodeMap :\n", MyPID);
  Comm->Barrier();
  cout << *OverlapNodeMap << endl;
  Comm->Barrier();
  printf("[%d] StandardMap :\n", MyPID);
  Comm->Barrier();
  cout << *StandardMap << endl;
  Comm->Barrier();
  printf("[%d] StandardMap :\n", MyPID);
  Comm->Barrier();
  cout << *OverlapMap << endl;
  Comm->Barrier();
#endif

  // Construct Linear Objects  
  Importer = new Epetra_Import(*OverlapMap, *StandardMap);
  nodeImporter = new Epetra_Import(*OverlapNodeMap, *StandardNodeMap);
  initialSolution = Teuchos::rcp(new Epetra_Vector(*StandardMap));
  oldSolution = new Epetra_Vector(*StandardMap);
  AA = Teuchos::rcp(new Epetra_CrsGraph(Copy, *StandardMap, 0));

  // Allocate the memory for a matrix dynamically (i.e. the graph is dynamic).
  generateGraphUsingNodes(*AA);

#ifdef DEBUG_GRAPH
  AA->Print(cout);
#endif
#ifdef DEBUG_IMPORTER
  Importer->Print(cout);
#endif

  // Create the element type int vector
  int numLocalElems = OverlapNodeMap->NumMyElements() - 1;
  Epetra_Map * elemMap = new Epetra_Map(-1, numLocalElems, 0, *Comm);
  elemTypes = Teuchos::rcp(new Epetra_IntVector(*elemMap)); 
  for( int i = 0; i < numLocalElems; ++i )
    if( i < NumGlobalElementsUO2 )
      (*elemTypes)[i] = UO2;
    else if( i < (NumGlobalElementsUO2 + NumGlobalElementsHe) )
      (*elemTypes)[i] = HELIUM;
      //(*elemTypes)[i] = UO2;
    else
      (*elemTypes)[i] = CLAD;
      //(*elemTypes)[i] = UO2;
  delete elemMap;

  // Create the nodal coordinates - only works in serial for now - RWH
  xptr = Teuchos::rcp(new Epetra_Vector(*StandardNodeMap));
  int inode = 0;
  double length = xmaxUO2 - xminUO2;
  double dx     = length/((double) NumGlobalElementsUO2 );
  (*xptr)[inode++] = xminUO2;
  for( int i = 1; i < NumGlobalElementsUO2; ++i )
  {
    (*xptr)[inode] = (*xptr)[inode-1] + dx;
    inode++;
  }
  length = xmaxHe - xminHe;
  dx     = length/((double) NumGlobalElementsHe );
  (*xptr)[inode++] = xminHe;
  for( int i = 1; i < NumGlobalElementsHe; ++i )
  {
    (*xptr)[inode] = (*xptr)[inode-1] + dx;
    inode++;
  }
  length = xmaxClad - xminClad;
  dx     = length/((double) NumGlobalElementsClad );
  (*xptr)[inode++] = xminClad;
  for( int i = 0; i < NumGlobalElementsClad; ++i )
  {
    (*xptr)[inode] = (*xptr)[inode-1] + dx;
    inode++;
  }

  initializeSoln();

}
Пример #4
0
// Constructor - creates the Epetra objects (maps and vectors) 
Brusselator::Brusselator(int numGlobalNodes, Epetra_Comm& comm) :
  xmin(0.0),
  xmax(1.0),
  Comm(&comm),
  NumGlobalNodes(numGlobalNodes),
  ColumnToOverlapImporter(0),
  AA(0),
  A(0),
  alpha(0.25),
  beta(1.5),
  D1(1.0/40.0),
  D2(1.0/40.0)
{

  // Commonly used variables
  int i;
  MyPID = Comm->MyPID();      // Process ID
  NumProc = Comm->NumProc();  // Total number of processes

  // Here we assume a 2-species Brusselator model, ie 2 dofs per node
  // Note that this needs to be echoed in thew anonymous enum for NUMSPECIES.
  NumSpecies = 2;
  NumGlobalUnknowns = NumSpecies * NumGlobalNodes;

  // Construct a Source Map that puts approximately the same 
  // number of equations on each processor 

  // Begin by distributing nodes fairly equally
  StandardNodeMap = new Epetra_Map(NumGlobalNodes, 0, *Comm);

  // Get the number of nodes owned by this processor
  NumMyNodes = StandardNodeMap->NumMyElements();

  // Construct an overlap node map for the finite element fill
  // For single processor jobs, the overlap and standard maps are the same
  if (NumProc == 1) 
    OverlapNodeMap = new Epetra_Map(*StandardNodeMap);
  else {

    int OverlapNumMyNodes;
    int OverlapMinMyNodeGID;

    OverlapNumMyNodes = NumMyNodes + 2;
    if ((MyPID == 0) || (MyPID == NumProc - 1))
      OverlapNumMyNodes --;
    
    if (MyPID==0)
      OverlapMinMyNodeGID = StandardNodeMap->MinMyGID();
    else
      OverlapMinMyNodeGID = StandardNodeMap->MinMyGID() - 1;
    
    int* OverlapMyGlobalNodes = new int[OverlapNumMyNodes];
    
    for (i = 0; i < OverlapNumMyNodes; i ++)
      OverlapMyGlobalNodes[i] = OverlapMinMyNodeGID + i;
    
    OverlapNodeMap = new Epetra_Map(-1, OverlapNumMyNodes, 
				    OverlapMyGlobalNodes, 0, *Comm);
    
    delete [] OverlapMyGlobalNodes;
  } // End Overlap node map construction ********************************

  // Now create the unknowns maps from the node maps
  NumMyUnknowns = NumSpecies * NumMyNodes;
  int* StandardMyGlobalUnknowns = new int[NumMyUnknowns];
  for (int k=0; k<NumSpecies; k++) 
    for (i=0; i<NumMyNodes; i++) {
      // For now, we employ an interleave of unknowns
      StandardMyGlobalUnknowns[ NumSpecies * i + k ] = 
	NumSpecies * StandardNodeMap->GID(i) + k;
    }

  StandardMap = new Epetra_Map(-1, NumMyUnknowns, StandardMyGlobalUnknowns,
			       0, *Comm);
  delete [] StandardMyGlobalUnknowns;

  assert(StandardMap->NumGlobalElements() == NumGlobalUnknowns);

  if (NumProc == 1) {
    OverlapMap = new Epetra_Map(*StandardMap);
  } 
  else {
    int OverlapNumMyNodes = OverlapNodeMap->NumMyElements();
    int OverlapNumMyUnknowns = NumSpecies * OverlapNumMyNodes;
    int* OverlapMyGlobalUnknowns = new int[OverlapNumMyUnknowns];
    for (int k=0; k<NumSpecies; k++) 
      for (i=0; i<OverlapNumMyNodes; i++)
        OverlapMyGlobalUnknowns[ NumSpecies * i + k ] = 
                 NumSpecies * OverlapNodeMap->GID(i) + k;

    OverlapMap = new Epetra_Map(-1, OverlapNumMyUnknowns, 
                                OverlapMyGlobalUnknowns, 0, *Comm);
    delete [] OverlapMyGlobalUnknowns;

  } // End Overlap unknowns map construction ***************************

  // Construct Linear Objects  
  Importer = new Epetra_Import(*OverlapMap, *StandardMap);
  nodeImporter = new Epetra_Import(*OverlapNodeMap, *StandardNodeMap);
  initialSolution = new Epetra_Vector(*StandardMap);
  AA = new Epetra_CrsGraph(Copy, *StandardMap, 0);

  // Allocate the memory for a matrix dynamically (i.e. the graph is dynamic).
  generateGraph(*AA);

  // Create the matrix
  A = new Epetra_CrsMatrix (Copy, *AA);
  A->FillComplete();

  // Create the nodal coordinates
  xptr = new Epetra_Vector(*StandardNodeMap);
  double Length= xmax - xmin;
  dx=Length/((double) NumGlobalNodes-1);
  for (i=0; i < NumMyNodes; i++) {
    (*xptr)[i]=xmin + dx*((double) StandardNodeMap->MinMyGID()+i);
  }

  initializeSoln();
}