assign function


274
views
1
7 months ago by
Ovais  
Hi there,

I am encountering an error when ever i use the following line in demo (demo_monodomain_adjoint.py) of cbc beat available on repo (https://bitbucket.org/meg/cbcbeat/src/b50822cc443ba023604159405e4ba78b424964bd/demo/monodomain/?at=default )
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: https://bitbucket.org/dolfin-adjoint/dolfin-adjoint/downloads/ and installed through sudo python setup.py install.

The original (demo) code have used the assign function as :-
vs_.assign(cell_model.initial_conditions(),solver.VS)

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

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
vs_.assign(cell_model.initial_conditions(),solver.VS)  
to
vs_.assign(cell_model.initial_conditions())

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.
Thanks.
Community: FEniCS Project

2 Answers


3
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
vs_.assign(cell_model.initial_conditions())​

--- 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 quay.io/dolfinadjoint/pyadjoint) . 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 ( https://bitbucket.org/dolfin- adjoint/dolfin-adjoint/ downloads/) and installing through sudo python setup.py 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 et.al

FROM quay.io/dolfinadjoint/dev-dolfin-adjoint:latest
MAINTAINER Simon Funke <simon@simula.no>

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

USER fenics
RUN hg clone https://bitbucket.org/meg/cbcbeat
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  
0
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
u.assign(u_exact)

# Assign u to v, method 1
assign(v,u)

# Assign u to w, method 2
w.assign(u)

# 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 »