LCOV - code coverage report
Current view: top level - coupling/filtering - SequentialFilter.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 7 0
Test Date: 2026-08-21 15:14:06 Functions: 0.0 % 1 0

            Line data    Source code
       1              : // This file is part of the Mamico project. For conditions of distribution
       2              : // and use, please see the copyright notice in Mamico's main folder, or at
       3              : // www5.in.tum.de/mamico
       4              : 
       5              : #pragma once
       6              : #include "coupling/CouplingMDDefinitions.h"
       7              : #include "coupling/filtering/interfaces/FilterInterface.h"
       8              : #include "coupling/indexing/IndexingService.h"
       9              : #include <mpi.h>
      10              : 
      11              : #define FILTER_SEQUENTIAL true
      12              : #define FILTER_PARALLEL false
      13              : 
      14              : // #define DEBUG_SEQ_FILTER
      15              : // #define DEBUG_SEQ_FILTER_VERBOSE
      16              : 
      17              : namespace coupling {
      18              : namespace filtering {
      19              : template <unsigned int dim> class SequentialFilter;
      20              : }
      21              : } // namespace coupling
      22              : 
      23              : /*
      24              :  * Implementation of FilterInterface.h for filters which operate in a sequential
      25              :  * manner, i.e. process data on one master rank. For such filters, operator()()
      26              :  * will
      27              :  *              - contribute to one dedicated processing rank: by calling
      28              :  * contribute()
      29              :  *              - process on master rank only and then scatter data correctly:
      30              :  * by calling process()
      31              :  *
      32              :  * Meant to be used as a wrapper class, i.e. take a pointer to a filter object
      33              :  * and then sequentualizes it. Used in
      34              :  * coupling::FilterSequence<dim>::loadFiltersFromXML.
      35              :  *
      36              :  * Disclaimer: Sequential filters be added to a sequence via XML only. This
      37              :  * implies FFF with e.g. a python function is not compatible.
      38              :  *
      39              :  * @author Felix Maurer
      40              :  */
      41              : template <unsigned int dim> class coupling::filtering::SequentialFilter : public coupling::filtering::FilterInterface<dim> {
      42              : public:
      43              :   SequentialFilter(coupling::filtering::FilterInterface<dim>* filter, const MPI_Comm comm);
      44              : 
      45            0 :   ~SequentialFilter() {
      46            0 :     delete _filter;
      47            0 :     for (auto cell : _inputCells_Global)
      48            0 :       delete cell;
      49            0 :     for (auto cell : _outputCells_Global)
      50            0 :       delete cell;
      51            0 :   }
      52              : 
      53              :   /*
      54              :    * Implements FilterInterface's requirement of having a ()-operand defined.
      55              :    */
      56              :   virtual void operator()();
      57              : 
      58              : private:
      59              :   /*
      60              :    * When sequentialized, all ranks call this function.
      61              :    */
      62              :   virtual void contribute();
      63              : 
      64              :   /*
      65              :    * When sequentialized, only the processing rank calls this function. It acts
      66              :    * as a wrapper of _filter's operator() member function.
      67              :    */
      68              :   virtual void process(bool sequential);
      69              : 
      70              :   /*
      71              :    * Auxilliary functions providing an interface between low-level double
      72              :    * buffers used by MPI and Coupling Cells.
      73              :    */
      74              :   void couplingCellToBuffer(std::vector<double>& buf, const coupling::datastructures::CouplingCell<dim>* cell);
      75              : 
      76              :   void bufferToCouplingCell(const std::vector<double>& buf, coupling::datastructures::CouplingCell<dim>* cell);
      77              : 
      78              :   // The sequentialized Filter
      79              :   coupling::filtering::FilterInterface<dim>* _filter;
      80              : 
      81              :   // MPI related stuff
      82              :   const MPI_Comm _comm;
      83              :   int _commSize;
      84              :   int _processingRank;
      85              :   int _myRank;
      86              : 
      87              :   // Globalized variants of cell data structures (i.e spanning across all cells
      88              :   // of the global domain). Only the master rank uses these.
      89              :   std::vector<coupling::datastructures::CouplingCell<dim>*> _inputCells_Global;
      90              :   std::vector<coupling::datastructures::CouplingCell<dim>*> _outputCells_Global;
      91              : 
      92              :   // Used by the processing rank to remember from which rank it received cells
      93              :   // located at which global index TODO: use CellIndex?
      94              :   std::vector<unsigned int> _cellRanks;
      95              : 
      96              :   // Buffers coupling cells for MPI communication
      97              :   std::vector<double> _cellbuf;
      98              : 
      99              :   // Used by the processing rank to remember its local domain
     100              :   std::vector<coupling::datastructures::CouplingCell<dim>*> _inputCells_Local;
     101              :   std::vector<coupling::datastructures::CouplingCell<dim>*> _outputCells_Local;
     102              : };
     103              : 
     104              : #include "SequentialFilter.cpph"
        

Generated by: LCOV version 2.0-1