New: config class

This commit is contained in:
L-Nafaryus 2021-10-25 17:19:15 +05:00
parent 0859b6bdf5
commit 120c2f260c
No known key found for this signature in database
GPG Key ID: EF672A5303B2FA96
4 changed files with 166 additions and 2 deletions

View File

@ -7,6 +7,59 @@ import ast
import os, sys, shutil
import logging
@anisotropy.command()
@click.option(
"-P", "--path", "path",
default = os.getcwd(),
help = "Specify directory to use (instead of cwd)"
)
@click.option(
"-C", "--conf", "configFile"
)
@click.option(
"-N", "--nprocs", "nprocs",
type = click.INT,
default = 1,
help = "Count of parallel processes"
)
@click.option(
"-s", "--stage", "stage",
type = click.Choice(["all", "mesh", "flow", "postProcessing"]),
default = "all",
help = "Current computation stage"
)
@click.option(
"-f", "--force", "overwrite",
is_flag = True,
default = False,
help = "Overwrite existing entries"
)
@click.option(
"-p", "--params", "params",
metavar = "key=value",
multiple = True,
cls = KeyValueOption,
help = "Overwrite existing parameter (except control variables)"
)
def compute(path, configFile, nprocs, stage, overwrite):
from anisotropy.core.runner import UltimateRunner
from anisotropy.core.config import Config, DefaultConfig
config = DefaultConfig()
if configFile:
config.load(configFile)
config.update(
nprocs = nprocs,
stage = stage,
overwrite = overwrite
)
config.expand()
runner = UltimateRunner()
class LiteralOption(click.Option):
def type_cast_value(self, ctx, value):
try:

View File

@ -2,4 +2,106 @@
# This file is part of anisotropy.
# License: GNU GPL version 3, see the file "LICENSE" for details.
import os
import toml
from copy import deepcopy
from numpy import arange, array
class Config(object):
def __init__(self):
self.content = {}
self.options = {},
self.cases = None
def __getitem__(self, key):
return self.options[key]
def __setitem__(self, key, value):
self.options[key] = value
def __delitem__(self, key):
del self.options[key]
def update(self, **kwargs):
self.options.update(**kwargs)
def __len__(self):
return len(self.options)
def __iter__(self):
for key in self.options:
yield key
def load(self, filename: str):
path = os.path.abspath(filename)
if not os.path.exists(path):
raise FileNotFoundError(path)
self.content = toml.load(path)
self.options = deepcopy(self.content["options"])
def dump(self, filename: str):
path = os.path.abspath(filename)
ext = os.path.splitext(path)[1]
if not ext == ".toml":
path += ".toml"
os.makedirs(os.path.split(path)[0], exist_ok = True)
with open(path, "w") as io:
toml.dump(self.content, io, encoder = toml.TomlNumpyEncoder())
def expand(self):
self.cases = []
# Expand structures for each direction and each theta
for structure in self.content["structures"]:
thetaA = arange(
structure["theta"][0],
structure["theta"][1] + structure["thetaStep"],
structure["thetaStep"]
)
directionA = array(structure["directions"], dtype = float)
for direction in directionA:
for theta in thetaA:
self.cases.append({
"label": structure["label"],
"theta": theta,
"thetaStep": structure["thetaStep"],
"direction": direction,
"r0": structure["r0"],
"filletsEnabled": structure["filletsEnabled"]
})
class DefaultConfig(Config):
def __init__(self):
Config.__init__(self)
self.content = {
"options": {
"nprocs": 1,
"stage": "all",
"overwrite": False,
},
"structures": []
}
self.options = deepcopy(self.content["options"])
labels = ["simple", "bodyCentered", "faceCentered"]
thetas = array([[0.01, 0.28], [0.01, 0.17], [0.01, 0.13]], dtype = float)
for label, theta in zip(labels, thetas):
self.content["structures"].append({
"label": label,
"theta": theta,
"thetaStep": 0.01,
"directions": array([[1, 0, 0], [0, 0, 1], [1, 1, 1]], dtype = float),
"r0": 1,
"filletsEnabled": True
})

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# This file is part of anisotropy.
# License: GNU GPL version 3, see the file "LICENSE" for details.

View File

@ -19,8 +19,12 @@ class UltimateRunner(object):
pass
def _computeMesh(self):
"""Function for Salome"""
"""Function for Salome
Resolution pipeline:
cli(UR -> computeMesh) -> salomeRunner(salome -> cli) -> computemesh(UR -> _computeMesh)
"""
# TODO: add logger configuration here
sample = samples.__dict__[..]
# Build a shape