source: XIOS/trunk/src/node/field_impl.hpp @ 640

Last change on this file since 640 was 640, checked in by rlacroix, 7 years ago

Start using the filter infrastructure to read and write fields.

Note that currently only the simple cases are working. References and all types of operations are disabled.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 9.9 KB
Line 
1
2#ifndef __FIELD_IMPL_HPP__
3#define __FIELD_IMPL_HPP__
4
5#include "xios_spl.hpp"
6#include "field.hpp"
7#include "context.hpp"
8#include "grid.hpp"
9#include "timer.hpp"
10#include "array_new.hpp"
11#include "source_filter.hpp"
12#include "store_filter.hpp"
13
14
15namespace xios {
16
17  template <int N>
18  void CField::setData(const CArray<double, N>& _data)
19  {
20    if (clientSourceFilter)
21      clientSourceFilter->streamData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data);
22    else if (!field_ref.isEmpty() || !content.empty())
23      ERROR("void CField::setData(const CArray<double, N>& _data)",
24            << "Impossible to receive data from the model for a field [ id = " << getId() << " ] with a reference or an arithmetic operation.");
25
26    /*if (hasInstantData)
27    {
28      grid->inputField(_data, instantData);
29      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
30    }
31
32    if (!hasExpression)
33    {
34      const std::vector<CField*>& refField=getAllReference();
35      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end(),
36                                            itFilterSrc, iteFilterSrc;
37
38      for (; it != end; it++)
39      {
40        const std::vector<CField*>& fieldFilterSources = (*it)->getFilterSources();
41        if (!fieldFilterSources.empty())
42        {
43          itFilterSrc  = fieldFilterSources.begin();
44          iteFilterSrc = fieldFilterSources.end();
45          for (; itFilterSrc != iteFilterSrc; ++itFilterSrc)
46          {
47            (*itFilterSrc)->updateDataWithoutOperation(_data, (*itFilterSrc)->data);
48            if ((*it)->filteredData.numElements() != (*it)->grid->storeIndex_client.numElements())
49            {
50               (*it)->filteredData.resize((*it)->grid->storeIndex_client.numElements());
51            }
52            (*it)->applyFilter((*itFilterSrc)->data, (*it)->filteredData);
53          }
54          if ((*it)->hasOutputFile || (*it)->hasFieldOut) (*it)->updateFilteredData((*it)->filteredData);
55        }
56        else
57        {
58          (*it)->setData(_data);
59        }
60      }
61      if (hasOutputFile || hasFieldOut) updateData(_data);
62    }*/
63  }
64
65  void CField::setDataFromExpression(const CArray<double, 1>& _data)
66  {
67    if (hasInstantData)
68    {
69      instantData=_data;
70      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
71    }
72
73    if (!hasExpression)
74    {
75      const std::vector<CField*>& refField=getAllReference();
76      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
77
78      for (; it != end; it++) (*it)->setDataFromExpression(_data);
79      if (hasOutputFile || hasFieldOut) updateDataFromExpression(_data);
80    }
81  }
82
83   template<int N>
84   void CField::updateDataWithoutOperation(const CArray<double, N>& _data, CArray<double,1>& updatedData)
85   {
86     if (updatedData.numElements() != this->grid->storeIndex_client.numElements())
87     {
88        updatedData.resize(this->grid->storeIndex_client.numElements());
89        this->grid->inputField(_data, updatedData);
90     }
91   }
92
93   template<int N>
94   bool CField::updateFilteredData(CArray<double, N>& filteredData)
95   {
96      CContext* context=CContext::getCurrent();
97      const CDate & currDate = context->getCalendar()->getCurrentDate();
98      const CDate opeDate      = *last_operation + freq_operation;
99      const CDate writeDate    = *last_Write     + freq_write;
100      bool doOperation, doWrite;
101
102
103      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
104      info(50) << "Next operation "  << opeDate<<std::endl;
105
106      doOperation = (opeDate <= currDate);
107      if (isOnceOperation)
108        if (isFirstOperation) doOperation=true;
109        else doOperation=false;
110
111      if (doOperation)
112      {
113         if (this->data.numElements() != filteredData.numElements())
114         {
115            this->data.resize(filteredData.numElements());
116         }
117
118         (*this->foperation)(filteredData);
119
120         *last_operation = currDate;
121         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
122      }
123
124      doWrite = (writeDate < (currDate + freq_operation));
125      if (isOnceOperation)
126      {
127        if(isFirstOperation)
128        {
129          doWrite=true;
130          isFirstOperation=false;
131        }
132        else doWrite=false;
133      }
134
135      if (doWrite)
136      {
137         this->foperation->final();
138         *last_Write = writeDate;
139         if (hasOutputFile)
140         {
141           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
142           CTimer::get("XIOS Send Data").resume();
143           sendUpdateData();
144           CTimer::get("XIOS Send Data").suspend();
145         }
146
147//         if (hasFieldOut)
148//         {
149//           fieldOut->setDataFromExpression(data);
150//         }
151         return (true);
152      }
153
154      return (false);
155   }
156
157   template <int N>
158   bool CField::updateData(const CArray<double, N>& _data)
159   {
160      CContext* context=CContext::getCurrent();
161      const CDate & currDate = context->getCalendar()->getCurrentDate();
162      const CDate opeDate      = *last_operation + freq_operation;
163      const CDate writeDate    = *last_Write     + freq_write;
164      bool doOperation, doWrite;
165
166
167      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
168      info(50) << "Next operation "  << opeDate<<std::endl;
169
170      doOperation = (opeDate <= currDate);
171      if (isOnceOperation)
172        if (isFirstOperation) doOperation=true;
173        else doOperation=false;
174
175      if (doOperation)
176      {
177         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
178         {
179            this->data.resize(this->grid->storeIndex_client.numElements());
180         }
181
182         CArray<double,1> input(data.numElements());
183         this->grid->inputField(_data, input);
184         (*this->foperation)(input);
185
186         *last_operation = currDate;
187         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
188      }
189
190      doWrite = (writeDate < (currDate + freq_operation));
191      if (isOnceOperation)
192      {
193        if(isFirstOperation)
194        {
195          doWrite=true;
196          isFirstOperation=false;
197        }
198        else doWrite=false;
199      }
200
201      if (doWrite)
202      {
203         this->foperation->final();
204         *last_Write = writeDate;
205         if (hasOutputFile)
206         {
207           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
208           CTimer::get("XIOS Send Data").resume();
209           sendUpdateData();
210           CTimer::get("XIOS Send Data").suspend();
211         }
212
213         if (hasFieldOut)
214         {
215           fieldOut->setDataFromExpression(data);
216         }
217         return (true);
218      }
219
220      return (false);
221   }
222
223   bool CField::updateDataFromExpression(const CArray<double, 1>& _data)
224   {
225      CContext* context=CContext::getCurrent();
226      const CDate & currDate = context->getCalendar()->getCurrentDate();
227      const CDate opeDate      = *last_operation + freq_operation;
228      const CDate writeDate    = *last_Write     + freq_write;
229      bool doOperation, doWrite;
230
231
232      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
233      info(50) << "Next operation "  << opeDate<<std::endl;
234
235      doOperation = (opeDate <= currDate);
236      if (isOnceOperation)
237        if (isFirstOperation) doOperation=true;
238        else doOperation=false;
239
240      if (doOperation)
241      {
242         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
243         {
244            this->data.resize(this->grid->storeIndex_client.numElements());
245         }
246
247        (*this->foperation)(_data);
248
249         *last_operation = currDate;
250         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
251      }
252
253      doWrite = (writeDate < (currDate + freq_operation));
254      if (isOnceOperation)
255      {
256        if(isFirstOperation)
257        {
258          doWrite=true;
259          isFirstOperation=false;
260        }
261        else doWrite=false;
262      }
263
264      if (doWrite)
265      {
266         this->foperation->final();
267         *last_Write = writeDate;
268         if (hasOutputFile)
269         {
270           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
271           CTimer::get("XIOS Send Data").resume();
272           sendUpdateData();
273           CTimer::get("XIOS Send Data").suspend();
274         }
275
276         if (hasFieldOut)
277         {
278           fieldOut->setDataFromExpression(data);
279         }
280         return (true);
281      }
282
283      return (false);
284   }
285
286  template <int N>
287  void CField::getData(CArray<double, N>& _data) const
288  {
289    if (storeFilter)
290    {
291      CDataPacket::StatusCode status = storeFilter->getData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data);
292
293      if (status == CDataPacket::END_OF_STREAM)
294        ERROR("void CField::getData(CArray<double, N>& _data) const",
295              << "Impossible to access field data, all the records of the field [ id = " << getId() << " ] have been already read.");
296
297      /*CContext* context = CContext::getCurrent();
298      const CDate& currentDate = context->getCalendar()->getCurrentDate();
299
300      while (isReadDataRequestPending)
301        context->checkBuffersAndListen();
302
303      if (isEOF)
304        ERROR("void CField::getData(CArray<double, N>& _data) const",
305              << "Impossible to access field data, all the records of the field [ id = " << getId() << " ] have been already read.");
306
307      grid->outputField(instantData, _data);*/
308    }
309    else
310    {
311      ERROR("void CField::getData(CArray<double, N>& _data) const",
312            << "Impossible to access field data, the field [ id = " << getId() << " ] does not have read access.");
313    }
314  }
315} // namespace xios
316
317#endif
Note: See TracBrowser for help on using the repository browser.