On Tue, Oct 18, 2011 at 11:50 AM, Julien Derr <julien.d...@gmail.com> wrote: > Thanks Daniel, > > ok so I can generate a function to do it but it is quite slow : > > def interface(phi): > tmp = CellVariable(name="interface", mesh=mesh,value=0.,hasOld=1) > for i in range(len(phi._cellInterfaceFlag)): > if phi._cellInterfaceFlag[i]==1: > tmp[i]=1 > return tmp
Never iterate over arrays, always use vector indexing. CellVariables are fully compatible with numpy arrays in that regard. > I tried to implement your class idea, but I am not sure with the syntax : > this doesn't seem to work : > > > class classeinterface(CellVariable): > def _calcValue(self,phi): > for i in range(len(phi._cellInterfaceFlag)): > if phi._cellInterfaceFlag[i]==1: > self[i]=1 > return self > > > Interface_Variable = CellVariable(name="InterfacecellvvariableI", > mesh=mesh,value=0.,hasOld=1) > Interface_Variable=classeinterface(phi) An __init__ is needed that calls CellVariable's __init__ and specifies the phi dependence. See <http://matforge.org/fipy/browser/trunk/fipy/variables/cellToFaceVariable.py#L40> -- Daniel Wheeler _______________________________________________ fipy mailing list fipy@nist.gov http://www.ctcms.nist.gov/fipy [NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy]