ryujin 2.5.0 revision c64172211cf21344cb9b9b0f3a1266aa6400d392
Loading...
Searching...
No Matches
flux_function.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2023 - 2026 by the ryujin authors
4//
5
6#pragma once
7
8#include <ryujin/base/compile_time_options.h>
10
11#include <deal.II/base/function_parser.h>
12
13#include <boost/algorithm/string/classification.hpp>
14#include <boost/algorithm/string/split.hpp>
15
16#include <numeric>
17
18namespace ryujin
19{
20 namespace Fluxes
21 {
27 class Function : public Flux
28 {
29 public:
30 Function(const std::string &subsection)
31 : Flux("function", subsection)
32 {
33 expression_ = "0.5*u*u";
34 add_parameter("expression",
35 expression_,
36 "A function expression of the flux as a function of "
37 "state used to create a muparser object to evaluate the "
38 "flux. For two, or three dimensional fluxes, components "
39 "are separated with a semicolon (;).");
40
41 this->derivative_approximation_delta_ = 1.0e-10;
42 add_parameter("derivative approximation delta",
44 "Step size of the central difference quotient to compute "
45 "an approximation of the flux derivative");
46
47 /*
48 * Set up the muparser object with the final flux description from
49 * the parameter file:
50 */
51 const auto set_up_muparser = [this] {
52 std::vector<std::string> split_expressions;
53 boost::split(split_expressions, expression_, boost::is_any_of(";"));
54
55 const auto size = split_expressions.size();
56
57 Assert(0 < size && size <= 3,
58 dealii::ExcMessage(
59 "user specified flux description must be either one, two, "
60 "or three strings separated by a comma"));
61 flux_function_ = std::make_unique<dealii::FunctionParser<1>>(
62 size, 0.0, this->derivative_approximation_delta_);
63 flux_function_->initialize({"u"}, split_expressions, {});
64
65 flux_formula_ = "f(u)={" + expression_ + "}";
66 };
67
68 set_up_muparser();
69 ParameterAcceptor::parse_parameters_call_back.connect(set_up_muparser);
70 }
71
72
73 double value(const double state,
74 const unsigned int direction) const override
75 {
76 return flux_function_->value(dealii::Point<1>(state), direction);
77 }
78
79
80 double gradient(const double state,
81 const unsigned int direction) const override
82 {
83 return flux_function_->gradient(dealii::Point<1>(state), direction)[0];
84 }
85
86
87 private:
88 std::string expression_;
89
90 std::unique_ptr<dealii::FunctionParser<1>> flux_function_;
91 };
92 } // namespace Fluxes
93} // namespace ryujin
std::string flux_formula_
Definition flux.h:84
double derivative_approximation_delta_
Definition flux.h:83
double value(const double state, const unsigned int direction) const override
Function(const std::string &subsection)
double gradient(const double state, const unsigned int direction) const override