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

Last change on this file since 593 was 593, checked in by rlacroix, 9 years ago

Add a new interface xios_recv_field to get local instant data from a field.

  • 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: 5.6 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
29      for (; it != end; it++) (*it)->setData(_data);
30      if (hasOutputFile || hasFieldOut) updateData(_data);
31    }
32  }
33
34  void CField::setDataFromExpression(const CArray<double, 1>& _data)
35  {
36    if (hasInstantData)
37    {
38      instantData=_data;
39      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
40    }
41
42    if (!hasExpression)
43    {
44      const std::vector<CField*>& refField=getAllReference();
45      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
46
47      for (; it != end; it++) (*it)->setDataFromExpression(_data);
48      if (hasOutputFile || hasFieldOut) updateDataFromExpression(_data);
49    }
50  }
51
52   template <int N>
53   bool CField::updateData(const CArray<double, N>& _data)
54   {
55      CContext* context=CContext::getCurrent();
56      const CDate & currDate = context->getCalendar()->getCurrentDate();
57      const CDate opeDate      = *last_operation + freq_operation;
58      const CDate writeDate    = *last_Write     + freq_write;
59      bool doOperation, doWrite;
60
61
62      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
63      info(50) << "Next operation "  << opeDate<<std::endl;
64
65      doOperation = (opeDate <= currDate);
66      if (isOnceOperation)
67        if (isFirstOperation) doOperation=true;
68        else doOperation=false;
69
70      if (doOperation)
71      {
72         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
73         {
74            this->data.resize(this->grid->storeIndex_client.numElements());
75         }
76
77         CArray<double,1> input(data.numElements());
78         this->grid->inputField(_data, input);
79         (*this->foperation)(input);
80
81         *last_operation = currDate;
82         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
83      }
84
85      doWrite = (writeDate < (currDate + freq_operation));
86      if (isOnceOperation)
87      {
88        if(isFirstOperation)
89        {
90          doWrite=true;
91          isFirstOperation=false;
92        }
93        else doWrite=false;
94      }
95
96      if (doWrite)
97      {
98         this->foperation->final();
99         *last_Write = writeDate;
100         if (hasOutputFile)
101         {
102           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
103           CTimer::get("XIOS Send Data").resume();
104           sendUpdateData();
105           CTimer::get("XIOS Send Data").suspend();
106         }
107
108         if (hasFieldOut)
109         {
110           fieldOut->setDataFromExpression(data);
111         }
112         return (true);
113      }
114
115      return (false);
116   }
117
118   bool CField::updateDataFromExpression(const CArray<double, 1>& _data)
119   {
120      CContext* context=CContext::getCurrent();
121      const CDate & currDate = context->getCalendar()->getCurrentDate();
122      const CDate opeDate      = *last_operation + freq_operation;
123      const CDate writeDate    = *last_Write     + freq_write;
124      bool doOperation, doWrite;
125
126
127      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
128      info(50) << "Next operation "  << opeDate<<std::endl;
129
130      doOperation = (opeDate <= currDate);
131      if (isOnceOperation)
132        if (isFirstOperation) doOperation=true;
133        else doOperation=false;
134
135      if (doOperation)
136      {
137         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
138         {
139            this->data.resize(this->grid->storeIndex_client.numElements());
140         }
141
142        (*this->foperation)(_data);
143
144         *last_operation = currDate;
145         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
146      }
147
148      doWrite = (writeDate < (currDate + freq_operation));
149      if (isOnceOperation)
150      {
151        if(isFirstOperation)
152        {
153          doWrite=true;
154          isFirstOperation=false;
155        }
156        else doWrite=false;
157      }
158
159      if (doWrite)
160      {
161         this->foperation->final();
162         *last_Write = writeDate;
163         if (hasOutputFile)
164         {
165           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
166           CTimer::get("XIOS Send Data").resume();
167           sendUpdateData();
168           CTimer::get("XIOS Send Data").suspend();
169         }
170
171         if (hasFieldOut)
172         {
173           fieldOut->setDataFromExpression(data);
174         }
175         return (true);
176      }
177
178      return (false);
179   }
180
181  template <int N>
182  void CField::getData(CArray<double, N>& _data) const
183  {
184    if (!read_access.isEmpty() && read_access.getValue() && hasInstantData)
185    {
186      grid->outputField(instantData, _data);
187    }
188    else
189    {
190      ERROR("void CField::getData(CArray<double, N>& _data) const",
191            << "Impossible to access field data, the field [ id = " << getId() << " ] does not have read access.");
192    }
193  }
194} // namespace xios
195
196#endif
Note: See TracBrowser for help on using the repository browser.