OpenLB 1.8.1
Loading...
Searching...
No Matches
analyticalF.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2012 Lukas Baron, Tim Dornieden, Mathias J. Krause, Albert Mink
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef ANALYTICAL_F_H
25#define ANALYTICAL_F_H
26
27#include <vector>
28#include <random>
29
30#include "analyticalBaseF.h"
34#include "utilities/adHelpers.h"
37
38
45namespace olb {
46
47template<typename T, typename S, bool> class SmoothIndicatorSphere3D;
48template<typename T, typename DESCRIPTOR> class RadiativeUnitConverter;
49
53
54template <unsigned D, typename T, typename S>
55class AnalyticalComposed final : public AnalyticalF<D,T,S> {
56private:
57 std::vector<std::reference_wrapper<AnalyticalF<D,T,S>>> _f;
58public:
59 template <unsigned otherD=D, typename = typename std::enable_if_t<otherD==2>>
61 : AnalyticalF<D,T,S>(2), _f{f0, f1}
62 {
63 this->getName() = "composed";
64 }
65 template <unsigned otherD=D, typename = typename std::enable_if_t<otherD==3>>
67 : AnalyticalF<D,T,S>(3), _f{f0, f1, f2}
68 {
69 this->getName() = "composed";
70 }
72 bool operator() (T output[], const S x[]) override;
73};
74
76template <unsigned D, typename T, typename S>
77class AnalyticalFfromCallableF final: public AnalyticalF<D,T,S> {
78private:
79 std::function<bool(T*,const S*)> _f;
80
81public:
82 template <typename F>
84 AnalyticalF<D,T,S>(typename decltype(std::function(f))::result_type{}.d),
85 _f([&,f](T* output, const S* input) -> bool {
86 auto out = f(input);
87 for (unsigned iD=0; iD < typename decltype(std::function(f))::result_type{}.d; ++iD) {
88 output[iD] = out[iD];
89 }
90 return true;
91 })
92 { }
93
94 bool operator() (T output[], const S input[]) override {
95 return _f(output, input);
96 }
97};
98
100template <unsigned D, typename T, typename S>
101class AnalyticalConst final: public AnalyticalF<D,T,S> {
102private:
103 // is constant return value of operator()
104 std::vector<T> _c;
105public:
106 AnalyticalConst(T value);
107 AnalyticalConst(T value0, T value1);
108 AnalyticalConst(T value0, T value1, T value2);
109 AnalyticalConst(const Vector<T,2>& value);
110 AnalyticalConst(const Vector<T,3>& value);
111 AnalyticalConst(const std::vector<T>& value);
112 bool operator() (T output[], const S x[]) override;
113
114 template<typename V, typename U>
116
117 template<typename V, typename U>
118 auto copyAs() const {
119 return exchange_type<V,U>(util::copyAs<V,T,util::StdVector>(_c));
120 }
121};
122
124template <unsigned D, typename T, typename S>
125class AnalyticalNormal final: public AnalyticalF<D,T,S> {
126private:
127 // is constant return value of operator()
128 std::vector<T> _mean;
129 T _stdDev;
130public:
131 AnalyticalNormal(std::vector<T> mean, T stdDev);
132 bool operator() (T output[], const S x[]) override;
133};
134
136template <unsigned D, typename T, typename S>
137class AnalyticalRandomBase : public AnalyticalF<D,T,S> {
138protected:
140 std::random_device rd;
141 std::mt19937 gen;
142};
143
145template <unsigned D, typename T, typename S, unsigned seed>
147protected:
149 std::random_device rd;
150 std::mt19937 gen;
151};
152
154template <unsigned D, typename T, typename S>
156public:
157 AnalyticalRandomUniform(T minVal=0., T maxVal=1.);
158 bool operator() (T output[], const S x[]) override;
159private:
160 std::uniform_real_distribution<T> distro;
161};
162
164template <unsigned D, typename T, typename S>
166public:
167 AnalyticalRandomNormal(T mean=0., T stdDev=1.);
168 bool operator() (T output[], const S x[]) override;
169protected:
170 std::normal_distribution<T> distro;
171};
172
174template <unsigned D, typename T, typename S, unsigned seed>
176public:
177 AnalyticalRandomSeededNormal(T mean=0., T stdDev=1.);
178 bool operator() (T output[], const S x[]) override;
179protected:
180 std::normal_distribution<T> distro;
181};
182
185template <unsigned D, typename T, typename S>
187public:
188 AnalyticalRandomTruncatedNormal(T mean=0., T stdDev=1., T n=3.);
189 bool operator() (T output[], const S x[]) override;
190private:
191 T _min;
192 T _max;
193};
194
195
197template <unsigned D, typename T, typename S>
198class AnalyticalRandomOld : public AnalyticalF<D,T,S> {
199public:
201 bool operator() (T output[], const S x[]) override;
202};
203
204
210template <typename T, typename S, typename DESCRIPTOR>
222
229template <typename T, typename S, typename DESCRIPTOR>
243
244
245
248template <unsigned D, typename T, typename S>
249class AnalyticalSquareWave : public AnalyticalF<D,T,S> {
250public:
251 AnalyticalSquareWave(T period=1, T amplitude=1, T difference=0.5);
252 bool operator() (T output[], const S x[]) override;
253protected:
257};
258
259
261template <unsigned D, typename T, typename S>
263public:
264 AnalyticalSmoothedSquareWave(T period=1, T amplitude=1, T difference=0.5, T epsilon=1.e-3);
265 bool operator() (T output[], const S x[]) override;
266protected:
268};
269
270
283template <unsigned D, typename U, typename T, typename S,
284 bool ComponentWise, bool ReturnArray>
286protected:
287 using return_type_g = std::conditional_t<ReturnArray,U*,U>;
288 using function_t = std::conditional_t<ComponentWise,
289 std::function<return_type_g(T)>, std::function<return_type_g(T*)>>;
290
293
294public:
298 template <typename G>
299 AnalyticalConcatenation(AnalyticalF<D,T,S>& f, G g, unsigned targetDim=1)
300 : AnalyticalF<D,U,S>((ComponentWise) ? f.getTargetDim() : targetDim),
301 _f(f), _g(g) { }
302
307 : AnalyticalF<D,U,S>(f.getTargetDim()), _f(f), _g(g) {
308 static_assert(ComponentWise);
309 static_assert(! std::is_pointer_v<U>);
310 }
311
315 // wrapped_U equals U or a pointer to U
316 template<typename wrapped_U>
318 AnalyticalF<D,T,S>& f, wrapped_U (*g)(T*), unsigned targetDim=1)
319 : AnalyticalF<D,U,S>(targetDim),
320 _f(f), _g(g) {
321 static_assert(! ComponentWise);
322 }
323
327 // wrapped_U equals U or a pointer to U
328 template<typename wrapped_U>
330 AnalyticalF<D,T,S>& f, wrapped_U (*g)(const T*), unsigned targetDim=1)
331 : AnalyticalF<D,U,S>(targetDim),
332 _f(f), _g(g) {
333 static_assert(! ComponentWise);
334 }
335
336 bool operator() (U output[], const S x[]) override {
337 T outputTmp[_f.getTargetDim()];
338 _f(outputTmp, x);
339 if constexpr (ComponentWise) {
340 for (int i = 0; i < _f.getTargetDim(); ++i) {
341 output[i] = _g(outputTmp[i]);
342 }
343 } else { // g works on the vector
344 if constexpr (ReturnArray) {
345 for (int i = 0; i < this->getTargetDim(); ++i) {
346 const auto* outputTmp2 = _g(outputTmp);
347 output[i] = outputTmp2[i];
348 }
349 } else { // g returns value
350 output[0] = _g(outputTmp);
351 }
352 }
353 return true;
354 }
355};
356
357template <unsigned D, typename T, typename S, typename G>
360 std::remove_pointer_t<decltype(
361 g(std::conditional_t<std::is_invocable_v<G,T>,T,T*>{}))>,T,S,
362 std::is_invocable_v<G,T>,
363 std::is_pointer_v<decltype(
364 g(std::conditional_t<std::is_invocable_v<G,T>,T,T*>{}))>>;
365
366// default for U seems to be necessary for multiply overloaded functions
367template <unsigned D, typename T, typename S, typename U=T>
370
371template <unsigned D, typename wrapped_U, typename T, typename S>
374 false,std::is_pointer_v<wrapped_U>>;
375
376template <unsigned D, typename wrapped_U, typename T, typename S>
377AnalyticalConcatenation(AnalyticalF<D,T,S>&, wrapped_U(const T*), unsigned)
379 false,std::is_pointer_v<wrapped_U>>;
380
382
383template <typename T, typename S>
385template <typename T, typename S>
387template <typename T, typename S>
389
390template <typename T, typename S>
392template <typename T, typename S>
394
395template <typename T, typename S>
397template <typename T, typename S>
399template <typename T, typename S>
401
402
403
404
405
406
408
409
411
413// Punktsteigungsform
414template <typename T, typename S>
416private:
417 T _a;
418 T _b;
419public:
420 AnalyticalLinear1D(T a, T b);
421 AnalyticalLinear1D(S x0, T v0, S x1, T v1);
422 bool operator() (T output[], const S x[]) override;
423
424 template<typename V, typename U>
426
427 template<typename V, typename U>
428 auto copyAs() const {
429 return exchange_type<V,U>(_a, _b);
430 }
431};
432
433
436template <typename T, typename S>
438private:
439 S _cp;
440 S _r;
441 T _maxi;
442public:
443 AnalyticalSquare1D(S cp, S r, T maxi);
444 bool operator() (T output[], const S x[]) override;
445};
446
447
449template <typename T, typename S>
450class SinusStartScale : public AnalyticalF1D<T,S> {
451protected:
454public:
455 SinusStartScale(int numTimeSteps=1, T maxValue=1);
456 bool operator() (T output[], const S x[]) override;
457};
458
459
461template <typename T, typename S>
463protected:
466public:
467 PolynomialStartScale(S numTimeSteps=S(1), T maxValue=T(1));
468 bool operator() (T output[], const S x[]) override;
469};
470
472template <typename T, typename S>
473class Sinus : public AnalyticalF1D<T,S> {
474protected:
477public:
478 Sinus (T period=1, T amplitude=1);
479 bool operator() (T output[], const S x[]) override;
480};
481
483template <typename T, typename S>
484class Cosinus : public AnalyticalF1D<T,S> {
485protected:
488public:
489 Cosinus(T period=1, T amplitude=1);
490 bool operator() (T output[], const S x[]) override;
491
492 template<typename V, typename U>
494
495 template<typename V, typename U>
496 auto copyAs() const {
497 return exchange_type<V,U>(_period, _amplitude);
498 }
499};
500
502template <typename T, typename S>
503class CosinusComposite : public AnalyticalF1D<T,S> {
504protected:
508public:
509 CosinusComposite(T period=1, T amplitude=1, T difference = 1);
510 bool operator() (T output[], const S x[]) override;
511};
512
513
514
516
518template <typename T, typename S>
519class AnalyticalLinear2D final : public AnalyticalF2D<T,S> {
520protected:
521 T _a;
522 T _b;
523 T _c;
524public:
525 AnalyticalLinear2D(T a, T b, T c);
526 AnalyticalLinear2D(S x0, S y0, T v0, S x1, S y1, T v1, S x2, S y2, T v2);
527 bool operator() (T output[], const S x[]) override;
528
529 template<typename V, typename U>
531
532 template<typename V, typename U>
533 auto copyAs() const {
534 return exchange_type<V,U>(_a, _b, _c);
535 }
536};
537
539template <typename T, typename S>
541protected:
542 T _center[2];
545public:
546 AnalyticalParticleAdsorptionLinear2D(T center[], T radius, T maxValue);
547 bool operator() (T output[], const S x[]);
548};
549
550
553template <typename T, typename S>
554class AnalyticalLinear3D final : public AnalyticalF3D<T,S> {
555protected:
556 T _a;
557 T _b;
558 T _c;
559 T _d;
560public:
561 AnalyticalLinear3D(T a, T b, T c, T d);
562 AnalyticalLinear3D(S x0, S y0, S z0, T v0, S x1, S y1, S z1, T v1, S x2, S y2,
563 S z2, T v2, S x3, S y3, S z3, T v3);
564 bool operator() (T output[], const S x[]) override;
565};
566
568template <typename T, typename S>
569class AnalyticalScaled3D final : public AnalyticalF3D<T,S> {
570private:
572 T _scale;
573public:
575 bool operator() (T output[], const S x[]) override;
576};
577
579template <typename T, typename S, typename DESCRIPTOR>
580class PLSsolution3D : public AnalyticalF3D<T,S> {
581private:
582 T _physSigmaEff;
583 T _physDiffusionCoefficient;
584public:
585 PLSsolution3D(T absorption, T scattering);
586 bool operator()(T output[1], const S x[3]) override;
587};
588
590template <typename T, typename S, typename DESCRIPTOR>
592private:
593 T _physSigmaEff;
594 T _physDiffusionCoefficient;
595 Vector<T,3> _center;
596public:
597 LightSourceCylindrical3D(RadiativeUnitConverter<T,DESCRIPTOR> const& converter, Vector<T,3> center = {T(0), T(0), T(0)});
598 bool operator()(T output[1], const S x[3]) override;
599};
600
606template <typename T, typename S>
607class Spotlight : public AnalyticalF3D<T,S> {
608private:
609 Vector<T,3> const _position;
610 Vector<T,3> const _orientation;
611 T const _falloff;
612public:
613 Spotlight(Vector<T,3> position, Vector<T,3> direction, T falloff);
614 bool operator()(T output[1], const S x[3]) override;
615};
616
618template <typename T, typename S>
619class GaussianHill2D : public AnalyticalF2D<T,S> {
620private:
621 T _sigma;
622 Vector<T,2> _x0;
623 T _c0;
624public:
625 GaussianHill2D(T sigma, Vector<T,2> x0, T c0);
626 bool operator()(T output[1], const S x[2]) override;
627};
628
630template <typename T, typename S>
632private:
633 T _sigma02;
634 T _D;
635 T _t;
636 Vector<T,2> _x0;
637 Vector<T,2> _u;
638 T _c0;
639public:
640 GaussianHillTimeEvolution2D(T sigma0, T D, T t, Vector<T,2> x0, Vector<T,2> u, T c0);
641 bool operator()(T output[1], const S x[2]) override;
642};
643
652template <unsigned D, typename T, typename S>
653class AnalyticalCuboidwiseConst final : public AnalyticalF<D,T,S>{
654private:
655 const unsigned _numberOfCuboids;
656
657 std::shared_ptr<const CuboidDecomposition<T,D>> _cuboids;
658 const std::vector<T> _values;
659
660public:
662 const std::vector<T>& values, unsigned targetDim=D)
663 : AnalyticalF<D,T,S>(targetDim),
664 _numberOfCuboids(values.size()),
665 _cuboids(std::make_shared<CuboidDecomposition<T,D>>(
666 sGeometry.getCuboidDecomposition().getMotherCuboid(),
667 _numberOfCuboids)),
668 _values(values)
669 {
670 this->getName() = "cuboidwiseConst";
671 }
672
673 bool operator() (T output[], const S input[]) override {
674 const auto index = _cuboids->getC(input);
675 for (int i = 0; i < this->getTargetDim(); ++i) {
676 output[i] = _values[*index];
677 }
678 return true;
679 }
680};
681
682} // end namespace olb
683#endif
Some helper functions for the ADf data type.
bool operator()(T output[], const S x[]) override
has to be implemented for 'every' derived class
AnalyticalComposed(AnalyticalF< D, T, S > &f0, AnalyticalF< D, T, S > &f1, AnalyticalF< D, T, S > &f2)
Definition analyticalF.h:66
AnalyticalComposed(AnalyticalF< D, T, S > &f0, AnalyticalF< D, T, S > &f1)
Definition analyticalF.h:60
AnalyticalF< D, T, S > & _f
AnalyticalConcatenation(AnalyticalF< D, T, S > &f, G g, unsigned targetDim=1)
concatenate functor f and some lambda expression g.
std::conditional_t< ReturnArray, U *, U > return_type_g
std::conditional_t< ComponentWise, std::function< return_type_g(T)>, std::function< return_type_g(T *)> > function_t
AnalyticalConcatenation(AnalyticalF< D, T, S > &f, wrapped_U(*g)(const T *), unsigned targetDim=1)
concatenate functor f and some function g.
AnalyticalConcatenation(AnalyticalF< D, T, S > &f, wrapped_U(*g)(T *), unsigned targetDim=1)
concatenate functor f and some function g.
AnalyticalConcatenation(AnalyticalF< D, T, S > &f, U(*g)(T))
concatenate functor f and some function g.
AnalyticalConst: DD -> XD, where XD is defined by value.size()
auto copyAs() const
Returns a constant value on every cuboids.
AnalyticalCuboidwiseConst(SuperGeometry< T, D > &sGeometry, const std::vector< T > &values, unsigned targetDim=D)
AnalyticalF are applications from DD to XD, where X is set by the constructor.
User friendly AnalyticalF accepting strictly typed callables Vector<T,OUT>(Vector<S,...
Definition analyticalF.h:77
AnalyticalLinear1D: 1D -> 1D troughout given points (x0,v0) and (x1,v1)
AnalyticalLinear2D: 2D -> 1D troughout given points (x0,y0,v0), (x1,y1,v1), (x2,y2,...
3D//////////////////////////////////////////// AnalyticalLinear3D: 3D -> 1D troughout given points (x...
AnalyticalNormal: DD -> XD, where XD is defined by value.size()
AnalyticalRandom2D: 2D -> 1D with maxValue in the center decreasing linearly with the distrance to th...
AnalyticalRandomBase: virtual base class for all the random functionals.
std::random_device rd
AnalyticalRandomNormal: DD -> 1D with random image in (0,1)
std::normal_distribution< T > distro
AnalyticalRandomOld: DD -> 1D with random image in (0,1)
AnalyticalRamdomSeededBase: alternative version with seed specification.
AnalyticalRamdomSeededNormal: alternative version with seed specification.
std::normal_distribution< T > distro
AnalyticalRandomNormal: DD -> 1D with random image in (0,1) Normal distribution cut off outside [mean...
AnalyticalRandomUniform: DD -> 1D with random image in (0,1)
AnalyticalScaled3D: 3D -> Image(AnalyticalF) scales AnalyticalF by _scale.
Smoothed square wave. epsilon = width of the mollified interval.
represents an inverse parabola profile like it is used in Poiseuille inflow note: output depends only...
Square wave with given period length, amplitude, difference (= length of positive time / length of pe...
CosinusComposite: Composition of two Cosinus to shift the low point within a period - difference deno...
Cosinus: Cosinus with period and amplitude.
auto copyAs() const
Decomposition of a physical volume into a set of disjoint cuboids.
Computes resulting lattice velocity of an object from translational and rotational velocity.
Vector< T, DESCRIPTOR::d > _position
UnitConverter< T, DESCRIPTOR > const & _converter
Vector< T, utilities::dimensions::convert< DESCRIPTOR::d >::rotation > _angularVelocity
Vector< T, DESCRIPTOR::d > _velocity
Computes resulting velocity of an object from translational and rotational velocity.
Vector< T, DESCRIPTOR::d > _velocity
Vector< T, utilities::dimensions::convert< DESCRIPTOR::d >::rotation > _angularVelocity
Vector< T, DESCRIPTOR::d > _position
8.6.1 Gauss Hill inital values
8.6.1 Gauss Hill time evolution
int getTargetDim() const
read only access to member variable _n
Definition genericF.hh:45
std::string & getName()
read and write access to name
Definition genericF.hh:51
light source as a cylinder along z-axis
see Mink et al. 2016 in Sec.3.1.
PolynomialStartScale: 1D -> 1D a start curve based on a polynomial fifth order for a continuous trans...
Conversion between physical and lattice units, as well as discretization.
Definition analyticalF.h:48
SinusStartScale: 1D -> 1D a start curve based on sinus for a continuous transition at 0 and 1.
Sinus: Sinus with period and amplitude.
Representation of a statistic for a parallel 2D geometry.
Conversion between physical and lattice units, as well as discretization.
Plain old scalar vector.
Top level namespace for all of OpenLB.
std::string getName(OperatorScope scope)
Returns human-readable name of scope.
Converts dimensions by deriving from given cartesian dimension D.
Representation of a parallel 2D geometry – header file.