fmm3d_setup.cpp

Go to the documentation of this file.
00001 /* Kernel Independent Fast Multipole Method
00002    Copyright (C) 2004 Lexing Ying, New York University
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2, or (at your option)
00007 any later version.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00012 for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; see the file COPYING.  If not, write to the Free
00016 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017 02111-1307, USA.  */
00018 #include "fmm3d.hpp"
00019 
00020 using std::cerr;
00021 using std::endl;
00022 
00023 using std::istringstream;
00024 
00025 // ---------------------------------------------------------------------- 
00026 int FMM3d::setup(map<string,string>& opts)
00027 {
00028   //-----------------------------------------------------
00029   map<string,string>::iterator mi;
00030   mi = opts.find("-" + prefix() + "np"); iA(mi!=opts.end());
00031   { istringstream ss((*mi).second); ss>>_np; }
00032     
00033   //-----------------------------------------------------
00034   iA(_srcPos!=NULL && _srcNor!=NULL && _trgPos!=NULL);
00035   iA((*_srcPos).m()==dim() && (*_trgPos).m()==dim());  //nothing to do
00036   //1. _let
00037   _let = new Let3d(prefix()+"let3d_");
00038   _let->srcPos()=_srcPos;  _let->trgPos()=_trgPos;  _let->center()=_center;  _let->rootLevel()=_rootLevel;
00039   iC( _let->setup(opts) );
00040   //2. decide _eq_mm and _mul_mm, and get matmgnt based on that
00041   switch(_knl.kernelType()) {
00042          //laplace kernels
00043   case KNL_LAP_S_U: _knl_mm = Kernel3d(KNL_LAP_S_U, _knl.coefs()); break;
00044   case KNL_LAP_D_U: _knl_mm = Kernel3d(KNL_LAP_S_U, _knl.coefs()); break;
00045          //stokes kernels
00046   case KNL_STK_S_U: _knl_mm = Kernel3d(KNL_STK_F_U, _knl.coefs()); break;
00047   case KNL_STK_S_P: _knl_mm = Kernel3d(KNL_LAP_S_U, vector<double>()); break;
00048   case KNL_STK_D_U: _knl_mm = Kernel3d(KNL_STK_F_U, _knl.coefs()); break;
00049   case KNL_STK_D_P: _knl_mm = Kernel3d(KNL_LAP_S_U, vector<double>()); break;
00050          //navier kernels
00051   case KNL_NAV_S_U: _knl_mm = Kernel3d(KNL_NAV_S_U, _knl.coefs()); break;
00052   case KNL_NAV_D_U: _knl_mm = Kernel3d(KNL_NAV_S_U, _knl.coefs()); break;
00053          //others
00054   case KNL_SQRTLAP: _knl_mm = Kernel3d(KNL_SQRTLAP, _knl.coefs()); break;
00055   case KNL_EXP    : _knl_mm = Kernel3d(KNL_EXP    , _knl.coefs()); break;
00056   default: iA(0);
00057   }
00058   _mul_mm = 1; //for the time being
00059   
00060   _matmgnt  = MatMgnt3d::getmmptr(_knl_mm, _np);
00061   //3. self setup
00062   iC( srcData() );
00063   iC( trgData() );
00064   //-----------------------------------------------------
00065   return (0);
00066 }
00067 // ---------------------------------------------------------------------- 
00068 int FMM3d::srcData()
00069 {
00070   //1. create vecs
00071   int srcNodeCnt = _let->srcNodeCnt();
00072   int srcExaCnt = _let->srcExaCnt();
00073   _srcExaPos.resize(dim(), srcExaCnt);
00074   _srcExaNor.resize(dim(), srcExaCnt);
00075   _srcExaDen.resize(srcExaCnt * srcDOF());
00076   _srcUpwEquDen.resize(srcNodeCnt * datSze(UE));
00077   _srcUpwChkVal.resize(srcNodeCnt * datSze(UC));
00078   
00079   //2. gather the Position using the Pos scatter
00080   vector<int> ordVec;  iC( _let->upwOrderCollect(ordVec) );
00081   for(int i=0; i<ordVec.size(); i++) {
00082          int gNodeIdx = ordVec[i];
00083          if(_let->tag(gNodeIdx) & LET_SRCNODE) { //contributor
00084                 if(_let->terminal(gNodeIdx)==true) { //terminal cbtr
00085                   DblNumMat srcExaPos(this->srcExaPos(gNodeIdx));
00086                   DblNumMat srcExaNor(this->srcExaNor(gNodeIdx));
00087                   vector<int>& curVecIdxs = _let->node(gNodeIdx).srcOwnVecIdxs();
00088                   for(int k=0; k < curVecIdxs.size(); k++) {
00089                          int poff = curVecIdxs[k];
00090                          for(int d=0; d < dim(); d++) {
00091                                 srcExaPos(d,k) = (*_srcPos)(d,poff);//Pos
00092                                 srcExaNor(d,k) = (*_srcNor)(d,poff);//Nor
00093                          }
00094                   }
00095                 }
00096          }
00097   }
00098   return (0);
00099 }
00100 // ---------------------------------------------------------------------- 
00101 int FMM3d::trgData()
00102 {
00103   //1. create vecs
00104   int trgNodeCnt = _let->trgNodeCnt();
00105   int trgExaCnt = _let->trgExaCnt();
00106   _trgExaPos.resize(dim(), trgExaCnt);
00107   _trgExaVal.resize(trgExaCnt * trgDOF());
00108   _trgDwnEquDen.resize(trgNodeCnt * datSze(DE));
00109   _trgDwnChkVal.resize(trgNodeCnt * datSze(DC));
00110   
00111   //2. gather data from _trgPos
00112   vector<int> ordVec; iC( _let->upwOrderCollect(ordVec) );
00113   for(int i=0; i<ordVec.size(); i++) {
00114          int gNodeIdx = ordVec[i];
00115          if(_let->tag(gNodeIdx) & LET_TRGNODE) {
00116                 if(_let->terminal(gNodeIdx)==true) {
00117                   DblNumMat trgExaPos(this->trgExaPos(gNodeIdx));
00118                   vector<int>& curVecIdxs = _let->node(gNodeIdx).trgOwnVecIdxs();
00119                   for(int k=0; k<curVecIdxs.size(); k++) {
00120                          int poff = curVecIdxs[k];
00121                          for(int d=0; d<dim(); d++)
00122                                 trgExaPos(d,k) = (*_trgPos)(d, poff);
00123                   }
00124                 }
00125          }
00126   }
00127   
00128   //3. allocate ENExt
00129   _nodeVec.resize( _let->nodeVec().size() );
00130   for(int i=0; i<ordVec.size(); i++) {
00131          int gNodeIdx = ordVec[i];
00132          if(_let->tag(gNodeIdx) & LET_TRGNODE) {
00133                 //V
00134                 Let3d::Node& gg = _let->node(gNodeIdx);
00135                 _nodeVec[gNodeIdx].VinNum() = gg.Vnodes().size();
00136                 for(vector<int>::iterator vi=gg.Vnodes().begin(); vi!=gg.Vnodes().end(); vi++) {
00137                   _nodeVec[*vi].VotNum() ++;
00138                 }
00139          }
00140   }
00141   
00142   return (0);
00143 }

Generated on Sun Dec 4 19:24:39 2005 for fmm3d by  doxygen 1.4.5