Created
December 13, 2011 20:44
-
-
Save swarbhanu/1473811 to your computer and use it in GitHub Desktop.
Subtracting two CellFunctions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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