Mercurial > repos > iuc > icqsol_add_surface_field_from_expression
comparison icqsol_add_surface_field_from_expression.py @ 0:e12b55e960de draft default tip
Uploaded
author | iuc |
---|---|
date | Tue, 23 Aug 2016 14:54:04 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e12b55e960de |
---|---|
1 #!/usr/bin/env python | |
2 import argparse | |
3 import shutil | |
4 | |
5 import icqsol_utils | |
6 | |
7 # Parse Command Line. | |
8 parser = argparse.ArgumentParser() | |
9 parser.add_argument('--input', dest='input', help='Shape dataset selected from history') | |
10 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type') | |
11 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type') | |
12 parser.add_argument('--field_name', dest='field_name', help='Surface field name') | |
13 parser.add_argument('--location', dest='location', help='Location of field within cell, either point or cell') | |
14 parser.add_argument('--expression', dest='expression', help='Expression for applying surface field to shape') | |
15 parser.add_argument('--time_point', dest='time_points', type=float, action='append', nargs=1, help='Points in time') | |
16 parser.add_argument('--max_edge_length', dest='max_edge_length', type=float, default=float('inf'), help='Maximum edge length') | |
17 parser.add_argument('--output', dest='output', help='Output dataset') | |
18 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type') | |
19 | |
20 args = parser.parse_args() | |
21 | |
22 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type) | |
23 time_points = [tp[0] for tp in args.time_points] | |
24 tmp_dir = icqsol_utils.get_temp_dir() | |
25 | |
26 # Instantiate a ShapeManager for loading the input. | |
27 shape_mgr = icqsol_utils.get_shape_manager(input_format, args.input_dataset_type) | |
28 | |
29 # Get the vtkPolyData object. | |
30 pdata = shape_mgr.loadAsVtkPolyData(args.input) | |
31 | |
32 # Add surface field to shape data. | |
33 vtk_poly_data = shape_mgr.addSurfaceFieldFromExpressionToVtkPolyData(pdata, | |
34 args.field_name, | |
35 args.expression, | |
36 time_points, | |
37 args.max_edge_length, | |
38 args.location) | |
39 | |
40 # Write min/max field values and surface integral. | |
41 for comp in range(len(time_points)): | |
42 minVal, maxVal = shape_mgr.getFieldRange(vtk_poly_data, args.field_name, comp) | |
43 surfIntegral = shape_mgr.integrateSurfaceField(vtk_poly_data, args.field_name, comp) | |
44 print 'component {2} min/max values of {3}: {0}/{1} surf integral: {4}'.format(minVal, maxVal, comp, args.field_name, surfIntegral) | |
45 | |
46 # Define the output file format and type (the outpur_format can only be 'vtk'). | |
47 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) | |
48 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format) | |
49 | |
50 # Make sure the ShapeManager's writer is vtk. | |
51 shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA) | |
52 | |
53 # Save the output. | |
54 shape_mgr.saveVtkPolyData(vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) | |
55 shutil.move(tmp_output_path, args.output) |