Hello,
I'm new to FEniCS but i want to use it to solve an optimal control problem. The control as well as the solutions of my state system are time-dependent, therefore i'm using TimeSeries to store the data of my simulation code. I now want to use the data in an optimization algorithm like gradients descent. This requires an update to the control. Therefore i need to be able to change the data stored in the TimeSeries which represents the control function. But it seems that i'm not allowed to change stored data. As a minimal example i just tried to write new data to an already existing TimeSeries which results in the same error message:
# from dolfin import *
import math
import numpy, sys
# Define load
l=Expression(("sin(pi*x[0])*sin(pi*x[1])*t","cos(pi*x[0])*cos(pi*x[1])*t"), t=0)
g=Expression(("cos(pi*x[0])*cos(pi*x[1])*t","sin(pi*x[0])*sin(pi*x[1])*t"), t=0)
# Create mesh and define function space
mesh=UnitSquareMesh(5,5)
Z=VectorFunctionSpace(mesh,'Lagrange',1)
L=TimeSeries(mesh.mpi_comm(),"Test"+"Control l")
j=0
while j<=1+1.0/5:
l.t=j
L.store(interpolate(l,Z).vector(),j)
L.store(mesh,j)
j+=1.0/5
k=0
while k<1.0+1.0/5:
g.t=k
L.store(interpolate(g,Z).vector(),k)
L.store(mesh,k)
k+=1.0/5
Then the following error message occurs:
Traceback (most recent call last):
File "Test.py", line 22, in
L.store(interpolate(g,Z).vector(),k)
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
*** fenics@fenicsproject.org
*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.
*** -------------------------------------------------------------------------
*** Error: Unable to store object to time series.
*** Reason: Sample points must be strictly monotone (t_0 = 1, t_1 = 1.2, t_2 = 0).
*** Where: This error was encountered inside TimeSeries.cpp.
*** Process: 0
*** DOLFIN version: 1.6.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------
Now my question is: Is it possible to change the data stored to a TimeSeries and i just tried it in the wrong way? Or if not is there a better way to store the data if i want to use it in an optimization algorithm?
Thanks in advance for any advice,
Marita