Skip to content

Commit

Permalink
Add extra additional arguments to ABAQUS (#18)
Browse files Browse the repository at this point in the history
Allows passing additional arguments to the ABAQUS solver in the command
line call. This has been needed, for instance, to pass the number of
CPUs to use during a simulation.
  • Loading branch information
ruicoelhopedro authored Mar 25, 2024
1 parent 91c0501 commit 4368403
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions piglot/solver/abaqus/solver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Module for Abaqus solver."""
from typing import Dict, Any
from typing import Dict, Any, List
import os
import time
import shutil
Expand All @@ -22,6 +22,7 @@ def __init__(
abaqus_bin: str,
parallel: int,
tmp_dir: str,
extra_args: str = None,
) -> None:
"""Constructor for the Abaqus solver class.
Expand All @@ -44,6 +45,7 @@ def __init__(
self.abaqus_bin = abaqus_bin
self.parallel = parallel
self.tmp_dir = tmp_dir
self.extra_args = extra_args

def _post_proc_variables(self, input_data: AbaqusInputData) -> Dict[str, Any]:
"""Generate the post-processing variables.
Expand Down Expand Up @@ -98,9 +100,15 @@ def _run_case(self, values: np.ndarray, case: Case, tmp_dir: str) -> CaseResult:

# Run ABAQUS (we don't use high precision timers here to keep track of the start time)
begin_time = time.time()
extra_args: List[str] = self.extra_args.split() if self.extra_args else []
run_inp = subprocess.run(
[self.abaqus_bin, f"job={input_data.job_name}", f"input={os.path.basename(input_file)}",
'interactive', 'ask_delete=OFF'],
[
self.abaqus_bin,
f"job={input_data.job_name}",
f"input={os.path.basename(input_file)}",
'interactive',
'ask_delete=OFF',
] + extra_args,
cwd=tmp_dir,
shell=False,
stdout=subprocess.DEVNULL,
Expand Down Expand Up @@ -215,6 +223,7 @@ def read(config: Dict[str, Any], parameters: ParameterSet, output_dir: str) -> S
# Read the parallelism and temporary directory (if present)
parallel = int(config.get('parallel', 1))
tmp_dir = os.path.join(output_dir, config.get('tmp_dir', 'tmp'))
extra_args = config.get('extra_args', None)
# Read the cases
if 'cases' not in config:
raise ValueError("Missing 'cases' in solver configuration.")
Expand All @@ -235,4 +244,12 @@ def read(config: Dict[str, Any], parameters: ParameterSet, output_dir: str) -> S
step_name,
instance_name), fields))
# Return the solver
return AbaqusSolver(cases, parameters, output_dir, abaqus_bin, parallel, tmp_dir)
return AbaqusSolver(
cases,
parameters,
output_dir,
abaqus_bin,
parallel,
tmp_dir,
extra_args=extra_args,
)

0 comments on commit 4368403

Please sign in to comment.