{ "cells": [ { "cell_type": "markdown", "id": "faad71d7", "metadata": {}, "source": [ "# Nuclear Fusion Tokamak\n", "![](./nuclearfusion_banner.png)" ] }, { "cell_type": "markdown", "id": "9abd82ad", "metadata": {}, "source": [ "### Connect to BioExplorer backend" ] }, { "cell_type": "code", "execution_count": null, "id": "ecf1c452", "metadata": {}, "outputs": [], "source": [ "from bioexplorer import BioExplorer, Vector3\n", "\n", "be = BioExplorer('localhost:5000')\n", "core = be.core_api()\n", "be.reset_scene()\n", "print('BioExplorer version ' + be.version())" ] }, { "cell_type": "markdown", "id": "0ba057d7", "metadata": {}, "source": [ "### Generate random data set:\n", "Vectors composed of a position and a direction. The length of the vector is the value of the voltage" ] }, { "cell_type": "code", "execution_count": null, "id": "ce421549", "metadata": {}, "outputs": [], "source": [ "import math\n", "import random\n", "import numpy as np\n", "import time\n", "\n", "''' Settings '''\n", "nb_particles = 2000\n", "use_randomness = True\n", "\n", "def generate_random_point_in_torus(main_radius, tube_radius):\n", " theta = 2 * math.pi * random.random()\n", " phi = 2 * math.pi * random.random()\n", " x = (main_radius + tube_radius * math.cos(phi)) * math.cos(theta)\n", " y = tube_radius * math.sin(phi)\n", " z = (main_radius + tube_radius * math.cos(phi)) * math.sin(theta)\n", " return x, y, z\n", "\n", "origins = list()\n", "targets = list()\n", "origins_radii = list()\n", "targets_radii = list()\n", "\n", "seed = int(time.time())\n", "random.seed(seed)\n", "for i in range(nb_particles):\n", " x = 0\n", " y = 0\n", " z = 0\n", " x, y, z = generate_random_point_in_torus(10.0, 2.0)\n", " origin = Vector3(x, y ,z)\n", " \n", "\n", " length = 0.2\n", " cp = np.cross([x, y, z], [0, 1, 0])\n", " if use_randomness:\n", " cp[0] += (random.random() - 0.5)\n", " cp[1] += (random.random() - 0.5)\n", " cp[2] += (random.random() - 0.5)\n", " length = random.random() * 0.2\n", "\n", " target = Vector3(\n", " origin.x + cp[0] * length,\n", " origin.y + cp[1] * length,\n", " origin.z + cp[2] * length\n", " )\n", " origins.append(origin)\n", " targets.append(target)\n", " origins_radii.append(0.1)\n", " targets_radii.append(0.0)\n", "\n", "status = be.add_cones(\n", " name='Particles',\n", " origins=origins, origins_radii=origins_radii,\n", " targets=targets, targets_radii=targets_radii,\n", " color=Vector3(1.0, 1.0, 1.0), opacity=1.0)" ] }, { "cell_type": "markdown", "id": "5a21827f", "metadata": {}, "source": [ "## Generate new model containing the field" ] }, { "cell_type": "code", "execution_count": null, "id": "a9f39aa3", "metadata": {}, "outputs": [], "source": [ "be.build_fields(\n", " voxel_size=0.25, density=1.0,\n", " data_type=be.FIELD_DATA_TYPE_VECTOR\n", ")\n", "\n", "status = core.set_renderer(current='advanced')" ] }, { "cell_type": "markdown", "id": "b751ad42", "metadata": {}, "source": [ "### Volume settings" ] }, { "cell_type": "code", "execution_count": null, "id": "9da4c165", "metadata": {}, "outputs": [], "source": [ "status = core.set_field_parameters(\n", " distance=1, cutoff=200, epsilon=0.001,\n", " gradient_shading=False, sampling_rate=0.25)" ] }, { "cell_type": "markdown", "id": "f7c0c1a2", "metadata": {}, "source": [ "### Attach transfer function to newly created model" ] }, { "cell_type": "code", "execution_count": null, "id": "2034dc01", "metadata": { "scrolled": false }, "outputs": [], "source": [ "from bioexplorer import TransferFunction\n", "model_ids = be.get_model_ids()['ids']\n", "model_id = model_ids[len(model_ids)-1]\n", "tf = TransferFunction(\n", " bioexplorer=be, model_id=model_id,\n", " filename='fusion.1dt',\n", " value_range=[0.1, 5.0])" ] }, { "cell_type": "markdown", "id": "aa04cb63", "metadata": {}, "source": [ "## Fusion reactor Tokamak 3D model\n", "Can be downloaded from: https://blendermarket.com/products/fusion-reactor-tokamak" ] }, { "cell_type": "code", "execution_count": null, "id": "b69e7773", "metadata": {}, "outputs": [], "source": [ "import os\n", "transformation={\n", " 'rotation': [0.0, -0.25038000405444144, 0.0, 0.9681476403781076],\n", " 'rotation_center': [0.0, 0.0, 0.0],\n", " 'scale': [12.0, 12.0, 12.0],\n", " 'translation': [0.0, -1.0, 0.0]\n", "}\n", "model_filename = 'Fusion_reactor_by_www_up3d_de_without_plasma.obj'\n", "core.add_model(name='Fusion Reactor Tokamak', path=model_filename)\n", "model_ids = be.get_model_ids()['ids']\n", "status = core.update_model(id=model_ids[len(model_ids)-1], transformation=transformation)" ] }, { "cell_type": "markdown", "id": "805cbbeb", "metadata": {}, "source": [ "## Rendering settings" ] }, { "cell_type": "code", "execution_count": null, "id": "8b48082a", "metadata": {}, "outputs": [], "source": [ "status = be.reset_camera()" ] }, { "cell_type": "code", "execution_count": null, "id": "09f3a8ca", "metadata": {}, "outputs": [], "source": [ "status = core.set_renderer(\n", " background_color=[0.25, 0.25, 0.25],\n", " current='advanced', \n", " samples_per_pixel=1,\n", " subsampling=4,\n", " max_accum_frames=1024)\n", "params = core.AdvancedRendererParams()\n", "params.gi_samples = 0\n", "params.gi_strength = 0.0\n", "params.gi_ray_length = 150.0\n", "params.shadow_intensity = 0.5\n", "params.soft_shadow_strength = 0.1\n", "params.max_ray_depth = 3\n", "params.show_background = True\n", "params.fog_start = 100.0\n", "params.fog_thickness = 20.0\n", "status = core.set_renderer_params(params)\n", "status = core.set_renderer()" ] }, { "cell_type": "markdown", "id": "8713d0c5", "metadata": {}, "source": [ "## Widgets to modify materials" ] }, { "cell_type": "code", "execution_count": null, "id": "afcf63a4", "metadata": {}, "outputs": [], "source": [ "from bioexplorer import Widgets\n", "w = Widgets(be)\n", "w.display_model_material()" ] } ], "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.6" } }, "nbformat": 4, "nbformat_minor": 5 }