Back to index

salome-med  6.5.0
InterpKernelDEC.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include <mpi.h>
00021 #include "CommInterface.hxx"
00022 #include "Topology.hxx"
00023 #include "BlockTopology.hxx"
00024 #include "ComponentTopology.hxx"
00025 #include "ParaFIELD.hxx"
00026 #include "MPIProcessorGroup.hxx"
00027 #include "ParaMESH.hxx"
00028 #include "DEC.hxx"
00029 #include "InterpolationMatrix.hxx"
00030 #include "InterpKernelDEC.hxx"
00031 #include "ElementLocator.hxx"
00032 
00033 namespace ParaMEDMEM
00034 {  
00035 
00107   InterpKernelDEC::InterpKernelDEC():_interpolation_matrix(0)
00108   {  
00109   }
00110 
00120   InterpKernelDEC::InterpKernelDEC(ProcessorGroup& source_group, ProcessorGroup& target_group):
00121     DisjointDEC(source_group, target_group),_interpolation_matrix(0)
00122   {
00123 
00124   }
00125 
00126   InterpKernelDEC::InterpKernelDEC(const std::set<int>& src_ids, const std::set<int>& trg_ids,
00127                                    const MPI_Comm& world_comm):DisjointDEC(src_ids,trg_ids,world_comm),
00128                                                                _interpolation_matrix(0)
00129   {
00130   }
00131 
00132   InterpKernelDEC::~InterpKernelDEC()
00133   {
00134     if (_interpolation_matrix !=0)
00135       delete _interpolation_matrix;
00136   } 
00137 
00150   void InterpKernelDEC::synchronize()
00151   {
00152     if(!isInUnion())
00153       return ;
00154     delete _interpolation_matrix;
00155     _interpolation_matrix = new InterpolationMatrix (_local_field, *_source_group,*_target_group,*this,*this); 
00156 
00157     //setting up the communication DEC on both sides  
00158     if (_source_group->containsMyRank())
00159       {
00160         //locate the distant meshes
00161         ElementLocator locator(*_local_field, *_target_group, *_source_group);
00162         //transfering option from InterpKernelDEC to ElementLocator   
00163         locator.copyOptions(*this);
00164         MEDCouplingPointSet* distant_mesh=0; 
00165         int* distant_ids=0;
00166         std::string distantMeth;
00167         for (int i=0; i<_target_group->size(); i++)
00168           {
00169             //        int idistant_proc = (i+_source_group->myRank())%_target_group->size();
00170             int idistant_proc=i;
00171 
00172             //gathers pieces of the target meshes that can intersect the local mesh
00173             locator.exchangeMesh(idistant_proc,distant_mesh,distant_ids);
00174             if (distant_mesh !=0)
00175               {
00176                 locator.exchangeMethod(_method,idistant_proc,distantMeth);
00177                 //adds the contribution of the distant mesh on the local one
00178                 int idistant_proc_in_union=_union_group->translateRank(_target_group,idistant_proc);
00179                 std::cout <<"add contribution from proc "<<idistant_proc_in_union<<" to proc "<<_union_group->myRank()<<std::endl;
00180                 _interpolation_matrix->addContribution(*distant_mesh,idistant_proc_in_union,distant_ids,_method,distantMeth);
00181                 distant_mesh->decrRef();
00182                 delete [] distant_ids;
00183                 distant_mesh=0;
00184                 distant_ids=0;
00185               }
00186           }
00187        _interpolation_matrix->finishContributionW(locator);
00188       }
00189 
00190     if (_target_group->containsMyRank())
00191       {
00192         ElementLocator locator(*_local_field, *_source_group, *_target_group);
00193         //transfering option from InterpKernelDEC to ElementLocator
00194         locator.copyOptions(*this);
00195         MEDCouplingPointSet* distant_mesh=0;
00196         int* distant_ids=0;
00197         for (int i=0; i<_source_group->size(); i++)
00198           {
00199             //        int idistant_proc = (i+_target_group->myRank())%_source_group->size();
00200             int  idistant_proc=i;
00201             //gathers pieces of the target meshes that can intersect the local mesh
00202             locator.exchangeMesh(idistant_proc,distant_mesh,distant_ids);
00203             std::cout << " Data sent from "<<_union_group->myRank()<<" to source proc "<< idistant_proc<<std::endl;
00204             if (distant_mesh!=0)
00205               {
00206                 std::string distantMeth;
00207                 locator.exchangeMethod(_method,idistant_proc,distantMeth);
00208                 distant_mesh->decrRef();
00209                 delete [] distant_ids;
00210                 distant_mesh=0;
00211                 distant_ids=0;
00212               }
00213           }
00214         _interpolation_matrix->finishContributionL(locator);
00215       }
00216     _interpolation_matrix->prepare();
00217   }
00218 
00219 
00223   void InterpKernelDEC::recvData()
00224   {
00225     if (_source_group->containsMyRank())
00226       _interpolation_matrix->transposeMultiply(*_local_field->getField());
00227     else if (_target_group->containsMyRank())
00228       {
00229         _interpolation_matrix->multiply(*_local_field->getField());
00230         if (getForcedRenormalization())
00231           renormalizeTargetField(getMeasureAbsStatus());
00232       }
00233   }
00234 
00235 
00241   void InterpKernelDEC::recvData( double time )
00242   {
00243     _interpolation_matrix->getAccessDEC()->setTime(time);
00244     recvData() ;
00245   }
00246 
00251   void InterpKernelDEC::sendData()
00252   {
00253     if (_source_group->containsMyRank())
00254       {
00255     
00256         _interpolation_matrix->multiply(*_local_field->getField());
00257         if (getForcedRenormalization())
00258           renormalizeTargetField(getMeasureAbsStatus());
00259     
00260       }
00261     else if (_target_group->containsMyRank())
00262       _interpolation_matrix->transposeMultiply(*_local_field->getField());
00263   }
00264 
00270   void InterpKernelDEC::sendData( double time , double deltatime )
00271   {
00272     _interpolation_matrix->getAccessDEC()->setTime(time,deltatime);
00273     sendData() ;
00274   }
00275 
00280 }