assign function

7 months ago by
Hi there,

I am encountering an error when ever i use the following line in demo ( of cbc beat available on repo ( )
I am using fenics 2017.1.0 on win 7 through docker.

The documentation of this demo says that latest version of fenics should be used.  I have downloaded dolfin adjoint from: and installed through sudo python install.

The original (demo) code have used the assign function as :-

which is giving me the following error:-
TypeError: assign() takes exactly 2 arguments (3 given)
Complete code ( screen shot)   is as under.

screen shot of error :

is there any recent change in syntax of assign ?? When i make following change to the code , there are no error and code runs i I change

I am not sure if that is a valid ammendment. Can the community please guide me on use of assign and the validity/correctness of change which i am  making in the demo code.
Community: FEniCS Project

2 Answers

7 months ago by
Well you can take a look at the source and see that assign only takes one argument (2 because of self being counted as an argument as well).

The basic usage is to supply an argument that is a Function or a linear combination of Functions that comes from the same FunctionSpace as the Function from which you call the assign method.

I didn't try out your example but try deleting solver.VS from the argument list such that the line reads

--- Edit ---
It seems I replied too quickly without thoroughly grasping your problem. In dolfin-adjoint, the function assignment behaves differently and takes two arguments, I don't know what it does though. Through the from cbcbeat import * dolfin-adjoint and not dolfin is imported.
So if your import of dolfin-adjoint works, the line vs_.assign(cell_model.initial_conditions(),solver.VS)  should not give the error message you're quoting.
thanks klunkean!
I am trying to install dolfin-adjoint again .. hope fully itll work.
written 7 months ago by Ovais  
Hi klunkean , despite repeated attempts somehow i am unable to install dolfin adjoint. I have tried 3 x different ways.
1. through docker file (attached) mentioned in documentation gives a strange error
ImportError:No module named dolfin

2. through method mentioned on dolfin adjoint webpage (fenicsproject run . I get another error relate to a line in demo still pointing towards the fact that adjoint has not been installed

3. by obtaining clone of latest dev version from ( adjoint/dolfin-adjoint/ downloads/) and installing through sudo python install.
Can you very kindly suggest a way through which dolfin adjoint can be installed and dolfin /fenics would not cease to function
# Builds a Docker image for reproducing the results in the wetting and drying
# adjoint paper by Funke

MAINTAINER Simon Funke <>

USER root
RUN sudo apt-get update && sudo apt-get -y install mercurial

USER fenics
RUN hg clone
RUN cd cbcbeat && pip install . --user

USER root​
written 7 months ago by Ovais  
Sorry, I'm the wrong person to ask here. I have never used nor have I even installed dolfin-adjoint.
written 7 months ago by klunkean  
7 months ago by
To the best of my knowledge, no changes have been made in the Function.assign() method. From within Python, you can use assign in two different ways. Maybe you are confusing these two approaches. To illustrate this, consider the following:

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(2,2)
V = FunctionSpace(mesh,'CG',1)

u,v,w = Function(V), Function(V), Function(V) 
u_exact = Expression('x[0]', degree = 1)

# Initialize u from expression

# Assign u to v, method 1

# Assign u to w, method 2

# Check if v,w are equal to u
print u.vector().array()
print np.linalg.norm(u.vector().array() - v.vector().array())
print np.linalg.norm(u.vector().array() - v.vector().array())

# Something like this will fail for obvious reasons
# w.assign(u,V)
Please login to add an answer/comment or follow this question.

Similar posts:
Search »