463 lines
9.9 KiB
Plaintext
463 lines
9.9 KiB
Plaintext
{
|
|
"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.10.0"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|