source: XIOS/dev/dev_trunk_omp/src/filter/spatial_transform_filter.hpp @ 1601

Last change on this file since 1601 was 1601, checked in by yushan, 5 years ago

branch_openmp merged with trunk r1597

File size: 5.6 KB
Line 
1#ifndef __XIOS_CSpatialTransformFilter__
2#define __XIOS_CSpatialTransformFilter__
3
4#include "filter.hpp"
5
6namespace xios
7{
8  class CGrid;
9  class CGridTransformation;
10  class CSpatialTransformFilterEngine;
11
12  /*!
13   * A generic filter with multiple input slots wrapping any type of spatial transformations.
14   */
15  class CSpatialTransformFilter : public CFilter
16  {
17    public:
18      /*!
19       * Constructs a filter wrapping the specified spatial transformation.
20       *
21       * \param gc the associated garbage collector
22       * \param engine the engine defining the spatial transformation
23       * \param outputValue default value of output pin
24       * \param [in] inputSlotsCount number of input, by default there is only one for field src
25       */
26      CSpatialTransformFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine, double outputValue, size_t inputSlotsCount = 1);
27
28      /*!
29       * Builds the filter graph needed to transform the specified source grid into the specified destination grid.
30       *
31       * \param gc the associated garbage collector
32       * \param srcGrid the source grid
33       * \param destGrid the destination grid
34       * \param hasMissingValue whether field source has missing value
35       * \param defaultValue default value
36       * \return the first and the last filters of the filter graph
37       */
38      static std::pair<std::shared_ptr<CSpatialTransformFilter>, std::shared_ptr<CSpatialTransformFilter> >
39      buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, bool hasMissingValue, double defaultValue);
40
41    protected:
42      /*!
43        Overriding this function to process transformations with auxillary inputs
44      */
45      void virtual onInputReady(std::vector<CDataPacketPtr> data);
46
47    protected:
48      //! Default value of output pin
49      double outputDefaultValue;
50  }; // class CSpatialTransformFilter
51
52
53 /*!
54   * A specific spatial filter for the temporal_splitting transformation scalar -> axis. An incoming flux will be stored in an aditional dimension given by the destination axis.
55   * At each flux received, the storing index (record) is increased. When it reach the size of the axis (nrecords) a new flux is generated and the record is reset to 0
56   */
57
58 class CSpatialTemporalFilter : public CSpatialTransformFilter
59  {
60    public:
61      /*!
62       * Constructs a filter wrapping the specified spatial transformation.
63       *
64       * \param gc the associated garbage collector
65       * \param engine the engine defining the spatial transformation
66       * \param [in] gridTransformation the associated transformations
67       * \param outputValue default value of output pin
68       * \param [in] inputSlotsCount number of input, by default there is only one for field src
69       */
70      CSpatialTemporalFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine, CGridTransformation* gridTransformation, double outputValue, size_t inputSlotsCount = 1);
71
72
73    protected:
74      /*!
75        Overriding this function to process transformations with auxillary inputs
76      */
77      void virtual onInputReady(std::vector<CDataPacketPtr> data);
78      //! Current record in the filter
79      int record ;
80      //! Maximum number of records
81      int nrecords;
82      //! Temporary storage for output flux
83      CArray<double, 1> tmpData; 
84
85
86  }; // class CSpatialTemporalFilter
87
88
89  /*!
90   * A generic filter engine wrapping a grid transformation.
91   */
92  class CSpatialTransformFilterEngine : public IFilterEngine
93  {
94    public:
95      /*!
96       * Returns the engine wrapping the specified grid transformation.
97       * If the engine already exists it is reused, otherwise it is created.
98       *
99       * \param gridTransformation the grid transformation the engine will use
100       * \return the engine wrapping the specified grid transformation
101       */
102      static CSpatialTransformFilterEngine* get(CGridTransformation* gridTransformation);
103
104      /*!
105       * Applies the grid transformation to the input data and returns the result.
106       *
107       * \param data a vector of packets corresponding to each slot (one in this case)
108       * \param [in] defaultValue default value of output data
109       * \return the result of the grid transformation
110       */
111      CDataPacketPtr applyFilter(std::vector<CDataPacketPtr> data, double defaultValue = 0);
112
113       /*!
114       * Applies the grid transformation to the input data and returns the result.
115       *
116       * \param data a vector of packets corresponding to each slot (one in this case)
117       * \return the result of the grid transformation
118       */
119      CDataPacketPtr virtual apply(std::vector<CDataPacketPtr> data);
120
121
122
123    protected:
124      /*!
125       * Constructs a filter engine wrapping the specified grid transformation.
126       *
127       * \param gridTransformation the grid transformation the engine will use
128       */
129      CSpatialTransformFilterEngine(CGridTransformation* gridTransformation);
130
131      /*!
132       * Applies the grid transformation to the input data and returns the result.
133       * This helper function handles all the communications.
134       *
135       * \param dataSrc the source data
136       * \param dataDest the resulting transformed data
137       */
138      void apply(const CArray<double, 1>& dataSrc, CArray<double,1>& dataDest);
139
140      CGridTransformation* gridTransformation; //!< The grid transformation used by the engine
141
142      //! The allocated engines
143
144      static std::map<CGridTransformation*, std::shared_ptr<CSpatialTransformFilterEngine> > *engines_ptr;
145      #pragma omp threadprivate(engines_ptr)
146  }; // class CSpatialTransformFilterEngine
147} // namespace xios
148
149#endif //__XIOS_CSpatialTransformFilter__
Note: See TracBrowser for help on using the repository browser.