Skip to content
Snippets Groups Projects
Compmods.ipynb 3.6 MiB
Newer Older
{
 "cells": [
  {
   "cell_type": "code",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "execution_count": 4,
   "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",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "execution_count": 1,
   "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",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "execution_count": 682,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "axialStrain (generic function with 1 method)"
      ]
     },
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
     "execution_count": 682,
     "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",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "execution_count": 693,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "axialStrain (generic function with 1 method)"
      ]
     },
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
     "execution_count": 693,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name= \"tutorial\"\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",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "execution_count": 694,
   "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))"
      ]
     },
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
     "execution_count": 694,
     "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",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "execution_count": 695,
   "metadata": {},
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "outputs": [],
   "source": [
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
    "# function externalForce(currentTimeStep,N_position,N_force)\n",
    "#     return N_force\n",
    "# end"
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Run Simulation"
   ]
  },
  {
   "cell_type": "code",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "execution_count": 686,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
      "[0.0, 10000.0, 11000.0, 21000.0, 41000.0, 141000.00000000003, 260999.99999999994, -1.0]\n",
      "dt: 1.0265185886837392e-5, s: 0.001, mass: 8.0e-6, momentInertiaInverse: 1.8749999999999997e11\n",
      "first timestep took 3.0233116 seconds\n",
      "ran 250 nodes and 625 edges for 30000 time steps took 19.600108399 seconds\n"
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
    "# name for simulation\n",
    "# name= \"tutorial\"\n",
    "# name=\"couponHex\"\n",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
    "# name=\"coupon\"\n",
    "# name=\"nonlinear\"\n",
    "\n",
    "\n",
    "folderPath=\"./json/tutorial/\" # make sure this folder exists\n",
    "setupSim=getSetup(name);\n",
    "runMetavoxelGPULive!(setupSim,folderPath)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Plot"
   ]
  },
  {
   "cell_type": "code",
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
   "execution_count": 687,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"tutorial\""
Loading
Loading full blame...