{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Connecting to server...\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import sys\n",
    "from RFEM.initModel import Model, Calculate_all\n",
    "from RFEM.enums import (\n",
    "    NodalSupportType, SurfaceGeometry, SurfaceLoadDirection,\n",
    "    SurfaceLoadDistribution, ActionCategoryType, LineSupportType,\n",
    "    MemberLoadDirection, MemberLoadDistribution, MemberType,\n",
    "    CaseObjectType, NodalLoadDirection\n",
    ")\n",
    "from RFEM.BasicObjects.node import Node\n",
    "from RFEM.BasicObjects.line import Line\n",
    "from RFEM.BasicObjects.material import Material\n",
    "from RFEM.BasicObjects.thickness import Thickness\n",
    "from RFEM.BasicObjects.surface import Surface\n",
    "from RFEM.BasicObjects.member import Member\n",
    "from RFEM.BasicObjects.section import Section\n",
    "from RFEM.TypesForLines.lineSupport import LineSupport\n",
    "from RFEM.TypesForNodes.nodalSupport import NodalSupport\n",
    "from RFEM.LoadCasesAndCombinations.loadCase import LoadCase\n",
    "from RFEM.LoadCasesAndCombinations.staticAnalysisSettings import StaticAnalysisSettings\n",
    "from RFEM.Loads.surfaceLoad import SurfaceLoad\n",
    "from RFEM.Loads.memberLoad import MemberLoad\n",
    "from RFEM.Loads.lineLoad import LineLoad\n",
    "from RFEM.Loads.nodalLoad import NodalLoad\n",
    "from RFEM.ImportExport.exports import ExportTo\n",
    "from RFEM.Results.resultTables import ResultTables, GetMaxValue, GetMinValue\n",
    "from RFEM.dataTypes import inf\n",
    "\n",
    "\n",
    "# Neues leeres Modell mit Reset\n",
    "Model(True, 'MeinTestModell')\n",
    "Model.clientModel.service.delete_all()  # 🔁 Alles löschen!\n",
    "Model.clientModel.service.begin_modification()\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Allgemeiner PROMPT\n",
    "\n",
    "#### Ich möchte einen zylindrischen Stahldruckbehälter mit einem Durchmesser von 2 m, einer Höhe von 5 m und einem oberen Deckel unter Schneelast auf der Oberseite erstellen. Die untere Kreislinie ist gelagert. Die Dicke des Deckels beträgt 10 mm und die des Zylindermantels 4 mm. Die Schneelast beträgt 0.25 kN/m².\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MATERIAL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<RFEM.BasicObjects.material.Material at 0x1d19a3dd550>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ---- Material Sec ----\n",
    "Material(1, \"Beton C20/25\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# GEOMETRY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<RFEM.TypesForLines.lineSupport.LineSupport at 0x1d19a5427b0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ---- Geometry Sec ----\n",
    "# Define nodes automatically\n",
    "Node(1, 0, 0, 0)        # Starting point at the top\n",
    "Node(2, 0, 0, -1.0)     # Point directly below the starting point\n",
    "Node(3, 0, -0.2, -1.0)  # Point 0.2 m back in Y-direction from the bottom point\n",
    "Node(4, 0, -0.2, 0)     # Point 0.2 m back in Y-direction from the top point\n",
    "\n",
    "# Define lines to form the perimeter of the surface\n",
    "Line(1, '1 2')  # Vertical line from top to bottom\n",
    "Line(2, '2 3')  # Horizontal line at the bottom, going back in Y-direction\n",
    "Line(3, '3 4')  # Vertical line from bottom to top, going forward in Y-direction\n",
    "Line(4, '4 1')  # Horizontal line at the top, going forward in Y-direction\n",
    "\n",
    "# Define the surface using the lines\n",
    "Surface(1, '1 2 3 4')  # Surface defined by the closed loop of lines\n",
    "# Add a fixed line support to the bottom edge\n",
    "LineSupport(1, '2', LineSupportType.FIXED)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CROSSSECTION"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ---- Cross Sections Sec ----\n",
    "\n",
    "# Define the thickness of the surface\n",
    "Thickness(1, '20 cm', material_no=1, uniform_thickness_d=0.20)\n",
    "\n",
    "# Define the surface using the boundary lines\n",
    "Surface.Standard(\n",
    "    no=1,\n",
    "    geometry_type=SurfaceGeometry.GEOMETRY_PLANE,\n",
    "    boundary_lines_no='1 2 3 4',\n",
    "    thickness=1\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LOADS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ---- Loads Sec ----\n",
    "\n",
    "# Define a load case with self-weight\n",
    "LoadCase(\n",
    "    no=1,\n",
    "    name='Self-weight',\n",
    "    self_weight=[True, 0.0, 0.0, 1.0]\n",
    ")\n",
    "\n",
    "# Define a variable surface load that increases linearly in the local Z-direction\n",
    "SurfaceLoad.Force(\n",
    "    no=1,\n",
    "    load_case_no=1,\n",
    "    surface_no='1',\n",
    "    load_direction=SurfaceLoadDirection.LOAD_DIRECTION_LOCAL_Z,\n",
    "    load_distribution=SurfaceLoadDistribution.LOAD_DISTRIBUTION_VARYING_IN_Z,\n",
    "    load_parameter=[\n",
    "        [0.0, 0.0],\n",
    "        [-1.0, -50000]\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SOLVER AUFRUFEN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "WebFault",
     "evalue": "b\"Server raised fault: 'Objekt: Material Nr. 1\\nAttribut: Parameter, die f\\xc3\\xbcr mehrere Temperaturen definiert werden k\\xc3\\xb6nnen\\nFehler: Bitte geben Sie einen positiven Wert ein.'\"",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mWebFault\u001b[39m                                  Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[6]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m      1\u001b[39m \u001b[38;5;66;03m# ---- Solver Sec ----\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[43mModel\u001b[49m\u001b[43m.\u001b[49m\u001b[43mclientModel\u001b[49m\u001b[43m.\u001b[49m\u001b[43mservice\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfinish_modification\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m      4\u001b[39m Calculate_all()\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\suds\\client.py:559\u001b[39m, in \u001b[36mMethod.__call__\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m    557\u001b[39m         \u001b[38;5;28;01mreturn\u001b[39;00m (\u001b[32m500\u001b[39m, e)\n\u001b[32m    558\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m559\u001b[39m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mclient\u001b[49m\u001b[43m.\u001b[49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\suds\\client.py:618\u001b[39m, in \u001b[36mSoapClient.invoke\u001b[39m\u001b[34m(self, args, kwargs)\u001b[39m\n\u001b[32m    614\u001b[39m metrics.log.debug(\u001b[33m\"\u001b[39m\u001b[33mmessage for \u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m created: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[33m\"\u001b[39m,\n\u001b[32m    615\u001b[39m                   \u001b[38;5;28mself\u001b[39m.method.name,\n\u001b[32m    616\u001b[39m                   timer)\n\u001b[32m    617\u001b[39m timer.start()\n\u001b[32m--> \u001b[39m\u001b[32m618\u001b[39m result = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43msoapenv\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m    619\u001b[39m timer.stop()\n\u001b[32m    620\u001b[39m metrics.log.debug(\u001b[33m\"\u001b[39m\u001b[33mmethod \u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m invoked: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[33m\"\u001b[39m,\n\u001b[32m    621\u001b[39m                   \u001b[38;5;28mself\u001b[39m.method.name,\n\u001b[32m    622\u001b[39m                   timer)\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\suds\\client.py:658\u001b[39m, in \u001b[36mSoapClient.send\u001b[39m\u001b[34m(self, soapenv)\u001b[39m\n\u001b[32m    656\u001b[39m         result = reply.message\n\u001b[32m    657\u001b[39m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m658\u001b[39m         result = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msucceeded\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbinding\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mreply\u001b[49m\u001b[43m.\u001b[49m\u001b[43mmessage\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m    659\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m TransportError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m    660\u001b[39m     \u001b[38;5;28;01mif\u001b[39;00m e.httpcode \u001b[38;5;129;01min\u001b[39;00m (\u001b[32m202\u001b[39m, \u001b[32m204\u001b[39m):\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\suds\\client.py:696\u001b[39m, in \u001b[36mSoapClient.succeeded\u001b[39m\u001b[34m(self, binding, reply)\u001b[39m\n\u001b[32m    694\u001b[39m plugins = PluginContainer(\u001b[38;5;28mself\u001b[39m.options.plugins)\n\u001b[32m    695\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(reply) > \u001b[32m0\u001b[39m:\n\u001b[32m--> \u001b[39m\u001b[32m696\u001b[39m     reply, result = \u001b[43mbinding\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_reply\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mreply\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m    697\u001b[39m     \u001b[38;5;28mself\u001b[39m.last_received(reply)\n\u001b[32m    698\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\suds\\bindings\\binding.py:152\u001b[39m, in \u001b[36mBinding.get_reply\u001b[39m\u001b[34m(self, method, reply)\u001b[39m\n\u001b[32m    150\u001b[39m soapenv.promotePrefixes()\n\u001b[32m    151\u001b[39m soapbody = soapenv.getChild(\u001b[33m'\u001b[39m\u001b[33mBody\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m--> \u001b[39m\u001b[32m152\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mdetect_fault\u001b[49m\u001b[43m(\u001b[49m\u001b[43msoapbody\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m    153\u001b[39m soapbody = \u001b[38;5;28mself\u001b[39m.multiref.process(soapbody)\n\u001b[32m    154\u001b[39m nodes = \u001b[38;5;28mself\u001b[39m.replycontent(method, soapbody)\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\suds\\bindings\\binding.py:183\u001b[39m, in \u001b[36mBinding.detect_fault\u001b[39m\u001b[34m(self, body)\u001b[39m\n\u001b[32m    181\u001b[39m p = unmarshaller.process(fault)\n\u001b[32m    182\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.options().faults:\n\u001b[32m--> \u001b[39m\u001b[32m183\u001b[39m     \u001b[38;5;28;01mraise\u001b[39;00m WebFault(p, fault)\n\u001b[32m    184\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\n",
      "\u001b[31mWebFault\u001b[39m: b\"Server raised fault: 'Objekt: Material Nr. 1\\nAttribut: Parameter, die f\\xc3\\xbcr mehrere Temperaturen definiert werden k\\xc3\\xb6nnen\\nFehler: Bitte geben Sie einen positiven Wert ein.'\""
     ]
    }
   ],
   "source": [
    "# ---- Solver Sec ----\n",
    "Model.clientModel.service.finish_modification()\n",
    "\n",
    "Calculate_all()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ERGEBNISSE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.153163"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
