FEI Version of the Day
fei_Aztec_Map.cpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 
00044 #include <fei_trilinos_macros.hpp>
00045 #include <fei_iostream.hpp>
00046 
00047 #ifdef HAVE_FEI_AZTECOO
00048 
00049 #include <cstdlib>
00050 
00051 #include <fei_mpi.h>
00052 
00053 #ifndef FEI_SER
00054 
00055 #define AZTEC_MPI AZTEC_MPI
00056 #define AZ_MPI AZ_MPI
00057 #ifndef MPI
00058 #define MPI MPI
00059 #endif
00060 
00061 #endif
00062 
00063 #include <az_aztec.h>
00064 #include <fei_Aztec_Map.hpp>
00065 
00066 namespace fei_trilinos {
00067 
00068 //==============================================================================
00069 Aztec_Map::Aztec_Map(int globalSz, int N_update, const int* update,
00070                      int localOffs, MPI_Comm comm)
00071  :
00072     proc_config(AZ_PROC_SIZE),
00073     update(update, update+N_update),
00074     external(NULL),
00075     update_index(NULL),
00076     extern_index(NULL),
00077     data_org(NULL),
00078     orderingUpdate(),
00079     az_transformed(false),
00080     globalSize_(globalSz),
00081     localSize_(N_update),
00082     localOffset_(localOffs),
00083     N_update_(N_update),
00084     comm_(comm)
00085 {
00086     checkInput();
00087     AZ_set_proc_config(&proc_config[0], comm_);
00088 }
00089  
00090 //==============================================================================
00091 Aztec_Map::Aztec_Map(const Aztec_Map& map) :
00092     proc_config(AZ_PROC_SIZE),
00093     update(map.update),
00094     external(NULL),
00095     update_index(NULL),
00096     extern_index(NULL),
00097     data_org(NULL),
00098     orderingUpdate(map.orderingUpdate),
00099     az_transformed(map.az_transformed),
00100     globalSize_(map.globalSize_),
00101     localSize_(map.localSize_),
00102     localOffset_(map.localOffset_),
00103     N_update_(map.localSize_),
00104     comm_(map.comm_)
00105 {
00106     AZ_processor_info(&proc_config[0]);
00107     update_index = (int*)AZ_allocate(N_update_*sizeof(int));
00108     for(int i=0; i<N_update_; ++i) {
00109       update_index[i] = map.update_index[i];
00110     }
00111     external = (int*)AZ_allocate(data_org[AZ_N_external]*sizeof(int));
00112     extern_index = (int*)AZ_allocate(data_org[AZ_N_external]*sizeof(int));
00113     for(int i=0; i<data_org[AZ_N_external]; ++i) {
00114       external[i] = map.external[i];
00115       extern_index[i] = map.extern_index[i];
00116     }
00117 }
00118 
00119 //==============================================================================
00120 Aztec_Map::~Aztec_Map()
00121 {
00122   globalSize_ = 0;
00123   localSize_ = 0;
00124   localOffset_ = 0;
00125 
00126   std::free(update_index);
00127   std::free(external);
00128   std::free(extern_index);
00129   std::free(data_org);
00130 }
00131 
00132 //==============================================================================
00133 void Aztec_Map::checkInput() {
00134 
00135     if (globalSize_ <= 0) {
00136         throw std::runtime_error("Aztec_Map: ERROR, globalSize <= 0.");
00137     }
00138 
00139     if (localSize_ < 0) {
00140         throw std::runtime_error("Aztec_Map: ERROR, localSize negative.");
00141     }
00142 
00143     if (localOffset_ < 0) {
00144         throw std::runtime_error("Aztec_Map: ERROR, localOffset negative.");
00145     }
00146 }
00147 
00148 }//namespace fei_trilinos
00149 
00150 #endif
00151 //HAVE_FEI_AZTECOO
00152 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends