Reference documentation for deal.II version 9.5.0
\(\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// Copyright (C) 2005 - 2022 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16
20#include <deal.II/base/tensor.h>
24
25#include <map>
26
28
29
30template <int rank, int dim, typename Number>
31const std::vector<std::string> &
33{
34 return this->expressions;
35}
36
37
38
39template <int rank, int dim, typename Number>
41 const double initial_time)
42 : TensorFunction<rank, dim, Number>(initial_time)
43 , n_components(Utilities::pow(dim, rank))
44{}
45
46
47template <int rank, int dim, typename Number>
49 const std::string &expression,
50 const std::string &constants,
51 const std::string &variable_names)
52 : TensorFunction<rank, dim, Number>()
53 , n_components(Utilities::pow(dim, rank))
54{
59 0,
61 ",",
62 "="));
63 initialize(variable_names,
64 expression,
65 constants_map,
66 Utilities::split_string_list(variable_names, ",").size() ==
67 dim + 1);
68}
69
70
71
72template <int rank, int dim, typename Number>
73void
75 const std::string & variables,
76 const std::vector<std::string> & expressions,
77 const std::map<std::string, double> &constants,
78 const bool time_dependent)
79{
80 AssertThrow(this->n_components == expressions.size(),
81 ExcInvalidExpressionSize(this->n_components, expressions.size()));
83 variables, expressions, constants, time_dependent);
84}
85
86
87
88template <int rank, int dim, typename Number>
89void
91 const std::string & vars,
92 const std::string & expression,
93 const std::map<std::string, double> &constants,
94 const bool time_dependent)
95{
96 initialize(vars,
97 Utilities::split_string_list(expression, ';'),
98 constants,
99 time_dependent);
100}
101
102
103
104template <int rank, int dim, typename Number>
107{
108 std::array<Number, Tensor<rank, dim, Number>::n_independent_components>
109 values;
110 auto values_view = make_array_view(values.begin(), values.end());
111 this->do_all_values(p, this->get_time(), values_view);
112
114 make_array_view(values.begin(), values.end()));
115}
116
117
118
119template <int rank, int dim, typename Number>
120void
122 const std::vector<Point<dim>> & p,
123 std::vector<Tensor<rank, dim, Number>> &values) const
124{
125 Assert(p.size() == values.size(),
126 ExcDimensionMismatch(p.size(), values.size()));
127
128 for (unsigned int i = 0; i < p.size(); ++i)
129 {
130 values[i] = value(p[i]);
131 }
132}
133
134// explicit instantiations
135#include "tensor_function_parser.inst"
136
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
Definition array_view.h:704
static const unsigned int max_int_value
Definition patterns.h:591
Definition point.h:112
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
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:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#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:702
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete