Skip to content
Snippets Groups Projects
Compmods.ipynb 518 KiB
Newer Older
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Amira Abdel-Rahman\n",
    "# (c) Massachusetts Institute of Technology 2020\n",
    "\n",
    "# tested using julia 1.5.2 and windows Nvidia geforce gtx 1070 Ti"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Include Dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "using LinearAlgebra\n",
    "import JSON\n",
    "using StaticArrays, BenchmarkTools\n",
    "using Base.Threads\n",
    "using CUDA\n",
    "import Base: +, * , -, ^\n",
    "using Plots\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 608,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "axialStrain (generic function with 1 method)"
      ]
     },
     "execution_count": 608,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "include(\"./julia/include/vector.jl\") #utils for vectors and quaternions\n",
    "include(\"./julia/include/material.jl\") #utils for node and edge material\n",
    "include(\"./julia/include/export.jl\") #export simulation data to json\n",
    "include(\"./julia/include/run.jl\") #turn setup to cuda arrays and run simulation\n",
    "include(\"./julia/include/updateEdges.jl\") #edges properties update\n",
    "include(\"./julia/include/externalForces.jl\") #external forces applied to the system\n",
    "include(\"./julia/include/forces.jl\") #force integration\n",
    "include(\"./julia/include/updateNodes.jl\") #nodes properties update"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Create Geometry"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 749,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "axialStrain (generic function with 1 method)"
      ]
     },
     "execution_count": 749,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name= \"tutorial\"\n",
    "# alternativly you can get a saved setup from an external julia file\n",
    "# include(\"./julia/examples/thermalTest.jl\") #template for multimaterial hierarchical voxels with different thermal coefficient of thermal expansion \n",
    "# include(\"./julia/examples/poissonTest.jl\") #template for hierarchical voxels with global poisson ratio\n",
    "# include(\"./julia/examples/latticeTest.jl\") #template for lattice voxel (small scale)\n",
    "# include(\"./julia/examples/latticeTest2.jl\") #template for lattice voxel (big scale with real params)\n",
    "# include(\"./julia/examples/rhinoTest.jl\") #template for importing geometry from rhino\n",
    "# include(\"./julia/examples/rhinoTestChiral.jl\") #template for importing chiral array\n",
    "# include(\"./julia/examples/rover.jl\") #template for importing chiral array\n",
    "# include(\"./julia/examples/wing.jl\") #template for importing chiral array\n",
    "# include(\"./julia/examples/walkingRobot.jl\") #template for importing chiral array\n",
    "include(\"./julia/examples/nonLinearTest.jl\") #template for hierarchical voxels with global poisson ratio\n",
    "\n",
    "\n",
    "\n",
    "## rerun these just for sanity check for dynamic loads\n",
    "include(\"./julia/include/run.jl\") #turn setup to cuda arrays and run simulation\n",
    "include(\"./julia/include/updateEdges.jl\") #edges properties update\n",
    "include(\"./julia/include/forces.jl\") #force integration\n",
    "include(\"./julia/include/updateNodes.jl\") #nodes properties update"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 750,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded rhino3dm.\n",
      "Success!\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Process(`\u001b[4mnode\u001b[24m \u001b[4mapp1.js\u001b[24m \u001b[4mtutorial\u001b[24m`, ProcessExited(0))"
      ]
     },
     "execution_count": 750,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#export prev. settings to json\n",
    "fileName=\"./json/$(name)Init.json\"\n",
    "setup1=Dict()\n",
    "setup1[\"setup\"]=setup\n",
    "stringdata = JSON.json(setup1)\n",
    "open(fileName, \"w\") do f\n",
    "        write(f, stringdata)\n",
    "end\n",
    "#run node.js to draw the gerometry using rhino3dm\n",
    "mycommand = `node app1.js $(name)`\n",
    "run(mycommand)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 759,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "externalForce (generic function with 1 method)"
      ]
     },
     "execution_count": 759,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function externalForce(currentTimeStep,N_position,N_force)\n",
    "    return N_force\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Run Simulation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 767,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dt: 1.4235251564292887e-5, s: 0.001, mass: 8.0e-6, momentInertiaInverse: 1.8749999999999997e11\n",
      "first timestep took 0.0005638 seconds\n",
      "ran 215 nodes and 374 edges for 5000 time steps took 3.921461 seconds\n"
     ]
    }
   ],
   "source": [
    "# set name for simulation\n",
    "# name= \"tutorial\"\n",
    "# name=\"couponHex\"\n",
    "name=\"coupon\"\n",
    "\n",
    "\n",
    "folderPath=\"./json/tutorial/\" # make sure this folder exists\n",
    "setupSim=getSetup(name);\n",
Loading
Loading full blame...