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

  ViewVC Help
Powered by ViewVC 1.1.26