-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaExporterService.py
More file actions
42 lines (39 loc) · 1.6 KB
/
AreaExporterService.py
File metadata and controls
42 lines (39 loc) · 1.6 KB
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
import json
import gmsh
from typing import Dict, List
import numpy as np
class AreaExporterService:
_EMPTY_NAME_CASE = ""
computedAreas:Dict[str,List]
geometry: Dict
def __init__(self):
self.computedAreas = {
"geometries": []
}
def addComputedArea(self, geometry:str, label:str, area:float):
geometry:Dict ={
"geometry": geometry,
"label": label,
"area": round(area,6),
}
self.computedAreas['geometries'].append(geometry)
def addPhysicalModelOfDimension(self, mappedElements:Dict[str,str], dimension=2):
physicalGroups = gmsh.model.getPhysicalGroups(dimension)
for physicalGroup in physicalGroups:
entityTags = gmsh.model.getEntitiesForPhysicalGroup(*physicalGroup)
geometryName = gmsh.model.getPhysicalName(*physicalGroup)
label = ''
for key, geometry in mappedElements.items():
if geometry == geometryName:
label = key
for tag in entityTags:
if dimension == 1:
rad = gmsh.model.occ.getMass(dimension, tag) / (2*np.pi)
area = rad*rad*np.pi
if dimension == 2:
area = gmsh.model.occ.getMass(dimension, tag)
if geometryName != AreaExporterService._EMPTY_NAME_CASE:
self.addComputedArea(geometryName, label, area)
def exportToJson(self, exportFileName:str):
with open(exportFileName + ".areas.json", 'w') as f:
json.dump(self.computedAreas, f, indent=3)