ryujin 2.5.0 revision c64172211cf21344cb9b9b0f3a1266aa6400d392
Loading...
Searching...
No Matches
electrostatic_configuration_function.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 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
13namespace ryujin
14{
15 namespace ElectrostaticConfigurations
16 {
22 template <int dim, typename Number = double>
23 class Function : public ElectrostaticConfiguration<dim, Number>
24 {
25 public:
27
28 Function(const std::string &subsection)
29 : ElectrostaticConfiguration<dim, Number>("function", subsection)
30 {
31 this->add_parameter("time dependent",
33 "Controls whether the function parsers support "
34 "time dependent function expressions");
35
36 background_density_expression_ = "0.";
37 this->add_parameter("background density",
38 background_density_expression_,
39 "A function expression for the background density");
40
41 if constexpr (dim >= 2) {
42 magnetic_field_z_expression_ = "0.";
43 this->add_parameter("magnetic field z",
44 magnetic_field_z_expression_,
45 "A function expression for the z component of "
46 "the magnetic field");
47 }
48
49 if constexpr (dim == 3) {
50 magnetic_field_x_expression_ = "0.";
51 this->add_parameter("magnetic field x",
52 magnetic_field_x_expression_,
53 "A function expression for the x component of "
54 "the magnetic field");
55
56 magnetic_field_y_expression_ = "0.";
57 this->add_parameter("magnetic field y",
58 magnetic_field_y_expression_,
59 "A function expression for the y component of "
60 "the magnetic field");
61 }
62
63 /* Set up all muparser objects: */
64
65 const auto set_up_muparser = [this] {
66 /*
67 * Add variable "t" in case of a time-dependent function:
68 */
69 using FP = dealii::FunctionParser<dim>;
70 auto variable_names = FP::default_variable_names();
71 if (this->is_time_dependent_)
72 variable_names += ",t";
73
74 background_density_ = std::make_unique<FP>(
75 background_density_expression_, "", variable_names);
76
77 if constexpr (dim >= 2) {
78 magnetic_field_z_ = std::make_unique<FP>(
79 magnetic_field_z_expression_, "", variable_names);
80 }
81
82 if constexpr (dim == 3) {
83 magnetic_field_x_ = std::make_unique<FP>(
84 magnetic_field_x_expression_, "", variable_names);
85 magnetic_field_y_ = std::make_unique<FP>(
86 magnetic_field_y_expression_, "", variable_names);
87 }
88 };
89
90 set_up_muparser();
91 this->parse_parameters_call_back.connect(set_up_muparser);
92 }
93
94 virtual double background_density(const dealii::Point<dim> &point,
95 Number t) const final
96 {
97 background_density_->set_time(t);
98 return static_cast<Number>(background_density_->value(point));
99 }
100
101 virtual curl_type magnetic_field(const dealii::Point<dim> &point,
102 Number t) const final
103 {
104 if constexpr (dim == 1) {
105 return curl_type{};
106 }
107
108 if constexpr (dim == 2) {
109 magnetic_field_z_->set_time(t);
110 return curl_type{
111 {static_cast<Number>(magnetic_field_z_->value(point))}};
112 }
113
114 if constexpr (dim == 3) {
115 magnetic_field_x_->set_time(t);
116 magnetic_field_y_->set_time(t);
117 magnetic_field_z_->set_time(t);
118 return curl_type{
119 {static_cast<Number>(magnetic_field_x_->value(point)),
120 static_cast<Number>(magnetic_field_y_->value(point)),
121 static_cast<Number>(magnetic_field_z_->value(point))}};
122 }
123 }
124
125 private:
126 std::string background_density_expression_;
127 std::string magnetic_field_x_expression_;
128 std::string magnetic_field_y_expression_;
129 std::string magnetic_field_z_expression_;
130
131 std::unique_ptr<dealii::FunctionParser<dim>> background_density_;
132 std::unique_ptr<dealii::FunctionParser<dim>> magnetic_field_x_;
133 std::unique_ptr<dealii::FunctionParser<dim>> magnetic_field_y_;
134 std::unique_ptr<dealii::FunctionParser<dim>> magnetic_field_z_;
135 };
136 } // namespace ElectrostaticConfigurations
137} // namespace ryujin
dealii::Tensor< 1, dim==2 ? 1 :dim, Number > curl_type
virtual double background_density(const dealii::Point< dim > &point, Number t) const final
ElectrostaticConfiguration< dim, Number >::curl_type curl_type
virtual curl_type magnetic_field(const dealii::Point< dim > &point, Number t) const final