26template <
typename T,
typename F>
27T
f2way(
const T
a,
const T
b,
const T c,
const T d,
const T x, F&& f) {
31 return 1.0 - f(c, d, x);
36template <MInt nDim,
typename T,
typename F>
37T
fbox(
const T*
const boxmin,
const T*
const boxmax,
const T width,
const T*
const x, F&& f) {
39 for(
MInt i = 0; i < nDim; i++) {
40 if(boxmin[i] - x[i] > 0.0) {
41 r += (boxmin[i] - x[i]) * (boxmin[i] - x[i]);
42 }
else if(x[i] - boxmax[i] > 0.0) {
43 r += (x[i] - boxmax[i]) * (x[i] - boxmax[i]);
46 return 1.0 - f(0.0, width, std::sqrt(r));
50template <MInt nDim,
typename T,
typename F>
51T
fmultibox(
const T*
const boxmin,
const T*
const boxmax,
const T*
const width,
const T*
const x, F&& f) {
53 for(
MInt i = 0; i < nDim; i++) {
54 filter *=
f2way(boxmin[i] - width[2 * i], boxmin[i], boxmax[i], boxmax[i] + width[2 * i + 1], x[i], f);
60template <MInt nDim,
typename T,
typename F>
61T
fsphere(
const T*
const center,
const T radius,
const T width,
const T*
const x, F&& f) {
63 for(
MInt i = 0; i < nDim; i++) {
64 r += (x[i] - center[i]) * (x[i] - center[i]);
66 return 1.0 - f(0.0, width, std::sqrt(r) - radius);
89 return (x -
a) / (
b -
a);
94T
linear2way(
const T
a,
const T
b,
const T c,
const T d,
const T x) {
98template <MInt nDim,
typename T>
99T
linearbox(
const T*
const boxmin,
const T*
const boxmax,
const T width,
const T*
const x) {
100 return detail_::fbox<nDim>(boxmin, boxmax, width, x, &linear<T>);
103template <MInt nDim,
typename T>
104T
linearmultibox(
const T*
const boxmin,
const T*
const boxmax,
const T*
const width,
const T*
const x) {
105 return detail_::fmultibox<nDim>(boxmin, boxmax, width, x, &linear<T>);
108template <MInt nDim,
typename T>
109T
linearsphere(
const T*
const center,
const T radius,
const T width,
const T*
const x) {
110 return detail_::fsphere<nDim>(center, radius, width, x, &linear<T>);
125T
cos(
const T
a,
const T
b,
const T x) {
131 return 0.5 * std::cos(PI / (
b -
a) * (x -
b)) + 0.5;
136T
cos2way(
const T
a,
const T
b,
const T c,
const T d,
const T x) {
140template <MInt nDim,
typename T>
141T
cosbox(
const T*
const boxmin,
const T*
const boxmax,
const T width,
const T*
const x) {
142 return detail_::fbox<nDim>(boxmin, boxmax, width, x, &cos<T>);
145template <MInt nDim,
typename T>
146T
cosmultibox(
const T*
const boxmin,
const T*
const boxmax,
const T*
const width,
const T*
const x) {
147 return detail_::fmultibox<nDim>(boxmin, boxmax, width, x, &cos<T>);
150template <MInt nDim,
typename T>
151T
cossphere(
const T*
const center,
const T radius,
const T width,
const T*
const x) {
152 return detail_::fsphere<nDim>(center, radius, width, x, &cos<T>);
155template <MInt nDim,
typename T>
156T
coscylinderzaxis(
const T*
const center,
const T radius,
const T width,
const T*
const x) {
157 return detail_::fsphere<nDim>(center, radius, width, x, &cos<T>);
220 std::map<MString, FilterType> filterMap;
225 filterMap[
"cossphere"] = FilterType::cossphere;
226 filterMap[
"linearsphere"] = FilterType::linearsphere;
227 filterMap[
"coscylinderzaxis"] = FilterType::coscylinderzaxis;
228 filterMap[
"cosbox"] = FilterType::cosbox;
229 filterMap[
"linearbox"] = FilterType::linearbox;
230 filterMap[
"cosmultibox"] = FilterType::cosmultibox;
231 filterMap[
"linearmultibox"] = FilterType::linearmultibox;
247 filterShape = Context::getSolverProperty<MString>(
"filterShape", m_solverId, AT_);
261 filterSlopeType = Context::getSolverProperty<MString>(
"filterSlopeType", m_solverId, AT_);
265 auto search = filterMap.find(filterSlopeType + filterShape);
266 if(search != filterMap.end()) {
267 m_filterId = filterMap[filterSlopeType + filterShape];
269 TERMM(1,
"Unknown filter type! Please check your property file.");
273 if(filterShape ==
"multibox") {
274 for(
MInt i = 0; i < 2 * nDim; i++) {
275 m_filterSlopeWidthMultiBox[i] = Context::getSolverProperty<MFloat>(
"filterSlopeWidth", m_solverId, AT_, i);
278 m_filterSlopeWidth = Context::getSolverProperty<MFloat>(
"filterSlopeWidth", m_solverId, AT_);
282 if(filterShape ==
"sphere" || filterShape ==
"cylinderzaxis") {
284 for(
MInt i = 0; i < nDim; i++) {
293 m_filterCenter[i] = Context::getSolverProperty<MFloat>(
"filterCenter", m_solverId, AT_, i);
303 m_filterRadius = Context::getSolverProperty<MFloat>(
"filterRadius", m_solverId, AT_);
306 for(
MInt i = 0; i < nDim; i++) {
315 m_filterRegionMin[i] = Context::getSolverProperty<MFloat>(
"filterRegionMin", m_solverId, AT_, i);
325 m_filterRegionMax[i] = Context::getSolverProperty<MFloat>(
"filterRegionMax", m_solverId, AT_, i);
330 m_isInitialized =
true;
341 if(!m_isInitialized) {
342 TERMM(1,
"Filter Object was not initialized correctly!");
348 case FilterType::cossphere:
350 return maia::filter::slope::cossphere<nDim>(&m_filterCenter[0], m_filterRadius, m_filterSlopeWidth, coordinates);
353 case FilterType::linearsphere:
354 TERMM(1,
"linearsphere type of filter has not been tested yet!");
357 return maia::filter::slope::linearsphere<nDim>(&m_filterCenter[0], m_filterRadius, m_filterSlopeWidth,
360 case FilterType::coscylinderzaxis:
363 return maia::filter::slope::cossphere<2>(&m_filterCenter[0], m_filterRadius, m_filterSlopeWidth, coordinates);
366 case FilterType::cosbox:
367 TERMM(1,
"Cosbox type of filter has not been tested yet!");
370 return maia::filter::slope::cosbox<nDim>(&m_filterRegionMin[0], &m_filterRegionMax[0], m_filterSlopeWidth,
374 case FilterType::linearbox:
375 TERMM(1,
"linearbox type of filter has not been tested yet!");
378 return maia::filter::slope::linearbox<nDim>(&m_filterRegionMin[0], &m_filterRegionMax[0], m_filterSlopeWidth,
382 case FilterType::cosmultibox:
384 return maia::filter::slope::cosmultibox<nDim>(&m_filterRegionMin[0], &m_filterRegionMax[0],
385 &m_filterSlopeWidthMultiBox[0], coordinates);
388 case FilterType::linearmultibox:
391 return maia::filter::slope::linearmultibox<nDim>(&m_filterRegionMin[0], &m_filterRegionMax[0],
392 &m_filterSlopeWidthMultiBox[0], coordinates);
395 TERMM(1,
"Unknown filter type! Please check your property file.");
409 if(!m_isInitialized) {
410 TERMM(1,
"Filter Object was not initialized correctly!");
416 case FilterType::cossphere:
418 for(
MInt j = 0; j < count; j++) {
419 values[j] = maia::filter::slope::cossphere<nDim>(&m_filterCenter[0], m_filterRadius, m_filterSlopeWidth,
420 coordinates + j * nDim);
425 case FilterType::linearsphere:
426 TERMM(1,
"linearsphere type of filter has not been tested yet!");
429 for(
MInt j = 0; j < count; j++) {
430 values[j] = maia::filter::slope::linearsphere<nDim>(&m_filterCenter[0], m_filterRadius, m_filterSlopeWidth,
431 coordinates + j * nDim);
435 case FilterType::coscylinderzaxis:
437 for(
MInt j = 0; j < count; j++) {
438 values[j] = maia::filter::slope::cossphere<2>(&m_filterCenter[0], m_filterRadius, m_filterSlopeWidth,
439 coordinates + j * nDim);
444 case FilterType::cosbox:
445 TERMM(1,
"Cosbox type of filter has not been tested yet!");
448 for(
MInt j = 0; j < count; j++) {
449 values[j] = maia::filter::slope::cosbox<nDim>(&m_filterRegionMin[0], &m_filterRegionMax[0], m_filterSlopeWidth,
450 coordinates + j * nDim);
454 case FilterType::linearbox:
455 TERMM(1,
"linearbox type of filter has not been tested yet!");
458 for(
MInt j = 0; j < count; j++) {
459 values[j] = maia::filter::slope::linearbox<nDim>(&m_filterRegionMin[0], &m_filterRegionMax[0],
460 m_filterSlopeWidth, coordinates + j * nDim);
465 case FilterType::cosmultibox:
467 for(
MInt j = 0; j < count; j++) {
468 values[j] = maia::filter::slope::cosmultibox<nDim>(&m_filterRegionMin[0], &m_filterRegionMax[0],
469 &m_filterSlopeWidthMultiBox[0], coordinates + j * nDim);
473 case FilterType::linearmultibox:
476 for(
MInt j = 0; j < count; j++) {
477 values[j] = maia::filter::slope::linearmultibox<nDim>(&m_filterRegionMin[0], &m_filterRegionMax[0],
478 &m_filterSlopeWidthMultiBox[0], coordinates + j * nDim);
483 TERMM(1,
"Unknown filter type! Please check your property file.");
501 case FilterType::cossphere:
502 filterName =
"cossphere";
504 case FilterType::linearsphere:
505 filterName =
"linearsphere";
507 case FilterType::coscylinderzaxis:
508 filterName =
"coscylinderzaxis";
510 case FilterType::cosbox:
511 filterName =
"cosbox";
513 case FilterType::linearbox:
514 filterName =
"linearbox";
516 case FilterType::cosmultibox:
517 filterName =
"cosmultibox";
519 case FilterType::linearmultibox:
520 filterName =
"linearmultibox";
523 TERMM(1,
"Unknown filter type! Please check your property file.");
Filter object for source terms.
void init()
Initializes the filter. Read all properties and set the filter function.
std::array< MFloat, nDim > m_filterCenter
std::array< MFloat, 2 *nDim > m_filterSlopeWidthMultiBox
MFloat m_filterSlopeWidth
std::array< MFloat, nDim > m_filterRegionMax
void filter(const MFloat *const points, const MInt count, MFloat *const values)
MFloat filter(const MFloat *const point) const
Filter(const MInt solverId)
std::array< MFloat, nDim > m_filterRegionMin
std::basic_string< char > MString
T fsphere(const T *const center, const T radius, const T width, const T *const x, F &&f)
Auxiliary function to create a sphere slope filter.
T fbox(const T *const boxmin, const T *const boxmax, const T width, const T *const x, F &&f)
Auxiliary function to create a box slope filter (constant slope width)
T fmultibox(const T *const boxmin, const T *const boxmax, const T *const width, const T *const x, F &&f)
Auxiliary function to create a box slope filter (variable slope width)
T f2way(const T a, const T b, const T c, const T d, const T x, F &&f)
Auxiliary function to create two-way slope filters.
T cosmultibox(const T *const boxmin, const T *const boxmax, const T *const width, const T *const x)
T cos2way(const T a, const T b, const T c, const T d, const T x)
T linear(const T a, const T b, const T x)
Linear slope filter.
T coscylinderzaxis(const T *const center, const T radius, const T width, const T *const x)
T linearsphere(const T *const center, const T radius, const T width, const T *const x)
T linearbox(const T *const boxmin, const T *const boxmax, const T width, const T *const x)
T cosbox(const T *const boxmin, const T *const boxmax, const T width, const T *const x)
T cossphere(const T *const center, const T radius, const T width, const T *const x)
T cos(const T a, const T b, const T x)
Cosine slope filter.
T linear2way(const T a, const T b, const T c, const T d, const T x)
T linearmultibox(const T *const boxmin, const T *const boxmax, const T *const width, const T *const x)
Namespace for auxiliary functions/classes.