Solver
The solver module is created in accordance with the principles of creating a Computer-Aided Engineering Analysis. There are several steps to take to commence the analysis and observe the results.
How to build an analysis
Steps to take
First Step
At first, the geometry should be defined with some major parameters. The first class of Solver, Analysis is defined to complete this task.
- class TwinAPI.SimulationTools.Solver.Analysis(**Init)
Analysis is the master class of Solver Module. This class handles every detail to construct a finite element analysis. Usually the required format of use is: NameOfAnalysis=Solver.Analysis()
- SetSolver(SolverName)
Most important part of an analysis is to choose which solver will accomplish the required analysis. Other methods of this module are developed around which solver will be used. Ergo it is highly recommended to use this method immediately.
- SetCPU(N_CPU)
This method is not required. If the constructed case needs more computational power this mathod can be used. However it is only effective for premium users.
- AddPart(Part, Material, **PartFeature)
For FEA cases this method is crucial. The mesh created using Mesher module and the material the geometry made out of are added with this method. Also, there are several optional arguments which can be entered here. One of the most important methods of FEA is to used reduced integration. If this method could not be used in TwinAPI it would not be whole. You can call Integration=’Reduced’ to accomplish calling a body made out of reduced element with the same shape functions. Also one might be curious to use a cut of a revolution of the 2D Geometry which is called axisymmetric. You may use Type=’Axisymmetric” to use this method.
- Assemble()
Let’s say you have added all the parts you needed to build an FEA. But you have been coding and you have no idea how the different parts are placed in the virtual space. This method helps you merge all the parts in the same space and show you on TwinAPI. After calling this method make sure to click Preview button on top of the coding space.
- Build(StepList, **BuildArgv)
This part is the last step before having the result you have wanted. The parts are defined, a step is commenced and the set boundary conditions are added to this step. Maybe you have more than one steps and they follow one another. With this method you can call these steps to be a part of an analysis you have been working on. Only thing that needs to be done is to write: NameOfAnalysis.Build([Step1]) or NameOfAnalysis.Build([Step1,Step2,Step3,…])
- Solve(**SolveArgs)
We are at the Processing phase where all the inputs are given and they are turned into a file which will be read by a solver and it will generate the wanted results. It only takes one line to finish an analysis and it is the following: NameOfAnalysis.Solve()
- Result(**Result)
The Result part is the Post-Processing stage of the analysis. If the analysis has been successfully resolved, the results will be shown on the console screen. The command to be written for this;
NameOfAnalysis.Result(Variable="Temperature", ID=15) NameOfAnalysis.Result(Variable="Temperature", Loc=(0,0,0)) NameOfAnalysis.Result(Variable="Temperature", Print=True)
Displacement X, Y, Z and ContactOpen can be written instead of Variable. Also, to see a specific Node ID result or a specified coordinate, it is sufficient to enter ID Number of a node (ID=X) or Location of a point (Loc=[X,Y,Z]) which will give the closest nodes result.
- Probe(**Result)
The Result part is the Post-Processing stage of the analysis. If the analysis has been successfully resolved, the results will be shown on the console screen. The command to be written for this;
NameOfAnalysis.Probe(Variable="Temperature", ID=15) NameOfAnalysis.Probe(Variable="Temperature", Loc=(0,0,0)) NameOfAnalysis.Probe(Variable="Temperature", Print=True)
Displacement X, Y, Z and ContactOpen can be written instead of Variable. Also, to see a specific Node ID result or a specified coordinate, it is sufficient to enter ID Number of a node (ID=X) or Location of a point (Loc=[X,Y,Z]) which will give the closest nodes result.
Second Step
Secondly, the boundary conditions should be defined. For this purpose, the CreateStep algorithm is added to the solver module.
- class TwinAPI.SimulationTools.Solver.CreateStep(NameOfStep)
This class is created for you to enter the boundary conditions for the geometry you have defined. You might want to add a fix or a displacement boundary condition to one side of a bar. Or you want a uniform heat flux on a surface of cylinder so you want to observe the temperature of overall body. You have to start a step before setting boundary conditions. You can add the BC’s mentioned above to this step and other conditions to other steps.
Below you can see how a step is initialized. .. code-block:
NameOfStep=Solver.CreateStep('new')
After this step is done, another step can be added with a different name in the same way. Now You can give the Boundary Conditions into NameOfStep2.
NameOfStep2=Solver.CreateStep('new')
Or you can inherit the BC’s defined on another step: .. code-block:
NameOfStep2=Solver.CreateStep(NameOfStep)
- Advanced(**AdvancedFeature)
Non-Linear Geometry, Increment Size and GapConductance information can be given from advanced solutions. As an example, it is shown below.
NameOfStep.Advanced(NLGEOM = True, INC = 1000) NameOfStep.Advanced(GapConductance = 100) NameOfStep.Advanced(Friction = [0.14, 145000] )
- Time(analysisType=None, timespan=None)
Time function decides whether the analysis is Steady State or Transient. At the same time, start, end time and time increment can be written. For example;
NameOfStep.Time('SteadyState',[0,1,1e-6]) NameOfStep.Time('Transient',[0,1,1e-2])
The first of these classes is Analysis and the second is the CreateStep. These two main classes create pre-processing and post-processing steps.
- “””
Boundary Conditions defined in the TwinAPI system are divided into 3 groups:
Initial Boundary Conditions
NameOfStep.AddBC('Initial Temperature',[GeometryPART],[373],'K')2) Dirichlet Boundary Conditions The boundary conditions for Dirichlet BC that must be defined in the system and are still being added are as follows.
-Temperature -Fix -Rigid Body
NameOfStep.AddBC('Fix,[GeometryPART.Left],[("Z",0)],"") NameOfStep.AddBC('Temperature',[GeometryPART],[373],'K') NameOfStep.AddBC("Rigid Body", [Box1.All], ["GeometryPART"]Another example will be given for one of our applications is 1DThermalFlow.These boundary conditions belong to 1DThermalFlow.
newStep.AddBC("Temperature", [Part.Inlet],[Value],"") newStep.AddBC("Temperature", [Part.Outer],[Value],"") newStep.AddBC("Temperature", [Part.Inner],[Value],"")3) Neumann Boundary Conditions The boundary conditions for Neumann BC that must be defined in the system and are still being added are as follows. You can find examples below how to use a few of them.
-Heat flux -Pressure -Radiation -Heat Generation -Gravity -Convection
NameOfStep.AddBC("Heat Flux", [GeometryPART], [0],"") NameOfStep.AddBC("Pressure",[GeometryPART .top],[("X",-1e6)],"N/m2") NameOfStep.AddBC('Radiation',[GeometryPART .top,GeometryPART .bottom] [(True,303,0.8)],'')Another example will be given for one of our applications is 1DThermalFlow.These boundary conditions belong to 1DThermalFlow.
newStep.AddBC("Heat Flux", [Part.Outer],[Value],"") newStep.AddBC("Heat Flux", [Part.Inner],[Value],"")“””
Calculix
A LOT
1 """How to select Calculix as solver"""
2
3 BarTemp= Solver.Analysis()
4 BarTemp.SetSolver("Calculix")
5
6 box1=Mesher.UnitCube(10)
7 box1=Mesher.Tetralizer(box1)
8 material="AL"
9 BarTemp.AddPart(box1,material)
10
11 BarTemp.Assemble()
12 Step1=Solver.CreateStep("new")
13 Step1.Time("SteadyState",[0,1,0.1])
14 Step1.AddBC("Heat Flux",[box1.top],[3e5],"W/m2")
15 Step1.AddBC("Temperature",[box1.left,box1.right],[200],"K")
16
17 BarTemp.Build([Step1])
18 BarTemp.Solve()
19
20 BarTemp.Result(Variable="Temperature", Loc=[0,0,0])
21
22 BarTemp.Result(Print=True)
Corefem
A LOT
1 """How to select Corefem as solver"""
2
3 CubeSolid= Solver.Analysis()
4 CubeSolid.SetSolver("corefem")
5
6
7 box1=Mesher.UnitCube(3)
8 box1=Mesher.Tetralizer(box1)
9 material="AL"
10 CubeSolid.AddPart(box1,material)
11
12
13 CubeSolid.Assemble()
14
15 Step1=Solver.CreateStep("new")
16 Step1.Time("SteadyState",[0,1,0.1])
17 Step1.AddBC("Fix",[box1.left],[("X",0)],"")
18 Step1.AddBC("Fix",[box1.left],[("Y",0)],"")
19 Step1.AddBC("Fix",[box1.left],[("Z",0)],"")
20
21 Step1.AddBC("Fix",[box1.right],[("X",0)],"")
22 Step1.AddBC("Fix",[box1.right],[("Y",0)],"")
23 Step1.AddBC("Fix",[box1.right],[("Z",0)],"")
24
25 Step1.AddBC("Pressure",[box1.top],[("Z",-1e10)],"N/m2")
26 CubeSolid.Build([Step1])
27 CubeSolid.Solve()
28 CubeSolid.Result(Variable="Displacement Z", Loc=(0,0,0),Print=True)
1D Thermal Flow
1 """How to select 1D Thermal Flow as solver"""
2
3 MyAnalysis=Solver.Analysis()
4 MyAnalysis.SetSolver("1DThermalFlow")
5
6 """1.Model Setup"""
7 The inputs required for Pipe Flow may vary according to the geometry. But there are a few input variables that are independent of geometry.Fluid can be Water,Oil and Air
8
9
10 meshNumber =20
11 pipeLength =1
12 Thickness =0.002
13 Fluid =Water
14
15 """1.a Geometry Definition"""
16 We have 3 different options for geometry. Circle, Square, and Concentric Circle.
17
18
19 """Circle
20 When Circle is selected as the geometry, it will be sufficient to enter one diameter."""
21
22 Diameter =0.2
23 Part= Mesher.CircleSection(Diameter, pipeLength, meshNumber,Thickness)
24 Name. AddPart(Part,Fluid)
25
26 """Square
27 When Square is selected as the geometry, it will be sufficient to enter Height and Width. """
28
29 Height = 0.2
30 Width=0.2
31 Part= Mesher.SquareSection(Height, Width ,pipeLength, meshNumber,Thickness)
32 Name. AddPart(Part,Fluid)
33
34 """Concentric Circle
35 When Concentric Circle is selected as the geometry, it will be sufficient to enter Diameter1
36 and Diameter2. Diameter1 representative inner diameter."""
37
38 Diameter1 = 0.0002
39 Diameter2=0.2
40 Plastic_L=7
41 h=2000
42 Part= Mesher.ConcetricCircleSection(Diameter1, Diameter2 ,pipeLength
43 meshNumber,Thickness)
44 Name. AddPart(Part,Fluid)
45
46 """1.b Boundary Condition Definition"""
47
48 You can see the how to use Boundary Conditions Examples of 1DThermalFlow from Solver.CreateStep.AddBC.
49 A few boundary conditions that belong to 1DThermalFlow application are shown here.
50
51 """1.b.a Mass Flow Define"""
52
53 newStep.AddBC("Mass Flow Rate", [Part.Inlet],[5],"")
54
55 """1.b.b Variable Temperature"""
56
57 The variable temperature boundary condition is a position dependent function.
58 Since the location depends on the length of the pipe, a bonded polynomial can be created.
59
60 def OuterTemperature(x,Length):
61 T_out=300-10*x/Length
62 return T_out
63
64 newStep.AddBC("Temperature", [Part.Outer],[OuterTemperature],"")
65
66 """2.Post-Processing"""
67
68 You can see the how to use Post-Processing step Examples of 1DThermalFlow from :doc
OpenFOAM
Work in progress. Please refrain from using this solver
1"""How to select OpenFOAM as solver"""
2
3MyAnalysis=Solver.Analysis()
4MyAnalysis.SetSolver("OpenFOAM")
Indices and tables