FEI Version of the Day
test_EqnCommMgr.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 #include <fei_macros.hpp>
00044 
00045 #include <test_utils/test_EqnCommMgr.hpp>
00046 #include <fei_CommUtils.hpp>
00047 #include <fei_defs.h>
00048 
00049 #include <fei_ProcEqns.hpp>
00050 #include <fei_EqnBuffer.hpp>
00051 #include <fei_EqnCommMgr.hpp>
00052 
00053 #undef fei_file
00054 #define fei_file "test_EqnCommMgr.cpp"
00055 #include <fei_ErrMacros.hpp>
00056 
00057 test_EqnCommMgr::test_EqnCommMgr(MPI_Comm comm)
00058  : tester(comm)
00059 {
00060 }
00061 
00062 test_EqnCommMgr::~test_EqnCommMgr()
00063 {
00064 }
00065 
00066 int test_EqnCommMgr::runtests()
00067 {
00068   CHK_ERR( test1() );
00069   CHK_ERR( test2() );
00070   CHK_ERR( test3() );
00071   CHK_ERR( test4() );
00072   return(0);
00073 }
00074 
00075 int test_EqnCommMgr::test1()
00076 {
00077   EqnCommMgr* eqnCommMgr = new EqnCommMgr(comm_);
00078 
00079   int numProcs = fei::numProcs(comm_);
00080   int localProc = fei::localProc(comm_);
00081 
00082 //  int numGlobalEqns = numProcs*5;
00083   int numLocalEqns = 5;
00084   int firstLocalEqn = localProc*numLocalEqns;
00085 //  int lastLocalEqn = (localProc+1)*numLocalEqns - 1;
00086 
00087   if (numProcs > 1) {
00088     for(int p=0; p<numProcs; p++) {
00089       if (p == localProc) continue;
00090 
00091       for(int i=0; i<numLocalEqns; i++) {
00092   if (p != 2) eqnCommMgr->addLocalEqn(firstLocalEqn+i, p);
00093       }
00094     }
00095   }
00096 
00097   eqnCommMgr->setNumRHSs(1);
00098 
00099   int p;
00100   for(p=0; p<numProcs; p++) {
00101     if (p == localProc) continue;
00102 
00103     for(int i=0; i<numLocalEqns; i++) {
00104       int eqn = p*numLocalEqns + i;
00105 
00106       eqnCommMgr->addRemoteIndices(eqn, p, &eqn, 1);
00107     }
00108   }
00109 
00110   CHK_ERR( eqnCommMgr->exchangeIndices() );
00111 
00112   double zero = 0.0;
00113   for(p=0; p<numProcs; p++) {
00114     if (p == localProc) continue;
00115 
00116     for(int i=0; i<numLocalEqns; i++) {
00117       int eqn = p*numLocalEqns + i;
00118 
00119       eqnCommMgr->addSolnValues(&eqn, &zero, 1);
00120     }
00121   }
00122 
00123   EqnCommMgr* eCopy = eqnCommMgr->deepCopy();
00124 
00125   std::vector<int>& localEqns = eqnCommMgr->localEqnNumbers();
00126   std::vector<int>& localEqnsCopy = eCopy->localEqnNumbers();
00127 
00128   if (localEqns != localEqnsCopy) {
00129     ERReturn(-1);
00130   }
00131 
00132   eqnCommMgr->exchangeSoln();
00133 
00134   eqnCommMgr->resetCoefs();
00135 
00136   delete eqnCommMgr;
00137   delete eCopy;
00138 
00139   return(0);
00140 }
00141 
00142 int test_EqnCommMgr::test2()
00143 {
00144   FEI_COUT << "testing ProcEqns...";
00145 
00146   ProcEqns procEqns;
00147 
00148   procEqns.addEqn(0, localProc_);
00149   procEqns.addEqn(1, localProc_);
00150   procEqns.addEqn(2, localProc_);
00151 
00152   procEqns.addEqn(3, 2, localProc_+1);
00153   procEqns.addEqn(4, 2, localProc_+1);
00154   procEqns.addEqn(5, 2, localProc_+1);
00155 
00156   ProcEqns* pCopy = procEqns.deepCopy();
00157 
00158   std::vector<int>& eqnsPerProc = procEqns.eqnsPerProcPtr();
00159   std::vector<int>& eqnsPerProcCopy = pCopy->eqnsPerProcPtr();
00160 
00161   if (eqnsPerProc != eqnsPerProcCopy) {
00162     ERReturn(-1);
00163   }
00164 
00165   delete pCopy;
00166 
00167   FEI_COUT << FEI_ENDL;
00168   return(0);
00169 }
00170 
00171 int test_EqnCommMgr::test3()
00172 {
00173   return(0);
00174 }
00175 
00176 int test_EqnCommMgr::test4()
00177 {
00178   return(0);
00179 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends