Skip to content

Commit 1536b12

Browse files
authored
Merge pull request #26 from equinor/mesh
Mesh
2 parents 83b70e2 + b4d9533 commit 1536b12

File tree

8 files changed

+68
-74
lines changed

8 files changed

+68
-74
lines changed

.github/workflows/build_docker.yml

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,31 @@ on:
66
paths:
77
- 'Dockerfile'
88
workflow_dispatch:
9-
permissions:
10-
id-token: write
11-
contents: read
12-
packages: write
9+
permissions: {}
1310
jobs:
1411
build:
1512
runs-on: ubuntu-20.04
16-
13+
permissions:
14+
id-token: write
15+
contents: read
16+
packages: write
1717
steps:
18-
-
19-
name: Set up QEMU
20-
uses: docker/setup-qemu-action@v1
21-
-
22-
name: Set up Docker Buildx
23-
uses: docker/setup-buildx-action@v1
24-
with:
25-
driver-opts: |
26-
image=moby/buildkit:v0.11.2
27-
-
28-
name: Login to GitHub Container Registry
29-
uses: docker/login-action@v1
30-
with:
31-
registry: ghcr.io
32-
username: ${{ github.actor }}
33-
password: ${{ secrets.GITHUB_TOKEN }}
34-
-
35-
name: Build
36-
uses: docker/build-push-action@v2
37-
with:
38-
push: true
39-
platforms: linux/amd64
40-
tags: ghcr.io/equinor/warmth:latest
18+
- name: Set up QEMU
19+
uses: docker/setup-qemu-action@v1
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v1
22+
with:
23+
driver-opts: |
24+
image=moby/buildkit:v0.11.2
25+
- name: Login to GitHub Container Registry
26+
uses: docker/login-action@v1
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
- name: Build
32+
uses: docker/build-push-action@v2
33+
with:
34+
push: true
35+
platforms: linux/amd64
36+
tags: ghcr.io/equinor/warmth:latest

.github/workflows/docs.yml

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,30 @@ on:
88
tags:
99
- '[0-9]+.[0-9]+.[0-9]'
1010

11-
permissions:
12-
id-token: write
13-
contents: write
11+
permissions: {}
1412

1513
jobs:
1614
deploy:
17-
1815
runs-on: ubuntu-latest
19-
16+
permissions:
17+
id-token: write
18+
contents: write
2019
steps:
21-
- uses: actions/checkout@v2
22-
23-
24-
- name: Install dependencies
25-
run: |
26-
curl -sSL https://install.python-poetry.org | python3
27-
poetry install --with dev --no-interaction
28-
29-
- name: Build
30-
run: |
31-
cd docs
32-
sudo apt-get install pandoc
33-
poetry run make html
20+
- uses: actions/checkout@v2
21+
- name: Install dependencies
22+
run: |
23+
curl -sSL https://install.python-poetry.org | python3
24+
poetry install --with dev --no-interaction
25+
26+
- name: Build
27+
run: |
28+
cd docs
29+
sudo apt-get install pandoc
30+
poetry run make html
3431
35-
- name: Deploy
36-
uses: peaceiris/actions-gh-pages@v3
37-
with:
38-
github_token: ${{ secrets.GITHUB_TOKEN }}
39-
publish_dir: ./docs/_build/html
40-
destination_dir: ./
32+
- name: Deploy
33+
uses: peaceiris/actions-gh-pages@v3
34+
with:
35+
github_token: ${{ secrets.GITHUB_TOKEN }}
36+
publish_dir: ./docs/_build/html
37+
destination_dir: ./

.github/workflows/publish.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ on:
88
tags:
99
- '*'
1010

11-
permissions:
12-
id-token: write
13-
contents: write
11+
permissions: {}
1412

1513
jobs:
1614
tests:
@@ -22,13 +20,14 @@ jobs:
2220
uses: equinor/warmth/.github/workflows/snyk.yml@main
2321
secrets:
2422
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
25-
GITHUB_TOKEN_WORKFLOW: ${{ secrets.GITHUB_TOKEN }}
2623

2724
deploy:
2825
needs: [tests, snyk]
2926
environment: deploy
3027
runs-on: ubuntu-latest
31-
28+
permissions:
29+
id-token: write
30+
contents: write
3231
steps:
3332
- uses: actions/checkout@v2
3433
with:

.github/workflows/snyk.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
secrets:
55
SNYK_TOKEN:
66
required: true
7-
GITHUB_TOKEN_WORKFLOW:
8-
required: true
97
jobs:
108
security:
119
runs-on: ubuntu-latest

warmth/build.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from pathlib import Path
23
import pickle
34
from typing import Iterator, List, Literal
@@ -497,7 +498,7 @@ def __init__(self, parameters: Parameters):
497498
self._ymax = 0
498499
self.boundary = None
499500
self.grid: Grid | None = None
500-
self.nodes: list[single_node] = []
501+
self.nodes: list[list[single_node]] = []
501502

502503
@property
503504
def single_node_sediments_inputs_template(self):
@@ -901,10 +902,16 @@ def iter_node(self)->Iterator[single_node]:
901902
Iterator[single_node]
902903
1D node
903904
"""
905+
logging.info("Iterating 1D nodes")
904906
for row in self.nodes:
905907
for col in row:
906908
if isinstance(col,bool)==False:
907909
yield col
910+
911+
def node_flat(self) -> np.ndarray[single_node]:
912+
arr = np.array(self.nodes).flatten()
913+
return arr[arr!=False]
914+
908915
@property
909916
def indexer_full_sim(self)->list:
910917
return [i.indexer for i in self.iter_node() if i._full_simulation is True]

warmth/mesh_model.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from typing import Tuple
23
from pathlib import Path
34
import numpy as np
@@ -28,10 +29,10 @@ def tic():
2829
def toc(msg=""):
2930
if 'startTime_for_tictoc' in globals():
3031
delta = time.time() - startTime_for_tictoc
31-
logger.debug(msg+": Elapsed time is " + str(delta) + " seconds.")
32+
logging.debug(msg+": Elapsed time is " + str(delta) + " seconds.")
3233
return delta
3334
else:
34-
logger.debug("Toc: start time not set")
35+
logging.debug("Toc: start time not set")
3536

3637
@dataclass
3738
class rddms_upload_data_initial:
@@ -81,7 +82,7 @@ class UniformNodeGridFixedSizeMeshModel:
8182
def __init__(self, builder:Builder,parameters:Parameters, sedimentsOnly = False, padding_num_nodes=0):
8283
self._builder = builder
8384
self._parameters=parameters
84-
self.node1D = [n for n in self._builder.iter_node()]
85+
self.node1D = self._builder.node_flat() #[n for n in self._builder.iter_node()]
8586
self.num_nodes = len(self.node1D)
8687
self.mesh = None
8788

@@ -701,19 +702,17 @@ def updateVertices(self):
701702
def buildMesh(self,tti:int):
702703
"""Construct a new mesh at the given time index tti, and determine the vertex re-indexing induced by dolfinx
703704
"""
705+
logging.info("Building 3D mesh")
704706
self.tti = tti
705707
self.buildVertices(time_index=tti)
706-
logger.debug("Built vertices")
707708
self.constructMesh()
708-
logger.debug("Built mesh")
709-
self.updateMesh(tti)
710-
logger.debug(f"Updated vertices for time {tti}")
711-
709+
self.updateMesh(tti)
712710

713711
def updateMesh(self,tti:int, optimized=False):
714712
"""Construct the mesh positions at the given time index tti, and update the existing mesh with the new values
715713
"""
716714
assert self.mesh is not None
715+
logging.info(f"Updating 3D mesh for time {tti}")
717716
self.tti = tti
718717
self.buildVertices(time_index=tti, optimized=optimized)
719718
self.updateVertices()
@@ -1755,7 +1754,6 @@ def global_except_hook(exctype, value, traceback):
17551754
def run_3d( builder:Builder, parameters:Parameters, start_time=182, end_time=0, pad_num_nodes=0,
17561755
out_dir = "out-mapA/", sedimentsOnly=False, writeout=True, base_flux=None,
17571756
callback_fcn_initial=None, callback_fcn_timestep=None):
1758-
logger.setLevel(10) # numeric level equals DEBUG
17591757
comm = MPI.COMM_WORLD
17601758
builder=interpolate_all_nodes(builder)
17611759
nums = 4
@@ -1771,13 +1769,11 @@ def run_3d( builder:Builder, parameters:Parameters, start_time=182, end_time=0,
17711769
for tti in range(start_time, end_time-1,-1): #start from oldest
17721770
rebuild_mesh = (tti==start_time)
17731771
if rebuild_mesh:
1774-
logger.debug(f"Rebuild/reload mesh at {tti}")
17751772
mm2 = UniformNodeGridFixedSizeMeshModel(builder, parameters,sedimentsOnly, padding_num_nodes=pad_num_nodes)
17761773
mm2.buildMesh(tti)
17771774
if (base_flux is not None):
17781775
mm2.baseFluxMagnitude = base_flux
17791776
else:
1780-
logger.debug(f"Re-generating mesh vertices at {tti}")
17811777
tic()
17821778
mm2.updateMesh(tti, optimized=True)
17831779
toc(msg="update mesh")

warmth/mesh_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dataclasses import dataclass
2+
import logging
23
from typing import List
34
import itertools
45
import numpy as np
@@ -117,7 +118,6 @@ def volumeOfTet(points):
117118
def volumeOfHex(points):
118119
""" Computes the volume of a hexahedron, given as eight 3D-points
119120
"""
120-
import numpy as np
121121
tetsplit1 = [ [1,2,4,8], [1,2,5,8], [4,8,2,3], [2,3,7,8], [2,5,6,8], [2,6,7,8] ]
122122
vol = 0.0
123123
for f in tetsplit1:
@@ -173,6 +173,7 @@ def interpolateNode(interpolationNodes: List[single_node], interpolationWeights=
173173

174174

175175
def interpolate_all_nodes(builder:Builder)->Builder:
176+
logging.info("Interpolating 1D tectonic model results")
176177
for ni in range(len(builder.nodes)):
177178
for nj in range(len(builder.nodes[ni])):
178179
if (builder.nodes[ni][nj] is False) or (not builder.nodes[ni][nj]._full_simulation):

warmth/simulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def dump_input_data(self, use_mpi=False):
127127
from mpi4py.futures import MPIPoolExecutor
128128
with MPIPoolExecutor(max_workers=10) as th:
129129
futures = [th.submit(self.dump_input_nodes, i)
130-
for i in self._builder.iter_node() if i is not False]
130+
for i in self._builder.iter_node()]
131131
for future in concurrent.futures.as_completed(futures):
132132
p.append([parameter_data_path, future.result()])
133133
else:
@@ -136,7 +136,7 @@ def dump_input_data(self, use_mpi=False):
136136
self._builder.grid.dump(self._grid_path)
137137
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as th:
138138
futures = [th.submit(self.dump_input_nodes, i)
139-
for i in self._builder.iter_node() if i is not False]
139+
for i in self._builder.iter_node()]
140140
for future in concurrent.futures.as_completed(futures):
141141
p.append([parameter_data_path, future.result()])
142142
return p

0 commit comments

Comments
 (0)