/* This file is part of the OpenLB library
*
* Copyright (C) 2012-2017 Lukas Baron, Tim Dornieden, Mathias J. Krause,
* Albert Mink, Benjamin Förster, Adrian Kummerlaender
* E-mail contact: info@openlb.net
* The most recent release of OpenLB can be downloaded at
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef SUPER_BASE_F_3D_HH
#define SUPER_BASE_F_3D_HH
#include "superBaseF3D.h"
#include "blockBaseF3D.h"
namespace olb {
template
SuperF3D::SuperF3D(SuperStructure3D& superStructure, int targetDim)
: GenericF(targetDim,4), _superStructure(superStructure) { }
template
SuperStructure3D& SuperF3D::getSuperStructure()
{
return _superStructure;
}
template
int SuperF3D::getBlockFSize() const
{
OLB_ASSERT(_blockF.size() < INT32_MAX,
"cast from std::size_t to int unsafe");
return _blockF.size();
}
template
BlockF3D& SuperF3D::getBlockF(int iCloc)
{
OLB_ASSERT(iCloc < int(_blockF.size()) && iCloc >= 0,
"block functor index outside bounds");
return *(_blockF[iCloc]);
}
template
SuperDataF3D::SuperDataF3D(SuperData3D& superData)
: SuperF3D(superData, superData.getDataSize()),
_superData(superData)
{
for (int iC = 0; iC < _superData.getLoadBalancer().size(); ++iC) {
this->_blockF.emplace_back(
new BlockDataViewF3D(_superData.get(iC),
_superData.getOverlap())
);
}
}
template
bool SuperDataF3D::operator() (BaseType output[], const int input[])
{
const auto& load = _superData.getLoadBalancer();
if (load.rank(input[0]) == singleton::mpi().getRank()) {
return this->getBlockF(load.loc(input[0]))(output, &input[1]);
}
else {
return false;
}
}
template
SuperData3D& SuperDataF3D::getSuperData()
{
return _superData;
}
template
SuperIdentity3D::SuperIdentity3D(FunctorPtr>&& f)
: SuperF3D(f->getSuperStructure(), f->getTargetDim()),
_f(std::move(f))
{
this->getName() = "Id(" + _f->getName() + ")";
for (int iC = 0; iC < _f->getBlockFSize(); ++iC) {
this->_blockF.emplace_back(
new BlockIdentity3D(_f->getBlockF(iC)));
}
}
template
bool SuperIdentity3D::operator()(W output[], const int input[])
{
return _f(output, input);
}
template
SuperExtractComponentF3D::SuperExtractComponentF3D(
FunctorPtr>&& f, int extractDim)
: SuperF3D(f->getSuperStructure(), 1),
_f(std::move(f)),
_extractDim(extractDim)
{
this->getName() = _f->getName();
for (int iC = 0; iC < _f->getBlockFSize(); ++iC) {
this->_blockF.emplace_back(
new BlockExtractComponentF3D(_f->getBlockF(iC), extractDim));
}
}
template
int SuperExtractComponentF3D::getExtractDim()
{
return _extractDim;
}
template
bool SuperExtractComponentF3D::operator()(W output[], const int input[])
{
std::vector outTmp(_f->getTargetDim(), T{});
_f(outTmp.data(), input);
output[0] = outTmp[_extractDim];
return true;
}
template
SuperExtractComponentIndicatorF3D::SuperExtractComponentIndicatorF3D(
FunctorPtr>&& f, int extractDim,
FunctorPtr>&& indicatorF)
: SuperExtractComponentF3D(std::forward(f), extractDim),
_indicatorF(std::move(indicatorF))
{
this->getName() = f->getName();
for (int iC = 0; iC < f->getBlockFSize(); ++iC) {
this->_blockF.emplace_back(
new BlockExtractComponentIndicatorF3D(
f->getBlockF(iC), extractDim,
_indicatorF->getBlockIndicatorF(iC))
);
}
}
template
bool SuperExtractComponentIndicatorF3D::operator()(W output[], const int input[])
{
output[0] = W{};
if (_indicatorF(input)) {
return SuperExtractComponentF3D::operator()(output, input);
}
return true;
}
template
SuperExtractIndicatorF3D::SuperExtractIndicatorF3D(
FunctorPtr>&& f,
FunctorPtr>&& indicatorF)
: SuperF3D(f->getSuperStructure(), f->getTargetDim()),
_f(std::move(f)),
_indicatorF(std::move(indicatorF))
{
this->getName() = _f->getName();
for (int iC = 0; iC < f->getBlockFSize(); ++iC) {
this->_blockF.emplace_back(
new BlockExtractIndicatorF3D(
f->getBlockF(iC),
_indicatorF->getBlockIndicatorF(iC))
);
}
}
template
bool SuperExtractIndicatorF3D::operator()(W output[], const int input[])
{
for (int i = 0; i < this->getTargetDim(); ++i) {
output[i] = W{};
}
if (_indicatorF(input)) {
_f(output, input);
}
return true;
}
template
SuperDotProductF3D::SuperDotProductF3D(SuperF3D& f, T vector[])
: SuperF3D(f.getSuperStructure(),1 ), _f(f), _vector(vector)
{
this->getName() = _f.getName();
/*if ( (sizeof(_vector)/sizeof(T)) != _f.getTargetDim() ) {
std::cout << "WARNING: dimension of vectors do not match!" << std::endl;
exit(-1);
}*/
}
template
bool SuperDotProductF3D::operator()(W output[], const int input[])
{
T outTmp[3];
_f(outTmp, input);
output[0] = T();
for (int iDim=0; iDim<_f.getTargetDim(); iDim++) {
output[0] += outTmp[iDim]*_vector[iDim];
}
return true;
}
template
SuperIdentityOnSuperIndicatorF3D::SuperIdentityOnSuperIndicatorF3D(SuperF3D& f,
SuperIndicatorF3D& indicatorF,
W defaultValue)
: SuperF3D(f.getSuperStructure(),f.getTargetDim() ),
_f(f),
_indicatorF(indicatorF),
_defaultValue(defaultValue)
{
this->getName() = _f.getName() + std::string("_on_") + _indicatorF.getName();
std::swap( _f._ptrCalcC, this->_ptrCalcC );
}
template
bool SuperIdentityOnSuperIndicatorF3D::operator()(W output[], const int input[])
{
bool indic;
_indicatorF(&indic, input);
if (indic) {
_f(output, input);
}
else {
for (int i=0; i<_f.getTargetDim(); i++) {
output[i] = _defaultValue;
}
}
return true;
}
template
SuperLatticeF3D::SuperLatticeF3D(SuperLattice3D& superLattice,
int targetDim)
: SuperF3D(superLattice, targetDim), _sLattice(superLattice) { }
template
SuperLattice3D& SuperLatticeF3D::getSuperLattice()
{
return _sLattice;
}
template
SuperLatticeIdentity3D::SuperLatticeIdentity3D(
FunctorPtr>&& f)
: SuperLatticeF3D(f->getSuperLattice(), f->getTargetDim()),
_f(std::move(f))
{
this->getName() = "Id(" + _f->getName() + ")";
for (int iC = 0; iC < _f->getBlockFSize(); ++iC) {
this->_blockF.emplace_back(
new BlockLatticeIdentity3D(
static_cast&>(_f->getBlockF(iC))));
}
}
template
bool SuperLatticeIdentity3D::operator()(T output[], const int input[])
{
return _f(output, input);
}
template
SuperLatticePhysF3D::SuperLatticePhysF3D
(SuperLattice3D& sLattice, const UnitConverter& converter,
int targetDim)
: SuperLatticeF3D(sLattice, targetDim), _converter(converter) { }
template
UnitConverter const& SuperLatticePhysF3D::getConverter() const
{
return this->_converter;
}
template
SuperLatticeThermalPhysF3D::SuperLatticeThermalPhysF3D
(SuperLattice3D& sLattice, const ThermalUnitConverter& converter,
int targetDim)
: SuperLatticeF3D(sLattice, targetDim), _converter(converter) { }
template
ThermalUnitConverter const& SuperLatticeThermalPhysF3D::getConverter() const
{
return this->_converter;
}
template
ComposedSuperLatticeF3D::ComposedSuperLatticeF3D
(SuperLatticeF3D& f0, SuperLatticeF3D& f1,
SuperLatticeF3D& f2)
: SuperLatticeF3D(f0.getSuperLattice(), 3), _f0(f0), _f1(f1), _f2(f2)
{
this->getName() = "composedSuperLatticeF3D";
}
template
bool ComposedSuperLatticeF3D::operator() (T output[], const int input[])
{
T tmp[3] = {};
SuperIdentity3D ff0(_f0), ff1(_f1), ff2(_f2);
_f0(tmp,input);
output[0]=tmp[0];
_f1(tmp,input);
output[1]=tmp[0];
_f2(tmp,input);
output[2]=tmp[0];
return true;
}
} // end namespace olb
#endif