20 |
__url__="http://www.uq.edu.au/esscc/escript-finley" |
__url__="http://www.uq.edu.au/esscc/escript-finley" |
21 |
|
|
22 |
""" |
""" |
23 |
|
Author: Lutz Gross, l.gross@uq.edu.au |
24 |
|
Author: John Ngui, john.ngui@uq.edu.au |
25 |
Author: Ken Steube |
Author: Ken Steube |
26 |
""" |
""" |
27 |
|
|
28 |
# Example of creating an image in a file (without the need for an X connection) |
# Import the necesary modules. |
29 |
|
from esys.escript import * |
30 |
# Import the necessary modules. |
from esys.escript.linearPDEs import Poisson |
31 |
from esys.pyvisi import Scene, DataCollector, Map, ImageReader, Image, Camera |
from esys.finley import Rectangle |
32 |
from esys.pyvisi import GlobalPosition |
from esys.pyvisi import Scene, DataCollector, Map, Camera |
33 |
from esys.pyvisi.constant import * |
from esys.pyvisi.constant import * |
34 |
import os, sys |
import os |
35 |
|
|
|
PYVISI_EXAMPLE_MESHES_PATH = "data_meshes" |
|
36 |
PYVISI_EXAMPLE_IMAGES_PATH = "data_sample_images" |
PYVISI_EXAMPLE_IMAGES_PATH = "data_sample_images" |
37 |
X_SIZE = 400 |
X_SIZE = 400 |
38 |
Y_SIZE = 400 |
Y_SIZE = 300 |
|
|
|
|
SCALAR_FIELD_POINT_DATA = "temperature" |
|
|
FILE_3D = "interior_3D.xml" |
|
|
LOAD_IMAGE_NAME = "flinders.jpg" |
|
39 |
JPG_RENDERER = Renderer.OFFLINE_JPG |
JPG_RENDERER = Renderer.OFFLINE_JPG |
40 |
|
|
41 |
|
# generate domain: |
42 |
|
mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20) |
43 |
|
# define characteristic function of Gamma |
44 |
|
x = mydomain.getX() |
45 |
|
gammaD = whereZero(x[0])+whereZero(x[1]) |
46 |
|
# define PDE and get its solution u |
47 |
|
mypde = Poisson(domain=mydomain) |
48 |
|
mypde.setValue(f=1,q=gammaD) |
49 |
|
u = mypde.getSolution() |
50 |
|
|
51 |
# Create a Scene. |
# Create a Scene. |
52 |
s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE, |
s = Scene(renderer = JPG_RENDERER, x_size = X_SIZE, y_size = Y_SIZE) |
|
y_size = Y_SIZE) |
|
53 |
|
|
54 |
if not os.path.isfile("data_meshes/interior_3D.xml"): |
# Create a DataCollector reading directly from an escript object. |
55 |
print "Cannot find file data_meshes/interior_3D.xml" |
dc = DataCollector(source = Source.ESCRIPT) |
56 |
sys.exit(1) |
dc.setData(sol = u) |
|
|
|
|
# Create a DataCollector reading from a XML file. |
|
|
dc1 = DataCollector(source = Source.XML) |
|
|
dc1.setFileName(file_name = "data_meshes/interior_3D.xml") |
|
57 |
|
|
58 |
# Create a Map. |
# Create a Map. |
59 |
m1 = Map(scene = s, data_collector = dc1, viewport = Viewport.SOUTH_WEST, |
Map(scene = s, data_collector = dc, viewport = Viewport.SOUTH_WEST, |
60 |
lut = Lut.COLOR, cell_to_point = False, outline = True) |
lut = Lut.COLOR, cell_to_point = False, outline = True) |
|
m1.setOpacity(0.3) |
|
|
|
|
|
# Create an ImageReader (in place of DataCollector). |
|
|
ir = ImageReader(ImageFormat.JPG) |
|
|
ir.setImageName(image_name = os.path.join(PYVISI_EXAMPLE_MESHES_PATH, \ |
|
|
LOAD_IMAGE_NAME)) |
|
|
|
|
|
# Create an Image. |
|
|
i = Image(scene = s, image_reader = ir, viewport = Viewport.SOUTH_WEST) |
|
|
i.setOpacity(opacity = 0.9) |
|
|
i.translate(0,0,-1) |
|
|
i.setPoint1(GlobalPosition(2,0,0)) |
|
|
i.setPoint2(GlobalPosition(0,2,0)) |
|
61 |
|
|
62 |
# Create a Camera. |
# Create a Camera. |
63 |
c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST) |
c = Camera(scene = s, viewport = Viewport.SOUTH_WEST) |
64 |
|
|
65 |
# Render the image. |
# Render the object. |
|
print "Creating image file ./offscreen.jpg" |
|
66 |
s.render(image_name = "offscreen.jpg") |
s.render(image_name = "offscreen.jpg") |
|
|
|