-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compute homogenized materials over mesh elements (#2971)
- Loading branch information
1 parent
c976653
commit 6e57f1d
Showing
7 changed files
with
215 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from contextlib import contextmanager | ||
import os | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
from typing import Optional | ||
|
||
from .checkvalue import PathLike | ||
|
||
@contextmanager | ||
def change_directory(working_dir: Optional[PathLike] = None, *, tmpdir: bool = False): | ||
"""Context manager for executing in a provided working directory | ||
Parameters | ||
---------- | ||
working_dir : path-like | ||
Directory to switch to. | ||
tmpdir : bool | ||
Whether to use a temporary directory instead of a specific working directory | ||
""" | ||
orig_dir = Path.cwd() | ||
|
||
# Set up temporary directory if requested | ||
if tmpdir: | ||
tmp = TemporaryDirectory() | ||
working_dir = tmp.name | ||
elif working_dir is None: | ||
raise ValueError('Must pass working_dir argument or specify tmpdir=True.') | ||
|
||
working_dir = Path(working_dir) | ||
working_dir.mkdir(parents=True, exist_ok=True) | ||
os.chdir(working_dir) | ||
try: | ||
yield | ||
finally: | ||
os.chdir(orig_dir) | ||
if tmpdir: | ||
tmp.cleanup() |
Oops, something went wrong.