Electrostatic Application Problem Type

From KratosWiki
(Difference between revisions)
Jump to: navigation, search
(Data Files for an Specific Example with Kratos in GiD)
(Files and Results in GiD)
 
(One intermediate revision by one user not shown)
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.
 
 
 
 
 
-----
 
 
 
 
 
=== Data files in GiD ===
 
 
After selecting our GiD problemtype ('''kPoisson'''),
 
 
[[Image:KPoissonGiDproblemtype.jpg]]
 
 
we can create our geometry,
 
 
[[Image:Our example geo.jpg]]
 
 
assign materials and conditions,
 
 
{|
 
| rowspan=2 |
 
[[Image:Our example mat.jpg]]
 
| [[Image:KPoisson.cnd.4.jpg|300px]]
 
|-
 
| [[Image:KPoisson.cnd.5.jpg|300px]]
 
|}
 
 
If we save now this problem with the name '''our_example''', GiD will automatically generate the following files:
 
* our_example.cnd
 
* our_example.geo
 
* our_example.lin
 
* our_example.mat
 
* our_example.png
 
* our_example.rdr
 
* our_example.vv
 
 
Now we can mesh our model, generating the already presented mesh:
 
 
[[Image:KPoisson.elem.jpg|200px]]
 
 
and creating the files:
 
* our_example.msh
 
 
If now we run our Kratos application, by doing:
 
 
[[Image:Our example calculate.jpg]]
 
 
a set of new files are generated:
 
 
* our_example.cond
 
* our_example.elem
 
* our_example.init
 
* our_example.node
 
* our_example.prop
 
* our_example.py
 
* our_example.log
 
* our_example.post.res
 
 
The first six files have been already explained.
 
 
The log file contains the details about how the simulation have been performed, including warnings or errors (if there is something).
 
 
=== Results files in GiD ===
 
 
'''our_example.log'''
 
 
Relevant aspects are indicated with '''bold''' characters:
 
 
"kerneal entered in AddApplication" : kerneal entered in AddApplication
 
Initializing '''KratosR1PoissonApplication'''...
 
"Application Registered" : Application Registered
 
"Variables Registered Registered" : Variables Registered Registered
 
"Elements Registered" : Elements Registered
 
"Conditions Registered" : Conditions Registered
 
'''our_example opened for io'''
 
'''our_example.node opened for io'''
 
'''our_example.prop opened for io'''
 
'''our_example.elem opened for io'''
 
'''our_example.cond opened for io'''
 
'''our_example.init opened for io'''
 
initializing result files
 
reading nodes
 
temp : Node #9 : (20.7379 , 12.7649 , 0)
 
Nodes succesfully read
 
reading Properties
 
Properties succesfully read
 
reading Elements
 
Properties succesfully read
 
reading Conditions
 
Properties succesfully read
 
reading Initial Values
 
  reading initiali values
 
  finished reading initial values
 
Initial Values succesfully read
 
Reading completed succesfully
 
writing a 2D mesh
 
"setting up the dofs" : setting up the dofs
 
Building Time : 0
 
LU factorization solver finished.
 
 
System Solve Time : 0
 
Building Time : 0
 
LU factorization solver finished.
 
 
System Solve Time : 0
 
DISPLACEMENT CRITERIA :: obtained tol = 0.0206048;  expected ratio = 1e-006absolute tol = 0.194195
 
Building Time : 0
 
LU factorization solver finished.
 
 
System Solve Time : 0
 
DISPLACEMENT CRITERIA :: obtained tol = 0.00405189;  expected ratio = 1e-006absolute tol = 0.0380348
 
Building Time : 0
 
LU factorization solver finished.
 
 
System Solve Time : 0
 
DISPLACEMENT CRITERIA :: obtained tol = 0.000159258;  expected ratio = 1e-006absolute tol = 0.00149484
 
Building Time : 0
 
LU factorization solver finished.
 
 
System Solve Time : 0
 
DISPLACEMENT CRITERIA :: obtained tol = 2.82165e-005;  expected ratio = 1e-006absolute tol = 0.000264855
 
Building Time : 0
 
LU factorization solver finished.
 
 
System Solve Time : 0
 
DISPLACEMENT CRITERIA :: obtained tol = 1.42173e-006;  expected ratio = 1e-006absolute tol = 1.33451e-005
 
Building Time : 0
 
LU factorization solver finished.
 
 
System Solve Time : 0
 
DISPLACEMENT CRITERIA :: obtained tol = 2.80121e-007;  expected ratio = 1e-006absolute tol = 2.62936e-006
 
"convergence is achieved" : convergence is achieved
 
before importing kratos
 
Kratos library imported
 
kernel created
 
Applications Available:
 
Import_ALEApplication: False
 
Import_IncompressibleFluidApplication: False
 
Import_StructuralApplication: False
 
Import_ConvectionDiffusionApplication: False
 
Import_FSIApplication: False
 
Import_ExternalSolversApplication: False
 
Import_ULFApplication: False
 
Import_MeshingApplication: False
 
Import_ElectrostaticApplication: False
 
'''Import_PoissonApplication: False'''
 
Applications Available:
 
Import_ALEApplication: False
 
Import_IncompressibleFluidApplication: False
 
Import_StructuralApplication: False
 
Import_ConvectionDiffusionApplication: False
 
Import_FSIApplication: False
 
Import_ExternalSolversApplication: False
 
Import_ULFApplication: False
 
Import_ULFApplication: False
 
Import_ ElectrostaticApplication: False
 
'''Import_ PoissonApplication: True'''
 
importing '''KratosR1PoissonApplication ...'''
 
Kratos '''PoissonApplication1''' sucessfully imported
 
'''PoissonPart''' model part
 
    Buffer Size : 1
 
    Current solution step index : 0
 
 
    Mesh 0 :
 
    Number of Nodes      : 9
 
    Number of Properties : 2
 
    Number of Elements  : 8
 
    Number of Conditions : 0
 
 
variables for the '''Poisson''' solver added correctly
 
 
 
 
The file '''our_example.post.res''' contains the results of the simulation, that is, the value of the unknowns for each node. It is written in binary format according to the GiD standards, and we can see the results by using the GiD post-processor:
 
 
[[Image:Our example results.jpg]]
 
 
If you want to get the results in a readable format, you can ask Gid to write them in an ascii format:
 
 
[[Image:Our example results ascii.jpg]]
 
 
If we write '''results_ascii''' as the name to write the results in ascii format, we will obtain two files:  '''results_ascii.msh''' and  '''results_ascii.res'''.
 
 
'''Mesh file: results_ascii.msh'''
 
 
# encoding utf-8
 
MESH "Kratos Triangle2D3 Mesh" dimension 3 ElemType Triangle Nnode 3
 
Coordinates
 
1 -8.5770302 -4.7918601 0
 
2 -8.5770302 3.98651 0
 
3 6.08043 -4.7918601 0
 
4 6.08043 3.98651 0
 
5 -8.5770302 12.76488 0
 
6 6.08043 12.76488 0
 
7 20.73789 -4.7918601 0
 
8 20.73789 3.98651 0
 
9 20.73789 12.76488 0
 
end coordinates
 
 
Elements
 
1 2 1 3 1
 
2 3 4 2 1
 
5 5 2 4 1
 
6 4 6 5 1
 
end elements
 
MESH "Kratos Triangle2D3 Mesh 2" dimension 3 ElemType Triangle Nnode 3
 
Coordinates
 
end coordinates
 
 
Elements
 
3 4 3 7 2
 
4 7 8 4 2
 
7 6 4 8 2
 
8 8 9 6 2
 
end elements
 
 
'''Results file: results_ascii.res'''
 
 
GiD Post Results File 1.0
 
 
# encoding utf-8
 
Result "DUMMY UNKNOWN" "Kratos" 0 Scalar OnNodes
 
ComponentNames "DUMMY UNKNOWN"
 
Values
 
1 0
 
2 0
 
3 8.92342
 
4 9.84336
 
5 0
 
6 9.37023
 
7 7
 
8 7
 
9 7
 
End values
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
  
Line 725: Line 476:
  
 
[[Category: Electrostatic Application]]
 
[[Category: Electrostatic Application]]
[[Category: Theory]]
 

Latest revision as of 09:05, 4 November 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:

KElectrostatic.mat.jpg

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

KElectrostatic.mat.2.jpg


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:

KElectrostatic.cnd.jpg

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

KElectrostatic.cnd.2.jpg


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:

KElectrostatic.cnd.4.jpg KElectrostatic.cnd.5.jpg

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.

Personal tools
Categories