### Without Initial Guess How can i solve simple equation ?

280
views
0
6 months ago by
Hello to all Fenics Community, i am a Novice user in Fenics
i am trying to solve heat equation over a line with Flux at both the ends
flux at one end is zero and flux at another end is  $\sqrt{u\left(1-u\right)}$u(1u)
i am getting nan in second itteration,
if i give some initial guess to u, then it solve the equation
how can i invoke Fenics such that it chooses its initial value automatically such that it does not gives nan, as abaqus or comsol solve this equation without any initial guess

from dolfin import *
from fenics import *
import math

########## Time Steps ########################
T = 1.00          # final time
num_steps = 10   # number of time steps
dt = T / num_steps # time step size

######Mesh###########
mesh = IntervalMesh(100, 0.0, 1.0)

########### FunctionSpace##################
V = FunctionSpace(mesh, 'P', 2)
u = Function(V)
v = TestFunction(V)

################ Boundaries ##################
class left(SubDomain):
def inside(self,x, on_boundary):
tol = 1e-14
return near(x[0],0.00,tol)

class right(SubDomain):
def inside(self,x, on_boundary):
tol = 1e-14
return near(x[0],1.00,tol)

############### Marking the boundaries #############
boundaries = FacetFunction("size_t",mesh)
boundaries.set_all(0)
left= left()
right = right()
left.mark(boundaries,0)
right.mark(boundaries,1)

########## initial values
u_n=project(Constant(0.10),V)

ds = Measure('ds', domain=mesh, subdomain_data=boundaries)

def flux(u):
return pow(u*(1-u),0.5)

#Weakform

#Solve
for n in range(num_steps):
solve(F == 0, u);
assign(u_n,u);



Thanks to all, for your Valuable time

Community: FEniCS Project

5
6 months ago by
The default behavior in codes like Abaqus and Comsol is probably to always initialize the solution to a predictor based on the previous time step (where we are interpreting the nonlinear iteration in solve() as a multi-corrector).  On this first time step, the predictor would be formed from the initial conditions.  In this case, the simple "same-temperature" predictor
u.assign(u_n)​
seems to work.  For predictor--multi-corrector methods in higher-order-in-time problems (e.g., an implicit Newmark scheme for structural dynamics, again interpreting Newton iterations as corrector iterations) there are a variety of possible choices of predictor (e.g., same-displacement, same-velocity, same-acceleration, etc.).
still giving nan, not solving this particular boundary condition
written 6 months ago by Md Ayub Ansari
Hmm... I just tried copy-pasting-editing the original code again this morning.  Maybe I should add some more context for where I put the predictor:

for n in range(num_steps):
# predictor (redundant on later time steps in this case)
u.assign(u_n)
# corrector iterations
solve(F == 0, u);
# update old solution
assign(u_n,u);
​
This does not give nan for me, using version 2017.2.0.
written 6 months ago by David Kamensky
Its Working now
written 6 months ago by Tom jamie
you get non if the number in square root is lower than zero.

you can use the following expression whenever you compute square root:

TOL=1E-10
u=conditional(lt(u*(1-u),TOL),TOL,u*(1-u))
u=pow(u*(1-u),0.5)
written 3 months ago by Birkan