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