/[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 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (15 months, 2 weeks ago) by uqaeller
File MIME type: text/x-python
File size: 4309 byte(s)
Updated the copyright header.


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

  ViewVC Help
Powered by ViewVC 1.1.26