-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Computing fundamental frequency
- Loading branch information
Showing
4 changed files
with
93 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from firedrake import * | ||
from slepc4py import SLEPc | ||
|
||
# Create mesh and function space | ||
mesh = UnitSquareMesh(32, 32) | ||
V = FunctionSpace(mesh, "CG", 1) | ||
|
||
# Define the bilinear and linear forms for the scalar wave equation | ||
u = TrialFunction(V) | ||
v = TestFunction(V) | ||
c = Constant(1.0) # Wave speed | ||
a = c**2 * inner(grad(u), grad(v)) * dx | ||
m = u * v * dx | ||
|
||
# Assemble the matrices | ||
A = assemble(a) | ||
M = assemble(m) | ||
|
||
# Set up the SLEPc eigensolver | ||
eigensolver = SLEPc.EPS().create() | ||
A_petsc = A.M.handle | ||
M_petsc = M.M.handle | ||
eigensolver.setOperators(A_petsc, M_petsc) | ||
eigensolver.setProblemType(SLEPc.EPS.ProblemType.GHEP) | ||
eigensolver.setWhichEigenpairs(SLEPc.EPS.Which.SMALLEST_REAL) | ||
eigensolver.setFromOptions() | ||
|
||
# Solve the eigenvalue problem | ||
eigensolver.solve() | ||
|
||
# Extract the eigenvalues | ||
nconv = eigensolver.getConverged() | ||
eigenvalues = [] | ||
for i in range(nconv): | ||
eigenvalue = eigensolver.getEigenvalue(i) | ||
eigenvalues.append(eigenvalue) | ||
|
||
print("Eigenvalues:", eigenvalues) | ||
|
||
|
||
https://github.com/firedrakeproject/slepc | ||
https://github.com/firedrakeproject/firedrake/blob/master/docs/source/install.rst | ||
https://slepc.upv.es/documentation/instal.htm | ||
https://pypi.org/project/slepc4py/ |