Skip to content

Instantly share code, notes, and snippets.

@swarbhanu
Created December 13, 2011 20:44
Show Gist options
  • Select an option

  • Save swarbhanu/1473811 to your computer and use it in GitHub Desktop.

Select an option

Save swarbhanu/1473811 to your computer and use it in GitHub Desktop.
Subtracting two CellFunctions
from dolfin import *
import numpy
mesh = UnitSquare(8, 8)
# Creating two mesh functions, empty to start with....
a = CellFunction("double", mesh)
b = CellFunction("double", mesh)
result = CellFunction("double", mesh)
# initializing mesh functions
# a.set_all(0.00)
# b.set_all(0.00)
# result.set_all(0.00)
# create two numpy arrays...
na1 = numpy.arange(20, dtype = 'd')
na2 = numpy.ones(50)
a.set_values(na1)
b.set_values(na2)
# Doing operation on the data
# for cell in cells(mesh):
# result[cell] = a[cell] - b[cell]
# method to do the subtraction operation
def subtract(a,b,result):
temp_result = a.array() - b.array()
return result.set_values(temp_result)
# calling the subtraction method
subtract(a,b,result)
print "The type of result:"
type(result)
info(result, True)
#info(cell_marker2, True)
# plot(cell_marker2, interactive=True)
# plot(mesh, interactive=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment