-
Notifications
You must be signed in to change notification settings - Fork 25
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 #735 from JonathanGSDUFOUR/Add_Quant(Issue638)
DerivedQuantities for fenicsx
- Loading branch information
Showing
26 changed files
with
680 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import festim as F | ||
from dolfinx import fem | ||
import numpy as np | ||
|
||
|
||
class AverageSurface(F.SurfaceQuantity): | ||
"""Computes the average value of a field on a given surface | ||
Args: | ||
field (festim.Species): species for which the average surface is computed | ||
surface (festim.SurfaceSubdomain): surface subdomain | ||
filename (str, optional): name of the file to which the average surface is exported | ||
Attributes: | ||
see `festim.SurfaceQuantity` | ||
""" | ||
|
||
@property | ||
def title(self): | ||
return f"Average {self.field.name} surface {self.surface.id}" | ||
|
||
def compute(self, ds): | ||
""" | ||
Computes the average value of the field on the defined surface | ||
subdomain, and appends it to the data list | ||
""" | ||
|
||
self.value = fem.assemble_scalar( | ||
fem.form(self.field.solution * ds(self.surface.id)) | ||
) / fem.assemble_scalar(fem.form(1 * ds(self.surface.id))) | ||
self.data.append(self.value) |
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,30 @@ | ||
import festim as F | ||
from dolfinx import fem | ||
import numpy as np | ||
|
||
|
||
class AverageVolume(F.VolumeQuantity): | ||
"""Computes the average value of a field in a given volume | ||
Args: | ||
field (festim.Species): species for which the average volume is computed | ||
volume (festim.VolumeSubdomain): volume subdomain | ||
filename (str, optional): name of the file to which the average volume is exported | ||
Attributes: | ||
see `festim.VolumeQuantity` | ||
""" | ||
|
||
@property | ||
def title(self): | ||
return f"Average {self.field.name} volume {self.volume.id}" | ||
|
||
def compute(self, dx): | ||
""" | ||
Computes the average value of solution function within the defined volume | ||
subdomain, and appends it to the data list | ||
""" | ||
self.value = fem.assemble_scalar( | ||
fem.form(self.field.solution * dx(self.volume.id)) | ||
) / fem.assemble_scalar(fem.form(1 * dx(self.volume.id))) | ||
self.data.append(self.value) |
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,27 @@ | ||
import festim as F | ||
import numpy as np | ||
|
||
|
||
class MaximumSurface(F.SurfaceQuantity): | ||
"""Computes the maximum value of a field on a given surface | ||
Args: | ||
field (festim.Species): species for which the maximum surface is computed | ||
surface (festim.SurfaceSubdomain): surface subdomain | ||
filename (str, optional): name of the file to which the maximum surface is exported | ||
Attributes: | ||
see `festim.SurfaceQuantity` | ||
""" | ||
|
||
@property | ||
def title(self): | ||
return f"Maximum {self.field.name} surface {self.surface.id}" | ||
|
||
def compute(self): | ||
""" | ||
Computes the maximum value of the field on the defined surface | ||
subdomain, and appends it to the data list | ||
""" | ||
self.value = np.max(self.field.solution.x.array[self.surface.indices]) | ||
self.data.append(self.value) |
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,28 @@ | ||
import festim as F | ||
import numpy as np | ||
|
||
|
||
class MaximumVolume(F.VolumeQuantity): | ||
"""Computes the maximum value of a field in a given volume | ||
Args: | ||
field (festim.Species): species for which the maximum volume is computed | ||
volume (festim.VolumeSubdomain): volume subdomain | ||
filename (str, optional): name of the file to which the maximum volume is exported | ||
Attributes: | ||
see `festim.VolumeQuantity` | ||
""" | ||
|
||
@property | ||
def title(self): | ||
return f"Maximum {self.field.name} volume {self.volume.id}" | ||
|
||
def compute(self): | ||
""" | ||
Computes the maximum value of solution function within the defined volume | ||
subdomain, and appends it to the data list | ||
""" | ||
self.value = np.max(self.field.solution.x.array[self.volume.entities]) | ||
self.data.append(self.value) |
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,27 @@ | ||
import festim as F | ||
import numpy as np | ||
|
||
|
||
class MinimumSurface(F.SurfaceQuantity): | ||
"""Computes the minimum value of a field on a given surface | ||
Args: | ||
field (festim.Species): species for which the minimum surface is computed | ||
surface (festim.SurfaceSubdomain): surface subdomain | ||
filename (str, optional): name of the file to which the minimum surface is exported | ||
Attributes: | ||
see `festim.SurfaceQuantity` | ||
""" | ||
|
||
@property | ||
def title(self): | ||
return f"Minimum {self.field.name} surface {self.surface.id}" | ||
|
||
def compute(self): | ||
""" | ||
Computes the minimum value of the field on the defined surface | ||
subdomain, and appends it to the data list | ||
""" | ||
self.value = np.min(self.field.solution.x.array[self.surface.indices]) | ||
self.data.append(self.value) |
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,27 @@ | ||
import festim as F | ||
import numpy as np | ||
|
||
|
||
class MinimumVolume(F.VolumeQuantity): | ||
"""Computes the minmum value of a field in a given volume | ||
Args: | ||
field (festim.Species): species for which the minmum volume is computed | ||
volume (festim.VolumeSubdomain): volume subdomain | ||
filename (str, optional): name of the file to which the minmum volume is exported | ||
Attributes: | ||
see `festim.VolumeQuantity` | ||
""" | ||
|
||
@property | ||
def title(self): | ||
return f"Minimum {self.field.name} volume {self.volume.id}" | ||
|
||
def compute(self): | ||
""" | ||
Computes the minimum value of solution function within the defined volume | ||
subdomain, and appends it to the data list | ||
""" | ||
self.value = np.min(self.field.solution.x.array[self.volume.entities]) | ||
self.data.append(self.value) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import festim as F | ||
from dolfinx import fem | ||
import ufl | ||
|
||
|
||
class TotalSurface(F.SurfaceQuantity): | ||
"""Computes the total value of a field on a given surface | ||
Args: | ||
field (`festim.Species`): species for which the total volume is computed | ||
surface (`festim.SurfaceSubdomain`): surface subdomain | ||
filename (str, optional): name of the file to which the total volume is exported | ||
Attributes: | ||
see `festim.SurfaceQuantity` | ||
""" | ||
|
||
@property | ||
def title(self): | ||
return f"Total {self.field.name} surface {self.surface.id}" | ||
|
||
def compute(self, ds: ufl.Measure): | ||
""" | ||
Computes the total value of the field on the defined surface | ||
subdomain, and appends it to the data list | ||
Args: | ||
ds (ufl.Measure): surface measure of the model | ||
""" | ||
self.value = fem.assemble_scalar( | ||
fem.form(self.field.solution * ds(self.surface.id)) | ||
) | ||
self.data.append(self.value) |
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
Oops, something went wrong.