Mod: merge cae to pipeline
This commit is contained in:
parent
88f07abf4a
commit
c56504f120
@ -1,4 +1,4 @@
|
||||
.. image:: https://circleci.com/gh/L-Nafaryus/anisotropy/tree/devel.svg?style=svg&circle-token=423bc964a997ded671ebd4ceacc25f9967acdffa
|
||||
.. image:: https://circleci.com/gh/L-Nafaryus/anisotropy/tree/devel.svg?style=shield&circle-token=423bc964a997ded671ebd4ceacc25f9967acdffa
|
||||
:target: https://circleci.com/gh/L-Nafaryus/anisotropy/tree/devel
|
||||
|
||||
anisotropy
|
||||
|
@ -3,11 +3,14 @@
|
||||
# License: GNU GPL version 3, see the file "LICENSE" for details.
|
||||
|
||||
from datetime import datetime
|
||||
from os import path
|
||||
|
||||
from anisotropy.core.config import DefaultConfig
|
||||
from anisotropy.database import *
|
||||
from anisotropy.salomepl.runner import SalomeRunner
|
||||
import anisotropy.samples as samples
|
||||
from anisotropy.shaping import Simple, BodyCentered, FaceCentered
|
||||
from anisotropy.meshing import Mesh
|
||||
from anisotropy.openfoam.presets import CreatePatchDict
|
||||
from anisotropy.solving.onephase import OnePhaseFlow
|
||||
|
||||
class UltimateRunner(object):
|
||||
def __init__(self, config = None, exec_id = False):
|
||||
@ -15,101 +18,134 @@ class UltimateRunner(object):
|
||||
self.config = config or DefaultConfig()
|
||||
|
||||
self.database = Database(self.config["database"])
|
||||
self.datebase.setup()
|
||||
self.database.setup()
|
||||
|
||||
if exec_id:
|
||||
self._exec_id = Execution(date = datetime.now())
|
||||
self._exec_id.save()
|
||||
|
||||
self.shape = None
|
||||
self.mesh = None
|
||||
self.flow = None
|
||||
|
||||
def casePath(self):
|
||||
case = self.config.cases[0]
|
||||
|
||||
return os.path.join(
|
||||
return path.join(
|
||||
self.config["build"],
|
||||
case["label"],
|
||||
"direction-{}".format(str(case["direction"]).replace(" ", "")),
|
||||
"direction-[{},{},{}]".format(*[ str(d) for d in case["direction"] ]),
|
||||
"theta-{}".format(case["theta"])
|
||||
)
|
||||
|
||||
def computeMesh(self):
|
||||
|
||||
def computeShape(self):
|
||||
case = self.config.cases[0]
|
||||
runner = SalomeRunner()
|
||||
cliArgs = [
|
||||
"computemesh",
|
||||
case["label"],
|
||||
case["direction"],
|
||||
case["theta"],
|
||||
path
|
||||
]
|
||||
filename = "shape.step"
|
||||
|
||||
out, err, returncode = runner.execute(
|
||||
env["CLI"],
|
||||
*cliArgs,
|
||||
timeout = self.config["salome_timeout"],
|
||||
root = env["ROOT"],
|
||||
logpath = self.casePath()
|
||||
)
|
||||
match case["label"]:
|
||||
case "simple":
|
||||
self.shape = Simple(case["direction"])
|
||||
|
||||
return out, err, returncode
|
||||
case "bodyCentered":
|
||||
self.shape = BodyCentered(case["direction"])
|
||||
|
||||
case "faceCentered":
|
||||
self.shape = FaceCentered(case["direction"])
|
||||
|
||||
def _computeMesh(self):
|
||||
"""Function for Salome
|
||||
self.shape.build()
|
||||
self.shape.export(path.join(case, filename))
|
||||
|
||||
Resolution pipeline:
|
||||
cli(UR -> computeMesh) -> salomeRunner(salome -> cli) -> computemesh(UR -> _computeMesh)
|
||||
"""
|
||||
|
||||
# TODO: add logger configuration here
|
||||
sample = samples.__dict__[..]
|
||||
|
||||
# Build a shape
|
||||
shape = sample.geometry(..)
|
||||
shape.build()
|
||||
shape.export(..)
|
||||
|
||||
# Build a mesh
|
||||
mesh = sample.mesh(shape)
|
||||
mesh.build()
|
||||
mesh.export(..)
|
||||
|
||||
# Fill database
|
||||
def computeMesh(self):
|
||||
case = self.config.cases[0]
|
||||
filename = "mesh.mesh"
|
||||
|
||||
self.mesh = Mesh(self.shape.shape)
|
||||
self.mesh.build()
|
||||
self.mesh.export(path.join(case, filename))
|
||||
|
||||
def computeFlow(self):
|
||||
case = self.config.cases[0]
|
||||
flow = OnePhaseFlow()
|
||||
|
||||
sample = samples.__dict__[..]
|
||||
# initial 43 unnamed patches ->
|
||||
# 6 named patches (inlet, outlet, wall, symetry0 - 3/5) ->
|
||||
# 4 inGroups (inlet, outlet, wall, symetry)
|
||||
createPatchDict = CreatePatchDict()
|
||||
createPatchDict["patches"] = []
|
||||
patches = {}
|
||||
|
||||
for n, patch in enumerate(self.shape.shape.faces):
|
||||
name = patch.name
|
||||
|
||||
if patches.get(name):
|
||||
patches[name].append(n)
|
||||
|
||||
else:
|
||||
patches[name] = [n]
|
||||
|
||||
for name in patches.keys():
|
||||
match name:
|
||||
case "inlet":
|
||||
patchGroup = "inlet"
|
||||
patchType = "patch"
|
||||
|
||||
case "outlet":
|
||||
patchGroup = "outlet"
|
||||
patchType = "patch"
|
||||
|
||||
case "wall":
|
||||
patchGroup = "wall"
|
||||
patchType = "wall"
|
||||
|
||||
case _:
|
||||
patchGroup = "symetry"
|
||||
patchType = "symetryPlane"
|
||||
|
||||
createPatchDict["patches"].append({
|
||||
"name": name,
|
||||
"patchInfo": {
|
||||
"type": patchType,
|
||||
"inGroups": [patchGroup]
|
||||
},
|
||||
"constructFrom": "patches",
|
||||
"patches": patches[name]
|
||||
})
|
||||
|
||||
flow.append(createPatchDict)
|
||||
|
||||
# Build a flow
|
||||
flow = sample.onephaseflow(..)
|
||||
flow.build()
|
||||
|
||||
|
||||
def pipeline(self, stage: str = None):
|
||||
stage = stage or config["stage"]
|
||||
stage = stage or self.config["stage"]
|
||||
|
||||
match stage:
|
||||
case "mesh" | "all":
|
||||
case "shape" | "all":
|
||||
with self.database.atomic():
|
||||
Shape.create(self._exec_id, **self.config.cases[0])
|
||||
|
||||
self.computeShape()
|
||||
|
||||
case "mesh" | "all":
|
||||
with self.database.atomic():
|
||||
Mesh.create(self._exec_id)
|
||||
|
||||
self.computeMesh(..)
|
||||
self.computeMesh()
|
||||
|
||||
case "flow" | "all":
|
||||
with self.database.atomic():
|
||||
Flow.create(self._exec_id)
|
||||
|
||||
self.computeFlow(..)
|
||||
self.computeFlow()
|
||||
|
||||
case "postProcess" | "all":
|
||||
self.postProcess(..)
|
||||
self.postProcess()
|
||||
|
||||
|
||||
|
||||
def parallel(queue: list, nprocs = None):
|
||||
nprocs = nprocs or config["nprocs"]
|
||||
nprocs = nprocs or self.config["nprocs"]
|
||||
|
||||
parallel(nprocs, [()] * len(queue), [ runner.pipeline for runner in queue ])
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from .database import *
|
@ -2,4 +2,4 @@
|
||||
# This file is part of anisotropy.
|
||||
# License: GNU GPL version 3, see the file "LICENSE" for details.
|
||||
|
||||
|
||||
from .mesh import Mesh
|
||||
|
@ -5,6 +5,7 @@
|
||||
from netgen.occ import OCCGeometry
|
||||
from netgen import meshing
|
||||
import numpy
|
||||
import os
|
||||
|
||||
class Mesh(object):
|
||||
def __init__(self, shape):
|
||||
@ -84,7 +85,7 @@ class Mesh(object):
|
||||
|
||||
def volumes(self) -> numpy.array:
|
||||
# TODO: check each polyhedron
|
||||
tetras = numpy.array([ [ [ vertex for vertex in mesh[index] ] for index in element.vertices ] for element in mesh.Elements3D() ])
|
||||
tetras = numpy.array([ [ [ vertex for vertex in mesh[index] ] for index in element.vertices ] for element in self.mesh.Elements3D() ])
|
||||
volumes = numpy.array([ 1 / 6 * linalg.det(numpy.append(tetra.transpose(), numpy.array([[1, 1, 1, 1]]), axis = 0)) for tetra in tetras ])
|
||||
|
||||
return volumes
|
||||
|
@ -73,6 +73,7 @@ class Simple(Periodic):
|
||||
yw = xl
|
||||
zh = height
|
||||
|
||||
# TODO: correct compasion for arrays
|
||||
if self.direction == [1, 0, 0]:
|
||||
vertices = numpy.array([
|
||||
(xl, 0, 0),
|
||||
|
@ -3,12 +3,12 @@
|
||||
# License: GNU GPL version 3, see the file "LICENSE" for details.
|
||||
|
||||
import anisotropy.openfoam as openfoam
|
||||
from openfoam.presets import (
|
||||
from anisotropy.openfoam.presets import (
|
||||
ControlDict, FvSchemes, FvSolution,
|
||||
TransportProperties, TurbulenceProperties, CreatePatchDict,
|
||||
P, U
|
||||
)
|
||||
from openfoam.foamcase import FoamCase
|
||||
from anisotropy.openfoam.foamcase import FoamCase
|
||||
|
||||
class OnePhaseFlow(FoamCase):
|
||||
def __init__(self):
|
||||
@ -66,34 +66,7 @@ class OnePhaseFlow(FoamCase):
|
||||
simulationType = "laminar"
|
||||
)
|
||||
|
||||
createPatchDict = CreatePatchDict()
|
||||
createPatchDict["patches"] = []
|
||||
|
||||
for patch in ["inlet", "outlet", "wall", "strips", *[ f"symetry{ n }" for n in range(6) ]]:
|
||||
newPatch = dict(
|
||||
name = patch,
|
||||
patchInfo = dict(
|
||||
type = "patch",
|
||||
inGroups = [patch]
|
||||
),
|
||||
constructFrom = "patches",
|
||||
patches = [ f"smesh_{ patch }" ]
|
||||
)
|
||||
|
||||
match patch:
|
||||
case "wall" | "strips":
|
||||
newPatch["patchInfo"].update(
|
||||
type = "wall",
|
||||
inGroups = [ "wall" ]
|
||||
)
|
||||
|
||||
case patch if patch.find("symetry") == 0:
|
||||
newPatch["patchInfo"]["inGroups"] = [ "symetryPlane" ]
|
||||
|
||||
createPatchDict["patches"].append(newPatch)
|
||||
|
||||
|
||||
boundaries = [ "inlet", "outlet", "symetryPlane", "wall", "strips" ]
|
||||
boundaries = [ "inlet", "outlet", "symetry", "wall"]
|
||||
p = P()
|
||||
p["boundaryField"] = {}
|
||||
u = U()
|
||||
@ -131,28 +104,33 @@ class OnePhaseFlow(FoamCase):
|
||||
)
|
||||
|
||||
self.extend([
|
||||
controlDict, fvSchemes, fvSolution, createPatchDict,
|
||||
transportProperties, turbulenceProperties,
|
||||
p, u
|
||||
controlDict,
|
||||
fvSchemes,
|
||||
fvSolution,
|
||||
transportProperties,
|
||||
turbulenceProperties,
|
||||
p,
|
||||
u
|
||||
])
|
||||
|
||||
def build(self):
|
||||
# TODO: configure working directory (FoamCase)
|
||||
self.write()
|
||||
with self:
|
||||
self.write()
|
||||
|
||||
openfoam.ideasUnvToFoam("mesh.unv")
|
||||
openfoam.createPatch()
|
||||
openfoam.checkMesh()
|
||||
openfoam.transformPoints((1e-5, 1e-5, 1e-5))
|
||||
openfoam.renumberMesh()
|
||||
openfoam.potentialFoam()
|
||||
openfoam.netgenNeutralToFoam("mesh.mesh")
|
||||
openfoam.createPatch()
|
||||
openfoam.checkMesh()
|
||||
openfoam.transformPoints((1e-5, 1e-5, 1e-5))
|
||||
openfoam.renumberMesh()
|
||||
openfoam.potentialFoam()
|
||||
|
||||
self.read()
|
||||
self.read()
|
||||
|
||||
self.solution.U["boundaryField"]["outlet"] = dict(
|
||||
type = "pressureInletVelocity",
|
||||
value = "uniform (0 0 0)" # * direction
|
||||
)
|
||||
self.write()
|
||||
self.solution.U["boundaryField"]["outlet"] = dict(
|
||||
type = "pressureInletVelocity",
|
||||
value = "uniform (0 0 0)" # * direction
|
||||
)
|
||||
self.write()
|
||||
|
||||
openfoam.simpleFoam()
|
||||
openfoam.simpleFoam()
|
||||
|
@ -15,12 +15,13 @@ class TestShaping(unittest.TestCase):
|
||||
if not NETGEN_MODULE:
|
||||
self.skipTest("Missing Netgen.")
|
||||
|
||||
from anisotropy import shaping
|
||||
else:
|
||||
from anisotropy import shaping
|
||||
|
||||
self.shaping = shaping
|
||||
self.shaping = shaping
|
||||
|
||||
self.outputPath = os.path.join(os.path.abspath("."), "tests/test_shaping_output")
|
||||
os.makedirs(self.outputPath, exist_ok = True)
|
||||
self.outputPath = os.path.join(os.path.abspath("."), "tests/test_shaping_output")
|
||||
os.makedirs(self.outputPath, exist_ok = True)
|
||||
|
||||
def test_simple(self):
|
||||
simple100 = self.shaping.Simple(direction = [1, 0, 0], alpha = 0.01)
|
||||
|
Loading…
Reference in New Issue
Block a user