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

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

Final tests of zoom and inverse on axis

+) Modify test_client and test_complete to work with new grid definition
+) Correct some bugs causing memory leak
+) Clean abundant code
+) Add more comments to new files

Test
+) On Curie
+) test_client and test_complete pass with correct results

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