#include "grid.hpp" #include "attribute_template_impl.hpp" #include "object_template_impl.hpp" #include "group_template_impl.hpp" namespace xmlioserver { namespace tree { /// ////////////////////// Définitions ////////////////////// /// CGrid::CGrid(void) : CObjectTemplate(), CGridAttributes() , withAxis(false), isChecked(false), axis(), domain() , storeIndex(), out_i_index(), out_j_index(), out_l_index() { /* Ne rien faire de plus */ } CGrid::CGrid(const StdString & id) : CObjectTemplate(id), CGridAttributes() , withAxis(false), isChecked(false), axis(), domain() , storeIndex(), out_i_index(), out_j_index(), out_l_index() { /* Ne rien faire de plus */ } CGrid::~CGrid(void) { /* Ne rien faire de plus */ } ///--------------------------------------------------------------- StdString CGrid::GetName(void) { return (StdString("grid")); } StdString CGrid::GetDefName(void){ return (CGrid::GetName()); } const ARRAY(int, 1) & CGrid::getStoreIndex(void) const { return (this->storeIndex ); } const ARRAY(int, 1) & CGrid::getOutIIndex(void) const { return (this->out_i_index ); } const ARRAY(int, 1) & CGrid::getOutJIndex(void) const { return (this->out_j_index ); } const ARRAY(int, 1) & CGrid::getOutLIndex(void) const { return (this->out_l_index ); } const boost::shared_ptr CGrid::getRelAxis (void) const { return (this->axis ); } const boost::shared_ptr CGrid::getRelDomain(void) const { return (this->domain ); } bool CGrid::hasAxis(void) const { return (this->withAxis); } //--------------------------------------------------------------- void CGrid::solveReference(void) { if (this->isChecked) return; this->solveDomainRef() ; this->solveAxisRef() ; this->computeIndex() ; this->isChecked = true; } void CGrid::solveDomainRef(void) { if (!domain_ref.isEmpty()) { if (CObjectFactory::HasObject(domain_ref.getValue())) { this->domain = CObjectFactory::GetObject(domain_ref.getValue()) ; domain->checkAttributes() ; } else ERROR("CGrid::solveDomainRef(void)", << "Référence au domaine incorrecte") ; } else ERROR("CGrid::solveDomainRef(void)", << "Domaine non défini") ; } void CGrid::solveAxisRef(void) { if (!axis_ref.isEmpty()) { this->withAxis = true ; if (CObjectFactory::GetObject(axis_ref.getValue())) { this->axis = CObjectFactory::GetObject(axis_ref.getValue()) ; axis->checkAttributes() ; } else ERROR("CGrid::solveAxisRef(void)", << "Référence a l'axe incorrecte") ; } else withAxis = false ; } void CGrid::computeIndex(void) { const int ni = domain->ni.getValue() , nj = domain->nj.getValue() , size = (this->hasAxis()) ? axis->size.getValue() : 1 ; /*std::cout << ni << " : " << nj << " : " << size << std::endl;*/ const int data_dim = domain->data_dim.getValue() , data_n_index = domain->data_n_index.getValue() , data_ibegin = domain->data_ibegin.getValue() , data_jbegin = (data_dim == 2) ? domain->data_jbegin.getValue() : -1; ARRAY(int, 1) data_i_index = domain->data_i_index.getValue() , data_j_index = domain->data_j_index.getValue() ; /*std::cout << data_n_index << " : " << data_i_index.size() << " : " << data_j_index.size() << std::endl;*/ ARRAY(bool, 2) mask = domain->mask.getValue() ; int indexCount = 0; for(int l = 0; l < size ; l++) { for(int n = 0, i = 0, j = 0; n < data_n_index; n++) { int temp_i = (*data_i_index)[n] + data_ibegin, temp_j = (data_dim == 1) ? -1 : (*data_j_index)[n] + data_jbegin; i = (data_dim == 1) ? (temp_i - 2) % ni : (temp_i - 1) ; j = (data_dim == 1) ? (temp_i - 2) / ni : (temp_j - 1) ; if ((i >= 0 && i < ni) && (j >= 0 && j < nj) && (*mask)[i][j]) indexCount++ ; } } //std::cout << indexCount << std::endl; ARRAY_ASSIGN(this->storeIndex , int, 1, [indexCount]); ARRAY_ASSIGN(this->out_l_index, int, 1, [indexCount]); ARRAY_ASSIGN(this->out_i_index, int, 1, [indexCount]); ARRAY_ASSIGN(this->out_j_index, int, 1, [indexCount]); for(int count = 0, indexCount = 0, l = 0; l < size; l++) { for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++) { int temp_i = (*data_i_index)[n] + data_ibegin, temp_j = (data_dim == 1) ? -1 : (*data_j_index)[n] + data_jbegin; i = (data_dim == 1) ? (temp_i - 2) % ni : (temp_i - 1) ; j = (data_dim == 1) ? (temp_i - 2) / ni : (temp_j - 1) ; if ((i >= 0 && i < ni) && (j >= 0 && j < nj) && (*mask)[i][j]) { (*this->storeIndex)[indexCount] = count ; (*this->out_l_index)[indexCount] = l ; (*this->out_i_index)[indexCount] = i ; (*this->out_j_index)[indexCount] = j ; indexCount++ ; } } } } //---------------------------------------------------------------- boost::shared_ptr CGrid::CreateGrid(boost::shared_ptr domain) { StdString new_id = StdString("__") + domain->getId() + StdString("__") ; boost::shared_ptr grid = CGroupFactory::CreateChild(CObjectFactory::GetObject ("grid_definition"), new_id); grid->domain_ref.setValue(domain->getId()); return (grid); } boost::shared_ptr CGrid::CreateGrid(boost::shared_ptr domain, boost::shared_ptr axis) { StdString new_id = StdString("__") + domain->getId() + StdString("_") + axis->getId() + StdString("__") ; boost::shared_ptr grid = CGroupFactory::CreateChild(CObjectFactory::GetObject ("grid_definition"), new_id); grid->domain_ref.setValue(domain->getId()); grid->axis_ref.setValue(axis->getId()); return (grid); } //---------------------------------------------------------------- template <> void CGrid::outputField (const ARRAY(double, 1) stored, ARRAY(double, 3) field) const { for(StdSize n = 0; n < storeIndex->num_elements(); n++) (*field)[(*out_i_index)[n]][(*out_j_index)[n]][(*out_l_index)[n]] = (*stored)[n] ; } template <> void CGrid::outputField (const ARRAY(double, 1) stored, ARRAY(double, 2) field) const { for(StdSize n = 0; n < storeIndex->num_elements(); n++) (*field)[(*out_i_index)[n]][(*out_j_index)[n]] = (*stored)[n] ; } template <> void CGrid::outputField (const ARRAY(double, 1) stored, ARRAY(double, 1) field) const { for(StdSize n = 0; n < storeIndex->num_elements(); n++) (*field)[(*out_i_index)[n]] = (*stored)[n] ; } void CGrid::storeField_arr (const double * const data, ARRAY(double, 1) stored) const { const StdSize size = storeIndex->num_elements() ; stored->resize(boost::extents[size]) ; for(StdSize i = 0; i < size; i++) (*stored)[i] = data[(*storeIndex)[i]] ; } ///--------------------------------------------------------------- } // namespace tree } // namespace xmlioserver