LCOV - code coverage report
Current view: top level - ugbase/pcl - pcl_layout_util.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 6 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2012-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__PCL__pcl_layout_util__
      34              : #define __H__PCL__pcl_layout_util__
      35              : 
      36              : #include <vector>
      37              : #include "common/util/hash.h"
      38              : #include "pcl_communication_structs.h"
      39              : 
      40              : 
      41              : namespace pcl{
      42              : 
      43              : /// \addtogroup pcl
      44              : /// \{
      45              : 
      46              : ///     removes all empty interfaces from the given layout.
      47              : template <class TLayout>
      48            0 : void RemoveEmptyInterfaces(TLayout& layout)
      49              : {
      50              :         typedef typename TLayout::iterator TInterfaceIter;
      51              :         typedef typename TLayout::Interface TInterface;
      52              : 
      53            0 :         for(size_t lvl = 0; lvl < layout.num_levels(); ++lvl){
      54            0 :                 for(TInterfaceIter iter = layout.begin(lvl); iter != layout.end(lvl);)
      55              :                 {
      56              :                         TInterface& intfc = layout.interface(iter);
      57            0 :                         if(intfc.empty())
      58            0 :                                 iter = layout.erase(iter, lvl);
      59              :                         else
      60              :                                 ++iter;
      61              :                 }
      62              :         }
      63            0 : }
      64              : 
      65              : ////////////////////////////////////////////////////////////////////////
      66              : ///     collects the ids of all processes to which interfaces exist.
      67              : /**
      68              :  * Fills a vector with the process-ids, to which interfaces exist in
      69              :  * the given layout.
      70              :  *
      71              :  * TLayout has to be compatible with pcl::Layout or pcl::MultiLevelLayout.
      72              :  *
      73              :  * \returns the number of associated processes.
      74              :  */
      75              : template <class TLayout>
      76              : size_t CollectAssociatedProcesses(std::vector<int>& procIDsOut,
      77              :                                                                   TLayout& layout)
      78              : {
      79              :         procIDsOut.clear();
      80              : 
      81              : //      iterate through the levels of the layout
      82              :         for(size_t i = 0; i < layout.num_levels(); ++i){
      83              :         //      iterate through the interfaces on that level
      84              :                 for(typename TLayout::iterator iIter = layout.begin(i);
      85              :                         iIter != layout.end(i); ++iIter)
      86              :                 {
      87              :                         int procID = layout.proc_id(iIter);
      88              :                 //      check whether the process is already contained in procIDsOut
      89              :                         if(i > 0){
      90              :                                 if(find(procIDsOut.begin(), procIDsOut.end(), procID)
      91              :                                    == procIDsOut.end())
      92              :                                 {
      93              :                                 //      the entry has not yet been added
      94              :                                         procIDsOut.push_back(procID);
      95              :                                 }
      96              :                         }
      97              :                         else{
      98              :                         //      on level 0 each process exists only once
      99              :                                 procIDsOut.push_back(procID);
     100              :                         }
     101              :                 }
     102              :         }
     103              : 
     104              :         return procIDsOut.size();
     105              : }
     106              : 
     107              : ///     writes all elements in the interfaces into the vector.
     108              : /**
     109              :  * This function extracts all elements from a layout and stores them into
     110              :  * a std::vector. Doubles may occur and are not removed. The container is
     111              :  * clear as default, before extracting.
     112              :  */
     113              : template <class TLayout>
     114              : void CollectElements(std::vector<typename TLayout::Element>& elemsOut,
     115              :                                         TLayout& layout,
     116              :                                         bool clearContainer = true)
     117              : {
     118              :         typedef typename TLayout::Interface Interface;
     119              : 
     120              : //      clear the return value
     121              :         if(clearContainer) elemsOut.clear();
     122              : 
     123              : //      iterate over all interfaces
     124              :         for(size_t lvl = 0; lvl < layout.num_levels(); ++lvl){
     125              :                 for(typename TLayout::const_iterator interfaceIter = layout.begin(lvl);
     126              :                         interfaceIter != layout.end(lvl); ++interfaceIter)
     127              :                 {
     128              :                 //      iterate over the entries of the interface
     129              :                         const Interface& interface = layout.interface(interfaceIter);
     130              :                         for(typename Interface::const_iterator iter = interface.begin();
     131              :                                 iter != interface.end(); ++iter)
     132              :                         {
     133              :                         //      add elem to vector
     134              :                                 elemsOut.push_back(interface.get_element(iter));
     135              :                         }
     136              :                 }
     137              :         }
     138              : }
     139              : 
     140              : ///     writes all elements in the interfaces into the resulting vector. avoids doubles.
     141              : template <class TLayout>
     142              : void CollectUniqueElements(std::vector<typename TLayout::Element>& elemsOut,
     143              :                                                    const TLayout& layout)
     144              : {
     145              :         typedef typename TLayout::Interface Interface;
     146              :         typedef typename TLayout::Element TElem;
     147              : 
     148              : //      clear the return value
     149              :         elemsOut.clear();
     150              : 
     151              : //      we'll use a hash to make sure that each element only exists once
     152              :         ug::Hash<TElem, int> hash(layout.num_interface_elements());
     153              :         hash.reserve(layout.num_interface_elements());
     154              : 
     155              : //      iterate over all interfaces
     156              :         for(size_t lvl = 0; lvl < layout.num_levels(); ++lvl){
     157              :                 for(typename TLayout::const_iterator interfaceIter = layout.begin(lvl);
     158              :                         interfaceIter != layout.end(lvl); ++interfaceIter)
     159              :                 {
     160              :                 //      iterate over the entries of the interface
     161              :                         const Interface& interface = layout.interface(interfaceIter);
     162              :                         for(typename Interface::const_iterator iter = interface.begin();
     163              :                                 iter != interface.end(); ++iter)
     164              :                         {
     165              :                         //      check whether the entry already exists in the hash
     166              :                                 if(!hash.has_entry(interface.get_element(iter))){
     167              :                                 //      we don't care about the value
     168              :                                         hash.insert(interface.get_element(iter), 0);
     169              :                                         elemsOut.push_back(interface.get_element(iter));
     170              :                                 }
     171              :                         }
     172              :                 }
     173              :         }
     174              : }
     175              : 
     176              : // end group pcl
     177              : /// \}
     178              : 
     179              : }// end of namespace
     180              : 
     181              : #endif
        

Generated by: LCOV version 2.0-1