FEApp_CZeroDiscretization.cpp

Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 #include "Epetra_Export.h"
00032 
00033 #include "FEApp_CZeroDiscretization.hpp"
00034 
00035 FEApp::CZeroDiscretization::CZeroDiscretization(
00036       const std::vector<double>& coords,
00037       unsigned int num_equations,
00038       const Teuchos::RCP<const Epetra_Comm>& epetra_comm,
00039       const Teuchos::RCP<Teuchos::ParameterList>& params) :
00040   x(coords),
00041   comm(epetra_comm),
00042   elemFactory(Teuchos::rcp(&(params->sublist("Element")),false)),
00043   mesh(),
00044   elem_map(),
00045   map(),
00046   overlap_map(),
00047   graph(),
00048   overlap_graph(),
00049   myPID(comm->MyPID()),
00050   numMyElements(0),
00051   nodes_per_element(0),
00052   neq(num_equations)
00053 {
00054   // Distribute the elements equally among processors
00055   elem_map = Teuchos::rcp(new Epetra_Map(x.size()-1, 0, *comm));
00056   numMyElements = elem_map->NumMyElements();
00057 
00058   Teuchos::RCP<AbstractElement> base_element = 
00059     elemFactory.create();
00060   nodes_per_element = base_element->numNodes();
00061 }
00062 
00063 FEApp::CZeroDiscretization::~CZeroDiscretization()
00064 {
00065 }
00066 
00067 void
00068 FEApp::CZeroDiscretization::createMesh()
00069 {
00070   mesh = Teuchos::rcp(new FEApp::Mesh);
00071 
00072   // Create elements and node IDs
00073   Teuchos::RCP<FEApp::AbstractElement> e;
00074   unsigned int elem_GID;
00075   for (unsigned int i=0; i<numMyElements; i++) {
00076     elem_GID = elem_map->GID(i);
00077     e = elemFactory.create();
00078     e->createNodes(x[elem_GID], x[elem_GID+1], elem_GID*(nodes_per_element-1));
00079     mesh->addElement(e);
00080   }
00081 }
00082 
00083 void
00084 FEApp::CZeroDiscretization::createMaps()
00085 {
00086   // Create overlap DOF map
00087   unsigned int overlapNumMyNodes = numMyElements*(nodes_per_element-1) + 1;
00088   unsigned int overlapNumMyDOF = overlapNumMyNodes*neq;
00089   unsigned int overlap_dof_GID_base = 
00090     elem_map->MinMyGID()*(nodes_per_element-1)*neq;
00091   std::vector<int> overlap_dof_GID(overlapNumMyDOF);
00092   for (unsigned int i=0; i<overlapNumMyDOF; i++)
00093     overlap_dof_GID[i] = overlap_dof_GID_base + i;
00094   overlap_map = 
00095     Teuchos::rcp(new Epetra_Map(-1, overlapNumMyDOF, &(overlap_dof_GID[0]), 
00096                                 0, *comm));
00097   
00098   // Create non-overlap DOF map
00099   if (myPID == 0) {
00100     int numMyDOF = overlapNumMyNodes*neq;
00101     map = 
00102       Teuchos::rcp(new Epetra_Map(-1, numMyDOF, &(overlap_dof_GID[0]), 
00103                                   0, *comm));
00104   }
00105   else {
00106     int numMyDOF = (overlapNumMyNodes - 1)*neq;
00107     map = 
00108       Teuchos::rcp(new Epetra_Map(-1, numMyDOF, &(overlap_dof_GID[neq]), 
00109                                   0, *comm));
00110   }
00111 }
00112 
00113 void
00114 FEApp::CZeroDiscretization::createJacobianGraphs()
00115 {
00116   // Generate matrix graphs
00117   graph = 
00118     Teuchos::rcp(new Epetra_CrsGraph(Copy, *map, neq*nodes_per_element, 
00119                                      false));
00120   overlap_graph = 
00121     Teuchos::rcp(new Epetra_CrsGraph(Copy, *overlap_map, 
00122                                      neq*nodes_per_element, false));
00123   int row, col;
00124   
00125   // Loop over elements
00126   Teuchos::RCP<FEApp::AbstractElement> e;
00127   for (FEApp::Mesh::iterator eit=mesh->begin(); eit!=mesh->end(); ++eit) {
00128     e = *eit;
00129 
00130     // Loop over nodes in element
00131     for (unsigned int node_row=0; node_row<nodes_per_element; node_row++) {
00132 
00133       // Loop over equations per node
00134       for (unsigned int eq_row=0; eq_row<neq; eq_row++) {
00135 
00136         // Matrix row
00137         row = static_cast<int>(e->nodeGID(node_row)*neq + eq_row);
00138 
00139         // Loop over nodes in element
00140         for (unsigned int node_col=0; node_col<nodes_per_element; 
00141              node_col++){
00142           
00143           // Loop over equations per node
00144           for (unsigned int eq_col=0; eq_col<neq; eq_col++) {
00145             
00146             // Matrix column
00147             col = static_cast<int>(e->nodeGID(node_col)*neq + eq_col);
00148             
00149             // Add column indices
00150             overlap_graph->InsertGlobalIndices(row, 1, &col);
00151             
00152           } // column equations
00153           
00154         } // column nodes
00155         
00156       } // row equations
00157       
00158     } // row node
00159     
00160   } // element
00161   
00162   overlap_graph->FillComplete();
00163   
00164   Epetra_Export exporter(*overlap_map, *map);
00165   graph->Export(*overlap_graph, exporter, Insert);
00166   graph->FillComplete();
00167 }
00168       
00169 Teuchos::RCP<const FEApp::Mesh>
00170 FEApp::CZeroDiscretization::getMesh() const
00171 {
00172   return mesh;
00173 }
00174 
00175 Teuchos::RCP<const Epetra_Map>
00176 FEApp::CZeroDiscretization::getMap() const
00177 {
00178   return map;
00179 }
00180 
00181 Teuchos::RCP<const Epetra_Map>
00182 FEApp::CZeroDiscretization::getOverlapMap() const
00183 {
00184   return overlap_map;
00185 }
00186 
00187 Teuchos::RCP<const Epetra_CrsGraph>
00188 FEApp::CZeroDiscretization::getJacobianGraph() const
00189 {
00190   return graph;
00191 }
00192 
00193 Teuchos::RCP<const Epetra_CrsGraph>
00194 FEApp::CZeroDiscretization::getOverlapJacobianGraph() const
00195 {
00196   return overlap_graph;
00197 }
00198 
00199 int
00200 FEApp::CZeroDiscretization::getNumNodesPerElement() const
00201 {
00202   return nodes_per_element;
00203 }

Generated on Wed May 12 21:39:32 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7