|
129 | 129 | "degree_basis = 10 #degree_basis = n_points-1\n",
|
130 | 130 | "(p_Legn, p_Legn_prime,\n",
|
131 | 131 | "p_Legn1, p_Legn1_prime,\n",
|
132 |
| - "x_LG, w_LG,\n", |
133 |
| - "x_LGL, w_LGL) = generate_LGL_points(degree_basis)\n", |
| 132 | + "x_LG_unsorted, w_LG_unsorted,\n", |
| 133 | + "x_LGL_unsorted, w_LGL_unsorted) = generate_LGL_points(degree_basis)\n", |
| 134 | + "\n", |
| 135 | + "#####\n", |
| 136 | + "#The root finder returns unsorted roots,\n", |
| 137 | + "#We fix that in these lines\n", |
| 138 | + "#####\n", |
| 139 | + "#Indexes that would sort x_LG using value\n", |
| 140 | + "sort_idxs_LG = np.argsort(x_LG_unsorted)\n", |
| 141 | + "#Sorting x_LG and w_LG using those indexes\n", |
| 142 | + "x_LG = x_LG_unsorted[sort_idxs_LG]\n", |
| 143 | + "w_LG = w_LG_unsorted[sort_idxs_LG]\n", |
| 144 | + "\n", |
| 145 | + "#Indexes that would sort x_LG using value\n", |
| 146 | + "sort_idxs_LGL = np.argsort(x_LGL_unsorted)\n", |
| 147 | + "#Sorting x_LG and w_LG using those indexes\n", |
| 148 | + "x_LGL = x_LGL_unsorted[sort_idxs_LGL]\n", |
| 149 | + "w_LGL = w_LGL_unsorted[sort_idxs_LGL]\n", |
| 150 | + "\n", |
134 | 151 | "x = np.linspace(-1,1,1000)"
|
135 | 152 | ]
|
136 | 153 | },
|
|
243 | 260 | },
|
244 | 261 | {
|
245 | 262 | "cell_type": "markdown",
|
246 |
| - "id": "29b4e4b2", |
| 263 | + "id": "fd474626", |
247 | 264 | "metadata": {},
|
248 | 265 | "source": [
|
249 | 266 | "### First Order Differential Operator\n",
|
|
264 | 281 | "degree_basis = 2 #degree_basis = n_nodes-1\n",
|
265 | 282 | "(p_Legn, p_Legn_prime,\n",
|
266 | 283 | "p_Legn1, p_Legn1_prime,\n",
|
267 |
| - "x_LG, w_LG,\n", |
268 |
| - "x_LGL, w_LGL) = generate_LGL_points(degree_basis)\n", |
| 284 | + "x_LG_unsorted, w_LG_unsorted,\n", |
| 285 | + "x_LGL_unsorted, w_LGL_unsorted) = generate_LGL_points(degree_basis)\n", |
| 286 | + "\n", |
| 287 | + "#####\n", |
| 288 | + "#The root finder returns unsorted roots,\n", |
| 289 | + "#We fix that in these lines\n", |
| 290 | + "#####\n", |
| 291 | + "#Indexes that would sort x_LG using value\n", |
| 292 | + "sort_idxs_LG = np.argsort(x_LG_unsorted)\n", |
| 293 | + "#Sorting x_LG and w_LG using those indexes\n", |
| 294 | + "x_LG = x_LG_unsorted[sort_idxs_LG]\n", |
| 295 | + "w_LG = w_LG_unsorted[sort_idxs_LG]\n", |
| 296 | + "\n", |
| 297 | + "#Indexes that would sort x_LG using value\n", |
| 298 | + "sort_idxs_LGL = np.argsort(x_LGL_unsorted)\n", |
| 299 | + "#Sorting x_LG and w_LG using those indexes\n", |
| 300 | + "x_LGL = x_LGL_unsorted[sort_idxs_LGL]\n", |
| 301 | + "w_LGL = w_LGL_unsorted[sort_idxs_LGL]\n", |
269 | 302 | "\n",
|
270 | 303 | "n_nodes = len(x_LGL)\n",
|
271 | 304 | "x = np.linspace(-0.5,0.5,n_nodes)\n",
|
|
282 | 315 | },
|
283 | 316 | {
|
284 | 317 | "cell_type": "markdown",
|
285 |
| - "id": "3b0cdff7", |
| 318 | + "id": "c42c58a3", |
286 | 319 | "metadata": {},
|
287 | 320 | "source": [
|
288 | 321 | "### Computing P and Q\n",
|
|
299 | 332 | "metadata": {},
|
300 | 333 | "outputs": [],
|
301 | 334 | "source": [
|
302 |
| - "P_LG, Q_LG = first_order_P_Q(x_Lagrange_nodes=x_LG)\n", |
303 |
| - "P_LGL, Q_LGL = first_order_P_Q(x_Lagrange_nodes=x_LGL)\n", |
304 |
| - "P, Q = first_order_P_Q(x_Lagrange_nodes=x)\n", |
| 335 | + "P_LG, Q_LG = first_order_P_Q(x_Lagrange_nodes=x_LG, x_abcissae=x_LG, w_abcissae=w_LG)\n", |
| 336 | + "P_LGL, Q_LGL = first_order_P_Q(x_Lagrange_nodes=x_LGL, x_abcissae=x_LGL, w_abcissae=w_LGL)\n", |
| 337 | + "P, Q = first_order_P_Q(x_Lagrange_nodes=x, x_abcissae=x_LGL, w_abcissae=w_LGL)\n", |
305 | 338 | "print(\"P_LG:\")\n",
|
306 | 339 | "print(np.round(P_LG,2))\n",
|
307 | 340 | "print(\"P_LGL:\")\n",
|
|
415 | 448 | },
|
416 | 449 | {
|
417 | 450 | "cell_type": "markdown",
|
418 |
| - "id": "6b9af948", |
| 451 | + "id": "6b96145a", |
419 | 452 | "metadata": {},
|
420 | 453 | "source": [
|
421 | 454 | "## LGL nodes and weights, and SBP operators mapped to a new interval"
|
422 | 455 | ]
|
423 | 456 | },
|
424 | 457 | {
|
425 | 458 | "cell_type": "markdown",
|
426 |
| - "id": "21e75e21", |
| 459 | + "id": "ba077555", |
427 | 460 | "metadata": {},
|
428 | 461 | "source": [
|
429 | 462 | "It is often desired to work in a different interval than $[-1,1]$, say $[x_\\min, x_\\max]$. \n",
|
|
450 | 483 | {
|
451 | 484 | "cell_type": "code",
|
452 | 485 | "execution_count": null,
|
453 |
| - "id": "5d3c6e4d", |
| 486 | + "id": "0b1296b3", |
454 | 487 | "metadata": {},
|
455 | 488 | "outputs": [],
|
456 | 489 | "source": [
|
457 | 490 | "degree_basis = 4 #degree_basis = n_nodes-1\n",
|
458 |
| - "(p_Legn, p_Legn_prime,\n", |
459 |
| - "p_Legn1, p_Legn1_prime,\n", |
460 |
| - "xi_LG, w_LG,\n", |
461 |
| - "xi_LGL, w_LGL) = generate_LGL_points(degree_basis)\n", |
| 491 | + "(_, _,\n", |
| 492 | + "_, _,\n", |
| 493 | + "_, _,\n", |
| 494 | + "xi_LGL_unsorted, w_LGL_unsorted) = generate_LGL_points(degree_basis)\n", |
| 495 | + "\n", |
| 496 | + "#######################\n", |
| 497 | + "#######################\n", |
| 498 | + "#The root finder returns unsorted roots,\n", |
| 499 | + "#We fix that in these lines\n", |
| 500 | + "\n", |
| 501 | + "#Indexes that would sort x_LG using value\n", |
| 502 | + "sort_idxs_LGL = np.argsort(xi_LGL_unsorted)\n", |
| 503 | + "#Sorting x_LG and w_LG using those indexes\n", |
| 504 | + "xi_LGL = xi_LGL_unsorted[sort_idxs_LGL]\n", |
| 505 | + "w_LGL = w_LGL_unsorted[sort_idxs_LGL]\n", |
462 | 506 | "\n",
|
463 | 507 | "xmin = -3; xmax=3\n",
|
464 | 508 | "a = (xmax-xmin)/2.; b = (xmax+xmin)/2.\n",
|
465 | 509 | "x_mapped = a*xi_LGL+b\n",
|
466 |
| - "w_mapped = a*w_LGL" |
| 510 | + "w_mapped = a*w_LGL\n", |
| 511 | + "#######################\n", |
| 512 | + "#######################\n", |
| 513 | + "\n" |
467 | 514 | ]
|
468 | 515 | },
|
469 | 516 | {
|
470 | 517 | "cell_type": "code",
|
471 | 518 | "execution_count": null,
|
472 |
| - "id": "eab7e897", |
| 519 | + "id": "89b8b473", |
473 | 520 | "metadata": {},
|
474 | 521 | "outputs": [],
|
475 | 522 | "source": [
|
| 523 | + "print(f\"x={x_mapped}\")\n", |
| 524 | + "print(f\"Sum of weights\")\n", |
476 | 525 | "print(np.sum(w_LGL))\n",
|
477 | 526 | "print(np.sum(w_mapped))"
|
478 | 527 | ]
|
479 | 528 | },
|
480 | 529 | {
|
481 | 530 | "cell_type": "markdown",
|
482 |
| - "id": "d5880876", |
| 531 | + "id": "51b660f3", |
483 | 532 | "metadata": {},
|
484 | 533 | "source": [
|
485 | 534 | "Since the Lagrange basis and, therefore, the first order differential operator just require a set of nodes for computation, they are computed exactly as before.\n",
|
|
490 | 539 | {
|
491 | 540 | "cell_type": "code",
|
492 | 541 | "execution_count": null,
|
493 |
| - "id": "6b5647d5", |
| 542 | + "id": "f9eb7843", |
494 | 543 | "metadata": {},
|
495 | 544 | "outputs": [],
|
496 | 545 | "source": [
|
497 |
| - "poly, polyp = generate_lagrange_poly(1,x_mapped)\n", |
| 546 | + "idx_support = 3 #Which node is going to be 1\n", |
| 547 | + "poly, polyp = generate_lagrange_poly(idx_support,x_mapped)\n", |
498 | 548 | "x = np.linspace(-3.5,3.5,50)\n",
|
499 | 549 | "vpoly = np.vectorize(poly)\n",
|
500 | 550 | "vpolyp = np.vectorize(polyp)\n",
|
501 | 551 | "fig = plt.figure(dpi=100, figsize=(8,4))\n",
|
502 | 552 | "ax = fig.add_subplot(1, 1, 1)\n",
|
503 | 553 | "ax.set_ylim([-5,5])\n",
|
504 | 554 | "ax.plot(x,np.zeros(len(x)),color='k', lw=1)\n",
|
505 |
| - "ax.plot(x, vpoly(x), label=f'$L_{1}(x)$')\n", |
506 |
| - "ax.plot(x, vpolyp(x),color='g', label=f'$L_{1}\\'(x)$')\n", |
| 555 | + "ax.plot(x, vpoly(x), label=f'$L_{idx_support}(x)$')\n", |
| 556 | + "ax.plot(x, vpolyp(x),color='g', label=f'$L_{idx_support}\\'(x)$')\n", |
507 | 557 | "ax.scatter(x_mapped,vpoly(x_mapped),marker='x', color='r')\n",
|
508 | 558 | "plt.legend()\n",
|
509 | 559 | "plt.show()"
|
510 | 560 | ]
|
511 | 561 | },
|
512 | 562 | {
|
513 | 563 | "cell_type": "markdown",
|
514 |
| - "id": "8f096353", |
| 564 | + "id": "b8f02bdd", |
515 | 565 | "metadata": {},
|
516 | 566 | "source": [
|
517 | 567 | "### First Order Differential Operator D"
|
|
520 | 570 | {
|
521 | 571 | "cell_type": "code",
|
522 | 572 | "execution_count": null,
|
523 |
| - "id": "8a818d8b", |
| 573 | + "id": "4507dee6", |
524 | 574 | "metadata": {},
|
525 | 575 | "outputs": [],
|
526 | 576 | "source": [
|
|
530 | 580 | },
|
531 | 581 | {
|
532 | 582 | "cell_type": "markdown",
|
533 |
| - "id": "b7d79ad0", |
| 583 | + "id": "a8b92631", |
534 | 584 | "metadata": {},
|
535 | 585 | "source": [
|
536 | 586 | "### Computing P and Q\n",
|
|
545 | 595 | {
|
546 | 596 | "cell_type": "code",
|
547 | 597 | "execution_count": null,
|
548 |
| - "id": "4e4dde46", |
| 598 | + "id": "9f690af2", |
549 | 599 | "metadata": {
|
550 | 600 | "scrolled": true
|
551 | 601 | },
|
552 | 602 | "outputs": [],
|
553 | 603 | "source": [
|
554 |
| - "P, Q = first_order_P_Q(x_Lagrange_nodes=x_mapped, x_abcissae=x_mapped)\n", |
| 604 | + "P, Q = first_order_P_Q(x_Lagrange_nodes=x_mapped, x_abcissae=x_mapped, w_abcissae=w_mapped)\n", |
555 | 605 | "print(\"P:\")\n",
|
556 | 606 | "print(np.round(P,2))\n",
|
557 | 607 | "print(\"Q:\")\n",
|
|
560 | 610 | },
|
561 | 611 | {
|
562 | 612 | "cell_type": "markdown",
|
563 |
| - "id": "51c85785", |
| 613 | + "id": "585fcfa2", |
564 | 614 | "metadata": {},
|
565 | 615 | "source": [
|
566 | 616 | "### Verifying SBP properties\n",
|
|
570 | 620 | {
|
571 | 621 | "cell_type": "code",
|
572 | 622 | "execution_count": null,
|
573 |
| - "id": "ce1d4970", |
| 623 | + "id": "c3b4dc89", |
574 | 624 | "metadata": {},
|
575 | 625 | "outputs": [],
|
576 | 626 | "source": [
|
|
579 | 629 | },
|
580 | 630 | {
|
581 | 631 | "cell_type": "markdown",
|
582 |
| - "id": "33b9a684", |
| 632 | + "id": "1ccd0d8b", |
583 | 633 | "metadata": {},
|
584 | 634 | "source": [
|
585 | 635 | "Now we check if\n",
|
|
591 | 641 | {
|
592 | 642 | "cell_type": "code",
|
593 | 643 | "execution_count": null,
|
594 |
| - "id": "f6ad6b75", |
| 644 | + "id": "46f1b6a5", |
595 | 645 | "metadata": {},
|
596 | 646 | "outputs": [],
|
597 | 647 | "source": [
|
|
0 commit comments