[Please keep the discussion on the list]

Scalar equations are rank-0. Vector equations are rank-1. 

If you look at the terms in the latter (vector) part of 

  
http://www.ctcms.nist.gov/fipy/examples/cahnHilliard/generated/examples.cahnHilliard.mesh2DCoupled.html

you see that some of the coefficients (of TransientTerm, DiffusionTerm, and 
ImplicitSourceTerm) are rank-2, but that the `source` is not.  This reflects 
that the implicit terms must keep track of 

  "the part of equation 0 that is implicit in v[0]", 
  "the part of equation 0 that is implicit in v[1]", 
  "the part of equation 1 that is implicit in v[0]", 
  "the part of equation 1 that is implicit in v[1]".

The source is explicit, however, so there's just 

  "the source for equation 0" and 
  "the source for equation 1".

Having said that, your source will probably have better convergence if it's 
implicit. 
I think you want

  Q1 = (-v[1] * CellVariable(mesh=m, value=((1, 0),
                                            (0, 0)), elementshape=(2,2))
        + v[0] * CellVariable(mesh=m, value=((0, 0),
                                             (1, 0)), elementshape=(2,2)))

  ImplicitSourceTerm(coeff=Q1)


Note: you should be able to write

  ImplicitSourceTerm(coeff=-v[1] * [[1, 0]
                                    [0, 0] + v[0] * [[0, 0],
                                                     [1, 0]])

but this doesn't work in 1D, which is a bug. 
I've filed https://github.com/usnistgov/fipy/issues/436 to look into that.

On Feb 6, 2015, at 10:55 AM, Dhisa Minerva <[email protected]> wrote:

> 
> Thanks for your answer. Why it has to be rank-1 CellVariable? The system 
> involves 2 equations. I was thinking it should be rank-2, isn't it? Or is it 
> because the domain solution is 1D? but it doesn't make sense since what we 
> have here is 2 variables.
> 
> Look forward to your reply
> 
> Dhisa
> On Friday, February 6, 2015 8:08 AM, "Guyer, Jonathan E. Dr." 
> <[email protected]> wrote:
> 
> 
>   Q = (-v[0] * v[1], v[0]**2) 
> 
> produces a tuple of two rank-0 CellVariables. You need a rank-1 CellVariable. 
> Try:
> 
>   Q = (-v[0] * v[1]) * [[1], [0]] + v[0]**2 * [[0], [1]]
> 
> 
> On Feb 5, 2015, at 3:05 PM, Dhisa Minerva <[email protected]> wrote:
> 
> > Hi everyone,
> > 
> > I am working with RDE system. I tried to search on fipy documentation and 
> > examples about how to write source term in vector form.  For example, the 
> > code bellow is to solve 2 RDEs on case 1D.
> > 
> > from fipy import *
> > m = Grid1D(nx=100, Lx=1.)
> > v = CellVariable(mesh=m, hasOld=True, value=[[0.5], [0.5]], 
> > elementshape=(2,))
> > v.constrain([[0], [1]], where=m.facesLeft)
> > v.constrain([[1], [0]], where=m.facesRight)
> > M = [[1,0],[0,1]]
> > N = [[1,0],[0,1]]
> > Q = (-v[0] * v[1], v[0]**2) 
> > eqn = TransientTerm(N) == DiffusionTerm([M]) + (Q)
> > vi = Viewer((v[0],v[1]))
> > for t in range(20): 
> >      v.updateOld()
> >      eqn.solve(var=v, dt=1.e-3)
> >      if __name__ == '__main__':
> >          vi.plot()
> > if __name__ == '__main__':
> >      raw_input("Press <return> to proceed...")
> > 
> > Can anybody tell me how to write the source term 'Q'? The point why I don't 
> > define each variable separately is because I want to work with big RDE 
> > system.
> > 
> > Thanks,
> > Dhisa
> > Vanderbilt
> 
> > 
> > _______________________________________________
> > fipy mailing list
> > [email protected]
> > http://www.ctcms.nist.gov/fipy
> >  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
> 
> 
> _______________________________________________
> fipy mailing list
> [email protected]
> http://www.ctcms.nist.gov/fipy
>   [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy
> ]
> 
> 


_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to