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
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"
[352]11
[369]12
[352]13namespace xios {
14
[459]15  template <int N>
16  void CField::setData(const CArray<double, N>& _data)
17  {
[572]18    if (hasInstantData)
[459]19    {
[572]20      grid->inputField(_data, instantData);
21      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
[459]22    }
[572]23
[459]24    if (!hasExpression)
25    {
26      const std::vector<CField*>& refField=getAllReference();
27      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
[572]28
29      for (; it != end; it++) (*it)->setData(_data);
30      if (hasOutputFile || hasFieldOut) updateData(_data);
[352]31    }
[459]32  }
33
[460]34  void CField::setDataFromExpression(const CArray<double, 1>& _data)
35  {
[572]36    if (hasInstantData)
[460]37    {
[572]38      instantData=_data;
39      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second);
[460]40    }
[572]41
[460]42    if (!hasExpression)
43    {
44      const std::vector<CField*>& refField=getAllReference();
45      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
[572]46
47      for (; it != end; it++) (*it)->setDataFromExpression(_data);
48      if (hasOutputFile || hasFieldOut) updateDataFromExpression(_data);
[460]49    }
50  }
[459]51
[369]52   template <int N>
[459]53   bool CField::updateData(const CArray<double, N>& _data)
[572]54   {
[352]55      CContext* context=CContext::getCurrent();
56      const CDate & currDate = context->getCalendar()->getCurrentDate();
57      const CDate opeDate      = *last_operation + freq_operation;
[572]58      const CDate writeDate    = *last_Write     + freq_write;
59      bool doOperation, doWrite;
[352]60
[572]61
[352]62      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
63      info(50) << "Next operation "  << opeDate<<std::endl;
[459]64
[572]65      doOperation = (opeDate <= currDate);
[436]66      if (isOnceOperation)
[572]67        if (isFirstOperation) doOperation=true;
68        else doOperation=false;
[459]69
[436]70      if (doOperation)
[352]71      {
[369]72         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
[352]73         {
[369]74            this->data.resize(this->grid->storeIndex_client.numElements());
[352]75         }
[572]76
77         CArray<double,1> input(data.numElements());
78         this->grid->inputField(_data, input);
[352]79         (*this->foperation)(input);
[572]80
[352]81         *last_operation = currDate;
[572]82         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
[352]83      }
[459]84
[572]85      doWrite = (writeDate < (currDate + freq_operation));
[459]86      if (isOnceOperation)
[572]87      {
88        if(isFirstOperation)
[459]89        {
[572]90          doWrite=true;
91          isFirstOperation=false;
[459]92        }
[572]93        else doWrite=false;
[459]94      }
[572]95
[459]96      if (doWrite)
97      {
98         this->foperation->final();
99         *last_Write = writeDate;
[460]100         if (hasOutputFile)
101         {
102           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
[572]103           CTimer::get("XIOS Send Data").resume();
104           sendUpdateData();
105           CTimer::get("XIOS Send Data").suspend();
[460]106         }
[572]107
[460]108         if (hasFieldOut)
109         {
[572]110           fieldOut->setDataFromExpression(data);
[460]111         }
[572]112         return (true);
[459]113      }
114
115      return (false);
116   }
[572]117
[459]118   bool CField::updateDataFromExpression(const CArray<double, 1>& _data)
[572]119   {
[459]120      CContext* context=CContext::getCurrent();
121      const CDate & currDate = context->getCalendar()->getCurrentDate();
122      const CDate opeDate      = *last_operation + freq_operation;
[572]123      const CDate writeDate    = *last_Write     + freq_write;
124      bool doOperation, doWrite;
[459]125
[572]126
[459]127      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
128      info(50) << "Next operation "  << opeDate<<std::endl;
129
[572]130      doOperation = (opeDate <= currDate);
[459]131      if (isOnceOperation)
[572]132        if (isFirstOperation) doOperation=true;
133        else doOperation=false;
[459]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         }
[572]141
[459]142        (*this->foperation)(_data);
[572]143
[459]144         *last_operation = currDate;
[572]145         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
[459]146      }
147
[572]148      doWrite = (writeDate < (currDate + freq_operation));
[436]149      if (isOnceOperation)
[572]150      {
151        if(isFirstOperation)
[436]152        {
[572]153          doWrite=true;
154          isFirstOperation=false;
[436]155        }
[572]156        else doWrite=false;
[436]157      }
[572]158
[436]159      if (doWrite)
[352]160      {
161         this->foperation->final();
162         *last_Write = writeDate;
[572]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);
[352]176      }
177
178      return (false);
179   }
180
[593]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  }
[352]194} // namespace xios
195
196#endif
Note: See TracBrowser for help on using the repository browser.