/[escript]/trunk/finley/py_src/readers.py
ViewVC logotype

Contents of /trunk/finley/py_src/readers.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4019 - (show annotations)
Thu Oct 11 08:12:55 2012 UTC (6 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 4106 byte(s)
More tabbing errors,
range/xrange
...
1 # -*- coding: utf-8 -*-
2
3 ##############################################################################
4 #
5 # Copyright (c) 2003-2012 by University of Queensland
6 # http://www.uq.edu.au
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 # Development since 2012 by School of Earth Sciences
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 """
25 some mesh handling
26
27 :var __author__: name of author
28 :var __licence__: licence agreement
29 :var __url__: url entry point on documentation
30 :var __version__: version
31 :var __date__: date of the version
32 """
33
34 __author__="Lutz Gross, l.gross@uq.edu.au"
35
36 from esys.pycad.gmsh import Design as GMSHDesign
37 from .finleycpp import ReadGmsh, ReadMesh, LoadMesh
38
39 def MakeDomain(design,integrationOrder=-1, reducedIntegrationOrder=-1, optimizeLabeling=True, useMacroElements=False):
40 """
41 Creates a Finley `Domain` from a `esys.pycad.design.Design` object.
42 Currently only gmsh is supported.
43
44 :param design: the geometry
45 :type design: `esys.pycad.design.Design`
46 :param integrationOrder: integration order. If -1 the default is used.
47 :type integrationOrder: ``int``
48 :param reducedIntegrationOrder: reduced integration order. If -1 the
49 default is used.
50 :type reducedIntegrationOrder: ``int``
51 :param optimizeLabeling: if set the labeling of the mesh nodes is optimized
52 :type optimizeLabeling: ``bool``
53 :param useMacroElements: uses macro elements.
54 :type useMacroElements: ``bool``
55 :return: the Finley domain defined by the design
56 :rtype: `Domain`
57 """
58 if isinstance(design, GMSHDesign):
59 if useMacroElements: design.setElementOrder(2)
60 ff=design.getFileFormat()
61 design.setFileFormat(design.GMSH)
62 mshname=design.getMeshHandler()
63 dom = ReadGmsh(mshname,
64 design.getDim(),
65 integrationOrder,
66 reducedIntegrationOrder,
67 optimizeLabeling,
68 useMacroElements)
69 design.setFileFormat(ff)
70 else:
71 raise TypeError("Finley does not support %s designs."%design.__class__.__name__)
72 # fill in the tag map
73 design.getTagMap().passToDomain(dom)
74 return dom
75
76 def GetMeshFromFile(filename, **kwargs):
77 """
78 Reads a mesh from a file, determines the reader to use based on the file
79 extension. All cases require a filename and gmsh files require a number
80 of dimensions (it doesn't hurt to pass this in all the time). Other
81 keyword args come from the underlying reader functions.
82 """
83 spl=filename.split('.')
84 ext=spl[len(spl)-1]
85 # extract possible params
86 integrationOrder=-1
87 if "integrationOrder" in kwargs:
88 integrationOrder=kwargs["integrationOrder"]
89 reducedIntegrationOrder=-1
90 if "reducedIntegrationOrder" in kwargs:
91 integrationOrder=kwargs["reducedIntegrationOrder"]
92 optimize=True
93 if "optimize" in kwargs:
94 integrationOrder=kwargs["optimize"]
95 useMacroElements=False
96 if "useMacroElements" in kwargs:
97 integrationOrder=kwargs["useMacroElements"]
98 if ext=="fly":
99 return ReadMesh(filename, integrationOrder, reducedIntegrationOrder, optimize)
100 elif ext=="msh":
101 if not "numDim" in kwargs:
102 raise ValueError("The numDim argument is required in order to read .msh files.")
103 return ReadGmsh(filename, kwargs['numDim'], integrationOrder, reducedIntegrationOrder, optimize, useMacroElements)
104 else:
105 # return LoadMesh(filename)
106 raise ValueError("Unsupported extension .%s"%ext)

  ViewVC Help
Powered by ViewVC 1.1.26