File: SimpleGougeConfig.py

package info (click to toggle)
esys-particle 2.3.5%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,132 kB
  • sloc: cpp: 81,480; python: 5,872; makefile: 1,259; sh: 313; perl: 225
file content (175 lines) | stat: -rw-r--r-- 5,785 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#############################################################
##                                                         ##
## Copyright (c) 2003-2017 by The University of Queensland ##
## Centre for Geoscience Computing                         ##
## http://earth.uq.edu.au/centre-geoscience-computing      ##
##                                                         ##
## Primary Business: Brisbane, Queensland, Australia       ##
## Licensed under the Open Software License version 3.0    ##
## http://www.apache.org/licenses/LICENSE-2.0              ##
##                                                         ##
#############################################################

from __future__   import division
from esys.escript import *
from esys.finley import Rectangle,Brick
from esys.finley import Merge

from esys.lsm.geometry import *
from esys.lsm.util     import *

from .MeshToVtkConverter import MeshToVtkConverter

def roundToInt(flt):
    return int(round(flt))

class SimpleGougeMesh:
    def __init__(
        self,
        boundingBox1,
        boundingBox2,
        gridSize,
    ):
        self.bBox1         = boundingBox1
        self.bBox2         = boundingBox2
        self.gridSize      = gridSize
        self.mesh          = None

    def getDim(self):
        dim = 3
        if (self.bBox1.getMinPt()[2] == self.bBox1.getMaxPt()[2]):
           dim = 2
        return dim

    def getGridPointsPerDim(self):
        sizes = (self.bBox1.getSize(), self.bBox2.getSize())
        return \
            (
               list(map(roundToInt, (sizes[0]/self.gridSize).toList())),
               list(map(roundToInt, (sizes[1]/self.gridSize).toList()))
            )

    def generate(self):
        (numGridPts1, numGridPts2) = self.getGridPointsPerDim()
        periodic0 = True
        if (self.getDim() == 2):
            mesh1 = \
                Rectangle(
                    numGridPts1[0],
                    numGridPts1[1],
                    order=1,
                    l0=self.bBox1.getSize()[0],
                    l1=self.bBox1.getSize()[1],
                    periodic0=periodic0
                )
            mesh2 = \
                Rectangle(
                    numGridPts2[0],
                    numGridPts2[1],
                    order=1,
                    l0=self.bBox2.getSize()[0],
                    l1=self.bBox2.getSize()[1],
                    periodic0=periodic0
                )
        else:
            mesh1 = \
                Brick(
                    numGridPts1[0],
                    numGridPts1[1],
                    numGridPts1[2],
                    order=1,
                    l0=self.bBox1.getSize()[0],
                    l1=self.bBox1.getSize()[1],
                    l2=self.bBox1.getSize()[2],
                    periodic0=periodic0
                )
            mesh2 = \
                Brick(
                    numGridPts2[0],
                    numGridPts2[1],
                    numGridPts2[2],
                    order=1,
                    l0=self.bBox2.getSize()[0],
                    l1=self.bBox2.getSize()[1],
                    l2=self.bBox2.getSize()[2],
                    periodic0=periodic0
                )
        x1 = mesh1.getX()
        x2 = mesh2.getX()
        #
        # To get the same identical tags on the particle boundary elements
        # of both meshes, reflect about the y-axis.
        # 
        x2[1] = -x2[1]
        x2[1] += abs(inf(x2[1]))

        #
        # Now translate the meshes so they correspond to the
        # specified bounding boxes.
        #
        for d in range(0, self.getDim()):
            x1[d] += self.bBox1.getMinPt()[d]
            x2[d] += self.bBox2.getMinPt()[d]

        mesh1.setX(x1)
        mesh2.setX(x2)
        self.mesh = Merge([mesh1, mesh2])

    def write(self, fileName):
        self.mesh.write(fileName)

class SimpleGougeConfig:
    def __init__(
        self,
        particleGougePrms,
        continuumBlockHeight,
        fileNamePrefix="gouge",
        gridSize = None
    ):
        self.gougeBlock = GougeBlock(particleGougePrms)
        if (gridSize == None):
            gridSize = 2.0*particleGougePrms.getMinRadius()
        self.gridSize = gridSize
        self.continuumHeight = continuumBlockHeight
        self.fileNamePrefix = fileNamePrefix
        self.meshGenerator = None

    def generateDomain(self):
        self.gougeBlock.generate()
        particleBBox = self.gougeBlock.getDomainBoundingBox()
        minPt = particleBBox.getMinPt()
        maxPt = particleBBox.getMaxPt()
        upperMinPt = Vec3(minPt[0], maxPt[1], minPt[2])
        upperMaxPt = maxPt + Vec3(0, self.continuumHeight, 0)
        lowerMinPt = minPt - Vec3(0, self.continuumHeight, 0)
        lowerMaxPt = Vec3(maxPt[0], minPt[1], maxPt[2])

        self.meshGenerator = \
            SimpleGougeMesh(
                BoundingBox(lowerMinPt, lowerMaxPt),
                BoundingBox(upperMinPt, upperMaxPt),
                self.gridSize
            )
        self.meshGenerator.generate()

    def getParticleGeometryXmlFileName(self):
        return self.fileNamePrefix + "ParticlesVtk.xml"

    def getMeshXmlFileName(self):
        return self.fileNamePrefix + "MeshVtk.xml"

    def getParticleGeometryFileName(self):
        return self.fileNamePrefix + ".geo"

    def getMeshFileName(self):
        return self.fileNamePrefix + ".msh"

    def writeVtkXml(self):
        self.write()
        self.gougeBlock.writeVtkXml(self.getParticleGeometryXmlFileName())
        MeshToVtkConverter(self.getMeshFileName(), self.getMeshXmlFileName()).convert()

    def write(self):
        self.gougeBlock.write(self.getParticleGeometryFileName())
        self.meshGenerator.write(self.getMeshFileName())