Electrostatic Application Problem Type
(→Data Files for an Specific Example with Kratos in GiD) |
(→Files and Results in GiD) |
||
Line 469: | Line 469: | ||
If everything is ok, now you can create your geometry, assign materials and conditions with GiD, launch your Kratos application and see the results. | If everything is ok, now you can create your geometry, assign materials and conditions with GiD, launch your Kratos application and see the results. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Revision as of 18:13, 8 October 2009
We will use GiD as our favourite pre and post-processor. To customise GiD for our Kratos kElectrostatic application, we will create two kind of files:
- code to customise the GiD windows for input data (files with .mat, .cnd and .prb extensions);
- code to get the user's input data from the windows and translate them to Kratos input data (files with .bas extension);
Note: An excellent introduction to GiD customisation for especific applications can be found in the GiD's Reference Manual
For our kElectrostatic application, it is enough to create two data files: the materials and the conditions windows.
Go to the GiD's problemtype directory (in MS Windows typically in something like "C:\Archivos de programa\GiD\GiD 9.1.1b\problemtypes\") and create a new folder with the name of your application, for example, kElectrostatic.gid.
Contents |
Customising GiD input data Windows
Materials GiD window: kElectrostatic.mat
Create a new text file with the name kElectrostatic.mat in your GiD kElectrostatic problemtype directory (kElectrostatic.gid).
Defining the materials' properties in GiD requires just to indicate the variable name and value of the property, for example:
MATERIAL: Air QUESTION: Electrical_Permittivity VALUE: 1.0 END MATERIAL
This will generate in GiD:
If you want to include different material values, you can add them by simply copying the same lines:
MATERIAL: Air QUESTION: Electrical_Permittivity VALUE: 1.0 END MATERIAL MATERIAL: Aluminium QUESTION: Electrical_Permittivity VALUE: 1210.0 END MATERIAL
Conditions GiD window: KElectrostatic.cnd
Create a new text file with the name KElectrostatic.cnd in your GiD KElectrostatic problemtype directory (KElectrostatic.gid).
We will define the following conditions:
- the Dirichlet boundary condition to be applied on points or lines;
- the Neumman and infinit condition to be applied on lines;
- the source conditions (to be applied on points or surfaces).
We will split all these conditions by using the "BOOK" tab of GiD:
BOOK: Electric_Conditions CONDITION: Point_Voltage CONDTYPE: over points CONDMESHTYPE: over nodes QUESTION: Voltage VALUE: 0.0 END CONDITION CONDITION: Line_Voltage CONDTYPE: over lines CONDMESHTYPE: over nodes QUESTION: Voltage VALUE: 0.0 END CONDITION CONDITION: Surface_Voltage CONDTYPE: over surfaces CONDMESHTYPE: over nodes QUESTION: Voltage VALUE: 0.0 END CONDITION
This will generate in GiD the window:
The Neumann and infinit condition:
BOOK: Electric_Contour_Conditions CONDITION: Contour_Electric_Displacement CONDTYPE: over lines CONDMESHTYPE: over face elements QUESTION: Dn VALUE: 0.0 END CONDITION CONDITION: Infinit_Condition CONDTYPE: over lines CONDMESHTYPE: over face elements QUESTION: Exponent VALUE: 1.0 END CONDITION
And for the sources conditions:
BOOK: Electric_Sources CONDITION: Point_Electrical_Charge CONDTYPE: over points CONDMESHTYPE: over nodes QUESTION: Q VALUE: 0.0 END CONDITION CONDITION: Surface_Electrical_Charge CONDTYPE: over surfaces CONDMESHTYPE: over elems QUESTION: Qs VALUE: 0.0 END CONDITION
with the result of:
Transferring GiD input data to Kratos input data files
All the data in GiD (geometrical data, mesh information, material and conditions assigned to our model) will be transferred to Kratos by using .bas files. Basically, you have to translate the GiD labels to the Kratos variable name's.
We will use three .bas files, one for the data and two for the batch process (the python files):
- kElectrostatic.bas (the template to create the main python file)
- 001_kElectrostatic.py.bas (the template to create a complementary python file)
- 002_kElectrostatic.dat.bas (the template for the data file)
Properties data file: 002_kElectrostatic.dat.bas
Note: Check New Kratos Input Data for a more generic description of the Kratos data format.
Create a new text file with the name 002_kElectrostatic.dat.bas in your GiD kPoisson problemtype directory (kElectrostatic.gid).
For the materials properties, you have to translate the GiD material label (Electrical_Permittivity) to our Kratos variable (ELECTRICAL_PERMITTIVITY), as follows:
*loop materials Begin Properties *MatNum *format "%i%f%f%f" ELECTRICAL_PERMITTIVITY [3] (*MatProp(Electrical_Permittivity), *MatProp(Electrical_Permittivity), 0.0) End Properties *end materials
This part of code will generate in the data file the description of the different materials used in our problem, like this one:
Begin Properties 1 ELECTRICAL_PERMITTIVITY [3] ( 1210.0 , 1210.0, 0.0) End Properties Begin Properties 2 ELECTRICAL_PERMITTIVITY [3] ( 1.0 , 1.0, 0.0) End Properties
To write the information of the nodes, you should write:
Begin Nodes *RealFormat "%10.5f" *loop nodes *nodesnum *NodesCoord(1) *NodesCoord(2) *NodesCoord(3) *end nodes End Nodes
An example of the data generated should be:
Begin Nodes 1 -7.00000 -7.00000 0.00000 2 -7.00000 -6.00000 0.00000 ... 122 4.50000 -6.06218 0.00000 123 -3.46410 4.00000 0.00000 124 4.00000 -3.46410 0.00000 125 0.86603 1.50000 0.00000 End Nodes
In general terms, you will not modify this part of code in your applications, because it is just the list of nodes' coordinates of your problem.
Now you have to indicate the kind of Kratos element you are going to use for your problem, in order to create a list with the elements numbers, connectivities and assigned material. In this case is Electrostatic2D.
Begin Elements Electrostatic2D *loop elems *ElemsNum *ElemsMat *ElemsConec *end elems End Elements
This template file will generate something like:
Begin Elements Electrostatic2D 1 2 196 188 169 2 2 169 188 165 3 2 106 120 95 ... 197 1 137 120 142 198 1 220 219 210 199 1 170 193 191 End Elements
And now we have to prepare the file to write all the conditions. We have to take care about how to transfer the GiD condition name to the Kratos condition name and if it is a condition to be applied on nodes or over elements.
Begin ElementalData ELECTROSTATIC_SURFACE_CHARGE *Set cond Surface_Electrical_Charge *elems *loop elems *OnlyInCond *ElemsNum *cond(Qs) *end elems End ElementalData
Begin NodalData ELECTROSTATIC_POTENTIAL *Set cond Surface_Voltage *nodes *Add cond Line_Voltage *nodes *Add cond Point_Voltage *nodes *loop nodes *OnlyInCond *format "%i%i%f" *NodesNum 1 *cond(Voltage) *end nodes End NodalData
Begin NodalData ELECTROSTATIC_POINT_CHARGE *Set cond Point_Electrical_Charge *nodes *format "%i%i%f" *loop nodes *OnlyInCond *NodesNum 0 *cond(Q) *end nodes End NodalData
Begin Conditions PointCharge2D *Set cond Point_Electrical_Charge *nodes *format "%i%i%f" *loop nodes *OnlyInCond 1 1 *NodesNum *end nodes End Conditions
Begin ElementalData ELECTRIC_DISPLACEMENT_FIELD *Set cond Contour_Electric_Displacement *elems *loop elems *OnlyInCond *ElemsNum [3] (*cond(Dn) ,*cond(Dn) ,*cond(Dn)) //vector *end elems End ElementalData
Begin ElementalData INFINIT_COEFFICIENT *Set cond Infinit_Condition *elems *loop elems *OnlyInCond *ElemsNum *cond(Exponent) *end elems End ElementalData
Begin Conditions Efield2D *Set cond Contour_Electric_Displacement *elems *Add cond Infinit_Condition *elems *loop elems *OnlyInCond *ElemsNum *ElemsMat *LocalNodes *end elems End Conditions
this part of file will produce a data file like the following:
Begin ElementalData ELECTROSTATIC_SURFACE_CHARGE End ElementalData Begin NodalData ELECTROSTATIC_POTENTIAL 1 1 0.0 3 1 0.0 ... 4274 1 0.0 4390 1 0.0 End NodalData Begin NodalData ELECTROSTATIC_POINT_CHARGE 2199 0 3 End NodalData Begin Conditions PointCharge2D 1 1 2199 End Conditions Begin ElementalData ELECTRIC_DISPLACEMENT_FIELD 6 [3] (0.0 ,0.0 ,0.0) //vector 7 [3] (0.0 ,0.0 ,0.0) //vector 13 [3] (0.0 ,0.0 ,0.0) //vector ... 5489 [3] (0.0 ,0.0 ,0.0) //vector 5493 [3] (0.0 ,0.0 ,0.0) //vector End ElementalData Begin ElementalData INFINIT_COEFFICIENT End ElementalData Begin Conditions Efield2D 6 1 3 1 7 1 1 2 13 1 2 3 ... 5489 1 1 2 5493 1 1 2 End Conditions
Batch files for your GiD kElectrostatic Problemtype
We have almost customised our GiD problemtype. We only need to create three additional files:
- the template file kElectrostatic.bas and 001_kElectrostatic.py.bas to generate the python command lines for running our problem in Kratos;
- the MS Windows (or Linux) batch file kElectrostatic.win.bat, basically to clean our working directory, to rename our files and to do some stuff previously to run python with our problem;
Python application files: kElectrostatic.bas and 001_kElectrostatic.py.bas
Create two new text files with the names kElectrostatic.bas and 001_kElectrostatic.py.bas in your GiD kElectrostatic problemtype directory (kElectrostatic.gid).
These template files will create each python command line file customised to our specific GiD example and our Kratos application (with the kElectrostatic element and the selected solver).
The content for the 001_kElectrostatic.py.bas is:
################################################################## ################################################################## #setting the domain size for the problem to be solved domain_size = 2 SolverType = "static_poisson_solver" # Declare Python Variables problem_name="*tcl(file tail [GiD_Info project modelname])" problem_path="." kratos_path="../../../../"
and for an specific problem, will generate something like:
################################################################## ################################################################## #setting the domain size for the problem to be solved domain_size = 2 SolverType = "static_poisson_solver" # Declare Python Variables problem_name="electrostatic_test_c8" problem_path="." kratos_path="../../../../"
The content for the kElectrostatic.bas is:
import kElectrostatic ################################################################## ################################################################## #setting the domain size for the problem to be solved domain_size = kElectrostatic.domain_size ################################################################## ################################################################## ## ATTENTION: here the order is important #including kratos path kratos_libs_path = kElectrostatic.kratos_path + '/libs' ##kratos_root/libs kratos_applications_path = kElectrostatic.kratos_path + '/applications' ##kratos_root/applications import sys sys.path.append(kratos_libs_path) sys.path.append(kratos_applications_path)
#importing Kratos main library from Kratos import ** print "Kratos library imported" kernel = Kernel() #defining kernel print "kernel created" #importing applications import applications_interface applications_interface.Import_ElectrostaticApplication = True applications_interface.ImportApplications(kernel, kratos_applications_path) ## from now on the order is not anymore crucial ################################################################## ################################################################## from KratosR1ElectrostaticApplication import **
#defining a model part for the electrostatic electrostatic_model_part = ModelPart("ASABERQUEElectrostaticPart"); SolverType = kElectrostatic.SolverType #adding of Variables to Model Part import static_poisson_solver static_poisson_solver.AddVariables(electrostatic_model_part) #introducing input file name input_file_name = kElectrostatic.problem_name #reading the electrostatic part gid_mode = GiDPostMode.GiD_PostBinary multifile = MultiFileFlag.MultipleFiles deformed_mesh_flag = WriteDeformedMeshFlag.WriteUndeformed write_conditions = WriteConditionsFlag.WriteElementsOnly gid_io = GidIO(input_file_name,gid_mode,multifile,deformed_mesh_flag,write_conditions) model_part_io_electrostatic = ModelPartIO(input_file_name) model_part_io_electrostatic.ReadModelPart(electrostatic_model_part) #setting up the buffer size: SHOULD BE DONE AFTER READING!!! electrostatic_model_part.SetBufferSize(3) mesh_name = 0.0 gid_io.InitializeMesh( mesh_name ); gid_io.WriteMesh((electrostatic_model_part).GetMesh()); gid_io.FinalizeMesh() print electrostatic_model_part #importing the solver files static_poisson_solver.AddDofs(electrostatic_model_part) for node in electrostatic_model_part.Nodes: #adding dofs node.AddDof(ELECTROSTATIC_POTENTIAL); print "variables for the electromagnetic solver added correctly" #creating a electrostatic solver object electrostatic_solver = static_poisson_solver.StaticPoissonSolver(electrostatic_model_part,domain_size) electrostatic_solver.time_order = 1 electrostatic_solver.linear_solver = SkylineLUFactorizationSolver(); electrostatic_solver.echo_level = 0 electrostatic_solver.Initialize() print "static poisson solver created" gid_io.InitializeResults(mesh_name,(electrostatic_model_part).GetMesh()) print "GiD IO initialized" electrostatic_solver.Solve() print "solver solved" gid_io.WriteNodalResults(ELECTROSTATIC_POTENTIAL,electrostatic_model_part.Nodes,0,0) gid_io.PrintOnGaussPoints(ELECTRIC_FIELD, electrostatic_model_part, 0) gid_io.PrintOnGaussPoints(ELECTRIC_DISPLACEMENT_FIELD, electrostatic_model_part, 0) gid_io.PrintOnGaussPoints(ELECTRICAL_PERMITTIVITY, electrostatic_model_part, 0) gid_io.FinalizeResults()
MS Window Batch file: kElectrostatic.win.bat
Create a new text file with the name kElectrostatic.win.bat in your GiD kPoisson problemtype directory (kElectrostatic.gid).
No special comments are needed for this file. Just take cure about where your python bin is located. For Linux or Unix systems is almost the same.
@ECHO OFF rem OutputFile: %1.log del %2\%1.info del %2\%1.flavia.res del %2\%1.flavia.dat del %2\%1.err del %2\%1.py del %2\%1.py del %2\kElectrostatic.py del %2\%1.mdpa ren %2\%1.dat %2\%1.py ren %2\%1-1.dat %2\kElectrostatic.py ren %2\%1-2.dat %2\%1.mdpa D:\Python26\python %2\%1.py >%2\%1.log del %2\%1.post.res ren %2\%1_0.post.bin %2\%1.post.res
Files and Results in GiD
If everything is ok, now you can create your geometry, assign materials and conditions with GiD, launch your Kratos application and see the results.