Generating Random Initial Guess for Nonlinear Problem
I'm working with an iteration method for solving nonlinear problems and would like to be able generate a random initial iterate as an attempt at a solution. I've been able to do this on the unit interval but would like to do the same on the unit square. Here's the code I am attempting to use:
import random
from dolfin import *
import sys
#Finite Element Set up
mesh = UnitSquare(64, 64)
V = FunctionSpace(mesh, 'CG', degree = 1)
#Construct an Initial Guess
class InitialConditio
def __init__(self):
def eval(self, values, x):
values[0] = random.random()
values[1] = random.random()
def value_shape(self):
return (2,)
uguess = InitialConditions()
uOld = Function(V)
uOld.interpolat
I would like to be able to use uOld in my variational form to solve for the next iterate, but I get the following error:
Traceback (most recent call last):
File "Random_Guess.py", line 22, in <module>
uOld.
RuntimeError: *** Error: Cannot interpolate functions of different ranks.
Ideally, I would also like to make my initial guess be zero on the boundary as well. Is there an easy mistake in my code or a better way to do this? Thanks in advance!
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Johan Hake
- Solved:
- Last query:
- Last reply: