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