Преглед на файлове

ansys-server is working

Willi Zschiebsch преди 5 години
родител
ревизия
9d7cce9775
променени са 6 файла, в които са добавени 87 реда и са изтрити 58 реда
  1. 3 1
      lib/CMakeLists.txt
  2. 0 0
      lib/include/ProcessorEvolution.h
  3. 0 0
      lib/src/ProcessorEvolution.cpp
  4. 27 48
      lib/test/server/gfk-plate.py
  5. 38 9
      lib/test/server/server-ansys.py
  6. 19 0
      lib/test/test_ModuleHTTP.cpp

+ 3 - 1
lib/CMakeLists.txt

@@ -22,7 +22,8 @@ add_library(${PROJECT_NAME} STATIC
         include/ModuleSwitch.h
         include/Output.h
         include/ProcessorBase.h
-        include/ProcessorManual.h
+        include/ProcessorEvolution.h
+	include/ProcessorManual.h
 
         src/Input.cpp
         src/ModuleBase.cpp
@@ -35,6 +36,7 @@ add_library(${PROJECT_NAME} STATIC
         src/ModuleSwitch.cpp
         src/Output.cpp
         src/ProcessorBase.cpp
+	src/ProcessorEvolution.cpp
         src/ProcessorManual.cpp
         )
 

+ 0 - 0
lib/include/ProcessorEvolution.h


+ 0 - 0
lib/src/ProcessorEvolution.cpp


+ 27 - 48
lib/test/server/gfk-plate.py

@@ -5,48 +5,18 @@ import numpy as np
 import os
 
 
-def plot_rotor(ansys):
-    ansys.run("/Post1")
-    ansys.run("ALLS")
-    ansys.run("/erase")
-    ansys.run("/win,1,ltop $/win,2,rtop")
-    ansys.run("/win,3,lbot $/win,4,rbot")
-    ansys.run("/win,1,off")
-    ansys.run("/win,2,off")
-    ansys.run("/win,3,off")
-    ansys.run("/win,4,off")
-    ansys.run("/win,1,on")
-    ansys.plnsol("S", "X")  # Stress in Radialrichtung
-    ansys.run("/noerase")
-    ansys.run("/win,1,off")
-    ansys.run("/win,2,on")
-    ansys.run("/view,2,0,0,-1")
-    ansys.plnsol("S", "X")  # Stress in Radialrichtung, Sicht von hinten
-    ansys.run("/noerase")
-    ansys.run("/win,2,off")
-    ansys.run("/win,3,on")
-    ansys.plnsol("S", "Y")  # Stress in Tangentialrichtung
-    ansys.run("/noerase")
-    ansys.run("/win,3,off")
-    ansys.run("/win,4,on")
-    ansys.plnsol("U", "SUM")
-    ansys.run("/noerase")
-    ansys.run("/win,4,off")
-    ansys.run("/EOF")
-
-
 def sim_rotor(materials, angles, outer_diameter=250, inner_diameter=50, thickness=5, omega=0.1):
     layers = len(angles)
     layer_thickness = thickness / layers
 
     path = os.getcwd()+"\\ws"
-    mapdl = pyansys.launch_mapdl(run_location=path, interactive_plotting=True)
+    mapdl = pyansys.launch_mapdl(run_location=path, interactive_plotting=True, loglevel='ERROR')
     # clear existing geometry
     mapdl.finish()
     mapdl.clear()
 
     th = 200  # [°C]        Herstellungstemperatur
-    tn = 20  # [°C]        Nutzungstemperatur
+    tn = 20  # [°C]         Nutzungstemperatur
 
     mapdl.prep7()
     # define Material
@@ -73,19 +43,19 @@ def sim_rotor(materials, angles, outer_diameter=250, inner_diameter=50, thicknes
         mapdl.mpdata("ALPZ", i + 1, "", materials[i]["alp33"])
 
         # Waermeleitfaehigk
-    #    mapdl.mpdata("KXX", i + 1, "", materials[i]["k11"])
-    #    mapdl.mpdata("KYY", i + 1, "", materials[i]["k22"])
-    #    mapdl.mpdata("KZZ", i + 1, "", materials[i]["k33"])
+        mapdl.mpdata("KXX", i + 1, "", materials[i]["k11"])
+        mapdl.mpdata("KYY", i + 1, "", materials[i]["k22"])
+        mapdl.mpdata("KZZ", i + 1, "", materials[i]["k33"])
 
         # Quellkoeffizient
-    #    mapdl.mpdata("BETX", i + 1, "", materials[i]["bet11"])
-    #    mapdl.mpdata("BETY", i + 1, "", materials[i]["bet22"])
-    #    mapdl.mpdata("BETZ", i + 1, "", materials[i]["bet33"])
+        mapdl.mpdata("BETX", i + 1, "", materials[i]["bet11"])
+        mapdl.mpdata("BETY", i + 1, "", materials[i]["bet22"])
+        mapdl.mpdata("BETZ", i + 1, "", materials[i]["bet33"])
 
         # Diffusionskoeffizient
-    #    mapdl.mpdata("DXX", i + 1, "", materials[i]["d11"])
-    #    mapdl.mpdata("DYY", i + 1, "", materials[i]["d22"])
-    #    mapdl.mpdata("DZZ", i + 1, "", materials[i]["d33"])
+        mapdl.mpdata("DXX", i + 1, "", materials[i]["d11"])
+        mapdl.mpdata("DYY", i + 1, "", materials[i]["d22"])
+        mapdl.mpdata("DZZ", i + 1, "", materials[i]["d33"])
 
     # define Element
     mapdl.et(1, "SHELL181")
@@ -122,11 +92,9 @@ def sim_rotor(materials, angles, outer_diameter=250, inner_diameter=50, thicknes
     mapdl.lsel("S", "", "", 2, 4, 2)
     mapdl.lesize("ALL", "", "", 20)
     mapdl.lsel("ALL")
-    # mapdl.aplot()
     mapdl.mshape(0, "2D")  # quadratic 2D Shapes
     mapdl.mshkey(1)  # 0-free meshing
     mapdl.amesh("ALL")
-    # mapdl.eplot()
 
     mapdl.run("/SOLU")
     mapdl.omega("", "", omega)  # [rad/s]	Winkelgeschwindigkeit(+: gegen Uhrzeigersinn))
@@ -155,20 +123,30 @@ def sim_rotor(materials, angles, outer_diameter=250, inner_diameter=50, thicknes
 
     result = pyansys.read_binary(resultfile)
     # result = mapdl.result
-    result.plot_principal_nodal_stress(0, 'EQV')
+    #result.plot_nodal_solution(0, 'x')
 
 # plot_nodal_solution doesnt work
-    nodenum, stress = result.principal_nodal_stress(0)
+    nodenump, stress = result.principal_nodal_stress(0)
+
+    # von first principle stress is the first column
+    # must be nanmax as the shell element stress is not recorded
+    s1max = np.nanmax(stress[:, -5])
 
+    # von second principle stress is the first column
+    # must be nanmax as the shell element stress is not recorded
+    s2max = np.nanmax(stress[:, -4])
+
+    nodenum, stress = result.nodal_stress(0)
     # von Mises stress is the last column
     # must be nanmax as the shell element stress is not recorded
-    maxstress = np.nanmax(stress[:, -1])
+    srmax = np.nanmax(stress[:, -6])
+    stmax = np.nanmax(stress[:, -5])
 
     mapdl.exit()
 
-    return maxstress
-
+    return s1max, s2max, srmax, stmax
 
+"""
 print(sim_rotor(
     [{
         "e11": 42.5,
@@ -194,3 +172,4 @@ print(sim_rotor(
         "d22": 3.1E3,
         "d33": 3.1E3
     }], [90, 0, 0, 0, 0, 0]))
+"""

+ 38 - 9
lib/test/server/server-ansys.py

@@ -9,26 +9,55 @@ import json
 import sqlite3 as lite
 import sys
 
+import gfk_plate
+
 import logging
 
 from ini_logger import *
 
-#log_dir = r'/var/log/server'
-#ini_logger(log_dir)
+# log_dir = r'/var/log/server'
+# ini_logger(log_dir)
 
 inputs = [
-    {'type': "Material", [{}]},
-    {'type': "Angles", 'value': [0,90]}
+    {'type': "Materials", 'value':
+        [{
+            "e11": 42.5,
+            "e22": 11,
+            "e33": 11,
+            "pr12": 0.28,
+            "pr13": 0.28,
+            "pr23": 0.28,
+            "dens": 1950E-6,
+            "g12": 4.2,
+            "g13": 4.2,
+            "g23": 2.56,
+            "alp11": 5.7E-6,
+            "alp22": 45E-6,
+            "alp33": 45E-6,
+            "k11": 0.72E3,
+            "k22": 0.5E3,
+            "k33": 0.5E3,
+            "bet11": 0E-3,
+            "bet22": 4E-3,
+            "bet33": 4E-3,
+            "d11": 4.4E3,
+            "d22": 3.1E3,
+            "d33": 3.1E3
+        }]},
+    {'type': "Angles", 'value': [90, 0, 0, 0, 0, 0]}
 ]
 
 outputs = [
-    {'type': "Location", 'value': 0},
-    {'type': "Stress", 'value': 2},
-    {'type': "Temperature", 'value': 4}
+    {'type': "Srmax", 'value': 0},
+    {'type': "Stmax", 'value': 2},
+    {'type': "S1max", 'value': 4},
+    {'type': "S2max", 'value': 4}
 ]
 
+
 def update():
-    do_something = 1
+    outputs[0]['value'], outputs[1]['value'], outputs[2]['value'], outputs[3]['value'] = \
+        gfk_plate.sim_rotor(inputs[0]['value'], inputs[1]['value'])
 
 
 class MainHandler(tornado.web.RequestHandler, ABC):
@@ -58,7 +87,7 @@ class MainHandler(tornado.web.RequestHandler, ABC):
     def post(self, param):
         if param == "update":
             if self.json_args is not None:
-                print("INFO: GET /" + param + "with body: " + self.json_args.dump())
+                #print("INFO: GET /" + param + "with body: " + self.json_args.dump())
                 counter = 0
                 for entity in self.json_args:
                     inputs[counter]['value'] = entity['value']

+ 19 - 0
lib/test/test_ModuleHTTP.cpp

@@ -155,4 +155,23 @@ TEST(ModuleHTTP, update_intern){
     EXPECT_EQ(module.getOutput(outputs_ids[0])->getValue()["value"].get<int>(), 19);
     EXPECT_EQ(module.getOutput(outputs_ids[1])->getValue()["value"].get<int>(), 64);
     EXPECT_EQ(module.getOutput(outputs_ids[2])->getValue()["value"].get<int>(), 1);
+}
+
+TEST(ModuleHTTP, test_ansys_server) {
+    ModuleHTTP module("../../../lib/test/server/server-ansys.py", "localhost", 8888);
+
+    auto inputs_types = module.getInputs();
+    auto inputs_ids = module.getInputIDs();
+    EXPECT_EQ(inputs_types[0], "Materials");
+    EXPECT_EQ(inputs_types[1], "Angles");
+  
+    module.update();
+    
+    auto outputs_types = module.getOutputs();
+    auto outputs_ids = module.getOutputIDs();
+    for (int i = 0; i < outputs_ids.size(); ++i) {
+        std::cout << module.getOutput(outputs_ids[i])->getValue()["value"].dump() << std::endl;;
+    }
+    Client cli("localhost", 8888);
+    cli.Get("/stop");
 }