$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

multiGridDataField2D.hh

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 /* Main author: Daniel Lagrava
00026  **/
00027 
00028 #ifndef MULTI_GRID_DATA_FIELD_2D_HH
00029 #define MULTI_GRID_DATA_FIELD_2D_HH
00030 
00031 #include "core/globalDefs.h"
00032 #include "multiGrid/multiGridDataField2D.h"
00033 #include "multiGrid/multiGridGenerator2D.h"
00034 
00035 
00036 namespace plb {
00037 
00038 template<typename T>
00039 MultiGridScalarField2D<T>::MultiGridScalarField2D (
00040                         MultiGridManagement2D management_,
00041                         std::vector<BlockCommunicator2D* > communicators_,
00042                         std::vector<CombinedStatistics*> combinedStatistics_, 
00043                         plint behaviorLevel_ )
00044             : MultiGrid2D(management_, behaviorLevel_)
00045 {
00046     allocateFields(communicators_,combinedStatistics_);
00047 }
00048 
00049 template<typename T>
00050 MultiGridScalarField2D<T>::MultiGridScalarField2D (
00051                         MultiGridManagement2D management_,
00052                         plint behaviorLevel_ )
00053     : MultiGrid2D(management_, behaviorLevel_)
00054 {
00055     allocateFields();
00056 }
00057 
00058 template<typename T>
00059 MultiGridScalarField2D<T>::MultiGridScalarField2D(MultiGridScalarField2D<T> const& rhs)
00060     : MultiGrid2D(rhs)
00061 {
00062     allocateFields();
00063 }
00064 
00065 template<typename T>
00066 MultiGridScalarField2D<T>::MultiGridScalarField2D(MultiGrid2D const& rhs, Box2D subDomain, bool crop)
00067     : MultiGrid2D(extractManagement(rhs.getMultiGridManagement(),subDomain,crop),rhs.getBehaviorLevel())
00068 {
00069     allocateFields();
00070 }
00071 
00072 
00073 template<typename T>
00074 MultiGridScalarField2D<T>::~MultiGridScalarField2D(){
00075     for (plint iLevel=0; iLevel<(plint)fields.size(); ++iLevel){
00076         delete fields[iLevel];
00077     }
00078 }
00079 
00080 template<typename T>
00081 void MultiGridScalarField2D<T>::reset(){
00082     for (plint iLevel=0; iLevel<(plint)fields.size(); ++iLevel){
00083         fields[iLevel]->reset();
00084     }
00085 }
00086 
00087 template<typename T>
00088 T& MultiGridScalarField2D<T>::get(plint iX, plint iY){
00089     return fields[this->getBehaviorLevel()]->get(iX,iY);
00090 }
00091 
00092 template<typename T>
00093 T const& MultiGridScalarField2D<T>::get(plint iX, plint iY) const {
00094     return fields[this->getBehaviorLevel()]->get(iX,iY);
00095 }
00096 
00097 template<typename T>
00098 MultiScalarField2D<T>& MultiGridScalarField2D<T>::getComponent(plint level){
00099     PLB_PRECONDITION(level<(plint)fields.size());
00100     return *fields[level];
00101 }
00102 
00103 template<typename T>
00104 MultiScalarField2D<T> const& MultiGridScalarField2D<T>::getComponent(plint level) const{
00105     PLB_PRECONDITION(level<(plint)fields.size());
00106     return *fields[level];
00107 }
00108 
00110 template<typename T>
00111 void MultiGridScalarField2D<T>::allocateFields(){
00112     fields = generateScalarFields<T>( this->getMultiGridManagement(),
00113                                       defaultMultiGridPolicy2D().getBlockCommunicator<T>(this->getNumLevels()),
00114                                       defaultMultiGridPolicy2D().getCombinedStatistics(this->getNumLevels()) );
00115 }
00116 
00117 template<typename T>
00118 void MultiGridScalarField2D<T>::allocateFields( std::vector<BlockCommunicator2D* > communicators,
00119                                                 std::vector<CombinedStatistics*> combinedStatistics ){
00120     fields = generateScalarFields<T>( this->getMultiGridManagement(),
00121                                       communicators, combinedStatistics );
00122 }
00123 
00124 
00125 
00126 template<typename T>
00127 int MultiGridScalarField2D<T>::getBlockId() const {
00128     return fields[0]->getStaticId();
00129 }
00130 
00131 template<typename T>
00132 std::auto_ptr<MultiScalarField2D<T> > MultiGridScalarField2D<T>::convertToCoarsest(plint dimDx, plint dimDt){
00133     
00134 //TODO: modify avec new functions
00135 //     plint levels = this->getNumLevels();
00136 // 
00137 //     MultiScalarField2D<T> *copy, *tmp;
00138 //     copy = joinMultiScalarInCoarsest(
00139 //         *fields[levels-2],*fields[levels-1], dimDx, dimDt );
00140 // 
00141 //     tmp=copy;
00142 // 
00143 //     for (plint iLevel=levels-2; iLevel>0; --iLevel){
00144 //         copy = joinMultiScalarInCoarsest(
00145 //                     *fields[iLevel-1],*tmp, dimDx, dimDt );
00146 //         delete tmp; // erase the old value of copy
00147 //         tmp = copy; // keep always a pointer over copy
00148 //     }
00149 //     
00150 //     return std::auto_ptr<MultiScalarField2D<T> >(copy);
00151 }
00152 
00153 template<typename T>
00154 std::auto_ptr<MultiScalarField2D<T> > MultiGridScalarField2D<T>::convertToFinest(plint dimDx, plint dimDt){
00155     
00156 //TODO: modify avec new functions
00157 //     MultiScalarField2D<T> *copy, *tmp;
00158 //     copy = joinMultiScalarInFinest(
00159 //         *fields[0],*fields[1], dimDx, dimDt );
00160 //         
00161 //     tmp=copy;
00162 //                     
00163 //     for (plint iLevel=2; iLevel<(plint)fields.size(); ++iLevel){
00164 //         copy = joinMultiScalarInFinest(
00165 //                     *tmp,*fields[iLevel], dimDx, dimDt );
00166 //         delete tmp; // erase the old value of copy
00167 //         tmp = copy; // keep always a pointer over copy
00168 //     }
00169 //         
00170 //     return std::auto_ptr<MultiScalarField2D<T> >(copy);
00171 }
00172 
00173 
00174 /* ************** MultiGridTensorField2D ******************* */
00175 
00176 template<typename T, int nDim>
00177 MultiGridTensorField2D<T,nDim>::MultiGridTensorField2D ( MultiGridManagement2D management_,
00178                                                     std::vector<BlockCommunicator2D* > communicators_,
00179                                                     std::vector<CombinedStatistics*> combinedStatistics_, 
00180                                                     plint behaviorLevel_ )
00181 {
00182     allocateFields(communicators_,combinedStatistics_);
00183 }
00184 
00185 template<typename T, int nDim>
00186 MultiGridTensorField2D<T,nDim>::MultiGridTensorField2D (
00187                 MultiGridManagement2D management_,
00188                 plint behaviorLevel_ )
00189 {
00190     allocateFields( defaultMultiGridPolicy2D().getBlockCommunicator<T>(this->getNumLevels()),
00191                     defaultMultiGridPolicy2D().getCombinedStatistics(this->getNumLevels()) );
00192 }
00193                 
00194 template<typename T, int nDim>
00195 MultiGridTensorField2D<T,nDim>::MultiGridTensorField2D(MultiGridTensorField2D<T,nDim> const& rhs)
00196 {
00197     allocateFields();
00198 }
00199 
00200 template<typename T, int nDim>
00201 MultiGridTensorField2D<T,nDim>::MultiGridTensorField2D(MultiGrid2D const& rhs)
00202         : MultiGrid2D(rhs.getMultiGridManagement(),rhs.getBehaviorLevel())
00203 {
00204     allocateFields();
00205 }
00206 
00207 template<typename T, int nDim>
00208 MultiGridTensorField2D<T,nDim>::MultiGridTensorField2D(
00209                         MultiGrid2D const& rhs, 
00210                         Box2D subDomain, bool crop)
00211         : MultiGrid2D(extractManagement(rhs.getMultiGridManagement(),subDomain,crop),rhs.getBehaviorLevel())
00212 {
00213     allocateFields();
00214 }
00215 
00216 
00217 template<typename T, int nDim>
00218 MultiGridTensorField2D<T,nDim>::~MultiGridTensorField2D(){
00219     for (pluint iLevel=0; iLevel<fields.size(); ++iLevel){
00220         delete fields[iLevel];
00221     }
00222 }
00223 
00224 
00225 template<typename T, int nDim>
00226 void MultiGridTensorField2D<T,nDim>::reset(){
00227     for (pluint iLevel=0; iLevel<fields.size(); ++iLevel){
00228         fields[iLevel]->reset();
00229     }
00230 }
00231 
00232 template<typename T, int nDim>
00233 Array<T,nDim>& MultiGridTensorField2D<T,nDim>::get(plint iX, plint iY){
00234     return fields[this->getBehaviorLevel()]->get(iX,iY);
00235 }
00236 
00237 template<typename T, int nDim>
00238 Array<T,nDim> const& MultiGridTensorField2D<T,nDim>::get(plint iX, plint iY) const{
00239     return fields[this->getBehaviorLevel()]->get(iX,iY);
00240 }
00241 
00242 template<typename T, int nDim>
00243 MultiTensorField2D<T,nDim>& MultiGridTensorField2D<T,nDim>::getComponent(plint level){
00244     PLB_PRECONDITION(level<(plint)fields.size());
00245     return *fields[level];
00246 }
00247 
00248 template<typename T, int nDim>
00249 MultiTensorField2D<T,nDim> const& MultiGridTensorField2D<T,nDim>::getComponent(plint level) const{
00250     PLB_PRECONDITION(level<(plint)fields.size());
00251     return *fields[level];
00252 }
00253 
00254 template<typename T, int nDim>
00255 int MultiGridTensorField2D<T,nDim>::getBlockId() const{
00256     return fields[this->getBehaviorLevel()]->getStaticId();
00257 }
00258 
00260 template<typename T, int nDim>
00261 void MultiGridTensorField2D<T,nDim>::allocateFields(){
00262     fields = generateTensorFields<T,nDim>( this->getMultiGridManagement(),
00263                                       defaultMultiGridPolicy2D().getBlockCommunicator<T>(this->getNumLevels()),
00264                                       defaultMultiGridPolicy2D().getCombinedStatistics(this->getNumLevels()) );
00265 }
00266 
00267 template<typename T, int nDim>
00268 void MultiGridTensorField2D<T,nDim>::allocateFields( std::vector<BlockCommunicator2D* > communicators,
00269                                                 std::vector<CombinedStatistics*> combinedStatistics ){
00270     fields = generateTensorFields<T,nDim>(  this->getMultiGridManagement(),
00271                                             communicators, combinedStatistics );
00272 }
00273 
00274 
00275 template<typename T, int nDim>
00276 std::auto_ptr<MultiTensorField2D<T,nDim> > MultiGridTensorField2D<T,nDim>::convertToCoarsest(plint dimDx, plint dimDt){
00277 //TODO: modify avec new functions
00278 //     plint levels = this->getNumLevels();
00279 // 
00280 //     MultiTensorField2D<T,nDim> *copy, *tmp;
00281 //     copy = joinMultiTensorInCoarsest(
00282 //         *fields[levels-2],*fields[levels-1], dimDx, dimDt );
00283 // 
00284 //     tmp=copy;
00285 // 
00286 //     for (plint iLevel=levels-2; iLevel>0; --iLevel){
00287 //         copy = joinMultiTensorInCoarsest(
00288 //                     *fields[iLevel-1],*tmp, dimDx, dimDt );
00289 //         delete tmp; // erase the old value of copy
00290 //         tmp = copy; // keep always a pointer over copy
00291 //     }
00292 //     
00293 //     return std::auto_ptr<MultiTensorField2D<T,nDim> >(copy);
00294 }
00295 
00296 template<typename T, int nDim>
00297 std::auto_ptr<MultiTensorField2D<T,nDim> > MultiGridTensorField2D<T,nDim>::convertToFinest(plint dimDx, plint dimDt){
00298 //TODO: modify avec new functions
00299 //     MultiTensorField2D<T,nDim> *copy, *tmp;
00300 //     copy = joinMultiTensorInFinest(
00301 //         *fields[0],*fields[1], dimDx, dimDt );
00302 //         
00303 //     tmp=copy;
00304 //                     
00305 //     for (plint iLevel=2; iLevel<(plint)fields.size(); ++iLevel){
00306 //         copy = joinMultiTensorInFinest(
00307 //                     *tmp,*fields[iLevel], dimDx, dimDt );
00308 //         delete tmp; // erase the old value of copy
00309 //         tmp = copy; // keep always a pointer over copy
00310 //     }
00311 //         
00312 //     return std::auto_ptr<MultiTensorField2D<T,nDim> >(copy);
00313 }
00314 
00315 
00316 
00317 
00318 } // namespace plb
00319 
00320 #endif  // MULTI_GRID_DATA_FIELD_2D_HH
00321