Hi all,
How do I set this initial value
phi(x)=exp(-x**2) for t=0 for the problem
u_t=Du_xx
boundaryConditions
phi(x)=1 for x=0
phi(x)=0 for x=1
2008/8/11 franck kalala <[EMAIL PROTECTED]>
> I try to solve the problem:
>
> u_t=Du_xx
>
> with
>
> phi(x)=u(x,0)=0 for x<0
> phi(x)=u(x,0)=1 for x>0
> ph(x)=0 at x=0
>
> as boundary conditions at t=0
>
> and phi=1 at t=0
>
> I have some difficult to set this boundary condition in the following
> program(in red) could any one help to set it?
>
> nx=50
> dx=1.
> from fipy.meshes.grid1D import Grid1D
> mesh=Grid1D(nx=nx, dx=dx)
> from fipy.variables.cellVariable import CellVariable
> phi=CellVariable(name="solution variable",mesh=mesh,value=1)
> D=1.
> #valueLeft=1.
> #valueRight=0.
>
> x=mesh.getCellCenters()[...,0]
> valueLeft=phi.setValue(0, where=x < 0)
> valueRight=phi.setValue(1, where=x > 0)
>
> from fipy.boundaryConditions.fixedValue import FixedValue
> BCs=(FixedValue(faces=mesh.getFacesRight(), value=valueRight),
> FixedValue(faces=mesh.getFacesLeft(), value=valueLeft))
>
> from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm
> from fipy.terms.transientTerm import TransientTerm
> eqX=TransientTerm()==ExplicitDiffusionTerm(coeff=D)
> timeStepDuration=0.9*dx**2/(2*D)
> steps=100
> t=timeStepDuration*steps
> from fipy.tools.numerix import sqrt
> phiAnalytical=CellVariable(name="analytical value", mesh=mesh)
> try:
> from scipy.special import erf
> phiAnalytical.setValue(.5*(1+erf(x/(sqrt(4*D*t)))))
> except importError:
> print "The Scipy library is not available to test the solution to the
> transient diffusion equation"
> if __name__ =='__main__':
> from fipy import viewers
> viewer=viewers.make(vars=(phi, phiAnalytical), limits={'datamin':-1.,
> 'datamax':2.})
> viewer.plot()
> #raw_input("Explicit transient diffusion. Press <return> to
> proceed...")
> for step in range(steps):
> eqX.solve(var=phi,boundaryConditions=BCs,dt=timeStepDuration)
> if __name__ == '__main__':
> viewer.plot()
> print phi.allclose(phiAnalytical, atol = 7e-4)
>
> Regards
>
> 2008/8/10 franck kalala <[EMAIL PROTECTED]>
>
> Thanks I have already discover this miskate and fixed it.
>>
>> Regards.
>>
>> 2008/8/10 Daniel Stiles <[EMAIL PROTECTED]>
>>
>>> Hello,
>>>
>>>
>>> That error means that you are missing a quote somewhere in your program.
>>> I believe it is here:
>>>
>>> except importError:
>>> print "The Scipy library is not available to \
>>> test the solution to the transient diffusion equation
>>>
>>> You should have a " at the end of that last line
>>>
>>> Sincerely,
>>> Daniel
>>>
>>>
>>> On Sat, Aug 9, 2008 at 2:33 PM, franck kalala <
>>> [EMAIL PROTECTED]> wrote:
>>>
>>>> Thanks for the answer;
>>>>
>>>> I tryed the first example in the documentation.
>>>> I wanted just to write code for the first part as a python programme
>>>> but I have an error message, could any one correct this this programme
>>>> for me?
>>>>
>>>> ***************************************************************************************************************
>>>> nx=50
>>>> dx=1.
>>>> from fipy.grid1D import Grid1D
>>>> mesh=Grid1D(nx=nx, dx=dx)
>>>> from fipy.variables.cellVariables import CellVariable
>>>> phi=CellVariable(name="solution variable",mesh=mesh,value=0)
>>>> D=1.
>>>> valueLeft=1.
>>>> valueRight=0.
>>>> from fipy.boundaryConditions.fixedValue import FixedValue
>>>> BCs=(FixedValue(faces=mesh.getFacesRight(), value=valueLeft),
>>>> FixedValue(faces=mesh.getFacesLeft(), value=valueRight))
>>>> from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm
>>>> from fipy.terms.transientTerm import TransientTerm
>>>> eqX=TransientTerm()==ExplicitDiffusionTerm(coeff=D)
>>>> timeStepDuration=0.9*dx**2/(2*D)
>>>> steps=100
>>>> x=mesh.getCellCenters()[...,0]
>>>> t=timeStepDuration*steps
>>>> from fipy.tools.numerix import sqrt
>>>> phiAnalytical=CellVariable(name="analytical value", mesh=mesh)
>>>> try:
>>>> from scipy.special import erf
>>>> phiAnalytical.setValue(1-erf(x/(2*sqrt(D*t))))
>>>> except importError:
>>>> print "The Scipy library is not available to \
>>>> test the solution to the transient diffusion equation
>>>> if __name__ =='__main__':
>>>> from fipy import viewers
>>>> viewer=viewers.make(vars(phi, phiAnalytical), limits={'datamin':0,
>>>> 'datamax':1.})
>>>> viewer.plot()
>>>> for step in range(steps):
>>>> eqX.solve(var=phi,boundaryConditions=BCs,dt=timeStepDuration)
>>>> if __name__=='__main__':
>>>> viewer.plot()
>>>> print phi.allclose(phiAnalytical, atol=7e-4)
>>>> if __name__ == '__main__':
>>>> raw_input("Explicit transcient diffusion. Press <return> to
>>>> proceed...")
>>>>
>>>> ******************************************************************************************************************
>>>> here is the message error:
>>>>
>>>> There an error in your program:
>>>> EOL while scanning single-quoted string
>>>>
>>>> I dont understand this error message
>>>>
>>>> regards
>>>>
>>>> Franck.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> 2008/8/9 Jonathan Guyer <[EMAIL PROTECTED]>
>>>>
>>>>
>>>>>
>>>>> On Aug 9, 2008, at 10:15 AM, franck kalala wrote:
>>>>>
>>>>> Thanks for the answer. Then how do I set this initial value
>>>>>>
>>>>>> phi(x)=0 for x<0
>>>>>> phi(x)=1 for x>0
>>>>>>
>>>>>
>>>>> In FiPy 1.2:
>>>>>
>>>>> >>> x = mesh.getCellCenters()[..., 0]
>>>>> >>> phi.setValue(0, where=x < 0)
>>>>> >>> phi.setValue(1, where=x > 0)
>>>>>
>>>>> You should also specify what happens at x == 0.
>>>>>
>>>>>
>>>>> If you're using trunk/ then the first line would be
>>>>>
>>>>> >>> x, = mesh.getCellCenters()
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> ***********************************************
>>>> ***********************************************
>>>> Franck Kalala Mutombo
>>>> [EMAIL PROTECTED]
>>>> African Institut for Mathematical Sciences, Muizenberg Cape Town, South
>>>> Africa
>>>> [EMAIL PROTECTED]
>>>> ************************************************
>>>> ************************************************
>>>>
>>>
>>>
>>>
>>> --
>>> -Daniel Stiles
>>>
>>
>>
>>
>> --
>> ***********************************************
>> ***********************************************
>> Franck Kalala Mutombo
>> [EMAIL PROTECTED]
>> African Institut for Mathematical Sciences, Muizenberg Cape Town, South
>> Africa
>> [EMAIL PROTECTED]
>> ************************************************
>> ************************************************
>>
>
>
>
> --
> ***********************************************
> ***********************************************
> Franck Kalala Mutombo
> [EMAIL PROTECTED]
> African Institut for Mathematical Sciences, Muizenberg Cape Town, South
> Africa
> [EMAIL PROTECTED]
> ************************************************
> ************************************************
>
--
***********************************************
***********************************************
Franck Kalala Mutombo
[EMAIL PROTECTED]
African Institut for Mathematical Sciences, Muizenberg Cape Town, South
Africa
[EMAIL PROTECTED]
************************************************
************************************************