Dear,
Is it possible to update the Functional through frequency instead of Time?
See the equation below:
$J\left( \Omega \right) =\int^{w_{max}}_{w_{min}} \int_{\Gamma_{N} } [\rho \omega^{2} \left( u^{R}_{next_{i}}w^{R}_{i}\ -\ u^{R}_{i}w^{R}_{i}\ +\ u^{I}_{next_{i}}w^{I}_{i}\ -\ u^{I}_{i}w^{I}_{i}\ \right) dx\ -\ (\sigma (u^{R}_{i}):\nabla w^{R}_{i}\ -\ \sigma (u^{I}_{i}):\nabla w^{I}_{i})dx\ +\ (f^{R}_{i}.w^{R}_{i}\ +\ f^{I}_{i}.w^{I}_{i})ds]dw$
Here’s the code:
from dolfin import *
import numpy
L, H = 2, 1
Nx, Ny = 40, 20
mesh = RectangleMesh(Point(0., 0.), Point(L, H), Nx, Ny)
#Function space definition over the mesh
Element1 = VectorElement("CG", mesh.ufl_cell(), 1)
Element2 = VectorElement("CG", mesh.ufl_cell(), 1)
# Define the mixed element
V_elem = MixedElement([Element1, Element2])
# Define the mixed function space
Vcomplex = FunctionSpace(mesh, V_elem)
#Material properties
E, rho, nu = 1, 1, 0.3
# Lame coefficient for constitutive relation
mu = E/2./(1+nu)
lmbda = E*nu/(1+nu)/(1-2*nu)
def eps(v):
return sym(grad(v))
def sigma(v):
dim = v.geometric_dimension()
return 2.0*mu*eps(v) + lmbda*tr(eps(v))*Identity(dim)
# Load
boundaries = MeshFunction("size_t", mesh,mesh.topology().dim()-1)
CompiledSubDomain("x[0]==l && x[1]>=(h/2 - 0.05) && x[1]<=(h/2 + 0.05) ", l=L, h=H).mark(boundaries, 1)
ds = Measure("ds")(subdomain_data=boundaries)
t = Constant((0.0, 1.0))
#Applying the Boundary conditions
zero=Constant((0.0, 0.0))
def left(x, on_boundary):
return near(x[0], 0.)
DirichletBC(Vcomplex.sub(0), zero, bcrigth), DirichletBC(Vcomplex.sub(1), zero, bcrigth)]
boundary = [DirichletBC(Vcomplex.sub(0), zero, left), DirichletBC(Vcomplex.sub(1), zero, left)]
bc=boundary#+source
#Real and Imaginary parts of the trial and test functions
uR, uI = TrialFunctions(Vcomplex)
unR, unI = TrialFunctions(Vcomplex)
wR, wI = TestFunctions(Vcomplex)
freqstep = Constant(10)
omega=2*numpy.pi*freqstep
F=omega**2*rho*(dot(unR,wR) - dot(uR,wR) + dot(unI,wI) - dot(uI,wI))*dx - (inner(sigma(uR), grad(wR))+inner(sigma(uI), grad(wI)))*dx + (inner(t, wR) + inner(t, wI))*ds
wmin = 0.0 # t
wmax = 100 # end
JtempR = []
JlistR = [JtempR]
JtempI = []
JlistI = [JtempI]
while (wmin <= wmax):
a, L = lhs(F), rhs(F)
solnU = Function(Vcomplex)
problem = LinearVariationalProblem(a, L, solnU, bcs=bc)
solver = LinearVariationalSolver(problem)
solver.solve()
solnUR, solnUI=solnU.split()
unR.assign(solnUR)
unI.assign(solnUI)
wmin += float(freqstep)
JtempR = assemble(inner(t, unR)*ds)
JlistR.append(JtempR)
JtempI = assemble(inner(t, unI)*ds)
JlistI.append(JtempI)
JR = 0
for i in range(1, len(JlistR)):
JR += 0.5*(JlistR[i-1] + JlistR[i])*float(freqstep)
JI = 0
for i in range(1, len(JlistI)):
JI += 0.5*(JlistI[i-1] + JlistI[i])*float(freqstep)
Error:
unR.assign(solnUR)
AttributeError: 'ListTensor' object has no attribute 'assign'