{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: module JuliaFEM should explicitly import setindex! from Base\n"
     ]
    }
   ],
   "source": [
    "using JuliaFEM: Material, set_material!, get_element_set, ElasticityProblem,\n",
    "DirichletProblem, LoadCase, DisplacementBC, ForceBC, DirichletProblem,\n",
    "add_boundary_condition!, add_loadcase!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO: Parsing nodes\n",
      "INFO: Parsing elements. Type: JuliaFEM.Tet4\n",
      "INFO: Parsing elements. Type: JuliaFEM.Seg3\n",
      "INFO: Creating elset BC1\n",
      "INFO: Creating elset BC2\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "JuliaFEM.Material{ASCIIString,Float64}(\"steel\",Dict(\"poissons ratio\"=>0.3,\"youngs modulus\"=>210000.0,\"other values\"=>100000.0))"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO: Creating elset BC3\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# Reading nodes, elements and sets from input file\n",
    "model = open(JuliaFEM.parse_abaqus, \"/home/olli/.julia/v0.4/JuliaFEM/geometry/piston/piston_8789_P1.inp\")\n",
    "\n",
    "# Creating material\n",
    "# It is possible to create material data with one function\n",
    "steel = Material(\"steel\",\n",
    "    (\"youngs modulus\" => 210.0e3,\n",
    "     \"poissons ratio\" => 0.3,\n",
    "     \"other values\" => 100e3),\n",
    ")\n",
    "\n",
    "# Or by adding row by row\n",
    "steel2 = Material(\"Steel2\")\n",
    "steel2[\"youngs modulus\"] = 210.0e3\n",
    "steel2[\"poissons ratio\"] = 10.0\n",
    "\n",
    "# Setting material to element set\n",
    "set_material!(model, steel, \"PISTON\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\")"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Fetchig set from model\n",
    "piston = get_element_set(model, \"PISTON\")\n",
    "\n",
    "# Creating problems:\n",
    "# Elasticity \n",
    "elasticity_problem = ElasticityProblem()\n",
    "\n",
    "# Boundary conditions\n",
    "BC1 = DisplacementBC(\"displacement u1\", 0.0, \"BC2\")\n",
    "F1 = ForceBC(\"displacement traction force\", 1000, \"BC1\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2-element Array{Array{Union{JuliaFEM.DirichletBC{S<:AbstractString},JuliaFEM.NeumannBC{S<:AbstractString}},1},1}:\n",
       " Union{JuliaFEM.DirichletBC{S<:AbstractString},JuliaFEM.NeumannBC{S<:AbstractString}}[JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\"),JuliaFEM.DirichletBC{ASCIIString}(\"displacement u1\",0.0,\"BC2\"),JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\"),JuliaFEM.DirichletBC{ASCIIString}(\"displacement u1\",0.0,\"BC2\")]\n",
       " Union{JuliaFEM.DirichletBC{S<:AbstractString},JuliaFEM.NeumannBC{S<:AbstractString}}[JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\"),JuliaFEM.DirichletBC{ASCIIString}(\"displacement u1\",0.0,\"BC2\"),JuliaFEM.NeumannBC{ASCIIString}(\"displacement traction force\",1000,\"BC1\"),JuliaFEM.DirichletBC{ASCIIString}(\"displacement u1\",0.0,\"BC2\")]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# Possible ways to create a loadcase, whihc holds all data for calculation\n",
    "load4 = LoadCase(elasticity_problem)\n",
    "load = LoadCase(elasticity_problem, [BC1])\n",
    "load2 = LoadCase(elasticity_problem, [BC1, F1])\n",
    "load3 = LoadCase(elasticity_problem, BC1)\n",
    "\n",
    "# Couple of ways to add boundary conditions to loadcase\n",
    "add_boundary_condition!(load, BC1)\n",
    "add_boundary_condition!(load2, F1)\n",
    "add_boundary_condition!(load3, BC1)\n",
    "add_boundary_condition!(load4, [F1, BC1])\n",
    "add_boundary_condition!(load, [F1, BC1])\n",
    "add_boundary_condition!(load4, [F1, BC1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# Adding load case to model, various ways...\n",
    "add_loadcase!(model, load)\n",
    "add_loadcase!(model, [load, load2, load3])\n",
    "0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Select solver\n",
    "solver = DirectSolver()\n",
    "\n",
    "solve!(model, solver)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.4.1-pre",
   "language": "julia",
   "name": "julia-0.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.4.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
