deal.II version GIT relicensing-2114-gd9582acac8 2024-11-06 19:20:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
tensor_function_parser.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2019 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
19#include <deal.II/base/tensor.h>
23
24#include <map>
25
27
28
29template <int rank, int dim, typename Number>
30const std::vector<std::string> &
32{
33 return this->expressions;
34}
35
36
37
38template <int rank, int dim, typename Number>
40 const double initial_time)
41 : TensorFunction<rank, dim, Number>(initial_time)
42 , n_components(Utilities::pow(dim, rank))
43{}
44
45
46template <int rank, int dim, typename Number>
48 const std::string &expression,
49 const std::string &constants,
50 const std::string &variable_names)
51 : TensorFunction<rank, dim, Number>()
52 , n_components(Utilities::pow(dim, rank))
53{
58 0,
60 ",",
61 "="));
63 expression,
66 dim + 1);
67}
68
69
70
71template <int rank, int dim, typename Number>
72void
74 const std::string &variables,
75 const std::vector<std::string> &expressions,
76 const std::map<std::string, double> &constants,
77 const bool time_dependent)
78{
79 AssertThrow(this->n_components == expressions.size(),
80 ExcInvalidExpressionSize(this->n_components, expressions.size()));
82 variables, expressions, constants, time_dependent);
83}
84
85
86
87template <int rank, int dim, typename Number>
88void
90 const std::string &vars,
91 const std::string &expression,
92 const std::map<std::string, double> &constants,
93 const bool time_dependent)
94{
95 initialize(vars,
96 Utilities::split_string_list(expression, ';'),
97 constants,
99}
100
101
102
103template <int rank, int dim, typename Number>
106{
107 std::array<Number, Tensor<rank, dim, Number>::n_independent_components>
108 values;
109 auto values_view = make_array_view(values.begin(), values.end());
110 this->do_all_values(p, this->get_time(), values_view);
111
113 make_array_view(values.begin(), values.end()));
114}
115
116
117
118template <int rank, int dim, typename Number>
119void
121 const std::vector<Point<dim>> &p,
122 std::vector<Tensor<rank, dim, Number>> &values) const
123{
124 Assert(p.size() == values.size(),
125 ExcDimensionMismatch(p.size(), values.size()));
126
127 for (unsigned int i = 0; i < p.size(); ++i)
128 {
129 values[i] = value(p[i]);
130 }
131}
132
133// explicit instantiations
134#include "tensor_function_parser.inst"
135
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
Definition array_view.h:949
static const unsigned int max_int_value
Definition patterns.h:594
TensorFunctionParser(const double initial_time=0.0)
virtual Tensor< rank, dim, Number > value(const Point< dim > &p) const override
virtual void value_list(const std::vector< Point< dim > > &p, std::vector< Tensor< rank, dim, Number > > &values) const override
virtual void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false) override
const std::vector< std::string > & get_expressions() const
friend class Tensor
Definition tensor.h:865
std::conditional_t< rank_==1, std::array< Number, dim >, std::array< Tensor< rank_ - 1, dim, Number >, dim > > values
Definition tensor.h:851
virtual void initialize(const std::string &vars, const std::vector< std::string > &expressions, const std::map< std::string, double > &constants, const bool time_dependent=false)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define AssertThrow(cond, exc)
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Definition utilities.cc:701
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete