24#ifndef DUAL_FUNCTORS_3D_HH
25#define DUAL_FUNCTORS_3D_HH
35template <
typename T,
typename DESCRIPTOR>
44 this->
getName() =
"dPhysDissipationDf";
47template <
typename T,
typename DESCRIPTOR>
50 T omega = _converter.getLatticeRelaxationFrequency();
51 T dt = _converter.getConversionFactorTime();
63 this->_blockLattice.get(latticeR).computeAllMomenta(rho, u, pi);
65 for (
int i=0; i<DESCRIPTOR::q; i++) {
69 T pi2[DESCRIPTOR::d][DESCRIPTOR::d];
88 for (
int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
89 for (
int iDim=0; iDim < DESCRIPTOR::d; ++iDim) {
90 for (
int jDim=0; jDim < DESCRIPTOR::d; ++jDim) {
92 for (
int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
93 dPidf2ndTerm += descriptors::c<DESCRIPTOR>(iPop)[iDim] * descriptors::c<DESCRIPTOR>(iPop)[jDim]
96 T dpidf = descriptors::c<DESCRIPTOR>(jPop,iDim)*descriptors::c<DESCRIPTOR>(jPop,jDim) - dPidf2ndTerm;
98 dDdf[jPop] += 2.*(pi2[iDim][jDim]*(dpidf - pi2[iDim][jDim]/2./rho*2.));
101 dDdf[jPop] *=
util::pow(omega*descriptors::invCs2<T,DESCRIPTOR>()/rho,2)/2.*_converter.getPhysViscosity()/_converter.getLatticeViscosity()/dt/dt;
106template <
typename T,
typename DESCRIPTOR>
111 this->
getName() =
"dPhysDissipationDf";
122template <
typename T,
typename DESCRIPTOR>
125 auto& load = this->_sLattice.getLoadBalancer();
126 if (load.isLocal(input[0])) {
127 return this->getBlockF(load.loc(input[0]))(output, &input[1]);
135template <
typename T,
typename DESCRIPTOR>
140 int nDim,
int extractDim)
141 :
BlockLatticeF3D<T,DESCRIPTOR>(blockLattice,DESCRIPTOR::q*DESCRIPTOR::d),
143 _converter(converter),
144 _nDim(nDim), _extractDim(extractDim)
146 this->
getName() =
"dPhysVelocityDf";
149template <
typename T,
typename DESCRIPTOR>
152 for (
int i=0; i<DESCRIPTOR::d*DESCRIPTOR::q; i++) {
153 dVelocityDf[i] = T();
165 this->_blockLattice.get(latticeR).computeRhoU(rho, u);
167 for (
int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
168 for (
int iDim=0; iDim < DESCRIPTOR::d; ++iDim) {
169 if (iDim != _extractDim && _extractDim != -1) {
170 dVelocityDf[jPop*DESCRIPTOR::d + iDim] = T(0);
173 dVelocityDf[jPop*DESCRIPTOR::d + iDim] = (descriptors::c<DESCRIPTOR>(jPop,iDim)-u[iDim])/rho;
180template <
typename T,
typename DESCRIPTOR>
185 this->
getName() =
"dPhysVelocityDf";
197template <
typename T,
typename DESCRIPTOR>
204 this->
getName() =
"dPhysVelocityDf";
216template <
typename T,
typename DESCRIPTOR>
219 auto& load = this->_sLattice.getLoadBalancer();
220 if (load.isLocal(input[0])) {
221 return this->getBlockF(load.loc(input[0]))(output, &input[1]);
229template <
typename T,
typename DESCRIPTOR>
237 using namespace functor_dsl;
239 auto wantedLatticeF = restrictF(wantedF.toShared(), sLattice);
240 auto differenceF = norm<2>(f.toShared() - wantedLatticeF, indicatorF.toShared());
242 return util::pow(differenceF, 2) / T(2.0);
245 this->getName() =
"differenceObjective";
248template<
typename T,
typename DESCRIPTOR>
254 f->getSuperLattice(),
255 std::static_pointer_cast<
SuperF3D<T,T>>(f.toShared()),
256 std::forward<decltype(wantedF)>(wantedF),
257 std::forward<decltype(indicatorF)>(indicatorF))
260template<
typename T,
typename DESCRIPTOR>
269 std::forward<decltype(f)>(f),
270 std::forward<decltype(wantedF)>(wantedF),
271 geometry.getMaterialIndicator(material))
275template <
typename T,
typename DESCRIPTOR>
287 _indicatorF(indicatorF),
290 this->
getName() =
"BlockDdifferenceObjectiveDf";
293template <
typename T,
typename DESCRIPTOR>
296 for (
int i=0; i < DESCRIPTOR::q; i++) {
300 if (_indicatorF(latticeR)) {
301 const int nDim = _f.getTargetDim();
303 std::vector<T> dJdD(nDim,T());
309 _wantedF(wantedF, latticeR);
311 T dFdF[nDim*DESCRIPTOR::q];
312 _dFdF(dFdF,latticeR);
314 for (
int iDim=0; iDim<nDim; iDim++) {
315 dJdD[iDim] = (f[iDim] - wantedF[iDim]) * _weight*_weight;
317 for (
int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
318 dJdF[jPop] += dJdD[iDim] * dFdF[jPop*nDim + iDim];
326template <
typename T,
typename DESCRIPTOR>
332 :
SuperLatticeF3D<T,DESCRIPTOR>(f->getSuperLattice(), f->getTargetDim()),
334 _dFdF(std::move(dFdF)),
335 _wantedF(std::forward<decltype(wantedF)>(wantedF), f->getSuperLattice()),
336 _indicatorF(std::move(indicatorF))
338 this->
getName() =
"dDifferenceObjectiveDf";
340 const T weight =
util::pow(_f->getSuperStructure().getCuboidGeometry().getMinDeltaR(), 3);
342 for (
int iC = 0; iC < this->
getSuperLattice().getLoadBalancer().size(); ++iC) {
347 _dFdF->getBlockF(iC),
348 _wantedF.getBlockF(iC),
349 _indicatorF->getBlockIndicatorF(iC),
355template <
typename T,
typename DESCRIPTOR>
358 for (
int i=0; i < DESCRIPTOR::q; ++i) {
362 auto& load = this->getSuperLattice().getLoadBalancer();
364 if (load.isLocal(latticeR[0])) {
365 return this->getBlockF(load.loc(latticeR[0]))(dJdF, &latticeR[1]);
373template<
typename T,
typename DESCRIPTOR>
381 using namespace functor_dsl;
383 auto wantedLatticeF = restrictF(wantedF.toShared(), sLattice);
384 auto relativeDifferenceF = norm<2>(f.toShared() - wantedLatticeF, indicatorF.toShared()) /
385 norm<2>(wantedLatticeF, indicatorF.toShared());
387 return pow(relativeDifferenceF, 2) / T(2.0);
390 this->getName() =
"relativeDifferenceObjective";
393template<
typename T,
typename DESCRIPTOR>
399 f->getSuperLattice(),
400 std::static_pointer_cast<
SuperF3D<T,T>>(f.toShared()),
401 std::forward<decltype(wantedF)>(wantedF),
402 std::forward<decltype(indicatorF)>(indicatorF))
405template<
typename T,
typename DESCRIPTOR>
411 std::vector<int> materials)
414 std::forward<decltype(f)>(f),
415 std::forward<decltype(wantedF)>(wantedF),
416 geometry.getMaterialIndicator(materials))
419template<
typename T,
typename DESCRIPTOR>
428 std::forward<decltype(f)>(f),
429 std::forward<decltype(wantedF)>(wantedF),
430 geometry.getMaterialIndicator(material))
433template<
typename T,
typename DESCRIPTOR>
441 using namespace functor_dsl;
444 auto relativeDifferenceF = norm<2>(f.toShared() - wantedF.toShared(), indicatorF.toShared()) /
445 norm<2>(wantedF.toShared(), indicatorF.toShared());
447 return pow(relativeDifferenceF, 2) / T(2.0);
450 this->getName() =
"relativeDifferenceObjective";
454template <
typename T,
typename DESCRIPTOR>
463 BlockF3D<T>(blockStructure, DESCRIPTOR::q),
464 _f(f), _dFdF(dFdF), _wantedF(wantedF), _indicatorF(indicatorF),
465 _globalValue(globalValue), _weight(weight)
467 this->
getName() =
"BlockDrelativeDifferenceObjectiveDf";
470template <
typename T,
typename DESCRIPTOR>
473 for (
int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
477 if (_indicatorF(latticeR)) {
478 const int nDim = DESCRIPTOR::d;
486 _wantedF(wantedF, latticeR);
488 T dFdF[nDim*DESCRIPTOR::q] {};
489 _dFdF(dFdF, latticeR);
491 for (
int iDim=0; iDim < nDim; ++iDim) {
492 dJdD[iDim] = (f[iDim] - wantedF[iDim]) / _globalValue * _weight*_weight;
494 for (
int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
495 dJdF[jPop] += dJdD[iDim] * dFdF[jPop*nDim + iDim];
503template <
typename T,
typename DESCRIPTOR>
510 :
SuperF3D<T,T>(sLattice, DESCRIPTOR::q),
512 _dFdF(std::move(dFdF)),
513 _wantedF(std::forward<decltype(wantedF)>(wantedF), sLattice),
514 _indicatorF(std::move(indicatorF))
516 this->
getName() =
"dRelativeDifferenceObjectiveDf";
520 wantedFlp(output,
nullptr);
522 const T globalValue =
util::pow(output[0], 2);
523 const T weight =
util::pow(_f->getSuperStructure().getCuboidGeometry().getMinDeltaR(), 3);
530 _dFdF->getBlockF(iC),
531 _wantedF.getBlockF(iC),
532 _indicatorF->getBlockIndicatorF(iC),
539template <
typename T,
typename DESCRIPTOR>
546 std::vector<int> materials)
548 std::forward<decltype(f)>(f),
549 std::forward<decltype(dFdF)>(dFdF),
550 std::forward<decltype(wantedF)>(wantedF),
551 geometry.getMaterialIndicator(materials))
554template <
typename T,
typename DESCRIPTOR>
563 std::forward<decltype(f)>(f),
564 std::forward<decltype(dFdF)>(dFdF),
565 std::forward<decltype(wantedF)>(wantedF),
566 geometry.getMaterialIndicator(material))
569template <
typename T,
typename DESCRIPTOR>
572 for (
int i=0; i < DESCRIPTOR::q; ++i) {
578 if (load.isLocal(latticeR[0])) {
579 return this->getBlockF(load.loc(latticeR[0]))(dJdF, &latticeR[1]);
586template <
typename T,
typename DESCRIPTOR>
593 :
SuperF3D<T,T>(sLattice, DESCRIPTOR::q),
595 _dFdF(std::move(dFdF)),
596 _wantedF(std::move(wantedF)),
597 _indicatorF(std::move(indicatorF))
599 this->
getName() =
"dRelativeDifferenceObjectiveDf_Lattice";
603 wantedFlp(output,
nullptr);
605 const T globalValue =
util::pow(output[0], 2);
614 _dFdF->getBlockF(iC),
615 _wantedF->getBlockF(iC),
616 _indicatorF->getBlockIndicatorF(iC),
623template <
typename T,
typename DESCRIPTOR>
626 for (
int i=0; i < DESCRIPTOR::q; ++i) {
630 auto& load = _f->getSuperStructure().getLoadBalancer();
632 if (load.isLocal(latticeR[0])) {
633 return this->getBlockF(load.loc(latticeR[0]))(dJdF, &latticeR[1]);
641template <
typename T,
typename DESCRIPTOR>
650 BlockF3D<T>(blockStructure, DESCRIPTOR::q),
651 _f(f), _dFdF(dFdF), _wantedF(wantedF), _indicatorF(indicatorF),
652 _extractDim(f.getExtractDim()), _globalValue(globalValue), _weight(weight)
654 this->
getName() =
"BlockDrelativeDifferenceObjectiveComponentDf";
657template <
typename T,
typename DESCRIPTOR>
660 for (
int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
664 if (_indicatorF(latticeR)) {
665 const int nDim = DESCRIPTOR::d;
673 _wantedF(wantedF, latticeR);
675 T dFdF[nDim*DESCRIPTOR::q] {};
676 _dFdF(dFdF, latticeR);
678 for (
int iDim=0; iDim < nDim; ++iDim) {
679 if (iDim == _extractDim) {
682 dJdD[iDim] = (f[0] - wantedF[0]) / _globalValue * _weight*_weight;
685 for (
int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
686 dJdF[jPop] += dJdD[iDim] * dFdF[jPop*nDim + iDim];
694template <
typename T,
typename DESCRIPTOR>
701 :
SuperF3D<T,T>(sLattice, DESCRIPTOR::q),
702 _f(std::forward<decltype(f)>(f), extractDim),
703 _dFdF(std::move(dFdF)),
704 _wantedF(std::forward<decltype(wantedF)>(wantedF), sLattice),
705 _indicatorF(std::move(indicatorF))
707 this->
getName() =
"dRelativeDifferenceObjectiveDf";
711 wantedFlp(output,
nullptr);
713 const T globalValue =
util::pow(output[0], 2);
721 _dFdF->getBlockF(iC),
722 _wantedF.getBlockF(iC),
723 _indicatorF->getBlockIndicatorF(iC),
730template <
typename T,
typename DESCRIPTOR>
733 for (
int i=0; i < DESCRIPTOR::q; ++i) {
737 auto& load = _f.getSuperStructure().getLoadBalancer();
739 if (load.isLocal(latticeR[0])) {
740 return this->getBlockF(load.loc(latticeR[0]))(dJdF, &latticeR[1]);
AnalyticalF are applications from DD to XD, where X is set by the constructor.
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
Base block indicator functor.
represents all functors that operate on a DESCRIPTOR in general, e.g. getVelocity(),...
Platform-abstracted block lattice for external access and inter-block interaction.
Smart pointer for managing the various ways of passing functors around.
std::string & getName()
read and write access to name
represents all functors that operate on a SuperStructure<T,3> in general
SuperStructure< T, 3 > & getSuperStructure()
BlockF3D< W > & getBlockF(int iCloc)
std::vector< std::unique_ptr< BlockF3D< T > > > _blockF
Super functors may consist of several BlockF3D<W> derived functors.
Representation of a statistic for a parallel 2D geometry.
identity functor for memory management
Base indicator functor (discrete)
represents all functors that operate on a SuperLattice in general, e.g. getVelocity(),...
SuperLattice< T, DESCRIPTOR > & getSuperLattice()
represents all functors that operate on a DESCRIPTOR with output in Phys, e.g. physVelocity(),...
Super class maintaining block lattices for a cuboid decomposition.
BlockLattice< T, DESCRIPTOR > & getBlock(int locC)
Return BlockLattice with local index locC.
Functor that returns the Lp norm over omega of the the euklid norm of the input functor.
CuboidGeometry< T, D > & getCuboidGeometry()
Read and write access to cuboid geometry.
int getOverlap()
Read and write access to the overlap.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
Conversion between physical and lattice units, as well as discretization.
functor to compute 0.5*(f-f_wanted)^2 on a lattice
BlockDdifferenceObjectiveDf3D(BlockLattice< T, DESCRIPTOR > &blockLattice, BlockF3D< T > &f, BlockF3D< T > &dFdF, BlockF3D< T > &wantedF, BlockIndicatorF3D< T > &indicatorF, T weight)
bool operator()(T output[], const int input[])
has to be implemented for 'every' derived class
functor to compute 0.5*(f[extractDim]-f_wanted[0])^2/f_wanted^2 on a lattice
bool operator()(T output[], const int input[])
has to be implemented for 'every' derived class
BlockDrelativeDifferenceObjectiveComponentDf3D(BlockStructureD< 3 > &blockStructure, BlockExtractComponentF3D< T > &f, BlockF3D< T > &dFdF, BlockF3D< T > &wantedF, BlockIndicatorF3D< T > &indicatorF, T globalValue, T weight)
functor to compute 0.5(f-f_wanted)^2/f_wanted^2 on a lattice
bool operator()(T output[], const int input[])
has to be implemented for 'every' derived class
BlockDrelativeDifferenceObjectiveDf3D(BlockStructureD< 3 > &blockStructure, BlockF3D< T > &f, BlockF3D< T > &dFdF, BlockF3D< T > &wantedF, BlockIndicatorF3D< T > &indicatorF, T globalValue, T weight)
functor to get the pointwise dual dissipation density on local lattices, if globIC is not on the loca...
bool operator()(T output[], const int input[])
has to be implemented for 'every' derived class
BlockLatticeDphysDissipationDf3D(BlockLattice< T, DESCRIPTOR > &blockLattice, int overlap, const UnitConverter< T, DESCRIPTOR > &converter)
functor to get pointwise dual velocity density on local lattices, if globIC is not on the local proce...
BlockLatticeDphysVelocityDf3D(BlockLattice< T, DESCRIPTOR > &blockLattice, int overlap, const UnitConverter< T, DESCRIPTOR > &converter, int nDim, int extractDim)
bool operator()(T output[], const int input[])
has to be implemented for 'every' derived class
bool operator()(T output[], const int input[])
DdifferenceObjectiveDf3D(FunctorPtr< SuperLatticePhysF3D< T, DESCRIPTOR > > &&f, FunctorPtr< SuperLatticePhysF3D< T, DESCRIPTOR > > &&dFdF, FunctorPtr< AnalyticalF3D< T, T > > &&wantedF, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
functor to compute 0.5*L2Norm(f-f_wanted)^2 on a lattice
DifferenceObjective3D(SuperLattice< T, DESCRIPTOR > &sLattice, FunctorPtr< SuperF3D< T, T > > &&f, FunctorPtr< AnalyticalF3D< T, T > > &&wantedF, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
DrelativeDifferenceObjectiveComponentDf3D(SuperLattice< T, DESCRIPTOR > &sLattice, FunctorPtr< SuperF3D< T, T > > &&f, int extractDim, FunctorPtr< SuperF3D< T, T > > &&dFdF, FunctorPtr< AnalyticalF3D< T, T > > &&wantedF, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
bool operator()(T output[], const int input[])
DrelativeDifferenceObjectiveDf3D_Lattice(SuperLattice< T, DESCRIPTOR > &sLattice, FunctorPtr< SuperF3D< T, T > > &&f, FunctorPtr< SuperF3D< T, T > > &&dFdF, FunctorPtr< SuperF3D< T, T > > &&wantedF, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
bool operator()(T output[], const int input[])
functor to compute 0.5(f-f_wanted)^2/f_wanted^2 on a lattice
bool operator()(T output[], const int input[])
DrelativeDifferenceObjectiveDf3D(SuperLattice< T, DESCRIPTOR > &sLattice, FunctorPtr< SuperF3D< T, T > > &&f, FunctorPtr< SuperF3D< T, T > > &&dFdF, FunctorPtr< AnalyticalF3D< T, T > > &&wantedF, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
functor to compute 0.5*L2Norm(f-f_wanted)^2/L2Norm(f_wanted)^2 on a lattice
RelativeDifferenceObjective3D(SuperLattice< T, DESCRIPTOR > &sLattice, FunctorPtr< SuperF3D< T, T > > &&f, FunctorPtr< AnalyticalF3D< T, T > > &&wantedF, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
SuperLatticeDphysDissipationDf3D(SuperLattice< T, DESCRIPTOR > &sLattice, const UnitConverter< T, DESCRIPTOR > &converter)
bool operator()(T output[], const int input[])
bool operator()(T output[], const int input[])
SuperLatticeDphysVelocityDf3D(SuperLattice< T, DESCRIPTOR > &sLattice, const UnitConverter< T, DESCRIPTOR > &converter)
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Top level namespace for all of OpenLB.
static T equilibrium(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
Compute number of elements of a symmetric d-dimensional tensor.