# Just to make sure I'm getting the correct plots for the optimals

Hallo All

I want to have some graphs for the optimal control and the optimal solution for my problem. Thanks to the code

in https:/

here is my code

from dolfin import *

from dolfin_adjoint import *

# Setup

n = 40

mesh = UnitCircleMesh(n)

V = FunctionSpace(mesh, "CG", 1)

###W = FunctionSpace(mesh, "DG", degree = 0)

u = Function(

m = Function(V, name="Control")

v = TestFunction(V)

# Run the forward model once to create the simulation record

F = ( inner(grad(u), grad(v)) + u*v - m*v )*dx

###bc = DirichletBC(V, 0.0, "on_boundary")

solve(F == 0, u)

def max(x, y):

import ufl

x = triangle.x[0]

return ufl.conditional

# the alpha and gamma coefficients which appear in the cost functional

alpha=Constant(1.0)

gamma=Constant(

# The given u_0 , m_0 and b

x = triangle.x

u_0 = 4+1/pi -(1/(4*

m_0 = 4 +(1/(4*

b= (x[0]*x[

# The cost functional

J = Functional(( 0.5*inner(u-u_0, u-u_0) + alpha*0.

# Run the optimisation

reduced_functional = ReducedFunction

# Make sure you have scipy >= 0.11 installed

m_opt = minimize(

# desire solution u_0

proj_udes = project(u_0,V)

plot(u_0, mesh, interactive=True, title="u_0")

# Actual solution

solve(F == 0, u)

plot(u, interactive=True, title="Optimal State")

# L1 error

proj_error = project(u-u_0,V)

plot(proj_error, interactive=True, title="L1-Error")

# Optimal forcing

plot(m_opt, interactive=True, title="Optimal Control")

regardless of the problem or its parameters, I want to make sure if this code is really giving plots for the optimal control and optimal state.

I'm assuming if one wants to plot the optimal state , then one needs to slove a new bilinear form which has the optimal control.

Just I was testing the software on some problems with known solutions and I found a slight diferece.

so, I wanted to make sure if my code is really written in a way that gives the plots of the optimals.

## Question information

- Language:
- English Edit question

- Status:
- Solved

- Assignee:
- No assignee Edit question

- Solved by:
- Simon Funke

- Solved:

- Last query:

- Last reply: