Skip to content

Commit

Permalink
FEAT: use 1D path for 3d
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchengtkc committed Dec 4, 2023
1 parent c925088 commit 63441d9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 89 deletions.
47 changes: 23 additions & 24 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
FROM dolfinx/dolfinx:v0.6.0

LABEL org.opencontainers.image.source https://github.com/equinor/warmth
ARG DEBIAN_FRONTEND=noninteractive

RUN DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y build-essential --no-install-recommends make \
ca-certificates \
git \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev
&& apt-get install -y curl
# build-essential --no-install-recommends make \
# ca-certificates \
# git \
# libssl-dev \
# zlib1g-dev \
# libbz2-dev \
# libreadline-dev \
# libsqlite3-dev \
# wget \
# \
# llvm \
# libncurses5-dev \
# xz-utils \
# tk-dev \
# libxml2-dev \
# libxmlsec1-dev \
# libffi-dev \
# liblzma-dev

RUN useradd -rm -d /home/vscode -s /bin/bash -g root -G sudo -u 1000 vscode -p ""
USER vscode
WORKDIR /home/vscode
ENV HOME=/home/vscode
# RUN useradd -rm -d /home/vscode -s /bin/bash -g root -G sudo -u 1000 vscode -p ""
# USER vscode
# WORKDIR /home/vscode
# ENV HOME=/home/vscode
ENV PATH="/root/.local/bin:$HOME/.local/bin::$PATH"
RUN curl -sSL https://install.python-poetry.org | python3 -
8 changes: 4 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "warmth dolfinx poetry",
"image": "ghcr.io/equinor/warmth:latest",
"build": {"dockerfile": "Dockerfile"},

// 👇 Features to add to the Dev Container. More info: https://containers.dev/implementors/features.
// "features": {},
Expand All @@ -9,7 +9,7 @@
// "forwardPorts": [],

// 👇 Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bash .devcontainer/postCreate.sh",
"postCreateCommand": "poetry config virtualenvs.create false && poetry env use system && poetry install --with dev --no-interaction",

// 👇 Configure tool-specific properties.
"customizations": {
Expand All @@ -27,8 +27,8 @@
"features": {
"ghcr.io/devcontainers/features/git-lfs:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
}
},

// 👇 Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
"remoteUser": "root"
}
4 changes: 0 additions & 4 deletions .devcontainer/postCreate.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ehthumbs_vista.db

# Recycle Bin used on file shares
$RECYCLE.BIN/

simout/
# Windows Installer files
*.cab
*.msi
Expand Down
30 changes: 2 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
FROM dolfinx/dolfinx:v0.6.0

LABEL org.opencontainers.image.source https://github.com/equinor/warmth
ARG DEBIAN_FRONTEND=noninteractive
WORKDIR /home/warmth

RUN DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y build-essential --no-install-recommends make \
ca-certificates \
git \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev

RUN useradd -rm -d /home/vscode -s /bin/bash -g root -G sudo -u 1000 vscode -p ""
USER vscode
WORKDIR /home/vscode
ENV HOME=/home/vscode
ENV PATH="/root/.local/bin:$HOME/.local/bin::$PATH"
RUN curl -sSL https://install.python-poetry.org | python3 -
ENTRYPOINT pip install . pytest==7.4.2 pytest-cov==4.1.0 && pytest --cov-report=term-missing --cov=warmth tests | tee pytest-coverage.txt
9 changes: 1 addition & 8 deletions tests/warmth3d/test_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ def test_3d_compare():



try:
os.mkdir('mesh')
except FileExistsError:
pass
try:
os.mkdir('temp')
except FileExistsError:
pass

mm2 = run_3d(model.builder,model.parameters,start_time=model.parameters.time_start,end_time=0, pad_num_nodes=2,writeout=False, base_flux=None)


Expand Down
20 changes: 12 additions & 8 deletions warmth/mesh_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,9 @@ def constructMesh(self):
cell_data={"layer": [ (np.array(cell_data_layerID, dtype=np.float64)+3)*1e7 + np.array(node_index, dtype=np.float64) ] },
)


fn = self.modelName+"_mesh.xdmf"
p = self._parameters.output_path/ 'mesh'
p.mkdir(parents=True, exist_ok=True)
fn = p/(self.modelName+"_mesh.xdmf")

mesh.write( fn )
logger.info(f"saved mesh to {fn}")
Expand Down Expand Up @@ -1358,15 +1359,16 @@ def boundary(x):


def run_3d( builder:Builder, parameters:Parameters, start_time=182, end_time=0, pad_num_nodes=0,
out_dir = "out-mapA/",sedimentsOnly=False, writeout=True, base_flux=None):
sedimentsOnly=False, writeout=True, base_flux=None):
builder=interpolate_all_nodes(builder)
nums = 4
dt = parameters.myr2s / nums # time step is 1/4 of 1Ma
mms2 = []
mms_tti = []
tti = 0
# base_flux = 0.0033

