-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #593 from jhdark/subdomains
Subdomain classes
- Loading branch information
Showing
9 changed files
with
191 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from dolfinx import fem | ||
import numpy as np | ||
|
||
|
||
class SurfaceSubdomain1D: | ||
""" | ||
Surface subdomain class for 1D cases | ||
Args: | ||
id (int): the id of the surface subdomain | ||
x (float): the x coordinate of the surface subdomain | ||
Attributes: | ||
id (int): the id of the surface subdomain | ||
x (float): the x coordinate of the surface subdomain | ||
Usage: | ||
>>> surf_subdomain = F.SurfaceSubdomain1D(id=1, x=1) | ||
""" | ||
|
||
def __init__(self, id, x) -> None: | ||
self.id = id | ||
self.x = x | ||
|
||
def locate_dof(self, function_space): | ||
"""Locates the dof of the surface subdomain within the function space | ||
Args: | ||
function_space (dolfinx.fem.FunctionSpace): the function space of | ||
the model | ||
Returns: | ||
dof (np.array): the first value in the list of dofs of the surface | ||
subdomain | ||
""" | ||
dofs = fem.locate_dofs_geometrical( | ||
function_space, lambda x: np.isclose(x[0], self.x) | ||
) | ||
return dofs[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from dolfinx.mesh import locate_entities | ||
import numpy as np | ||
|
||
|
||
class VolumeSubdomain1D: | ||
""" | ||
Volume subdomain class for 1D cases | ||
Args: | ||
id (int): the id of the volume subdomain | ||
borders (list of float): the borders of the volume subdomain | ||
material (festim.Material): the material of the volume subdomain | ||
Attributes: | ||
id (int): the id of the volume subdomain | ||
borders (list of float): the borders of the volume subdomain | ||
material (festim.Material): the material of the volume subdomain | ||
Usage: | ||
>>> vol_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, 1], | ||
... material=F.Material(...)) | ||
""" | ||
|
||
def __init__(self, id, borders, material) -> None: | ||
self.borders = borders | ||
self.material = material | ||
self.id = id | ||
|
||
def locate_subdomain_entities(self, mesh, vdim): | ||
"""Locates all cells in subdomain borders within domain | ||
Args: | ||
mesh (dolfinx.cpp.mesh.Mesh): the mesh of the model | ||
vdim (int): the dimension of the volumes of the mesh, | ||
for 1D this is always 1 | ||
Returns: | ||
entities (np.array): the entities of the subdomain | ||
""" | ||
entities = locate_entities( | ||
mesh, | ||
vdim, | ||
lambda x: np.logical_and(x[0] >= self.borders[0], x[0] <= self.borders[1]), | ||
) | ||
return entities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import numpy as np | ||
import festim as F | ||
|
||
|
||
def test_different_surface_ids(): | ||
my_model = F.HydrogenTransportProblem() | ||
|
||
L = 3e-02 | ||
my_model.mesh = F.Mesh1D(np.linspace(0, L, num=3)) | ||
|
||
surfacec_subdomains_ids = [3, 8] | ||
surface_subdomain_1 = F.SurfaceSubdomain1D(id=surfacec_subdomains_ids[0], x=0) | ||
surface_subdomain_2 = F.SurfaceSubdomain1D(id=surfacec_subdomains_ids[1], x=L) | ||
my_model.subdomains = [surface_subdomain_1, surface_subdomain_2] | ||
|
||
my_model.define_function_space() | ||
my_model.define_markers_and_measures() | ||
|
||
for surf_id in surfacec_subdomains_ids: | ||
assert surf_id in np.array(my_model.facet_meshtags.values) | ||
|
||
|
||
def test_different_volume_ids(): | ||
my_model = F.HydrogenTransportProblem() | ||
|
||
sub_dom_1 = np.linspace(0, 1e-04, num=3) | ||
sub_dom_2 = np.linspace(1e-04, 2e-04, num=4) | ||
sub_dom_3 = np.linspace(2e-04, 3e-04, num=5) | ||
my_model.mesh = F.Mesh1D( | ||
np.unique(np.concatenate([sub_dom_1, sub_dom_2, sub_dom_3])) | ||
) | ||
|
||
vol_subdomains_ids = [2, 16, 7] | ||
vol_subdomain_1 = F.VolumeSubdomain1D( | ||
id=vol_subdomains_ids[0], borders=[sub_dom_1[0], sub_dom_1[-1]], material=None | ||
) | ||
vol_subdomain_2 = F.VolumeSubdomain1D( | ||
id=vol_subdomains_ids[1], borders=[sub_dom_2[0], sub_dom_2[-1]], material=None | ||
) | ||
vol_subdomain_3 = F.VolumeSubdomain1D( | ||
id=vol_subdomains_ids[2], borders=[sub_dom_3[0], sub_dom_3[-1]], material=None | ||
) | ||
my_model.subdomains = [vol_subdomain_1, vol_subdomain_2, vol_subdomain_3] | ||
|
||
my_model.define_markers_and_measures() | ||
|
||
for vol_id in vol_subdomains_ids: | ||
assert vol_id in np.array(my_model.volume_meshtags.values) |