Dear all, currently, I'm trying to solve a DAE problem (the Poisson-Nernst-Planck system) with 4 variables in Firedrake. The function spaces in the problem are defined as follows: *V0 = FunctionSpace(mesh, "DG",2)* *X = V0*V0*V0*V0* *C0,C1,C2,C3 = Function(X)v0,v1,v2,v3 = TestFunctions(X) * Because the problem is non-linear, I need to prescribe the initial values before running the solver. And the initial values are defined as follows: *ic_C = Constant(1)* *C0.assign(ic_C)* *C1.assign(ic_C)* *C2.assign(ic_C)* *C3.assign(ic_C)* An issue comes up during this step, which says the 'indexed' object (the C0, C1 and so on) has no attribute 'assign': *--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-20-803df79d259a> in <module> 7 ic_Phi = Constant(Phi_init)#project(Phi_0, X) 8 ----> 9 C0.assign(ic_C0); 10 #C1.assign(ic_C1); 11 #C2.assign(ic_C2); AttributeError: 'Indexed' object has no attribute 'assign'* The questions: 1. Do I defined the function spaces correctly? 2. If the Function Spaces are correctly defined, then how to assign the value to the indexed function spaces (the mixed function spaces)? Thank you in advance! Thomas
Dear Thomas, This is one of the most confusing “features” of the UFL language. If F is a Function in a mixed space then split(F) is equivalent to what you write below, splits F symbolically, providing indexed Functions which are what you need in specifying Forms. However you can’t access the numerical content of these indexed Functions, for example if you want to assign into them. F.split() on the other hand produces component Functions which point at the right chunk of F’s memory. Because these are Functions (as opposed to indexed objects), they do have .assign and .interpolate methods so you can use these to set initial conditions. Regards, David From: <firedrake-bounces@imperial.ac.uk> on behalf of Thoms 2015 <thoms1015@gmail.com> Date: Saturday, 23 November 2019 at 18:17 To: firedrake <firedrake@imperial.ac.uk> Subject: [firedrake] Assign Initial Value to Mixed Function Spaces Dear all, currently, I'm trying to solve a DAE problem (the Poisson-Nernst-Planck system) with 4 variables in Firedrake. The function spaces in the problem are defined as follows: V0 = FunctionSpace(mesh, "DG",2) X = V0*V0*V0*V0 C0,C1,C2,C3 = Function(X) v0,v1,v2,v3 = TestFunctions(X) Because the problem is non-linear, I need to prescribe the initial values before running the solver. And the initial values are defined as follows: ic_C = Constant(1) C0.assign(ic_C) C1.assign(ic_C) C2.assign(ic_C) C3.assign(ic_C) An issue comes up during this step, which says the 'indexed' object (the C0, C1 and so on) has no attribute 'assign': --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-20-803df79d259a> in <module> 7 ic_Phi = Constant(Phi_init)#project(Phi_0, X) 8 ----> 9 C0.assign(ic_C0); 10 #C1.assign(ic_C1); 11 #C2.assign(ic_C2); AttributeError: 'Indexed' object has no attribute 'assign' The questions: 1. Do I defined the function spaces correctly? 2. If the Function Spaces are correctly defined, then how to assign the value to the indexed function spaces (the mixed function spaces)? Thank you in advance! Thomas
Dear Ham, Thank you for your help. I did manage to get the problem solved, by using *split()* behind the *Function(X)* definition. *C0,C1,C2,C3 = Function(X).split()C0.assign(Constant(1));* Best Regards, Thomas Am So., 24. Nov. 2019 um 12:58 Uhr schrieb Ham, David A < david.ham@imperial.ac.uk>:
Dear Thomas,
This is one of the most confusing “features” of the UFL language. If F is
a Function in a mixed space then split(F) is equivalent to what you write below, splits F symbolically, providing indexed Functions which are what you need in specifying Forms. However you can’t access the numerical content of these indexed Functions, for example if you want to assign into them.
F.split() on the other hand produces component Functions which point at
the right chunk of F’s memory. Because these are Functions (as opposed to indexed objects), they do have .assign and .interpolate methods so you can use these to set initial conditions.
Regards,
David
From: <firedrake-bounces@imperial.ac.uk> on behalf of Thoms 2015 <
thoms1015@gmail.com>
Date: Saturday, 23 November 2019 at 18:17 To: firedrake <firedrake@imperial.ac.uk> Subject: [firedrake] Assign Initial Value to Mixed Function Spaces
Dear all,
currently, I'm trying to solve a DAE problem (the Poisson-Nernst-Planck system) with 4 variables in Firedrake. The function spaces in the problem are defined as follows:
V0 = FunctionSpace(mesh, "DG",2)
X = V0*V0*V0*V0
C0,C1,C2,C3 = Function(X) v0,v1,v2,v3 = TestFunctions(X)
Because the problem is non-linear, I need to prescribe the initial values before running the solver. And the initial values are defined as follows:
ic_C = Constant(1)
C0.assign(ic_C)
C1.assign(ic_C)
C2.assign(ic_C)
C3.assign(ic_C)
An issue comes up during this step, which says the 'indexed' object (the C0, C1 and so on) has no attribute 'assign':
---------------------------------------------------------------------------
AttributeError Traceback (most recent call
last)
<ipython-input-20-803df79d259a> in <module>
7 ic_Phi = Constant(Phi_init)#project(Phi_0, X)
8
----> 9 C0.assign(ic_C0);
10 #C1.assign(ic_C1);
11 #C2.assign(ic_C2);
AttributeError: 'Indexed' object has no attribute 'assign'
The questions:
1. Do I defined the function spaces correctly?
2. If the Function Spaces are correctly defined, then how to assign the
value to the indexed function spaces (the mixed function spaces)?
Thank you in advance!
Thomas
participants (2)
- 
                
                Ham, David A
- 
                
                Thoms 2015