Sapphire++
 v1.3.0-121-g2682132
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// Copyright (C) 2023 by the Sapphire++ authors
4//
5// This file is part of Sapphire++.
6//
7// Sapphire++ is free software: you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License as published by the Free
9// Software Foundation, either version 3 of the License, or (at your option) any
10// later version.
11//
12// Sapphire++ is distributed in the hope that it will be useful, but WITHOUT ANY
13// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14// A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15// details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with Sapphire++. If not, see <https://www.gnu.org/licenses/>.
19//
20// -----------------------------------------------------------------------------
21
28
29#ifndef CONFIG_H
30#define CONFIG_H
31
32#include <deal.II/base/exceptions.h>
33#include <deal.II/base/function.h>
34#include <deal.II/base/parameter_handler.h>
35#include <deal.II/base/point.h>
36
37#include <deal.II/lac/full_matrix.h>
38#include <deal.II/lac/vector.h>
39
40#include <cmath>
41#include <numbers>
42#include <vector>
43
44#include "pde-system.h"
46#include "vfp-flags.h"
47
48
49
50namespace sapphirepp
51{
56 {
57 public:
59 // !!!EDIT HERE!!!
61
62
63
65 PhysicalParameters() = default;
66
67
68
74 void
75 declare_parameters(dealii::ParameterHandler &prm)
76 {
77 dealii::LogStream::Prefix prefix_startup("Startup", saplog);
78 dealii::LogStream::Prefix prefix("PhysicalParameters", saplog);
79 saplog << "Declaring parameters" << std::endl;
80 prm.enter_subsection("Physical parameters");
81
91 // !!!EDIT HERE!!!
93
94 prm.leave_subsection();
95 }
96
97
98
104 void
105 parse_parameters(dealii::ParameterHandler &prm)
106 {
107 dealii::LogStream::Prefix prefix_startup("Startup", saplog);
108 dealii::LogStream::Prefix prefix("PhysicalParameters", saplog);
109 saplog << "Parsing parameters" << std::endl;
110 prm.enter_subsection("Physical parameters");
111
113 // !!!EDIT HERE!!!
115
116 prm.leave_subsection();
117 }
118 };
119
120
121
122 namespace VFP
123 {
125 // !!!EDIT HERE!!!
127 constexpr unsigned int dimension = 2;
129
130
131
133 // !!!EDIT HERE!!!
143
144
145
151 template <unsigned int dim>
152 class InitialValueFunction : public dealii::Function<dim>
153 {
154 public:
162 InitialValueFunction(const PhysicalParameters &physical_parameters,
163 const unsigned int system_size)
164 : dealii::Function<dim>(system_size)
165 , prm{physical_parameters}
166 , lms_indices{PDESystem::create_lms_indices(system_size)}
167 {}
168
169
170
205 void
206 vector_value([[maybe_unused]] const dealii::Point<dim> &point,
207 dealii::Vector<double> &f) const override
208 {
209 AssertDimension(f.size(), this->n_components);
210
211 // NOLINTNEXTLINE(modernize-loop-convert)
212 for (unsigned int i = 0; i < f.size(); ++i)
213 {
215 // !!!EDIT HERE!!!
216 f[i] = 0.;
218 }
219 }
220
221
222
223 private:
225 const PhysicalParameters prm;
230 const std::vector<std::array<unsigned int, 3>> lms_indices;
231 };
232
233
234
240 template <unsigned int dim>
241 class BoundaryValueFunction : public dealii::Function<dim>
242 {
243 public:
251
252 BoundaryValueFunction(const PhysicalParameters &physical_parameters,
253 const unsigned int system_size)
254 : dealii::Function<dim>(system_size)
255 , prm{physical_parameters}
256 , lms_indices{PDESystem::create_lms_indices(system_size)}
257 {}
258
259
260
318 void
320 [[maybe_unused]] const std::vector<dealii::Point<dim>> &points,
321 [[maybe_unused]] const unsigned int boundary_id,
322 [[maybe_unused]] std::vector<dealii::Vector<double>> &bc_values) const
323 {
324 AssertDimension(points.size(), bc_values.size());
325 AssertDimension(bc_values[0].size(), this->n_components);
326
327 for (unsigned int q_index = 0; q_index < points.size(); ++q_index)
328 {
330 // !!!EDIT HERE!!!
331 if (boundary_id == 0)
332 {
333 // lower x
334 }
335 else if (boundary_id == 1)
336 {
337 // upper x
338 }
339 else if (boundary_id == 2)
340 {
341 // lower p
342 }
343 else if (boundary_id == 3)
344 {
345 // upper p
346 }
348 }
349 }
350
351
352
353 private:
355 const PhysicalParameters prm;
360 const std::vector<std::array<unsigned int, 3>> lms_indices;
361 };
362
363
364
370 template <unsigned int dim>
371 class ScatteringFrequency : public dealii::Function<dim>
372 {
373 public:
379 ScatteringFrequency(const PhysicalParameters &physical_parameters)
380 : dealii::Function<dim>(1)
381 , prm{physical_parameters}
382 {}
383
384
385
408 void
410 const std::vector<dealii::Point<dim>> &points,
411 std::vector<double> &scattering_frequencies,
412 [[maybe_unused]] const unsigned int component = 0) const override
413 {
414 AssertDimension(scattering_frequencies.size(), points.size());
415
416 for (unsigned int q_index = 0; q_index < points.size(); ++q_index)
417 {
419 // !!!EDIT HERE!!!
420 scattering_frequencies[q_index] = 100.;
422 }
423 }
424
425
426
427 private:
429 const PhysicalParameters prm;
430 };
431
432
433
439 template <unsigned int dim>
440 class Source : public dealii::Function<dim>
441 {
442 public:
450 Source(const PhysicalParameters &physical_parameters,
451 unsigned int system_size)
452 : dealii::Function<dim>(system_size)
453 , prm{physical_parameters}
454 , lms_indices{PDESystem::create_lms_indices(system_size)}
455 {}
456
457
471 void
472 vector_value([[maybe_unused]] const dealii::Point<dim> &point,
473 dealii::Vector<double> &source_values) const override
474 {
475 AssertDimension(source_values.size(), this->n_components);
476
477 // NOLINTNEXTLINE(modernize-loop-convert)
478 for (unsigned int i = 0; i < source_values.size(); ++i)
479 {
481 // !!!EDIT HERE!!!
482 // Define parameters
483 const double p0 = 1.;
484 const double Q = 0.1;
485 const double sig_p = 0.1;
486 const double sig_x = 0.001;
487
488 // Get x and p value
489 const double x = point[0];
490 const double p = std::exp(point[1]); // point[1] = log(p)
491
492 // Convert i -> l, m, s
493 const unsigned int l = lms_indices[i][0];
494 const unsigned int m = lms_indices[i][1];
495 const unsigned int s = lms_indices[i][2];
496
497 // isotropic part
498 if (l == 0 && m == 0 && s == 0)
499 {
500 // shifted Gaussian in x and p
501 // s_000 = sqrt(4 pi) * s
502 source_values[i] =
503 Q / (std::sqrt(std::numbers::pi) * sig_p * sig_x) *
504 std::exp(-(p - p0) * (p - p0) / (2. * sig_p * sig_p)) *
505 std::exp(-x * x / (2. * sig_x * sig_x));
506 }
507 // vanishing anisotropic part
508 else
509 {
510 source_values[i] = 0.;
511 }
513 }
514 }
515
516
517
518 private:
520 const PhysicalParameters prm;
525 const std::vector<std::array<unsigned int, 3>> lms_indices;
526 };
527
528
529
535 template <unsigned int dim>
536 class MagneticField : public dealii::Function<dim>
537 {
538 public:
544 MagneticField(const PhysicalParameters &physical_parameters)
545 : dealii::Function<dim>(3)
546 , prm{physical_parameters}
547 {}
548
549
583 void
584 vector_value([[maybe_unused]] const dealii::Point<dim> &point,
585 dealii::Vector<double> &magnetic_field) const override
586 {
587 AssertDimension(magnetic_field.size(), this->n_components);
588
590 // !!!EDIT HERE!!!
591 magnetic_field[0] = 0.; // B_x
592 magnetic_field[1] = 0.; // B_y
593 magnetic_field[2] = 0.; // B_z
595 }
596
597
598
599 private:
601 const PhysicalParameters prm;
602 };
603
604
605
611 template <unsigned int dim>
612 class BackgroundVelocityField : public dealii::Function<dim>
613 {
614 public:
620 BackgroundVelocityField(const PhysicalParameters &physical_parameters)
621 : dealii::Function<dim>(3)
622 , prm{physical_parameters}
623 {}
624
625
626
638 void
639 vector_value([[maybe_unused]] const dealii::Point<dim> &point,
640 dealii::Vector<double> &velocity) const override
641 {
642 AssertDimension(velocity.size(), this->n_components);
643
645 // !!!EDIT HERE!!!
646 // u(x) = u_sh/2r * ((1-r)*tanh(x/d_sh) + (1+r))
647 const double r = 4.;
648 const double d_sh = 0.001;
649 const double u_sh = 0.1;
650
651 // u_x
652 velocity[0] =
653 u_sh / (2 * r) * ((1 - r) * std::tanh(point[0] / d_sh) + (1 + r));
654 velocity[1] = 0.; // u_y
655 velocity[2] = 0.; // u_z
657 }
658
659
673 void
675 [[maybe_unused]] const std::vector<dealii::Point<dim>> &points,
676 std::vector<double> &divergence) const
677 {
678 AssertDimension(divergence.size(), points.size());
679
680 for (unsigned int q_index = 0; q_index < points.size(); ++q_index)
681 {
683 // !!!EDIT HERE!!!
684 // u(x) = u_sh/2r * ((1-r)*tanh(x/d_sh) + (1+r))
685 // => d/dx u(x) = u_sh/2r 1/d_sh (1-r) (1-tanh(x/d_sh)^2)
686 const double r = 4.;
687 const double d_sh = 0.001;
688 const double u_sh = 0.1;
689
690 const double x = points[q_index][0];
691
692 // div u
693 divergence[q_index] =
694 u_sh / (2 * r) * (1 - r) / d_sh *
695 (1 - std::tanh(x / d_sh) * std::tanh(x / d_sh));
697 }
698 }
699
700
701
716 void
718 const std::vector<dealii::Point<dim>> &points,
719 std::vector<dealii::Vector<double>> &material_derivatives) const
720 {
721 AssertDimension(material_derivatives.size(), points.size());
722 AssertDimension(material_derivatives[0].size(), this->n_components);
723
724 for (unsigned int q_index = 0; q_index < points.size(); ++q_index)
725 {
727 // !!!EDIT HERE!!!
728 // u(x) = u_sh/2r * ((1-r)*tanh(x/d_sh) + (1+r))
729 // => D/Dt u(x) = d/dt u(x) + u d/dx u(x)
730 // = (u_sh/2r)^2 * ((1-r)*tanh(x/d_sh) + (1+r)) *
731 // 1/d_sh (1-r) (1-tanh(x/d_sh)^2)
732 const double r = 4.;
733 const double d_sh = 0.001;
734 const double u_sh = 0.1;
735
736 const double x = points[q_index][0];
737
738 // D/Dt u_x
739 material_derivatives[q_index][0] =
740 u_sh * u_sh / (4 * r * r) / d_sh * (1 - r) *
741 ((1 - r) * std::tanh(x / d_sh) + (1 + r)) *
742 (1 - std::tanh(x / d_sh) * std::tanh(x / d_sh));
743 material_derivatives[q_index][1] = 0.; // D/Dt u_y
744 material_derivatives[q_index][2] = 0.; // D/Dt u_z
746 }
747 }
748
749
750
764 void
765 jacobian_list(const std::vector<dealii::Point<dim>> &points,
766 std::vector<dealii::FullMatrix<double>> &jacobians) const
767 {
768 AssertDimension(jacobians.size(), points.size());
769 AssertDimension(jacobians[0].m(), this->n_components);
770 AssertDimension(jacobians[0].n(), this->n_components);
771
772 for (unsigned int q_index = 0; q_index < points.size(); ++q_index)
773 {
775 // !!!EDIT HERE!!!
776 // u(x) = u_sh/2r * ((1-r)*tanh(x/d_sh) + (1+r))
777 // => u_00 = du/dx = u_sh/2r 1/d_sh (1-r) (1-tanh(x/d_sh)^2)
778 const double r = 4.;
779 const double d_sh = 0.001;
780 const double u_sh = 0.1;
781
782 const double x = points[q_index][0];
783
784 // \partial u_x / \partial x
785 jacobians[q_index][0][0] =
786 u_sh / (2 * r) * (1 - r) / d_sh *
787 (1 - std::tanh(x / d_sh) * std::tanh(x / d_sh));
788 jacobians[q_index][0][1] = 0.; // \partial u_x / \partial y
789 jacobians[q_index][0][2] = 0.; // \partial u_x / \partial z
790
791 jacobians[q_index][1][0] = 0.; // \partial u_y / \partial x
792 jacobians[q_index][1][1] = 0.; // \partial u_y / \partial y
793 jacobians[q_index][1][2] = 0.; // \partial u_y / \partial z
794
795 jacobians[q_index][2][0] = 0.; // \partial u_z / \partial x
796 jacobians[q_index][2][1] = 0.; // \partial u_z / \partial y
797 jacobians[q_index][2][2] = 0.; // \partial u_z / \partial z
799 }
800 }
801
802
803
804 private:
806 const PhysicalParameters prm;
807 };
808 } // namespace VFP
809} // namespace sapphirepp
810#endif
Class to implement user defined parameters.
Definition config.h:56
void declare_parameters(dealii::ParameterHandler &prm)
Declare parameters in parameter file.
Definition config.h:75
void parse_parameters(dealii::ParameterHandler &prm)
Parse parameters from parameter file.
Definition config.h:105
void material_derivative_list(const std::vector< dealii::Point< dim > > &points, std::vector< dealii::Vector< double > > &material_derivatives) const
Evaluate the material derivative of the velocity field.
Definition config.h:717
BackgroundVelocityField(const PhysicalParameters &physical_parameters)
Constructor.
Definition config.h:620
void vector_value(const dealii::Point< dim > &point, dealii::Vector< double > &velocity) const override
Evaluate the velocity field at a point p.
Definition config.h:639
void divergence_list(const std::vector< dealii::Point< dim > > &points, std::vector< double > &divergence) const
Evaluate the divergence of the velocity field.
Definition config.h:674
void jacobian_list(const std::vector< dealii::Point< dim > > &points, std::vector< dealii::FullMatrix< double > > &jacobians) const
Evaluate the Jacobian matrix of the velocity field.
Definition config.h:765
BoundaryValueFunction(const PhysicalParameters &physical_parameters, const unsigned int system_size)
Constructor.
Definition config.h:252
void bc_vector_value_list(const std::vector< dealii::Point< dim > > &points, const unsigned int boundary_id, std::vector< dealii::Vector< double > > &bc_values) const
Values of the distribution function at the boundary specified by boundary_id.
Definition config.h:319
InitialValueFunction(const PhysicalParameters &physical_parameters, const unsigned int system_size)
Constructor.
Definition config.h:162
void vector_value(const dealii::Point< dim > &point, dealii::Vector< double > &f) const override
Evaluate the initial condition at point p.
Definition config.h:206
void vector_value(const dealii::Point< dim > &point, dealii::Vector< double > &magnetic_field) const override
Evaluate the magnetic field at a point p.
Definition config.h:584
MagneticField(const PhysicalParameters &physical_parameters)
Constructor.
Definition config.h:544
Calculate the matrices of the PDE system.
Definition pde-system.h:58
void value_list(const std::vector< dealii::Point< dim > > &points, std::vector< double > &scattering_frequencies, const unsigned int component=0) const override
Evaluate the scattering frequency.
Definition config.h:409
ScatteringFrequency(const PhysicalParameters &physical_parameters)
Constructor.
Definition config.h:379
Source(const PhysicalParameters &physical_parameters, unsigned int system_size)
Constructor.
Definition config.h:450
void vector_value(const dealii::Point< dim > &point, dealii::Vector< double > &source_values) const override
Evaluate the source term.
Definition config.h:472
Namespace for the Vlasov-Fokker-Planck module.
Definition config.h:123
VFPFlags
Flags to activate the different terms of the VFP equation.
Definition vfp-flags.h:75
@ time_independent_fields
Definition vfp-flags.h:109
@ source
Definition vfp-flags.h:128
@ momentum
Definition vfp-flags.h:116
@ time_evolution
Definition vfp-flags.h:81
@ time_independent_source
Definition vfp-flags.h:137
@ collision
Definition vfp-flags.h:93
@ spatial_advection
Definition vfp-flags.h:87
constexpr unsigned int dimension
Definition config.h:127
constexpr VFPFlags vfp_flags
Definition config.h:135
Namespace for Sapphire+⁠+.
Definition config.h:51
sapphirepp::Utils::SapphireppLogStream saplog
The standard log stream for Sapphire+⁠+.
Definition sapphirepp-logstream.cpp:46
Define sapphirepp::VFP::PDESystem.
Define sapphirepp::Utils::SapphireppLogStream and sapphirepp::saplog.
Define sapphirepp::VFP::VFPFlags and other enums used by the sapphirepp::VFP module.