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

Last change on this file since 619 was 619, checked in by mhnguyen, 9 years ago

Implementing the first prototype of filter

+) Create new class filter
+) Implement class for specific algorithm
+) Implement inversing algorithm

Test
+) On Curie
+) Grid with one axis: passed

  • 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: 8.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
12
13namespace xios {
14
15  template <int N>
16  void CField::setData(const CArray<double, N>& _data)
17  {
18    if (hasInstantData)
19    {
20      grid->inputField(_data, instantData);
21      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
22    }
23
24    if (!hasExpression)
25    {
26      const std::vector<CField*>& refField=getAllReference();
27      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end(),
28                                            itFilterSrc, iteFilterSrc;
29
30      for (; it != end; it++)
31      {
32        const std::vector<CField*>& fieldFilterSources = (*it)->getFilterSources();
33        if (!fieldFilterSources.empty())
34        {
35          itFilterSrc = fieldFilterSources.begin(); iteFilterSrc = fieldFilterSources.end();
36          for (; itFilterSrc != iteFilterSrc; ++itFilterSrc) (*itFilterSrc)->updateDataWithoutOperation(_data);
37          (*it)->applyFilter();
38          std::cout << "it data " << (*it)->data << std::endl;
39          std::cout << "it filtered data " << (*it)->filteredData << std::endl;
40          if ((*it)->hasOutputFile || (*it)->hasFieldOut) (*it)->updateFilteredData((*it)->filteredData);
41        }
42        else
43        {
44          (*it)->setData(_data);
45          if (hasOutputFile || hasFieldOut) updateData(_data);
46        }
47
48      }
49
50    }
51  }
52
53  void CField::setDataFromExpression(const CArray<double, 1>& _data)
54  {
55    if (hasInstantData)
56    {
57      instantData=_data;
58      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
59    }
60
61    if (!hasExpression)
62    {
63      const std::vector<CField*>& refField=getAllReference();
64      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
65
66      for (; it != end; it++) (*it)->setDataFromExpression(_data);
67      if (hasOutputFile || hasFieldOut) updateDataFromExpression(_data);
68    }
69  }
70
71   template<int N>
72   void CField::updateDataWithoutOperation(const CArray<double, N>& _data)
73   {
74     if (this->data.numElements() != this->grid->storeIndex_client.numElements())
75     {
76        this->data.resize(this->grid->storeIndex_client.numElements());
77        this->grid->inputField(_data, this->data);
78     }
79   }
80
81   template<int N>
82   bool CField::updateFilteredData(CArray<double, N>& filteredData)
83   {
84      CContext* context=CContext::getCurrent();
85      const CDate & currDate = context->getCalendar()->getCurrentDate();
86      const CDate opeDate      = *last_operation + freq_operation;
87      const CDate writeDate    = *last_Write     + freq_write;
88      bool doOperation, doWrite;
89
90
91      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
92      info(50) << "Next operation "  << opeDate<<std::endl;
93
94      doOperation = (opeDate <= currDate);
95      if (isOnceOperation)
96        if (isFirstOperation) doOperation=true;
97        else doOperation=false;
98
99      if (doOperation)
100      {
101         if (this->data.numElements() != filteredData.numElements())
102         {
103            this->data.resize(filteredData.numElements());
104         }
105
106         (*this->foperation)(filteredData);
107
108         *last_operation = currDate;
109         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
110      }
111
112      doWrite = (writeDate < (currDate + freq_operation));
113      if (isOnceOperation)
114      {
115        if(isFirstOperation)
116        {
117          doWrite=true;
118          isFirstOperation=false;
119        }
120        else doWrite=false;
121      }
122
123      if (doWrite)
124      {
125         this->foperation->final();
126         *last_Write = writeDate;
127         if (hasOutputFile)
128         {
129           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
130           CTimer::get("XIOS Send Data").resume();
131           sendUpdateData();
132           CTimer::get("XIOS Send Data").suspend();
133         }
134
135//         if (hasFieldOut)
136//         {
137//           fieldOut->setDataFromExpression(data);
138//         }
139         return (true);
140      }
141
142      return (false);
143   }
144
145   template <int N>
146   bool CField::updateData(const CArray<double, N>& _data)
147   {
148      CContext* context=CContext::getCurrent();
149      const CDate & currDate = context->getCalendar()->getCurrentDate();
150      const CDate opeDate      = *last_operation + freq_operation;
151      const CDate writeDate    = *last_Write     + freq_write;
152      bool doOperation, doWrite;
153
154
155      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
156      info(50) << "Next operation "  << opeDate<<std::endl;
157
158      doOperation = (opeDate <= currDate);
159      if (isOnceOperation)
160        if (isFirstOperation) doOperation=true;
161        else doOperation=false;
162
163      if (doOperation)
164      {
165         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
166         {
167            this->data.resize(this->grid->storeIndex_client.numElements());
168         }
169
170         CArray<double,1> input(data.numElements());
171         this->grid->inputField(_data, input);
172         (*this->foperation)(input);
173
174         *last_operation = currDate;
175         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
176      }
177
178      doWrite = (writeDate < (currDate + freq_operation));
179      if (isOnceOperation)
180      {
181        if(isFirstOperation)
182        {
183          doWrite=true;
184          isFirstOperation=false;
185        }
186        else doWrite=false;
187      }
188
189      if (doWrite)
190      {
191         this->foperation->final();
192         *last_Write = writeDate;
193         if (hasOutputFile)
194         {
195           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
196           CTimer::get("XIOS Send Data").resume();
197           sendUpdateData();
198           CTimer::get("XIOS Send Data").suspend();
199         }
200
201         if (hasFieldOut)
202         {
203           fieldOut->setDataFromExpression(data);
204         }
205         return (true);
206      }
207
208      return (false);
209   }
210
211   bool CField::updateDataFromExpression(const CArray<double, 1>& _data)
212   {
213      CContext* context=CContext::getCurrent();
214      const CDate & currDate = context->getCalendar()->getCurrentDate();
215      const CDate opeDate      = *last_operation + freq_operation;
216      const CDate writeDate    = *last_Write     + freq_write;
217      bool doOperation, doWrite;
218
219
220      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
221      info(50) << "Next operation "  << opeDate<<std::endl;
222
223      doOperation = (opeDate <= currDate);
224      if (isOnceOperation)
225        if (isFirstOperation) doOperation=true;
226        else doOperation=false;
227
228      if (doOperation)
229      {
230         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
231         {
232            this->data.resize(this->grid->storeIndex_client.numElements());
233         }
234
235        (*this->foperation)(_data);
236
237         *last_operation = currDate;
238         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
239      }
240
241      doWrite = (writeDate < (currDate + freq_operation));
242      if (isOnceOperation)
243      {
244        if(isFirstOperation)
245        {
246          doWrite=true;
247          isFirstOperation=false;
248        }
249        else doWrite=false;
250      }
251
252      if (doWrite)
253      {
254         this->foperation->final();
255         *last_Write = writeDate;
256         if (hasOutputFile)
257         {
258           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
259           CTimer::get("XIOS Send Data").resume();
260           sendUpdateData();
261           CTimer::get("XIOS Send Data").suspend();
262         }
263
264         if (hasFieldOut)
265         {
266           fieldOut->setDataFromExpression(data);
267         }
268         return (true);
269      }
270
271      return (false);
272   }
273
274  template <int N>
275  void CField::getData(CArray<double, N>& _data) const
276  {
277    if (!read_access.isEmpty() && read_access.getValue() && hasInstantData)
278    {
279      CContext* context = CContext::getCurrent();
280      const CDate& currentDate = context->getCalendar()->getCurrentDate();
281
282      while (isReadDataRequestPending)
283        context->checkBuffersAndListen();
284
285      if (isEOF)
286        ERROR("void CField::getData(CArray<double, N>& _data) const",
287              << "Impossible to access field data, all the records of the field [ id = " << getId() << " ] have been already read.");
288
289      grid->outputField(instantData, _data);
290    }
291    else
292    {
293      ERROR("void CField::getData(CArray<double, N>& _data) const",
294            << "Impossible to access field data, the field [ id = " << getId() << " ] does not have read access.");
295    }
296  }
297} // namespace xios
298
299#endif
Note: See TracBrowser for help on using the repository browser.