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