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

Last change on this file since 644 was 640, checked in by rlacroix, 9 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
RevLine 
[352]1
2#ifndef __FIELD_IMPL_HPP__
3#define __FIELD_IMPL_HPP__
4
[591]5#include "xios_spl.hpp"
[352]6#include "field.hpp"
7#include "context.hpp"
8#include "grid.hpp"
9#include "timer.hpp"
[369]10#include "array_new.hpp"
[640]11#include "source_filter.hpp"
12#include "store_filter.hpp"
[352]13
[369]14
[352]15namespace xios {
16
[459]17  template <int N>
18  void CField::setData(const CArray<double, N>& _data)
19  {
[640]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)
[459]27    {
[572]28      grid->inputField(_data, instantData);
29      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
[459]30    }
[572]31
[459]32    if (!hasExpression)
33    {
34      const std::vector<CField*>& refField=getAllReference();
[619]35      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end(),
36                                            itFilterSrc, iteFilterSrc;
[572]37
[619]38      for (; it != end; it++)
39      {
40        const std::vector<CField*>& fieldFilterSources = (*it)->getFilterSources();
41        if (!fieldFilterSources.empty())
42        {
[620]43          itFilterSrc  = fieldFilterSources.begin();
44          iteFilterSrc = fieldFilterSources.end();
45          for (; itFilterSrc != iteFilterSrc; ++itFilterSrc)
46          {
47            (*itFilterSrc)->updateDataWithoutOperation(_data, (*itFilterSrc)->data);
[621]48            if ((*it)->filteredData.numElements() != (*it)->grid->storeIndex_client.numElements())
49            {
50               (*it)->filteredData.resize((*it)->grid->storeIndex_client.numElements());
51            }
[620]52            (*it)->applyFilter((*itFilterSrc)->data, (*it)->filteredData);
53          }
[619]54          if ((*it)->hasOutputFile || (*it)->hasFieldOut) (*it)->updateFilteredData((*it)->filteredData);
55        }
56        else
57        {
58          (*it)->setData(_data);
59        }
60      }
[624]61      if (hasOutputFile || hasFieldOut) updateData(_data);
[640]62    }*/
[459]63  }
64
[460]65  void CField::setDataFromExpression(const CArray<double, 1>& _data)
66  {
[572]67    if (hasInstantData)
[460]68    {
[572]69      instantData=_data;
70      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
[460]71    }
[572]72
[460]73    if (!hasExpression)
74    {
75      const std::vector<CField*>& refField=getAllReference();
76      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
[572]77
78      for (; it != end; it++) (*it)->setDataFromExpression(_data);
79      if (hasOutputFile || hasFieldOut) updateDataFromExpression(_data);
[460]80    }
81  }
[459]82
[619]83   template<int N>
[620]84   void CField::updateDataWithoutOperation(const CArray<double, N>& _data, CArray<double,1>& updatedData)
[619]85   {
[620]86     if (updatedData.numElements() != this->grid->storeIndex_client.numElements())
[619]87     {
[620]88        updatedData.resize(this->grid->storeIndex_client.numElements());
89        this->grid->inputField(_data, updatedData);
[619]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
[369]157   template <int N>
[459]158   bool CField::updateData(const CArray<double, N>& _data)
[572]159   {
[352]160      CContext* context=CContext::getCurrent();
161      const CDate & currDate = context->getCalendar()->getCurrentDate();
162      const CDate opeDate      = *last_operation + freq_operation;
[572]163      const CDate writeDate    = *last_Write     + freq_write;
164      bool doOperation, doWrite;
[352]165
[572]166
[352]167      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
168      info(50) << "Next operation "  << opeDate<<std::endl;
[459]169
[572]170      doOperation = (opeDate <= currDate);
[436]171      if (isOnceOperation)
[572]172        if (isFirstOperation) doOperation=true;
173        else doOperation=false;
[459]174
[436]175      if (doOperation)
[352]176      {
[369]177         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
[352]178         {
[369]179            this->data.resize(this->grid->storeIndex_client.numElements());
[352]180         }
[572]181
182         CArray<double,1> input(data.numElements());
183         this->grid->inputField(_data, input);
[352]184         (*this->foperation)(input);
[572]185
[352]186         *last_operation = currDate;
[572]187         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
[352]188      }
[459]189
[572]190      doWrite = (writeDate < (currDate + freq_operation));
[459]191      if (isOnceOperation)
[572]192      {
193        if(isFirstOperation)
[459]194        {
[572]195          doWrite=true;
196          isFirstOperation=false;
[459]197        }
[572]198        else doWrite=false;
[459]199      }
[572]200
[459]201      if (doWrite)
202      {
203         this->foperation->final();
204         *last_Write = writeDate;
[460]205         if (hasOutputFile)
206         {
207           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
[572]208           CTimer::get("XIOS Send Data").resume();
209           sendUpdateData();
210           CTimer::get("XIOS Send Data").suspend();
[460]211         }
[572]212
[460]213         if (hasFieldOut)
214         {
[572]215           fieldOut->setDataFromExpression(data);
[460]216         }
[572]217         return (true);
[459]218      }
219
220      return (false);
221   }
[572]222
[459]223   bool CField::updateDataFromExpression(const CArray<double, 1>& _data)
[572]224   {
[459]225      CContext* context=CContext::getCurrent();
226      const CDate & currDate = context->getCalendar()->getCurrentDate();
227      const CDate opeDate      = *last_operation + freq_operation;
[572]228      const CDate writeDate    = *last_Write     + freq_write;
229      bool doOperation, doWrite;
[459]230
[572]231
[459]232      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
233      info(50) << "Next operation "  << opeDate<<std::endl;
234
[572]235      doOperation = (opeDate <= currDate);
[459]236      if (isOnceOperation)
[572]237        if (isFirstOperation) doOperation=true;
238        else doOperation=false;
[459]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         }
[572]246
[459]247        (*this->foperation)(_data);
[572]248
[459]249         *last_operation = currDate;
[572]250         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
[459]251      }
252
[572]253      doWrite = (writeDate < (currDate + freq_operation));
[436]254      if (isOnceOperation)
[572]255      {
256        if(isFirstOperation)
[436]257        {
[572]258          doWrite=true;
259          isFirstOperation=false;
[436]260        }
[572]261        else doWrite=false;
[436]262      }
[572]263
[436]264      if (doWrite)
[352]265      {
266         this->foperation->final();
267         *last_Write = writeDate;
[572]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);
[352]281      }
282
283      return (false);
284   }
285
[593]286  template <int N>
287  void CField::getData(CArray<double, N>& _data) const
288  {
[640]289    if (storeFilter)
[593]290    {
[640]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();
[598]298      const CDate& currentDate = context->getCalendar()->getCurrentDate();
299
300      while (isReadDataRequestPending)
301        context->checkBuffersAndListen();
302
[599]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
[640]307      grid->outputField(instantData, _data);*/
[593]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  }
[352]315} // namespace xios
316
317#endif
Note: See TracBrowser for help on using the repository browser.