Skip to content
Snippets Groups Projects
Voxel Designer (Frame).ipynb 2.44 MiB
Newer Older
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
{
 "cells": [
  {
   "cell_type": "markdown",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "metadata": {},
   "source": [
    "# Voxel Designer - Frame"
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "metadata": {},
   "outputs": [],
   "source": [
    "using Plots\n",
    "using LinearAlgebra\n",
    "using NLopt\n",
    "import JSON\n",
    "using SparseArrays\n",
    "using StaticArrays, BenchmarkTools\n",
    "using Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "simulateAndExport (generic function with 1 method)"
      ]
     },
     "execution_count": 27,
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "include(\"./julia/FEM_frame.jl\")\n",
    "include(\"./julia/compliant_mechanisms_frame.jl\")"
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "complianMechanismOptimization (generic function with 6 methods)"
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function complianMechanismOptimization(fileName,scale,dmax,amax,maxeval=500,SIMP=false,threshold=0.25,exageration=100.0,save=true)\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
    "    \n",
    "    setup = getSetup(\"json/$(fileName)\")\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
    "    E,f,g,idb,ien,ndf,nel,nen,nnp,nsd,xn,len,Ke,Te,Ls=getDataFromSetup3D(setup,scale);\n",
    "    problem=E,f,g,idb,ien,ndf,nel,nen,nnp,nsd,xn,len,Ke,Te;\n",
    "    \n",
    "    ##todo change based on hinge\n",
    "    free=map(node ->map(deg -> !deg, node[\"restrained_degrees_of_freedom\"]), setup[\"nodes\"])\n",
    "    free=reshape(collect(Iterators.flatten(free)),size(Ls[1]))\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
    "    nel=length(setup[\"edges\"])\n",
    "    X=ones(nel)\n",
    "    K,F,d,stress,dcomp,g=FEM_frame(problem,X);\n",
    "    display(\"Original Domain:\")\n",
    "    display(plotFrame3D(problem,X,1.0))\n",
    "    display(\"Optimization Details:\")\n",
    "    \n",
    "    X=optimizeCompliantMechanism(problem,Ls,free,dmax,amax,500,SIMP)\n",
    "    display(plotFrame3D(problem,X,1.0))\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
    "    display(\"Final Design:\")\n",
    "    display(plotFrameDeformed3D(problem,copy(X),scale,threshold,exageration))\n",
    "    \n",
    "    if(save)\n",
    "        K,F,d,stress,dcomp,g=FEM_frame(problem,X);\n",
    "        simulateAndExport(setup,X,dcomp,\"json/result_frame_$(fileName)\",threshold)\n",
    "    end\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
    "\n",
    "    return X\n",
    "    \n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"Original Domain:\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
       "<defs>\n",
       "  <clipPath id=\"clip3700\">\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "    <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip3700)\" d=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "M0 1600 L2400 1600 L2400 0 L0 0  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip3701\">\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "    <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<defs>\n",
       "  <clipPath id=\"clip3702\">\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "    <rect x=\"86\" y=\"47\" width=\"2267\" height=\"1475\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip3702)\" d=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "M86.9921 1433.95 L86.9921 308.423 L916.319 47.2441 L2352.76 134.304 L2352.76 1259.83 L1523.43 1521.01 L86.9921 1433.95  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<polyline clip-path=\"url(#clip3700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  86.9921,1433.95 1523.43,1521.01 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  1523.43,1521.01 2352.76,1259.83 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  86.9921,1433.95 86.9921,308.423 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3b00c3; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  387.961,1411.52 387.961,1146.07 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3500c9; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  387.961,1411.52 608.321,1424.88 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3700c7; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  387.961,1411.52 608.321,1159.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3500c9; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  387.961,1411.52 583.557,1349.92 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3700c7; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  387.961,1411.52 583.557,1084.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3a00c4; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  387.961,1411.52 803.917,1363.28 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3400ca; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  387.961,1411.52 803.917,1097.82 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3b00c3; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  583.557,1349.92 583.557,1084.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3700c7; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  583.557,1349.92 803.917,1363.28 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3a00c4; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  583.557,1349.92 803.917,1097.82 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3a00c4; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  583.557,1349.92 779.153,1288.32 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#2b00d3; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  583.557,1349.92 779.153,1022.87 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3a00c4; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  583.557,1349.92 999.513,1301.68 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3600c8; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  583.557,1349.92 999.513,1036.22 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#eb0013; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  779.153,1288.32 779.153,1022.87 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3c00c2; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  779.153,1288.32 999.513,1301.68 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#9c0062; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  779.153,1288.32 999.513,1036.22 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#3a00c4; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  779.153,1288.32 974.749,1226.72 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3702)\" style=\"stroke:#950069; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
       "  779.153,1288.32 974.749,961.27 \n",
       "  \"/>\n",
Loading
Loading full blame...