out_dir = parameters.output_path / 'results3d'/'layers'
out_dir.mkdir(parents=True, exist_ok=True)
time_solve = 0.0
with Bar('Processing...',check_tty=False, max=(start_time-end_time)) as bar:
for tti in range(start_time, end_time-1,-1): #start from oldest
Expand All @@ -1390,15 +1392,15 @@ def run_3d( builder:Builder, parameters:Parameters, start_time=182, end_time=0,
mm2.useBaseFlux = False
mm2.setupSolverAndSolve(n_steps=40, time_step = 314712e8 * 2e2, skip_setup=False)
time_solve = time_solve + toc(msg="setup solver and solve")
else:
else:
mm2.useBaseFlux = (base_flux is not None)
tic()
mm2.setupSolverAndSolve( n_steps=nums, time_step=dt, skip_setup=(not rebuild_mesh))
time_solve = time_solve + toc(msg="setup solver and solve")
if (writeout):
tic()
mm2.writeLayerIDFunction(out_dir+"LayerID-"+str(tti)+".xdmf", tti=tti)
mm2.writeTemperatureFunction(out_dir+"Temperature-"+str(tti)+".xdmf", tti=tti)
mm2.writeLayerIDFunction(out_dir/f"LayerID-{str(tti)}.xdmf", tti=tti)
mm2.writeTemperatureFunction(out_dir+f"Temperature-{str(tti)}.xdmf", tti=tti)
# mm2.writeOutputFunctions(out_dir+"test4-"+str(tti)+".xdmf", tti=tti)
toc(msg="write function")

Expand All @@ -1408,7 +1410,9 @@ def run_3d( builder:Builder, parameters:Parameters, start_time=182, end_time=0,
bar.next()
print("total time solve: " , time_solve)
if (writeout):
EPCfilename = mm2.write_hexa_mesh_resqml("temp/")
resqml_path= parameters.output_path / 'results3d'/'mesh'
resqml_path.mkdir(parents=True, exist_ok=True)
EPCfilename = mm2.write_hexa_mesh_resqml(resqml_path)
print("RESQML model written to: " , EPCfilename)
read_mesh_resqml_hexa(EPCfilename) # test reading of the .epc file
return mm2
1 change: 1 addition & 0 deletions warmth/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self) -> None:
self.starting_beta: float = 1.1
self.positive_down = True
self.name:str = "model"
self.output_path:Path=Path('./simout')
pass

@property
Expand Down
24 changes: 12 additions & 12 deletions warmth/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import time
import numpy as np
from warmth.parameters import Parameters
from warmth.postprocessing import Results_interpolator
from warmth.utils import load_pickle
from .logging import logger
Expand All @@ -23,8 +24,7 @@ def __init__(self, args) -> None:
self.parameter_path:Path = args[0]
self.node_path:Path = args[1]
self.node=load_node(self.node_path)
self.parameters = load_pickle(self.parameter_path)
self.out_path=args[2]
self.parameters:Parameters = load_pickle(self.parameter_path)
pass

def _pad_sediments(self):
Expand All @@ -39,7 +39,7 @@ def _pad_sediments(self):

def _save_results(self) -> Path:
filename = self.node._name+"_results"
filepath = self.out_path / NODES_DIR/filename
filepath = self.parameters.output_path / NODES_DIR/filename
self.node._dump(filepath)
return filepath

Expand Down Expand Up @@ -88,19 +88,19 @@ def __init__(self, builder: Builder) -> None:
self.process = 2
self.cpu=self.process
self.simulate_every = 1
self.out_path:Path=Path('./simout')
self._builder.parameters.output_path:Path=self._builder.parameters.output_path
pass

@property
def _nodes_path(self):
return self.out_path / NODES_DIR
return self._builder.parameters.output_path / NODES_DIR

@property
def _parameters_path(self):
return self.out_path / PARAMETER_FILE
return self._builder.parameters.output_path / PARAMETER_FILE
@property
def _grid_path(self):
return self.out_path / GRID_FILE
return self._builder.parameters.output_path / GRID_FILE



Expand All @@ -121,17 +121,17 @@ def dump_input_data(self):
futures = [th.submit(self.dump_input_nodes, i)
for i in self._builder.iter_node() if i is not False]
for future in concurrent.futures.as_completed(futures):
p.append([parameter_data_path, future.result(),self.out_path])
p.append([parameter_data_path, future.result()])
return p

def setup_directory(self, purge=False):
if self.out_path.exists():
if self._builder.parameters.output_path.exists():
if purge:
from shutil import rmtree
rmtree(self.out_path)
rmtree(self._builder.parameters.output_path)
else:
raise Exception(
f'Output directory {self.out_path} already exist. Use purge=True to delete existing data')
f'Output directory {self._builder.parameters.output_path} already exist. Use purge=True to delete existing data')
self._nodes_path.mkdir(parents=True, exist_ok=True)
return

Expand Down Expand Up @@ -206,7 +206,7 @@ def _parellel_run(self, save,purge):
logger.warning(f"No result file for node X:{n.X}, Y:{n.Y}")
if save==False:
from shutil import rmtree
rmtree(self.out_path)
rmtree(self._builder.parameters.output_path)
if filtered >0:
logger.info(f"Interpolating results back to {filtered} partial simulated nodes")
interp_res= Results_interpolator(self._builder,len(p)-filtered)
Expand Down

0 comments on commit 63441d9

Please sign in to comment.