source: XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/model_to_client_source_filter.cpp @ 2143

Last change on this file since 2143 was 2143, checked in by yushan, 3 years ago

Big commit on graph functionality. Add buildWorkflowGraph function for filters

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#include "model_to_client_source_filter.hpp"
2#include "grid.hpp"
3#include "exception.hpp"
4#include "calendar_util.hpp"
5#include <limits>
6#include "workflow_graph.hpp"
7
8namespace xios
9{
10  CModelToClientSourceFilter::CModelToClientSourceFilter(CGarbageCollector& gc, CGrid* grid, bool hasMissingValue, double defaultValue)
11    : COutputPin(gc)
12    , grid_(grid)
13    , hasMissingValue_(hasMissingValue), defaultValue_(defaultValue)
14  {
15    if (!grid)
16      ERROR("CSourceFilter::CSourceFilter(CGrid* grid)",
17            "Impossible to construct a source filter without providing a grid.");
18  }
19
20  template <int N>
21  void CModelToClientSourceFilter::streamData(CDate date, const CArray<double, N>& data)
22  {
23    CDataPacketPtr packet(new CDataPacket);
24    packet->date = date;
25    packet->timestamp = date;
26    packet->status = CDataPacket::NO_ERROR;
27   
28    auto connector = grid_->getModelToWorkflowConnector() ;
29
30    if (connector->getSrcSize() != data.numElements())
31      ERROR("void CModelToClientSourceFilter::streamData(CDate date, const CArray<double, N>& data)",
32            << "[ Awaiting data of size = " <<connector->getSrcSize() << ", "
33            << "Received data size = "      << data.numElements() << " ] "
34            << "The data array does not have the right size! "
35            << "grid = " << grid_->getId())
36    const double nanValue = std::numeric_limits<double>::quiet_NaN();
37    packet->data.resize(connector->getDstSize()) ;
38    connector->transfer(data, packet->data, nanValue) ;
39
40    if (hasMissingValue_)
41    {
42        const double nanValue = std::numeric_limits<double>::quiet_NaN();
43        const size_t nbData = packet->data.numElements();
44        for (size_t idx = 0; idx < nbData; ++idx)
45          if (defaultValue_ == packet->data(idx))   packet->data(idx) = nanValue;
46    }
47   
48    buildWorkflowGraph(packet);
49    onOutputReady(packet);
50  }
51 
52  void CModelToClientSourceFilter::buildWorkflowGraph(CDataPacketPtr packet)
53  {
54    if(this->graphEnabled)
55    {
56      this->graphPackage->filterId = CWorkflowGraph::getNodeSize();
57      if(!packet->graphPackage)
58      {
59        packet->graphPackage = new CGraphDataPackage;
60      }
61      packet->graphPackage->fromFilter = this->graphPackage->filterId;
62      packet->graphPackage->currentField = this->graphPackage->inFields[0];
63      CWorkflowGraph::addNode("Model to Client Source filter", 1, false, 0, packet);
64    }
65  }
66
67
68
69
70  template void CModelToClientSourceFilter::streamData<1>(CDate date, const CArray<double, 1>& data);
71  template void CModelToClientSourceFilter::streamData<2>(CDate date, const CArray<double, 2>& data);
72  template void CModelToClientSourceFilter::streamData<3>(CDate date, const CArray<double, 3>& data);
73  template void CModelToClientSourceFilter::streamData<4>(CDate date, const CArray<double, 4>& data);
74  template void CModelToClientSourceFilter::streamData<5>(CDate date, const CArray<double, 5>& data);
75  template void CModelToClientSourceFilter::streamData<6>(CDate date, const CArray<double, 6>& data);
76  template void CModelToClientSourceFilter::streamData<7>(CDate date, const CArray<double, 7>& data);
77
78} // namespace xios
Note: See TracBrowser for help on using the repository browser.