Lines Matching refs:n
7 "# libCEED for Python examples\n",
8 "\n",
9 …oject.org/) (CEED) of the [Exascale Computing Project](https://www.exascaleproject.org/) (ECP).\n",
10 "\n",
18 "## Setting up libCEED for Python\n",
19 "\n",
36 "## CeedElemRestriction\n",
37 "\n",
38 …ntation](https://libceed.org/en/latest/libCEEDapi.html#finite-element-operator-decomposition)).\n",
39 "\n",
49 "import libceed\n",
50 "import numpy as np\n",
51 "\n",
52 "# In this 1D example, the dofs are indexed as\n",
53 "#\n",
54 "# Restriction input:\n",
55 "# x -- x -- x -- x\n",
56 "# 10 -- 11 -- 12 -- 13\n",
57 "#\n",
58 "# Restriction output:\n",
59 "# x -- x | x -- x | x -- x\n",
60 "# 10 -- 11 | 11 -- 12 | 12 -- 13\n",
61 "\n",
62 "ceed = libceed.Ceed()\n",
63 "\n",
64 "num_elem = 3\n",
65 "\n",
66 "x = ceed.Vector(num_elem+1)\n",
67 "a = np.arange(10, 10 + num_elem+1, dtype=\"float64\")\n",
68 "x.set_array(a, cmode=libceed.USE_POINTER)\n",
69 "\n",
70 "indices = np.zeros(2*num_elem, dtype=\"int32\")\n",
71 "for i in range(num_elem):\n",
72 " indices[2*i+0] = i\n",
73 " indices[2*i+1] = i+1\n",
74 " \n",
75 "r = ceed.ElemRestriction(num_elem, 2, 1, 1, num_elem+1, indices, cmode=libceed.USE_POINTER)\n",
76 "\n",
77 "y = ceed.Vector(2*num_elem)\n",
78 "y.set_value(0)\n",
79 "\n",
80 "r.apply(x, y)\n",
81 "\n",
82 "with y.array_read() as y_array:\n",
83 " print('y =', y_array)\n"
99 "# In this 1D example, there are four nodes per element\n",
100 "# \n",
101 "# x -- o -- o -- x -- o -- o -- x -- o -- o -- x\n",
102 "\n",
103 "num_elem = 3\n",
104 "\n",
105 "indices = np.zeros(4*num_elem, dtype=\"int32\")\n",
106 "\n",
107 "for i in range(num_elem):\n",
108 " indices[4*i+0] = i*3+0\n",
109 " indices[4*i+1] = i*3+1\n",
110 " indices[4*i+2] = i*3+2\n",
111 " indices[4*i+3] = i*3+3\n",
112 "\n",
113 … "r = ceed.ElemRestriction(num_elem, 4, 1, 1, 3*num_elem+1, indices, cmode=libceed.USE_POINTER)\n",
114 "\n",
115 "mult = r.get_multiplicity()\n",
116 "\n",
117 "with mult.array_read() as m_array:\n",
118 " print('mult =', m_array)\n"
134 "# In this 1D example, the dofs are indexed as\n",
135 "#\n",
136 "# Restriction input:\n",
137 "# x -- x -- x\n",
138 "# 10-11 -- 12-13 -- 14-15\n",
139 "#\n",
140 "# Restriction output:\n",
141 "# x -- x | x -- x | x -- x\n",
142 "# 10 -- 11 | 12 -- 13 | 14 -- 15\n",
143 "\n",
144 "num_elem = 3\n",
145 "\n",
146 "x = ceed.Vector(2*num_elem)\n",
147 "a = np.arange(10, 10 + 2*num_elem, dtype=\"float64\")\n",
148 "x.set_array(a, cmode=libceed.USE_POINTER)\n",
149 "\n",
150 "strides = np.array([1, 2, 2], dtype=\"int32\")\n",
151 "\n",
152 "r = ceed.StridedElemRestriction(num_elem, 2, 1, 2*num_elem, strides)\n",
153 "\n",
154 "y = ceed.Vector(2*num_elem)\n",
155 "y.set_value(0)\n",
156 "\n",
157 "r.apply(x, y)\n",
158 "\n",
159 "with y.array_read() as y_array:\n",
160 " print('y =', y_array)\n"
176 "# In this 1D example, there are three elements (four nodes in total) \n",
177 "# \n",
178 "# x -- x -- x -- x\n",
179 "\n",
180 "num_elem = 3\n",
181 "\n",
182 "strides = np.array([1, 2, 2], dtype=\"int32\")\n",
183 "\n",
184 "r = ceed.BlockedStridedElemRestriction(num_elem, 2, 2, 1, 2*(num_elem+1), strides)\n",
185 "\n",
209 "# In this 1D example, the dofs are indexed as\n",
210 "# \n",
211 "# x -- x -- x -- x -- x -- x -- x -- x -- x\n",
212 "# 10 -- 11 -- 12 -- 13 -- 14 -- 15 -- 16 -- 17 -- 18\n",
213 "# \n",
214 "# We block elements into groups of 5:\n",
215 "# ________________________________________________________________________________________\n",
216 … "# | block 0: | block 1: |\n",
217 … "# | e0 | e1 | e2 | e3 | e4 | e0 | e1 | e2 |\n",
218 … "# | | |\n",
219 … "# | x -- x | x -- x | x -- x | x -- x | x -- x | x -- x | x -- x | x -- x |\n",
220 … "# | 10 -- 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 |\n",
221 "#\n",
222 "# Intermediate logical representation:\n",
223 "# ______________________________________________________________________________\n",
224 "# | block 0: | block 1: |\n",
225 "# | node0: node1: | node0: node1: |\n",
226 "# | 10-11-12-13-14 11-12-13-14-15 | 15-16-17- *- * 16-17-18- *- * |\n",
227 "# | e0 e1 e2 e3 e4 e0 e1 e2 e3 e4 | e0 e1 e2 e3 e4 e0 e1 e2 e3 e4 |\n",
228 "#\n",
229 "# Forward restriction output:\n",
230 "# ______________________________________________________________________________\n",
231 "# | block 0: | block 1: |\n",
232 "# | node0: node1: | node0: node1: |\n",
233 "# | 10-11-12-13-14 11-12-13-14-15 | 15-16-17-17-17 16-17-18-18-18 |\n",
234 "# | e0 e1 e2 e3 e4 e0 e1 e2 e3 e4 | e0 e1 e2 e3 e4 e0 e1 e2 e3 e4 |\n",
235 "\n",
236 "num_elem = 8\n",
237 "block_size = 5\n",
238 "\n",
239 "x = ceed.Vector(num_elem+1)\n",
240 "a = np.arange(10, 10 + num_elem+1, dtype=\"float64\")\n",
241 "x.set_array(a, cmode=libceed.USE_POINTER)\n",
242 "\n",
243 "indices = np.zeros(2*num_elem, dtype=\"int32\")\n",
244 "for i in range(num_elem):\n",
245 " indices[2*i+0] = i\n",
246 " indices[2*i+1] = i+1\n",
247 "\n",
248 "r = ceed.BlockedElemRestriction(num_elem, 2, block_size, 1, 1, num_elem+1, indices,\n",
249 " cmode=libceed.USE_POINTER)\n",
250 "\n",
251 "y = ceed.Vector(2*block_size*2)\n",
252 "y.set_value(0)\n",
253 "\n",
254 "r.apply(x, y)\n",
255 "\n",
256 "with y.array_read() as y_array:\n",
257 " print('y =', y_array)\n",
258 "\n",
259 "x.set_value(0)\n",
260 "r.T.apply(y, x)\n",
261 "\n",
262 "with x.array_read() as x_array:\n",
279 "# In this 1D example, the dofs are indexed as\n",
280 "# \n",
281 "# x -- x -- x -- x -- x -- x -- x -- x -- x\n",
282 "# 10 -- 11 -- 12 -- 13 -- 14 -- 15 -- 16 -- 17 -- 18\n",
283 "#\n",
284 "# We block elements into groups of 5:\n",
285 "# ________________________________________________________________________________________\n",
286 … "# | block 0: | block 1: |\n",
287 … "# | e0 | e1 | e2 | e3 | e4 | e0 | e1 | e2 |\n",
288 … "# | | |\n",
289 … "# | x -- x | x -- x | x -- x | x -- x | x -- x | x -- x | x -- x | x -- x |\n",
290 … "# | 10 -- 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 |\n",
291 "#\n",
292 "# Intermediate logical representation (extraction of block1 only in this case):\n",
293 "# _______________________________________\n",
294 "# | block 1: |\n",
295 "# | node0: node1: |\n",
296 "# | 15-16-17- *- * 16-17-18- *- * |\n",
297 "# | e0 e1 e2 e3 e4 e0 e1 e2 e3 e4 |\n",
298 "#\n",
299 "# Forward restriction output:\n",
300 "# _______________________________________\n",
301 "# | block 1: |\n",
302 "# | node0: node1: |\n",
303 "# | 15-16-17-17-17 16-17-18-18-18 |\n",
304 "# | e0 e1 e2 e3 e4 e0 e1 e2 e3 e4 |\n",
305 "\n",
306 "num_elem = 8\n",
307 "block_size = 5\n",
308 "\n",
309 "x = ceed.Vector(num_elem+1)\n",
310 "a = np.arange(10, 10 + num_elem+1, dtype=\"float64\")\n",
311 "x.set_array(a, cmode=libceed.USE_POINTER)\n",
312 "\n",
313 "indices = np.zeros(2*num_elem, dtype=\"int32\")\n",
314 "for i in range(num_elem):\n",
315 " indices[2*i+0] = i\n",
316 " indices[2*i+1] = i+1\n",
317 "\n",
318 "r = ceed.BlockedElemRestriction(num_elem, 2, block_size, 1, 1, num_elem+1, indices,\n",
319 " cmode=libceed.USE_POINTER)\n",
320 "\n",
321 "y = ceed.Vector(block_size*2)\n",
322 "y.set_value(0)\n",
323 "\n",
324 "r.apply_block(1, x, y)\n",
325 "\n",
326 "with y.array_read() as y_array:\n",
327 " print('y =', y_array)\n",
328 "\n",
329 "x.set_value(0)\n",
330 "r.T.apply_block(1, y, x)\n",
331 "\n",
332 "with x.array_read() as array:\n",