Mod: -
This commit is contained in:
parent
73e6c98675
commit
3b896fb3fc
@ -171,9 +171,12 @@ def update(force, params, path):
|
||||
if args.get("theta"):
|
||||
paramsAll = [ entry for entry in paramsAll if args["theta"] == entry["structure"]["theta"] ]
|
||||
|
||||
from anisotropy.core.models import Structure, Mesh
|
||||
from numpy
|
||||
for entry in paramsAll:
|
||||
database.update(entry)
|
||||
|
||||
|
||||
click.echo("{} entries was updated.".format(len(paramsAll)))
|
||||
|
||||
else:
|
||||
|
@ -313,6 +313,24 @@ class Anisotropy(object):
|
||||
##
|
||||
logger.info("Prepairing mesh ...")
|
||||
|
||||
params = db.Mesh()
|
||||
mesh = mesh.Mesh(shapeGeometry)
|
||||
algo3d = mesh.algo3d(Netgen3D)
|
||||
algo3d.apply(**params)
|
||||
|
||||
mesh = smesh.Mesh(shape)
|
||||
algo3d = mesh.Tetrahedron(algo = smeshBuilder.NETGEN_3D)
|
||||
algo2d = mesh.Triangle(algo = smeshBuilder.NETGEN_2D)
|
||||
hypo2d = algo2d.MaxElementArea(0.197375)
|
||||
algo1d = mesh.Segment()
|
||||
hypo1d = algo1d.AutomaticLength(1)
|
||||
|
||||
algo2d = mesh.Triangle(algo = smeshBuilder.NETGEN_2D, geom = strips)
|
||||
hypo2d = algo2d.LengthFromEdges()
|
||||
algo1d = mesh.Segment(algo = smeshBuilder.COMPOSITE, geom = strips)
|
||||
hypo1d = algo1d.AutomaticLength(0.633882)
|
||||
hypo1d.SetFineness( 1 )
|
||||
|
||||
mp = p["mesh"]
|
||||
|
||||
lengths = [
|
||||
|
@ -8,7 +8,7 @@ from peewee import (
|
||||
AutoField, ForeignKeyField,
|
||||
TextField, FloatField,
|
||||
IntegerField, BooleanField,
|
||||
TimeField
|
||||
TimeField, DateTimeField
|
||||
)
|
||||
import json
|
||||
|
||||
@ -51,6 +51,17 @@ class JSONField(TextField):
|
||||
return json.loads(value)
|
||||
|
||||
|
||||
class Execution(Model):
|
||||
execution_id = AutoField()
|
||||
|
||||
date = DateTimeField()
|
||||
executionTime = TimeField()
|
||||
|
||||
class Meta:
|
||||
database = db
|
||||
db_table = "executions"
|
||||
|
||||
|
||||
class Structure(BaseModel):
|
||||
structure_id = AutoField()
|
||||
|
||||
|
@ -17,6 +17,30 @@ class BodyCentered(StructureGeometry):
|
||||
def L(self):
|
||||
return self.r0 * 4 / sqrt(3)
|
||||
|
||||
@property
|
||||
def thetaMin(self):
|
||||
return 0.01
|
||||
|
||||
@property
|
||||
def thetaMax(self):
|
||||
return 0.18
|
||||
|
||||
@property
|
||||
def fillets(self):
|
||||
if self.direction == [1.0, 1.0, 1.0]:
|
||||
C1, C2 = 0.3, 0.2
|
||||
Cf = C1 + (C2 - C1) / (self.thetaMax - self.thetaMin) * (self.theta - self.thetaMin)
|
||||
delta = 0.02
|
||||
|
||||
return delta - Cf * (self.radius - self.r0)
|
||||
|
||||
else:
|
||||
C1, C2 = 0.3, 0.2
|
||||
Cf = C1 + (C2 - C1) / (self.thetaMax - self.thetaMin) * (self.theta - self.thetaMin)
|
||||
delta = 0.02
|
||||
|
||||
return delta - Cf * (self.radius - self.r0)
|
||||
|
||||
def build(self):
|
||||
###
|
||||
# Pore Cell
|
||||
|
@ -16,6 +16,41 @@ class FaceCentered(StructureGeometry):
|
||||
def L(self):
|
||||
return self.r0 * 4 / sqrt(2)
|
||||
|
||||
@property
|
||||
def thetaMin(self):
|
||||
return 0.01
|
||||
|
||||
@property
|
||||
def thetaMax(self):
|
||||
self.Cscale = 0.8
|
||||
return 0.13
|
||||
|
||||
@property
|
||||
def fillets(self):
|
||||
if self.direction == [1.0, 1.0, 1.0]:
|
||||
#C1, C2 = 0.3, 0.2
|
||||
#Cscale = 0.9 #C1 + (C2 - C1) / (self.thetaMax - self.thetaMin) * (self.theta - self.thetaMin)
|
||||
#delta = 0.thetaMin = 0.01
|
||||
thetaMax = 0.13
|
||||
|
||||
L = 1.0
|
||||
r0 = L * sqrt(2) / 4
|
||||
radius = r0 / (1 - structure["theta"])
|
||||
|
||||
C1, C2 = 0.3, 0.2
|
||||
Cf = C1 + (C2 - C1) / (thetaMax - thetaMin) * (structure["theta"] - thetaMin)
|
||||
delta = 0.012
|
||||
fillets = delta - Cf * (radius - r0)012
|
||||
|
||||
return self.Cscale * (2 - 1 / (1 - self.theta)) * self.r0 #delta - Cf * (self.radius - self.r0)
|
||||
|
||||
else:
|
||||
C1, C2 = 0.3, 0.2
|
||||
Cf = C1 + (C2 - C1) / (self.thetaMax - self.thetaMin) * (self.theta - self.thetaMin)
|
||||
delta = 0.012
|
||||
|
||||
return delta - Cf * (self.radius - self.r0)
|
||||
|
||||
def build(self):
|
||||
###
|
||||
# Pore Cell
|
||||
|
@ -16,6 +16,31 @@ class Simple(StructureGeometry):
|
||||
def L(self):
|
||||
return 2 * self.r0
|
||||
|
||||
@property
|
||||
def thetaMin(self):
|
||||
return 0.01
|
||||
|
||||
@property
|
||||
def thetaMax(self):
|
||||
return 0.28
|
||||
|
||||
@property
|
||||
def fillets(self):
|
||||
if self.direction == [1.0, 1.0, 1.0]:
|
||||
C1, C2 = 0.8, 0.5
|
||||
Cf = C1 + (C2 - C1) / (self.thetaMax - self.thetaMin) * (self.theta - self.thetaMin)
|
||||
delta = 0.2
|
||||
|
||||
return delta - Cf * (self.radius - self.r0)
|
||||
|
||||
else:
|
||||
C1, C2 = 0.8, 0.5
|
||||
Cf = C1 + (C2 - C1) / (self.thetaMax - self.thetaMin) * (self.theta - self.thetaMin)
|
||||
delta = 0.2
|
||||
|
||||
return delta - Cf * (self.radius - self.r0)
|
||||
|
||||
|
||||
def build(self):
|
||||
###
|
||||
# Pore Cell
|
||||
|
@ -9,11 +9,11 @@ class StructureGeometry(object):
|
||||
self,
|
||||
direction: list = None,
|
||||
theta: float = None,
|
||||
r0: float = None,
|
||||
r0: float = 1,
|
||||
#L: float = None,
|
||||
#radius: float = None,
|
||||
filletsEnabled: bool = False,
|
||||
fillets: float = None,
|
||||
#fillets: float = None,
|
||||
**kwargs
|
||||
):
|
||||
"""Constructor method.
|
||||
@ -29,16 +29,13 @@ class StructureGeometry(object):
|
||||
|
||||
:param filletsEnabled:
|
||||
Enable fillets beetween spheres.
|
||||
|
||||
:param fillets:
|
||||
Fillets radius.
|
||||
"""
|
||||
# Geometry parameters
|
||||
self.direction = direction
|
||||
self.theta = theta
|
||||
self.r0 = r0
|
||||
self.filletsEnabled = filletsEnabled
|
||||
self.fillets = fillets
|
||||
#self.fillets = fillets
|
||||
|
||||
# General attributes
|
||||
self.geo = geometry.getGeom()
|
||||
|
File diff suppressed because one or more lines are too long
462
playground/database.ipynb
Normal file
462
playground/database.ipynb
Normal file
@ -0,0 +1,462 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "c4317e7e-d7b9-4bec-9cad-e26a377458b8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from peewee import (\n",
|
||||
" SqliteDatabase, JOIN, \n",
|
||||
" Model, Field, \n",
|
||||
" AutoField, ForeignKeyField, \n",
|
||||
" TextField, FloatField, \n",
|
||||
" IntegerField, BooleanField, \n",
|
||||
" TimeField\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "db03ea1b-e950-4f0b-8c4f-c137417981ca",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"db = SqliteDatabase(\"test_db.db\", pragmas = { \"foreign_keys\" : 1, \"journal_mode\": \"wal\" })"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "e904a64b-9108-414b-974b-2dbf96018cf5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class ListField(Field):\n",
|
||||
" field_type = \"list\"\n",
|
||||
"\n",
|
||||
" def db_value(self, value):\n",
|
||||
" return str(value)\n",
|
||||
"\n",
|
||||
" def python_value(self, value):\n",
|
||||
" pval = []\n",
|
||||
"\n",
|
||||
" for entry in value[1 : -1].split(\",\"):\n",
|
||||
" try:\n",
|
||||
" pval.append(float(entry))\n",
|
||||
"\n",
|
||||
" except:\n",
|
||||
" pval.append(entry.strip().replace(\"'\", \"\"))\n",
|
||||
"\n",
|
||||
" return pval"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "a6049589-dd33-4cfa-8434-1c00285c01e0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Structure(Model):\n",
|
||||
" structure_id = AutoField()\n",
|
||||
"\n",
|
||||
" type = TextField()\n",
|
||||
" direction = ListField()\n",
|
||||
" theta = FloatField()\n",
|
||||
"\n",
|
||||
" r0 = FloatField(null = True)\n",
|
||||
" L = FloatField(null = True)\n",
|
||||
" radius = FloatField(null = True)\n",
|
||||
"\n",
|
||||
" filletsEnabled = BooleanField(null = True)\n",
|
||||
" fillets = FloatField(null = True)\n",
|
||||
" #path = TextField()\n",
|
||||
" \n",
|
||||
" class Meta:\n",
|
||||
" database = db\n",
|
||||
" db_table = \"structures\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class Mesh(Model):\n",
|
||||
" mesh_id = AutoField()\n",
|
||||
" structure_id = ForeignKeyField(Structure, backref = \"meshes\")\n",
|
||||
"\n",
|
||||
" maxSize = FloatField(null = True) \n",
|
||||
"\n",
|
||||
" class Meta:\n",
|
||||
" database = db\n",
|
||||
" db_table = \"meshes\"\n",
|
||||
" depends_on = Structure"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "77c8b505-8b72-4f41-9f6d-d0b4e44884ea",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"db.create_tables([Structure, Mesh])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"id": "708acdf5-a604-44c1-8631-d274d0273c1b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"id": "62c1c0a0-74ae-43cc-bc75-1fbd353540ae",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"s1 = Structure(type = \"simple\", direction = [1, 0, 0], theta = 0.01)\n",
|
||||
"s1.save()\n",
|
||||
"\n",
|
||||
"m1 = Mesh(structure_id = s1, maxSize = 1e-2)\n",
|
||||
"m1.save()\n",
|
||||
"\n",
|
||||
"#db.commit()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"id": "0e03bc08-94ea-4680-8223-dbafc13dcfe7",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"s1.theta = 0.12\n",
|
||||
"s1.save()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"id": "a2f68e62-0324-4ec2-8113-47cf6e1dc5bd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ss = numpy.array([\n",
|
||||
" Structure(type = \"simple\", direction = [1, 0, 0], theta = 0.01),\n",
|
||||
" Structure(type = \"simple\", direction = [1, 0, 0], theta = 0.02)\n",
|
||||
"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"id": "6683ea42-5fdc-4b33-b709-5ea31ae5567f",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"dtype('O')"
|
||||
]
|
||||
},
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"ss.dtype"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"id": "83cc7bde-e003-4f2c-ab9b-f9e37634c374",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"Structure.bulk_create(ss)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"id": "962010a5-68b8-4711-a067-962677aa406d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"1 simple [1.0, 0.0, 0.0] 0.12\n",
|
||||
"2 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"3 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"4 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"5 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"6 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"7 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"8 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"9 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"10 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"11 simple [1.0, 0.0, 0.0] 0.01\n",
|
||||
"12 simple [1.0, 0.0, 0.0] 0.02\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for row in Structure.select():\n",
|
||||
" print(row.structure_id, row.type, row.direction, row.theta)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "a5fc7787-7045-4bb1-a846-5fff8b21417c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"sel = Structure.select()[-1]\n",
|
||||
"sel2 = sel.meshes.select()[-1]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"id": "480edddc-478e-47ce-8678-490455badd35",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<Mesh: 8>"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"sel2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "8286c287-f89d-40bd-8045-a854013915c2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"sel3 = Structure.select().dicts().get()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "180b07cb-6c10-4390-9f9c-07bf9f74f39e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'structure_id': 1,\n",
|
||||
" 'type': 'simple',\n",
|
||||
" 'direction': [1.0, 0.0, 0.0],\n",
|
||||
" 'theta': 0.12,\n",
|
||||
" 'r0': None,\n",
|
||||
" 'L': None,\n",
|
||||
" 'radius': None,\n",
|
||||
" 'filletsEnabled': None,\n",
|
||||
" 'fillets': None}"
|
||||
]
|
||||
},
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"sel3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"id": "dc2e8b67-67ea-477a-af94-dd1ceb1a2a24",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from anisotropy.core.main import Anisotropy\n",
|
||||
"model = Anisotropy()\n",
|
||||
"params_: list = model.loadFromScratch(\"test_anisotropy.toml\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"id": "e73c9863-e8d7-4ed5-a27e-0c733c3daeb6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"171"
|
||||
]
|
||||
},
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"len(params_)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"id": "f532c668-965a-4c7c-aaa9-23a9e308a455",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"params = numpy.array(params_)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 40,
|
||||
"id": "6ad8131f-3e0f-43b9-ab41-b6e3e56a5245",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pandas import Series"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 41,
|
||||
"id": "6111802f-9e5f-47de-a6ea-f54dd062ecba",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"pparams = Series(params_)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 51,
|
||||
"id": "11f04e87-e2f1-4d22-be85-8b6967935c92",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"test = numpy.array([], dtype = object)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 52,
|
||||
"id": "e1a930c3-e591-41e3-8d76-8316f4b8bfac",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"test += 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 55,
|
||||
"id": "075e261f-4387-49c3-9c40-292885cffcc6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"\u001b[0;31mDocstring:\u001b[0m\n",
|
||||
"a.fill(value)\n",
|
||||
"\n",
|
||||
"Fill the array with a scalar value.\n",
|
||||
"\n",
|
||||
"Parameters\n",
|
||||
"----------\n",
|
||||
"value : scalar\n",
|
||||
" All elements of `a` will be assigned this value.\n",
|
||||
"\n",
|
||||
"Examples\n",
|
||||
"--------\n",
|
||||
">>> a = np.array([1, 2])\n",
|
||||
">>> a.fill(0)\n",
|
||||
">>> a\n",
|
||||
"array([0, 0])\n",
|
||||
">>> a = np.empty(2)\n",
|
||||
">>> a.fill(1)\n",
|
||||
">>> a\n",
|
||||
"array([1., 1.])\n",
|
||||
"\u001b[0;31mType:\u001b[0m builtin_function_or_method\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"?test.fill"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "448c99bf-2b6f-43de-92d3-dc1267e766d3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
164
playground/geometry.ipynb
Normal file
164
playground/geometry.ipynb
Normal file
File diff suppressed because one or more lines are too long
119
playground/mesh.py
Normal file
119
playground/mesh.py
Normal file
@ -0,0 +1,119 @@
|
||||
|
||||
class MeshAlgorithm(object):
|
||||
pass
|
||||
|
||||
class Netgen3D(MeshAlgorithm):
|
||||
def __init__(self, **kwargs):
|
||||
self.key = smeshBuilder.NETGEN_3D
|
||||
|
||||
def initialize(self, algo):
|
||||
self.algo = algo
|
||||
self.hypo = self.algo.Parameters()
|
||||
|
||||
|
||||
@property
|
||||
def minSize(self):
|
||||
return self.hypo.GetMinSize()
|
||||
|
||||
@minSize.setter
|
||||
def minSize(self, value):
|
||||
self.hypo.SetMinSize(value)
|
||||
|
||||
class MEFISTO(MeshAlgorithm):
|
||||
|
||||
|
||||
class Mesh(object):
|
||||
def __init__(self, geom):
|
||||
|
||||
self.smesh = smeshBuilder.New()
|
||||
self.geom = geom
|
||||
self.mesh = self.smesh.Mesh(self.geom.shape, self.geom.name)
|
||||
|
||||
def algo3d(self, algo: MeshAlgorithm, type = "tetrahedron"):
|
||||
smeshAlgo = self.mesh.__dict__.get(type.capitalize())
|
||||
self.meshAlgorithm3d = algo()
|
||||
self.meshAlgorithm3d.initialize(smeshAlgo(algo = self.meshAlgorithm3d.key))
|
||||
self.mesh.AddHypothesis(self.meshAlgorithm3d.hypo)
|
||||
|
||||
return self.meshAlgorithm3d
|
||||
|
||||
def algo2d(self, algo: MeshAlgorithm, type = "triangle"):
|
||||
smeshAlgo = self.mesh.__dict__.get(type.capitalize())
|
||||
self.meshAlgorithm2d = algo()
|
||||
self.meshAlgorithm2d.initialize(smeshAlgo(algo = self.meshAlgorithm2d.key))
|
||||
self.mesh.AddHypothesis(self.meshAlgorithm2d.hypo)
|
||||
|
||||
return self.meshAlgorithm2d
|
||||
|
||||
def algo1d(self, algo: MeshAlgorithm, type = "segment"):
|
||||
smeshAlgo = self.mesh.__dict__.get(type.capitalize())
|
||||
self.meshAlgorithm1d = algo()
|
||||
self.meshAlgorithm1d.initialize(smeshAlgo(algo = self.meshAlgorithm1d.key))
|
||||
self.mesh.AddHypothesis(self.meshAlgorithm1d.hypo)
|
||||
|
||||
return self.meshAlgorithm1d
|
||||
|
||||
def createGroups(self, prefix = None):
|
||||
prefix = prefix or ""
|
||||
|
||||
for group in self.shape.groups:
|
||||
name = group.GetName()
|
||||
|
||||
if name:
|
||||
name = prefix + name
|
||||
self.mesh.GroupOnGeom(group, name, SMESH.FACE)
|
||||
|
||||
def compute(self):
|
||||
"""Compute mesh.
|
||||
"""
|
||||
isDone = self.mesh.Compute()
|
||||
out = ""
|
||||
err = self.mesh.GetComputeErrors()
|
||||
returncode = int(not isDone)
|
||||
|
||||
return out, err, returncode
|
||||
|
||||
def stats(self):
|
||||
return {
|
||||
"elements": self.mesh.NbElements(),
|
||||
"edges": self.mesh.NbEdges(),
|
||||
"faces": self.mesh.NbFaces(),
|
||||
"volumes": self.mesh.NbVolumes(),
|
||||
"tetrahedrons": self.mesh.NbTetras(),
|
||||
"prisms": self.mesh.NbPrisms(),
|
||||
"pyramids": self.mesh.NbPyramids()
|
||||
}
|
||||
|
||||
def export(
|
||||
filename: str
|
||||
):
|
||||
"""Export a mesh.
|
||||
|
||||
Supported formats: unv.
|
||||
|
||||
:param filename:
|
||||
Name of the file to store the given mesh in.
|
||||
|
||||
:return:
|
||||
Output, error messages and returncode
|
||||
"""
|
||||
out, err, returncode = "", "", 0
|
||||
ext = os.path.splitext(filename)[1][1: ]
|
||||
|
||||
try:
|
||||
if ext == "unv":
|
||||
self.mesh.ExportUNV(self.mesh, filename)
|
||||
|
||||
else:
|
||||
raise NotImplementedError(f"{ ext } is not supported")
|
||||
|
||||
except NotImplementedError as e:
|
||||
err = e
|
||||
returncode = 1
|
||||
|
||||
except Exception as e:
|
||||
err = e.details.text
|
||||
returncode = 1
|
||||
|
||||
return out, err, returncode
|
||||
|
281
playground/test_anisotropy.toml
Normal file
281
playground/test_anisotropy.toml
Normal file
@ -0,0 +1,281 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# This file is part of anisotropy.
|
||||
# License: GNU GPL version 3, see the file "LICENSE" for details.
|
||||
|
||||
[logger]
|
||||
name = "anisotropy"
|
||||
format = "[ %(levelname)s ] %(message)s"
|
||||
|
||||
[base]
|
||||
simple = true
|
||||
bodyCentered = true
|
||||
faceCentered = true
|
||||
|
||||
[[structures]]
|
||||
[structures.structure]
|
||||
type = "simple"
|
||||
# auto # from theta: list # theta: float
|
||||
theta = [0.01, 0.28, 0.01] # [min, max, step]
|
||||
# auto # from directions:list # direction: list
|
||||
directions = [
|
||||
[1, 0, 0],
|
||||
[0, 0, 1],
|
||||
[1, 1, 1]
|
||||
]
|
||||
|
||||
# r0 =
|
||||
# L =
|
||||
# radius =
|
||||
|
||||
filletsEnabled = true
|
||||
# auto # fillets: float
|
||||
|
||||
[structures.mesh]
|
||||
maxSize = 0.5
|
||||
minSize = 0.05
|
||||
|
||||
fineness = 5
|
||||
growthRate = 0.5
|
||||
nbSegPerEdge = 2
|
||||
nbSegPerRadius = 1
|
||||
|
||||
chordalErrorEnabled = true
|
||||
chordalError = 0.25
|
||||
|
||||
secondOrder = false
|
||||
optimize = true
|
||||
quadAllowed = false
|
||||
useSurfaceCurvature = true
|
||||
fuseEdges = true
|
||||
checkChartBoundary = false
|
||||
|
||||
viscousLayers = false
|
||||
thickness = [0.01, 0.005] # [min, max] # step is controlled by theta count
|
||||
numberOfLayers = 1
|
||||
stretchFactor = 1
|
||||
isFacesToIgnore = true
|
||||
facesToIgnore = ["inlet", "outlet"]
|
||||
# auto # faces: list
|
||||
extrusionMethod = "SURF_OFFSET_SMOOTH"
|
||||
|
||||
[[structures.submesh]]
|
||||
name = "strips"
|
||||
maxSize = 0.5
|
||||
minSize = 0.05
|
||||
|
||||
fineness = 5
|
||||
growthRate = 0.2
|
||||
nbSegPerEdge = 2
|
||||
nbSegPerRadius = 3
|
||||
|
||||
chordalErrorEnabled = true
|
||||
chordalError = 0.25
|
||||
|
||||
secondOrder = false
|
||||
optimize = true
|
||||
quadAllowed = false
|
||||
useSurfaceCurvature = true
|
||||
fuseEdges = true
|
||||
checkChartBoundary = false
|
||||
|
||||
[structures.flowapproximation]
|
||||
transportProperties.nu = 1e-6
|
||||
|
||||
pressure.boundaryField.inlet = { type = "fixedValue", value = 1e-3 }
|
||||
pressure.boundaryField.outlet = { type = "fixedValue", value = 0.0 }
|
||||
|
||||
# multiplication velocity value with flow direction vector
|
||||
velocity.boundaryField.inlet = { type = "fixedValue", value = 6e-5 }
|
||||
velocity.boundaryField.outlet = { type = "zeroGradient", value = "None" }
|
||||
|
||||
[structures.flow]
|
||||
scale = [ 1e-5, 1e-5, 1e-5 ]
|
||||
|
||||
transportProperties.nu = 1e-6
|
||||
|
||||
pressure.boundaryField.inlet = { type = "fixedValue", value = 1e-3 }
|
||||
pressure.boundaryField.outlet = { type = "fixedValue", value = 0.0 }
|
||||
|
||||
velocity.boundaryField.inlet = { type = "pressureInletVelocity", value = 0.0 }
|
||||
velocity.boundaryField.outlet = { type = "zeroGradient", value = "None" }
|
||||
|
||||
|
||||
[[structures]]
|
||||
[structures.structure]
|
||||
type = "bodyCentered"
|
||||
# auto # from theta: list # theta: float
|
||||
theta = [0.01, 0.17, 0.01] # [min, max, step]
|
||||
# auto # from directions:list # direction: list
|
||||
directions = [
|
||||
[1, 0, 0],
|
||||
[0, 0, 1],
|
||||
[1, 1, 1]
|
||||
]
|
||||
|
||||
# r0 =
|
||||
# L =
|
||||
# radius =
|
||||
|
||||
filletsEnabled = true
|
||||
# auto # fillets: float
|
||||
|
||||
[structures.mesh]
|
||||
maxSize = 0.5
|
||||
minSize = 0.05
|
||||
|
||||
fineness = 5
|
||||
growthRate = 0.5
|
||||
nbSegPerEdge = 2
|
||||
nbSegPerRadius = 1
|
||||
|
||||
chordalErrorEnabled = true
|
||||
chordalError = 0.25
|
||||
|
||||
secondOrder = false
|
||||
optimize = true
|
||||
quadAllowed = false
|
||||
useSurfaceCurvature = true
|
||||
fuseEdges = true
|
||||
checkChartBoundary = false
|
||||
|
||||
viscousLayers = false
|
||||
thickness = [0.005, 0.0005] # [min, max] # step is controlled by theta count
|
||||
numberOfLayers = 1
|
||||
stretchFactor = 1
|
||||
isFacesToIgnore = true
|
||||
facesToIgnore = ["inlet", "outlet"]
|
||||
# auto # faces: list
|
||||
extrusionMethod = "SURF_OFFSET_SMOOTH"
|
||||
|
||||
[[structures.submesh]]
|
||||
name = "strips"
|
||||
maxSize = 0.5
|
||||
minSize = 0.05
|
||||
|
||||
fineness = 5
|
||||
growthRate = 0.2
|
||||
nbSegPerEdge = 2
|
||||
nbSegPerRadius = 3
|
||||
|
||||
chordalErrorEnabled = true
|
||||
chordalError = 0.25
|
||||
|
||||
secondOrder = false
|
||||
optimize = true
|
||||
quadAllowed = false
|
||||
useSurfaceCurvature = true
|
||||
fuseEdges = true
|
||||
checkChartBoundary = false
|
||||
|
||||
[structures.flowapproximation]
|
||||
transportProperties.nu = 1e-6
|
||||
|
||||
pressure.boundaryField.inlet = { type = "fixedValue", value = 1e-3 }
|
||||
pressure.boundaryField.outlet = { type = "fixedValue", value = 0.0 }
|
||||
|
||||
# multiplication velocity value with direction vector
|
||||
velocity.boundaryField.inlet = { type = "fixedValue", value = 6e-5 }
|
||||
velocity.boundaryField.outlet = { type = "zeroGradient", value = "None" }
|
||||
|
||||
[structures.flow]
|
||||
scale = [ 1e-5, 1e-5, 1e-5 ]
|
||||
|
||||
transportProperties.nu = 1e-6
|
||||
|
||||
pressure.boundaryField.inlet = { type = "fixedValue", value = 1e-3 }
|
||||
pressure.boundaryField.outlet = { type = "fixedValue", value = 0.0 }
|
||||
|
||||
velocity.boundaryField.inlet = { type = "pressureInletVelocity", value = 0.0 }
|
||||
velocity.boundaryField.outlet = { type = "zeroGradient", value = "None" }
|
||||
|
||||
|
||||
[[structures]]
|
||||
[structures.structure]
|
||||
type = "faceCentered"
|
||||
# auto # from theta: list # theta: float
|
||||
theta = [0.01, 0.12, 0.01] # [min, max, step]
|
||||
# auto # from directions:list # direction: list
|
||||
directions = [
|
||||
[1, 0, 0],
|
||||
[0, 0, 1],
|
||||
[1, 1, 1]
|
||||
]
|
||||
|
||||
# r0 =
|
||||
# L =
|
||||
# radius =
|
||||
|
||||
filletsEnabled = true
|
||||
# auto # fillets: float
|
||||
|
||||
[structures.mesh]
|
||||
maxSize = 0.5
|
||||
minSize = 0.05
|
||||
|
||||
fineness = 5
|
||||
growthRate = 0.5
|
||||
nbSegPerEdge = 2
|
||||
nbSegPerRadius = 1
|
||||
|
||||
chordalErrorEnabled = true
|
||||
chordalError = 0.25
|
||||
|
||||
secondOrder = false
|
||||
optimize = true
|
||||
quadAllowed = false
|
||||
useSurfaceCurvature = true
|
||||
fuseEdges = true
|
||||
checkChartBoundary = false
|
||||
|
||||
viscousLayers = false
|
||||
thickness = [0.001, 0.0005] # [min, max] # step is controlled by theta count
|
||||
numberOfLayers = 1
|
||||
stretchFactor = 1
|
||||
isFacesToIgnore = true
|
||||
facesToIgnore = ["inlet", "outlet"]
|
||||
# auto # faces: list
|
||||
extrusionMethod = "SURF_OFFSET_SMOOTH"
|
||||
|
||||
[[structures.submesh]]
|
||||
name = "strips"
|
||||
maxSize = 0.5
|
||||
minSize = 0.05
|
||||
|
||||
fineness = 5
|
||||
growthRate = 0.2
|
||||
nbSegPerEdge = 2
|
||||
nbSegPerRadius = 3
|
||||
|
||||
chordalErrorEnabled = true
|
||||
chordalError = 0.25
|
||||
|
||||
secondOrder = false
|
||||
optimize = true
|
||||
quadAllowed = false
|
||||
useSurfaceCurvature = true
|
||||
fuseEdges = true
|
||||
checkChartBoundary = false
|
||||
|
||||
[structures.flowapproximation]
|
||||
transportProperties.nu = 1e-6
|
||||
|
||||
pressure.boundaryField.inlet = { type = "fixedValue", value = 1e-3 }
|
||||
pressure.boundaryField.outlet = { type = "fixedValue", value = 0.0 }
|
||||
|
||||
# multiplication velocity value with direction vector
|
||||
velocity.boundaryField.inlet = { type = "fixedValue", value = 6e-5 }
|
||||
velocity.boundaryField.outlet = { type = "zeroGradient", value = "None" }
|
||||
|
||||
[structures.flow]
|
||||
scale = [ 1e-5, 1e-5, 1e-5 ]
|
||||
|
||||
transportProperties.nu = 1e-6
|
||||
|
||||
pressure.boundaryField.inlet = { type = "fixedValue", value = 1e-3 }
|
||||
pressure.boundaryField.outlet = { type = "fixedValue", value = 0.0 }
|
||||
|
||||
velocity.boundaryField.inlet = { type = "pressureInletVelocity", value = 0.0 }
|
||||
velocity.boundaryField.outlet = { type = "zeroGradient", value = "None" }
|
||||
|
||||
|
||||
|
BIN
playground/test_db.db
Normal file
BIN
playground/test_db.db
Normal file
Binary file not shown.
@ -550,6 +550,8 @@ NETGEN_3D_1 = Mesh_2.Tetrahedron()
|
||||
status = Mesh_2.RemoveHypothesis(NETGEN_3D_Parameters_1_1)
|
||||
isDone = Mesh_2.Compute()
|
||||
[ Group_1_2, inlet_2, Group_3_2, outlet_2, Group_5_2, symetry0_2, Group_7_2, symetry1_2, Group_9, symetry2_2, Group_11, symetry3_2, Group_13, Group_14, strips_2, Group_16, wall_2 ] = Mesh_2.GetGroups()
|
||||
|
||||
|
||||
Mesh_3 = smesh.Mesh(simple_1)
|
||||
status = Mesh_3.AddHypothesis(Automatic_Length_3)
|
||||
Regular_1D_4 = Mesh_3.Segment()
|
||||
@ -573,10 +575,12 @@ symetry3_3 = Mesh_3.GroupOnGeom(symetry3_1,'symetry3',SMESH.FACE)
|
||||
strips_3 = Mesh_3.GroupOnGeom(strips_1,'strips',SMESH.FACE)
|
||||
#Group_16_1 = Mesh_3.GroupOnGeom(__NOT__Published__Object__,'',SMESH.FACE)
|
||||
wall_3 = Mesh_3.GroupOnGeom(wall_1,'wall',SMESH.FACE)
|
||||
|
||||
Regular_1D_5 = Mesh_3.Segment(geom=strips_1)
|
||||
status = Mesh_3.AddHypothesis(Automatic_Length_2,strips_1)
|
||||
NETGEN_2D_5 = Mesh_3.Triangle(algo=smeshBuilder.NETGEN_2D,geom=strips_1)
|
||||
status = Mesh_3.AddHypothesis(Length_From_Edges_4,strips_1)
|
||||
|
||||
[ Group_1_3, inlet_3, Group_3_3, outlet_3, Group_5_3, symetry0_3, Group_7_3, symetry1_3, Group_9_1, symetry2_3, Group_11_1, symetry3_3, Group_13_1, Group_14_1, strips_3, Group_16_1, wall_3 ] = Mesh_3.GetGroups()
|
||||
isDone = Mesh_3.Compute()
|
||||
[ Group_1_3, inlet_3, Group_3_3, outlet_3, Group_5_3, symetry0_3, Group_7_3, symetry1_3, Group_9_1, symetry2_3, Group_11_1, symetry3_3, Group_13_1, Group_14_1, strips_3, Group_16_1, wall_3 ] = Mesh_3.GetGroups()
|
||||
|
87
playground/test_models.py
Normal file
87
playground/test_models.py
Normal file
@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from peewee import (
|
||||
SqliteDatabase, JOIN,
|
||||
Model, Field,
|
||||
AutoField, ForeignKeyField,
|
||||
TextField, FloatField,
|
||||
IntegerField, BooleanField,
|
||||
TimeField
|
||||
)
|
||||
|
||||
db = SqliteDatabase("test_db.db", pragmas = { "foreign_keys" : 1, "journal_mode": "wal" })
|
||||
|
||||
class ListField(Field):
|
||||
field_type = "list"
|
||||
|
||||
def db_value(self, value):
|
||||
return str(value)
|
||||
|
||||
def python_value(self, value):
|
||||
pval = []
|
||||
|
||||
for entry in value[1 : -1].split(","):
|
||||
try:
|
||||
pval.append(float(entry))
|
||||
|
||||
except:
|
||||
pval.append(entry.strip().replace("'", ""))
|
||||
|
||||
return pval
|
||||
|
||||
class Structure(Model):
|
||||
structure_id = AutoField()
|
||||
|
||||
type = TextField()
|
||||
direction = ListField()
|
||||
theta = FloatField()
|
||||
|
||||
r0 = FloatField(null = True)
|
||||
L = FloatField(null = True)
|
||||
radius = FloatField(null = True)
|
||||
|
||||
filletsEnabled = BooleanField(null = True)
|
||||
fillets = FloatField(null = True)
|
||||
#path = TextField()
|
||||
|
||||
class Meta:
|
||||
database = db
|
||||
db_table = "structures"
|
||||
|
||||
|
||||
class Mesh(Model):
|
||||
mesh_id = AutoField()
|
||||
structure_id = ForeignKeyField(Structure, backref = "meshes")
|
||||
|
||||
maxSize = FloatField(null = True)
|
||||
minSize = FloatField(null = True)
|
||||
|
||||
fineness = IntegerField(null = True)
|
||||
growthRate = FloatField(null = True)
|
||||
nbSegPerEdge = FloatField(null = True)
|
||||
nbSegPerRadius = FloatField(null = True)
|
||||
|
||||
chordalErrorEnabled = BooleanField(null = True)
|
||||
chordalError = FloatField(null = True)
|
||||
|
||||
secondOrder = BooleanField(null = True)
|
||||
optimize = BooleanField(null = True)
|
||||
quadAllowed = BooleanField(null = True)
|
||||
useSurfaceCurvature = BooleanField(null = True)
|
||||
fuseEdges = BooleanField(null = True)
|
||||
checkChartBoundary = BooleanField(null = True)
|
||||
|
||||
viscousLayers = BooleanField(null = True)
|
||||
thickness = FloatField(null = True)
|
||||
numberOfLayers = IntegerField(null = True)
|
||||
stretchFactor = FloatField(null = True)
|
||||
isFacesToIgnore = BooleanField(null = True)
|
||||
facesToIgnore = ListField(null = True)
|
||||
#faces = []
|
||||
extrusionMethod = TextField(null = True)
|
||||
|
||||
class Meta:
|
||||
database = db
|
||||
db_table = "meshes"
|
||||
depends_on = Structure
|
19
playground/test_smesh.py
Normal file
19
playground/test_smesh.py
Normal file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from salome.smesh import smeshBuilder
|
||||
|
||||
smesh = smeshBuilder.New()
|
||||
|
||||
ALGOS = [
|
||||
smeshBuilder.NETGEN_1D2D3D,
|
||||
smeshBuilder.NETGEN_3D, smeshBuilder.NETGEN_1D2D,
|
||||
smeshBuilder.NETGEN_2D,
|
||||
smeshBuilder.MEFISTO, # only 2d
|
||||
smeshBuilder.REGULAR, smeshBuilder.COMPOSITE
|
||||
]
|
||||
|
||||
mesh = smesh.Mesh(SHAPE)
|
||||
|
||||
algo = mesh.Tetrahedron(algo = ALGO)
|
||||
|
Loading…
Reference in New Issue
Block a user