Peano
Loading...
Searching...
No Matches
LagrangeBasis.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3
4
5from abc import abstractmethod
6
7
8
9
10def render_tensor_1(tensor,entry_seperator=",",vector_seperator=("{","}")):
11 """
12 Converts nested list or numpy matrix to nested list of strings.
13 :param tensor: list or numpy vector storing mpmath numbers
14 """
15 result = "{} {}".format( vector_seperator[0], tensor[0] )
16 for elem in tensor[1:]:
17 result += entry_seperator
18 result += str(elem)
19 result += vector_seperator[1]
20 return result
21
22
23def render_tensor_2(tensor,use_multidimensional_arrays,entry_seperator=",",vector_seperator=("{","}")):
24 """
25 Converts nested list or numpy matrix to nested list of strings.
26 :param tensor: nested list or numpy matrix storing mpmath numbers
27 """
28 def render_row(row):
29 row_result = ""
30 if use_multidimensional_arrays:
31 row_result += vector_seperator[0]
32 row_result += str(row[0])
33 for elem in row[1:]:
34 row_result += entry_seperator
35 row_result += str(elem)
36 if use_multidimensional_arrays:
37 row_result += vector_seperator[1]
38 return row_result
39
40
41 result = vector_seperator[0]
42 result += render_row(tensor[0])
43 for row in tensor[1:]:
44 result += entry_seperator
45 result += render_row(row)
46 result += vector_seperator[1]
47 return result
48
49
50def render_tensor_3(tensor,use_multidimensional_arrays,entry_seperator=",",vector_seperator=("{","}")):
51 """
52 Converts nested list or numpy matrix to nested list of strings.
53 :param tensor: nested list or numpy matrix storing mpmath numbers
54 """
55 def render_row(row):
56 row_result = ""
57 if use_multidimensional_arrays:
58 row_result += vector_seperator[0]
59 row_result += str(row[0])
60 for elem in row[1:]:
61 row_result += entry_seperator
62 row_result += str(elem)
63 if use_multidimensional_arrays:
64 row_result += vector_seperator[1]
65 return row_result
66
67
68 def render_block(block):
69 row_result = ""
70 if use_multidimensional_arrays:
71 row_result += vector_seperator[0]
72 row_result += render_row(block[0])
73 for elem in block[1:]:
74 row_result += entry_seperator
75 row_result += render_row(elem)
76 if use_multidimensional_arrays:
77 row_result += vector_seperator[1]
78 return row_result
79
80 result = vector_seperator[0]
81 result += render_block(tensor[0])
82 for row in tensor[1:]:
83 result += entry_seperator
84 result += render_block(row)
85 result += vector_seperator[1]
86 return result
87
88
89
91 """
92
93 Abstract base class for all Lagrange bases available in ExaHyPE 2
94
95 This tool relies heavily on SciPy. I could have used sympy as well, but
96 eventually decided to keep it as simple as possible. So I work with
97 functors and no symbolic representation. But I could
98
99 """
100
101
102 def __init__(self, polynomial_order, render_digits = 64):
103 self._polynomial_order = polynomial_order
104 self._render_digits = render_digits
105
106
107 @property
108 def order(self):
109 return self._polynomial_order
110
111
112 @property
113 def dofs_per_axis(self):
114 return self._polynomial_order+1
115
116
117 # protected
118 @abstractmethod
119 def init_dictionary_with_default_parameters(self,dictionary,use_multidimensional_arrays):
120 """
121
122 To be implemented by subclass.
123
124
125 multidimensional_arrays: Boolean
126 If it is to False, all the matrices should be flattened into one array (C
127 enumeration). If it is set, the matrices should be written down as proper
128 two-dimensional arrays. Analogously, all inter-grid transfer operators
129 either are represented as array or as d-dimensional construct.
130
131 """
132 assert False, "To be implemented by subclass."
Abstract base class for all Lagrange bases available in ExaHyPE 2.
init_dictionary_with_default_parameters(self, dictionary, use_multidimensional_arrays)
To be implemented by subclass.
__init__(self, polynomial_order, render_digits=64)
render_tensor_3(tensor, use_multidimensional_arrays, entry_seperator=",", vector_seperator=("{","}"))
Converts nested list or numpy matrix to nested list of strings.
render_tensor_2(tensor, use_multidimensional_arrays, entry_seperator=",", vector_seperator=("{","}"))
Converts nested list or numpy matrix to nested list of strings.
render_tensor_1(tensor, entry_seperator=",", vector_seperator=("{","}"))
Converts nested list or numpy matrix to nested list of strings.