annotate icqsol_solve_laplace.py @ 0:2294ae1842d5 draft default tip

Uploaded
author iuc
date Tue, 23 Aug 2016 15:04:45 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
1 #!/usr/bin/env python
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
2 import argparse
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
3 import shutil
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
4
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
5 import icqsol_utils
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
6
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
7 # Parse Command Line.
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
8 parser = argparse.ArgumentParser()
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
9 parser.add_argument('--input', dest='input', help='Shape dataset selected from history')
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
10 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type')
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
11 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type')
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
12 parser.add_argument('--input_potential_name', dest='input_potential_name', default='', help='Input surface potential field name.')
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
13 parser.add_argument('--output_jump_electric_field_name', dest='output_jump_electric_field_name', default='jump_normal_electric_field', help='Set the name of the output field name.')
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
14 parser.add_argument('--output', dest='output', help='Output dataset')
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
15 parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type')
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
16
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
17 args = parser.parse_args()
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
18
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
19 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
20 tmp_dir = icqsol_utils.get_temp_dir()
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
21
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
22 # Instantiate the shape manager.
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
23 shape_mgr = icqsol_utils.get_shape_manager(input_format, args.input_dataset_type)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
24
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
25 # Get the vtk polydata from the input dataset.
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
26 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
27
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
28 # Instantiate the Laplace solver.
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
29 solver = icqsol_utils.get_laplace_solver(vtk_poly_data)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
30
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
31 # Set the output field names.
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
32 solver.setResponseFieldName(args.output_jump_electric_field_name)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
33
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
34 # In place operation, vtk_poly_data will be modified.
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
35 solver.setSourceFieldName(args.input_potential_name)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
36 normalEJump = solver.computeResponseField()
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
37 surfIntegral = shape_mgr.integrateSurfaceField(solver.getVtkPolyData(), args.output_jump_electric_field_name)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
38 print 'Surface integral of normal electric field jump: {0}'.format(surfIntegral)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
39 minVal, maxVal = shape_mgr.getFieldRange(solver.getVtkPolyData(), args.output_jump_electric_field_name)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
40 print 'min/max values of normal electric field jump: {0}/{1}'.format(minVal, maxVal)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
41
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
42 # Define the output file format and type (the output_format can only be 'vtk').
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
43 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
44 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
45
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
46 # Make sure the ShapeManager's writer is vtk.
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
47 shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
48
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
49 # Save the output.
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
50 shape_mgr.saveVtkPolyData(vtk_poly_data=solver.getVtkPolyData(), file_name=tmp_output_path, file_type=output_file_type)
2294ae1842d5 Uploaded
iuc
parents:
diff changeset
51 shutil.move(tmp_output_path, args.output)