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

externalFieldAccess.h

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 
00030 #ifndef EXTERNAL_FIELD_ACCESS_H
00031 #define EXTERNAL_FIELD_ACCESS_H
00032 
00033 #include "core/globalDefs.h"
00034 
00035 namespace plb {
00036 
00037 // The two classes and the function which follow implement a template mechanism
00038 //   to compute the force according to the following rule:
00039 //   - If there is a force in the external fields (ExternalField::sizeOfForce=d), return it
00040 //   - If there is no force in the external fields (ExternalField::sizeOfForce=0), return 0
00041 
00043 template<typename T, template<typename U> class Descriptor, plint numForceComponents>
00044 struct ExternalForceAccess {
00045     static T getComponent(Cell<T,Descriptor> const& cell, plint iD) {
00046         PLB_PRECONDITION( Descriptor<T>::d == Descriptor<T>::ExternalField::sizeOfForce );
00047         PLB_PRECONDITION( iD < Descriptor<T>::d);
00048         return *(cell.getExternal(Descriptor<T>::ExternalField::forceBeginsAt+iD));
00049     }
00050 };
00051 
00052 template<typename T, template<typename U> class Descriptor, class ExternalField>
00053 struct RhoBarJAccess {
00054     static T getRhoBar(Cell<T,Descriptor> const& cell) {
00055         Dynamics<T,Descriptor> const& dynamics = cell.getDynamics();
00056         return dynamics.computeRhoBar(cell);
00057     }
00058     static void getJ(Cell<T,Descriptor> const& cell, Array<T,Descriptor<T>::d>& j)
00059     {
00060         T rhoBar;
00061         Dynamics<T,Descriptor> const& dynamics = cell.getDynamics();
00062         dynamics.computeRhoBarJ(cell, rhoBar, j);
00063     }
00064     static void getRhoBarJ(Cell<T,Descriptor> const& cell, T& rhoBar, Array<T,Descriptor<T>::d>& j)
00065     {
00066         Dynamics<T,Descriptor> const& dynamics = cell.getDynamics();
00067         dynamics.computeRhoBarJ(cell, rhoBar, j);
00068     }
00069 };
00070 
00072 template<typename T, template<typename U> class Descriptor>
00073 struct ExternalForceAccess<T,Descriptor,0> {
00074     static T getComponent(Cell<T,Descriptor> const& cell, plint iD) {
00075         return T();
00076     }
00077 };
00078 
00080 template<typename T, template<typename U> class Descriptor>
00081 T getExternalForceComponent(Cell<T,Descriptor> const& cell, plint iD) {
00082     return ExternalForceAccess<T, Descriptor, Descriptor<T>::ExternalField::sizeOfForce>::getComponent(cell,iD);
00083 }
00084 
00085 template<typename T, template<typename U> class Descriptor>
00086 struct RhoBarJAccess<T,Descriptor,descriptors::RhoBarJdescriptor3D> {
00087     static void getRhoBar(Cell<T,Descriptor> const& cell) {
00088         return *(cell.getExternal(Descriptor<T>::ExternalField::rhoBarBeginsAt));
00089     }
00090     static void getJ(Cell<T,Descriptor> const& cell, Array<T,3>& j) {
00091         T* externalJ = cell.getExternal(Descriptor<T>::ExternalField::jBeginsAt);
00092         j[0] = externalJ[0];
00093         j[1] = externalJ[1];
00094         j[2] = externalJ[2];
00095     }
00096     static void getRhoBarJ(Cell<T,Descriptor> const& cell, T& rhoBar, Array<T,3>& j)
00097     {
00098         rhoBar = *(cell.getExternal(Descriptor<T>::ExternalField::rhoBarBeginsAt));
00099         T const* externalJ = cell.getExternal(Descriptor<T>::ExternalField::jBeginsAt);
00100         j[0] = externalJ[0];
00101         j[1] = externalJ[1];
00102         j[2] = externalJ[2];
00103     }
00104 };
00105 
00106 template<typename T, template<typename U> class Descriptor>
00107 struct RhoBarJAccess<T,Descriptor,descriptors::RhoBarJdescriptor2D> {
00108     static void getRhoBar(Cell<T,Descriptor> const& cell) {
00109         return *(cell.getExternal(Descriptor<T>::ExternalField::rhoBarBeginsAt));
00110     }
00111     static void getJ(Cell<T,Descriptor> const& cell, Array<T,2>& j) {
00112         T* externalJ = cell.getExternal(Descriptor<T>::ExternalField::jBeginsAt);
00113         j[0] = externalJ[0];
00114         j[1] = externalJ[1];
00115     }
00116     static void getRhoBarJ(Cell<T,Descriptor> const& cell, T& rhoBar, Array<T,2>& j)
00117     {
00118         rhoBar = *(cell.getExternal(Descriptor<T>::ExternalField::rhoBarBeginsAt));
00119         T* externalJ = cell.getExternal(Descriptor<T>::ExternalField::jBeginsAt);
00120         j[0] = externalJ[0];
00121         j[1] = externalJ[1];
00122     }
00123 };
00124 
00125 template<typename T, template<typename U> class Descriptor>
00126 T getRhoBar(Cell<T,Descriptor> const& cell) {
00127     return RhoBarJAccess<T, Descriptor, typename Descriptor<T>::ExternalField>::getRhoBar(cell);
00128 }
00129 
00130 template<typename T, template<typename U> class Descriptor>
00131 void getJ(Cell<T,Descriptor> const& cell, Array<T,Descriptor<T>::d>& j) {
00132     RhoBarJAccess<T, Descriptor, typename Descriptor<T>::ExternalField>::getJ(cell, j);
00133 }
00134 
00135 template<typename T, template<typename U> class Descriptor>
00136 void getRhoBarJ(Cell<T,Descriptor> const& cell, T& rhoBar, Array<T,Descriptor<T>::d>& j) {
00137     RhoBarJAccess<T, Descriptor, typename Descriptor<T>::ExternalField>::getRhoBarJ(cell, rhoBar, j);
00138 }
00139 
00140 }  // namespace plb
00141 
00142 #endif  // EXTERNAL_FIELD_ACCESS_H