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

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

Implementing generic transformation algorithm (local commit)

+) Implement 3 important classes:

-gridTransformation to read transformation info from grid and interface with the rest of XIOS
-transformationMapping to be in charge of sending/receiving transformation info among clients
-transformationAlgorithm to represent various algorithms

+) Make some change on field to use the new classes

Test
+) Only test_new_features with inversed axis

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