@@ -458,23 +458,25 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
458
458
459
459
model = MPI .COMM_WORLD .bcast (model , root = 0 )
460
460
partitioner = dolfinx .cpp .mesh .create_cell_partitioner (dolfinx .mesh .GhostMode .shared_facet )
461
- msh , cell_tags , facet_tags = io .gmshio .model_to_mesh (
462
- model , MPI . COMM_WORLD , 0 , gdim = 2 , partitioner = partitioner
463
- )
461
+ mesh_data = io .gmshio .model_to_mesh (model , MPI . COMM_WORLD , 0 , gdim = 2 , partitioner = partitioner )
462
+ assert mesh_data . cell_tags is not None , "Cell tags are missing"
463
+ assert mesh_data . facet_tags is not None , "Facet tags are missing"
464
464
465
465
gmsh .finalize ()
466
466
MPI .COMM_WORLD .barrier ()
467
467
# -
468
468
469
469
# Visually check of the mesh and of the subdomains using PyVista:
470
470
471
- tdim = msh .topology .dim
471
+ tdim = mesh_data . mesh .topology .dim
472
472
if have_pyvista :
473
- topology , cell_types , geometry = plot .vtk_mesh (msh , 2 )
473
+ topology , cell_types , geometry = plot .vtk_mesh (mesh_data . mesh , 2 )
474
474
grid = pyvista .UnstructuredGrid (topology , cell_types , geometry )
475
475
plotter = pyvista .Plotter ()
476
- num_local_cells = msh .topology .index_map (tdim ).size_local
477
- grid .cell_data ["Marker" ] = cell_tags .values [cell_tags .indices < num_local_cells ]
476
+ num_local_cells = mesh_data .mesh .topology .index_map (tdim ).size_local
477
+ grid .cell_data ["Marker" ] = mesh_data .cell_tags .values [
478
+ mesh_data .cell_tags .indices < num_local_cells
479
+ ]
478
480
grid .set_active_scalars ("Marker" )
479
481
plotter .add_mesh (grid , show_edges = True )
480
482
plotter .view_xy ()
@@ -489,15 +491,17 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
489
491
# will use Lagrange elements:
490
492
491
493
degree = 3
492
- curl_el = element ("N1curl" , msh .basix_cell (), degree , dtype = real_type )
493
- lagr_el = element ("Lagrange" , msh .basix_cell (), degree , dtype = real_type )
494
- V = fem .functionspace (msh , mixed_element ([curl_el , lagr_el ]))
494
+ curl_el = element ("N1curl" , mesh_data . mesh .basix_cell (), degree , dtype = real_type )
495
+ lagr_el = element ("Lagrange" , mesh_data . mesh .basix_cell (), degree , dtype = real_type )
496
+ V = fem .functionspace (mesh_data . mesh , mixed_element ([curl_el , lagr_el ]))
495
497
496
498
# The integration domains of our problem are the following:
497
499
498
500
# +
499
501
# Measures for subdomains
500
- dx = ufl .Measure ("dx" , msh , subdomain_data = cell_tags , metadata = {"quadrature_degree" : 5 })
502
+ dx = ufl .Measure (
503
+ "dx" , mesh_data .mesh , subdomain_data = mesh_data .cell_tags , metadata = {"quadrature_degree" : 5 }
504
+ )
501
505
dDom = dx ((au_tag , bkg_tag ))
502
506
dPml = dx (pml_tag )
503
507
# -
@@ -509,10 +513,10 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
509
513
eps_bkg = n_bkg ** 2 # Background relative permittivity
510
514
eps_au = - 1.0782 + 1j * 5.8089
511
515
512
- D = fem .functionspace (msh , ("DG" , 0 ))
516
+ D = fem .functionspace (mesh_data . mesh , ("DG" , 0 ))
513
517
eps = fem .Function (D )
514
- au_cells = cell_tags .find (au_tag )
515
- bkg_cells = cell_tags .find (bkg_tag )
518
+ au_cells = mesh_data . cell_tags .find (au_tag )
519
+ bkg_cells = mesh_data . cell_tags .find (bkg_tag )
516
520
eps .x .array [au_cells ] = np .full_like (au_cells , eps_au , dtype = eps .x .array .dtype )
517
521
eps .x .array [bkg_cells ] = np .full_like (bkg_cells , eps_bkg , dtype = eps .x .array .dtype )
518
522
eps .x .scatter_forward ()
@@ -556,7 +560,7 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
556
560
# We now now define `eps_pml` and `mu_pml`:
557
561
558
562
# +
559
- rho , z = ufl .SpatialCoordinate (msh )
563
+ rho , z = ufl .SpatialCoordinate (mesh_data . mesh )
560
564
alpha = 5
561
565
r = ufl .sqrt (rho ** 2 + z ** 2 )
562
566
@@ -577,26 +581,28 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
577
581
Eh_m = fem .Function (V )
578
582
Esh = fem .Function (V )
579
583
580
- n = ufl .FacetNormal (msh )
584
+ n = ufl .FacetNormal (mesh_data . mesh )
581
585
n_3d = ufl .as_vector ((n [0 ], n [1 ], 0 ))
582
586
583
587
# Geometrical cross section of the sphere, for efficiency calculation
584
588
gcs = np .pi * radius_sph ** 2
585
589
586
590
# Marker functions for the scattering efficiency integral
587
591
marker = fem .Function (D )
588
- scatt_facets = facet_tags .find (scatt_tag )
589
- incident_cells = mesh .compute_incident_entities (msh .topology , scatt_facets , tdim - 1 , tdim )
590
- msh .topology .create_connectivity (tdim , tdim )
591
- midpoints = mesh .compute_midpoints (msh , tdim , incident_cells )
592
+ scatt_facets = mesh_data .facet_tags .find (scatt_tag )
593
+ incident_cells = mesh .compute_incident_entities (
594
+ mesh_data .mesh .topology , scatt_facets , tdim - 1 , tdim
595
+ )
596
+ mesh_data .mesh .topology .create_connectivity (tdim , tdim )
597
+ midpoints = mesh .compute_midpoints (mesh_data .mesh , tdim , incident_cells )
592
598
inner_cells = incident_cells [(midpoints [:, 0 ] ** 2 + midpoints [:, 1 ] ** 2 ) < (radius_scatt ) ** 2 ]
593
599
marker .x .array [inner_cells ] = 1
594
600
595
601
# Define integration domain for the gold sphere
596
602
dAu = dx (au_tag )
597
603
598
604
# Define integration facet for the scattering efficiency
599
- dS = ufl .Measure ("dS" , msh , subdomain_data = facet_tags )
605
+ dS = ufl .Measure ("dS" , mesh_data . mesh , subdomain_data = mesh_data . facet_tags )
600
606
# -
601
607
602
608
# We also specify a variable `phi`, corresponding to the $\phi$ angle of
@@ -620,7 +626,7 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
620
626
phi = np .pi / 4
621
627
622
628
# Initialize phase term
623
- phase = fem .Constant (msh , scalar_type (np .exp (1j * 0 * phi )))
629
+ phase = fem .Constant (mesh_data . mesh , scalar_type (np .exp (1j * 0 * phi )))
624
630
# -
625
631
626
632
# We now solve the problem:
@@ -655,7 +661,7 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
655
661
elif sys .hasExternalPackage ("superlu_dist" ): # type: ignore
656
662
mat_factor_backend = "superlu_dist"
657
663
else :
658
- if msh .comm .size > 1 :
664
+ if mesh_data . mesh .comm .size > 1 :
659
665
raise RuntimeError ("This demo requires a parallel linear algebra backend." )
660
666
else :
661
667
mat_factor_backend = "petsc"
@@ -705,26 +711,26 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
705
711
q_sca_fenics_proc = (
706
712
fem .assemble_scalar (fem .form ((P ("+" ) + P ("-" )) * rho * dS (scatt_tag ))) / gcs / I0
707
713
).real
708
- q_abs_fenics = msh .comm .allreduce (q_abs_fenics_proc , op = MPI .SUM )
709
- q_sca_fenics = msh .comm .allreduce (q_sca_fenics_proc , op = MPI .SUM )
714
+ q_abs_fenics = mesh_data . mesh .comm .allreduce (q_abs_fenics_proc , op = MPI .SUM )
715
+ q_sca_fenics = mesh_data . mesh .comm .allreduce (q_sca_fenics_proc , op = MPI .SUM )
710
716
elif m == m_list [0 ]: # initialize and add 2 factor
711
717
P = 2 * np .pi * ufl .inner (- ufl .cross (Esh_m , ufl .conj (Hsh_m )), n_3d ) * marker
712
718
Q = 2 * np .pi * eps_au .imag * k0 * (ufl .inner (Eh_m , Eh_m )) / Z0 / n_bkg
713
719
q_abs_fenics_proc = (fem .assemble_scalar (fem .form (Q * rho * dAu )) / gcs / I0 ).real
714
720
q_sca_fenics_proc = (
715
721
fem .assemble_scalar (fem .form ((P ("+" ) + P ("-" )) * rho * dS (scatt_tag ))) / gcs / I0
716
722
).real
717
- q_abs_fenics = msh .comm .allreduce (q_abs_fenics_proc , op = MPI .SUM )
718
- q_sca_fenics = msh .comm .allreduce (q_sca_fenics_proc , op = MPI .SUM )
723
+ q_abs_fenics = mesh_data . mesh .comm .allreduce (q_abs_fenics_proc , op = MPI .SUM )
724
+ q_sca_fenics = mesh_data . mesh .comm .allreduce (q_sca_fenics_proc , op = MPI .SUM )
719
725
else : # do not initialize and add 2 factor
720
726
P = 2 * np .pi * ufl .inner (- ufl .cross (Esh_m , ufl .conj (Hsh_m )), n_3d ) * marker
721
727
Q = 2 * np .pi * eps_au .imag * k0 * (ufl .inner (Eh_m , Eh_m )) / Z0 / n_bkg
722
728
q_abs_fenics_proc = (fem .assemble_scalar (fem .form (Q * rho * dAu )) / gcs / I0 ).real
723
729
q_sca_fenics_proc = (
724
730
fem .assemble_scalar (fem .form ((P ("+" ) + P ("-" )) * rho * dS (scatt_tag ))) / gcs / I0
725
731
).real
726
- q_abs_fenics += msh .comm .allreduce (q_abs_fenics_proc , op = MPI .SUM )
727
- q_sca_fenics += msh .comm .allreduce (q_sca_fenics_proc , op = MPI .SUM )
732
+ q_abs_fenics += mesh_data . mesh .comm .allreduce (q_abs_fenics_proc , op = MPI .SUM )
733
+ q_sca_fenics += mesh_data . mesh .comm .allreduce (q_sca_fenics_proc , op = MPI .SUM )
728
734
729
735
q_ext_fenics = q_abs_fenics + q_sca_fenics
730
736
# -
@@ -783,11 +789,11 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
783
789
# assert err_ext < 0.01
784
790
785
791
if has_vtx :
786
- v_dg_el = element ("DG" , msh .basix_cell (), degree , shape = (3 ,), dtype = real_type )
787
- W = fem .functionspace (msh , v_dg_el )
792
+ v_dg_el = element ("DG" , mesh_data . mesh .basix_cell (), degree , shape = (3 ,), dtype = real_type )
793
+ W = fem .functionspace (mesh_data . mesh , v_dg_el )
788
794
Es_dg = fem .Function (W )
789
795
Es_expr = fem .Expression (Esh , W .element .interpolation_points )
790
796
Es_dg .interpolate (Es_expr )
791
- with VTXWriter (msh .comm , "sols/Es.bp" , Es_dg ) as f :
797
+ with VTXWriter (mesh_data . mesh .comm , "sols/Es.bp" , Es_dg ) as f :
792
798
f .write (0.0 )
793
799
# -
0 commit comments