VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
KernelImp.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
32#include "KernelImp.h"
33
34#include <spdlog/fmt/fmt.h>
35
37#include "logger/Logger.h"
38
39namespace vf::gpu {
40
41void KernelImp::runOnIndices(const unsigned int *indices, unsigned int sizeIndices, CollisionTemplate collisionTemplate, CudaStreamIndex streamIndex)
42{
43 printf("Method not implemented for this Kernel \n");
44}
45
46std::vector<PreProcessorType> KernelImp::getPreProcessorTypes()
47{
49}
50
55
56std::string KernelImp::realToString(real kernelParameter)
57{
58 // use fmt library to control the formatting of the number
59 return fmt::format("{:1.4g}", kernelParameter);
60}
61
62std::string KernelImp::composeWarningForMaximumKernelParameterHardLimit(const std::string& kernelParameterName,
64{
65 return "The " + kernelParameterName + " (in LB units) is too high. It was set to " + realToString(kernelParameter) +
66 " but should be smaller than " + realToString(maximumHard) + " (hard limit).";
67}
68
69std::string KernelImp::composeWarningForMaximumKernelParameterRecommendation(const std::string& kernelParameterName,
71{
72 return "The " + kernelParameterName + " is " + realToString(kernelParameter) +
73 ", which is larger than the recommended value of " + realToString(maximumRecommended) + ".";
74}
75
76std::string KernelImp::composeRecommendationForMaximumKernelParameter(const std::string& kernelParameterName,
78{
79 return "A " + kernelParameterName + " smaller than " + realToString(maximumRecommended) + " is recommended.";
80}
81
82std::string KernelImp::composeInfoOnHardLimitForMaximumKernelParameter(const std::string& kernelParameterName,
84{
85 return "The hard limit for the " + kernelParameterName + " is " + realToString(maximumHard) + ".";
86}
87
88void KernelImp::checkViscosity(real viscosityLBOnFinestLevel, uint maxLevel) const
89{
90 const std::string kernelParameterName = "viscosity";
91 std::string message = "At level " + std::to_string(maxLevel) + ": ";
92
93 if (!viscosityMaximumHard.has_value() && !viscosityMaximumRecommended.has_value()) {
94 VF_LOG_INFO("There is no viscosity maximum defined for this kernel.");
95 return;
96 }
97
99 message += composeWarningForMaximumKernelParameterHardLimit(kernelParameterName, viscosityLBOnFinestLevel,
100 viscosityMaximumHard.value());
101 if (viscosityMaximumRecommended.has_value()) {
102 message += "\n" + composeRecommendationForMaximumKernelParameter(kernelParameterName,
104 }
106 return;
107 }
108
110 message += composeWarningForMaximumKernelParameterRecommendation(kernelParameterName, viscosityLBOnFinestLevel,
112 if (viscosityMaximumHard.has_value()) {
113 message +=
114 "\n" + composeInfoOnHardLimitForMaximumKernelParameter(kernelParameterName, viscosityMaximumHard.value());
115 }
117 }
118}
119
120void KernelImp::checkVelocity(real velocityLB) const
121{
122 const std::string kernelParameterName = "velocity";
123 std::string message;
124
127 composeWarningForMaximumKernelParameterHardLimit(kernelParameterName, velocityLB, velocityMaximumHard) + "\n" +
128 composeRecommendationForMaximumKernelParameter(kernelParameterName, velocityMaximumRecommended));
129 return;
130 }
131
133 VF_LOG_WARNING(composeWarningForMaximumKernelParameterRecommendation(kernelParameterName, velocityLB,
135 "\n" + composeInfoOnHardLimitForMaximumKernelParameter(kernelParameterName, velocityMaximumHard));
136 return;
137 }
138}
139
141{
142 checkVelocity(velocityLB);
143 checkViscosity(viscosityLBOnFinestLevel, maxLevel);
144}
145
146KernelImp::KernelImp(std::shared_ptr<Parameter> para, int level) : para(std::move(para)), level(level)
147{
148}
149
150KernelImp::KernelImp(std::shared_ptr<Parameter> para, int level, real viscosityMaximumRecommended, real viscosityMaximumHard)
151 : para(std::move(para)), level(level), viscosityMaximumRecommended(viscosityMaximumRecommended),
152 viscosityMaximumHard(viscosityMaximumHard)
153{
154}
155
156KernelImp::KernelImp(std::shared_ptr<Parameter> para, int level, real viscosityMaximumRecommended)
157 : para(std::move(para)), level(level), viscosityMaximumRecommended(viscosityMaximumRecommended)
158{
159}
160
161}
162
#define VF_LOG_INFO(...)
Definition Logger.h:50
#define VF_LOG_CRITICAL(...)
Definition Logger.h:52
#define VF_LOG_WARNING(...)
Definition Logger.h:51
std::vector< PreProcessorType > myPreProcessorTypes
Definition KernelImp.h:79
std::vector< PreProcessorType > getPreProcessorTypes() override
Definition KernelImp.cpp:46
const real velocityMaximumRecommended
Definition KernelImp.h:71
const real velocityMaximumHard
Definition KernelImp.h:70
const std::optional< real > viscosityMaximumHard
Definition KernelImp.h:74
bool getKernelUsesFluidNodeIndices() const
Definition KernelImp.cpp:51
void runOnIndices(const unsigned int *indices, unsigned int sizeIndices, CollisionTemplate collisionTemplate, CudaStreamIndex streamIndex=CudaStreamIndex::Legacy) override
Definition KernelImp.cpp:41
bool kernelUsesFluidNodeIndices
Definition KernelImp.h:82
void checkKernelParameters(uint maxLevel, real velocityLB, real viscosityLBOnFinestLevel) const override
check if velocityLB and viscosityLB are not too high, as this can lead to inaccurate results or a cra...
const std::optional< real > viscosityMaximumRecommended
Definition KernelImp.h:75
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47
CollisionTemplate
An enumeration for selecting a template of the collision kernel (CumulantK17)
Definition Calculation.h:57