Skip to content
Snippets Groups Projects
Voxel Designer Symmetry (Frame).ipynb 1.45 MiB
Newer Older
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Voxel Designer - Frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "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": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "simulateAndExport (generic function with 1 method)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "include(\"./julia/FEM_frame.jl\")\n",
    "include(\"./julia/compliant_mechanisms_frame.jl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "complianMechanismOptimization (generic function with 6 methods)"
      ]
     },
     "execution_count": 48,
     "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",
    "    \n",
    "    setup = getSetup(\"json/$(fileName)\")\n",
    "    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",
    "\n",
    "    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,maxeval,SIMP)\n",
    "    display(plotFrame3D(problem,X,1.0))\n",
    "    display(\"Final Design:\")\n",
    "    display(\"max:$(maximum(X)), min:$(minimum(X))\")\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",
    "\n",
    "    return X\n",
    "    \n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "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=\"clip3100\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip3100)\" d=\"\n",
       "M0 1600 L2400 1600 L2400 0 L0 0  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip3101\">\n",
       "    <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<defs>\n",
       "  <clipPath id=\"clip3102\">\n",
       "    <rect x=\"86\" y=\"47\" width=\"2267\" height=\"1475\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip3102)\" d=\"\n",
       "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(#clip3100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  86.9921,1433.95 1523.43,1521.01 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1523.43,1521.01 2352.76,1259.83 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  86.9921,1433.95 86.9921,308.423 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3800c6; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1411.52 387.961,1146.07 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3000ce; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1411.52 828.682,1438.23 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3300cb; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1411.52 828.682,1172.78 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3000ce; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1411.52 779.153,1288.32 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3200cc; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1411.52 779.153,1022.87 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3700c7; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1411.52 1219.87,1315.03 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#2e00d0; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1411.52 1219.87,1049.58 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3900c5; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  779.153,1288.32 779.153,1022.87 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3200cc; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  779.153,1288.32 1219.87,1315.03 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3500c9; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  779.153,1288.32 1219.87,1049.58 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3800c6; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  779.153,1288.32 1170.34,1165.13 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#2100dd; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  779.153,1288.32 1170.34,899.671 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3800c6; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  779.153,1288.32 1611.07,1191.84 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#2f00cf; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  779.153,1288.32 1611.07,926.382 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#ec0012; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1170.34,1165.13 1170.34,899.671 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3a00c4; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1170.34,1165.13 1611.07,1191.84 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#9c0062; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1170.34,1165.13 1611.07,926.382 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#4100bd; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1146.07 387.961,880.612 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3102)\" style=\"stroke:#3500c9; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  387.961,1146.07 828.682,1172.78 \n",
Loading
Loading full blame...