How to use the Cutting Isosurface Application
In many 3D models that are calculated, the part of the domain that we're interested in is a small fraction of the full domain and therefore in the postprocess we use the GiD tool Iso surface to create cuts of this small part, leaving all the rest unused. This is ok as long as the domain is small, but when it has a million or more elements, we end up with GBs of data that makes reading results a slow task. In other 3D models we're interested in all the domain but also in a specific Iso surface. GiD allows us to evaluate data in every iso surface we want, but it takes a lot of work.
The idea behind this utility is to print a postprocess file that can contain only the results of iso surfaces that have been defined as input, or the results in all the domain and also in the iso surfaces we have defined (each results are stored in a different layer). Therefore, if we are only interested in the iso surfaces data, results in the full domain are discarded once they are not (internally) needed anymore by the selected solver scheme. In the other hand if we need all models data but also iso surfaces results, data is available without any other operation to do. User can choose the layer in which each surface or full model will be printed, to turning them on and off is trivial.
To do this we will have to add the next tasks in our python file:
- Create a new, empty model part that will later contain the iso surfaces and add the same variables to this new model part.
- Define the iso surfaces that we want, determining the variables and their values.
- At each time step when we want the results call the constructor of the utility so that the nodes and triangles are created. To print results, call the function that interpolates the results from the original tetrahedra into the triangles.
- Tell Kratos to print the results of the new model part.
(It is important to call the utility at each time step we want because the mesh changes from one step to another).
Contents |
1. Importing the Meshing Application and defining the new model part
Since this utility is part of the Meshing App, we'll have to import it. For example in a fluid problem:
... #importing applications import applications_interface applications_interface.Import_IncompressibleFluidApplication = True applications_interface.Import_FluidDynamicsApplication = True applications_interface.Import_MeshingApplication = True #import the meshing app interface applications_interface.ImportApplications(kernel, kratos_applications_path) ## from now on the order is not anymore crucial ################################################################## ################################################################## from KratosIncompressibleFluidApplication import * from KratosFluidDynamicsApplication import * from KratosMeshingApplication import * #import the meshing app fluid_model_part = ModelPart("FluidPart"); #original model part cut_model_part = ModelPart("CutPart"); #define a new model part in which the results will be printed ...
In the default scripts (for example, the ones generated by GID) , only elements are printed. We will have to change this because the mesh we are about to generate contains conditions instead of elements: (if you get an empty mesh as output it might be that there is no point on the domain that satisfied the imposed conditions or you forgot to change this)
write_conditions = WriteConditionsFlag.WriteConditions # ORIGINAL: write_conditions = WriteConditionsFlag.WriteElementsOnly gid_io = GidIO(input_file_name,gid_mode,multifile,deformed_mesh_flag, write_conditions)
2. Defining the iso surfaces and calling the utility
variable1 = PRESSURE # scalar variable variable2 = VELOCITY_X # component of a vectorial variable</nowiki>
isovalue1 = 10 isovalue2 = 5
At each time step we must clone the time steps:
fluid_model_part.CloneTimeStep(time) cut_model_part.CloneTimeStep(time)
We call the constructor:
#constructor of the cutting isosurface application Cut_App = Cutting_Isosurface_Application();
At each time step we want the results:
First of all, we need to delete the data form previous steps, because the mesh will be different.
Cut_App.DeleteCutData (cut_model_part)
We are ready to fill the new model part with the iso surfaces. If we want to print the results in all the domain, we can do it. If skin conditions (using triangles) have been used, for example an inlet, we can also print the in the same way.
#Generate the cut. This function has to be called once per iso surf #layer(integer) is the layer in which the generated plane will be printed #Cut_App.Generate____________Cut(fluid_model_part,cut_model_part,variable1,isovalue1, layer , tolerance)
Cut_App.GenerateScalarVarCut(fluid_model_part,cut_model_part,variable1,isovalue1, 1 , tolerance) Cut_App.GenerateVectorialComponentVarCut(fluid_model_part,cut_model_part,variable2,isovalue2, 2 , tolerance) Cut_App.AddModelPartElements(fluid_model_part,cut_model_part, 3) # if we want to print the results in all the domain Cut_App.AddSkinConditions(fluid_model_part,cut_model_part, 4) # if we want to print the results in the skins of the domain
Now that we have the new mesh, we must print it:
#mesh to be printed mesh_name = 0.0 gid_io.InitializeMesh( mesh_name) gid_io.WriteMesh( cut_model_part.GetMesh() ) #ORIGINAL: gid_io.WriteMesh( fluid_model_part.GetMesh() ) gid_io.FinalizeMesh()
gid_io.InitializeResults(mesh_name,(cut_model_part).GetMesh())#originally: gid_io.InitializeResults(mesh_name,(fluid_model_part).GetMesh())
3. Updating and priting results
And after the system has been solved, in the timesteps that we want our results to be printed we will have to first interpolate the results. For example if we wanted to print these two variables:
#gid_io.WriteNodalResults(PRESSURE,fluid_model_part.Nodes,time,0) #gid_io.WriteNodalResults(VELOCITY,fluid_model_part.Nodes,time,0)
We call UpdateCutData, that interpolates the results in all the variables in the current timestep, and then we write using the new model part:
Cut_App.UpdateCutData(cut_model_part,fluid_model_part) gid_io.WriteNodalResults(PRESSURE,cut_model_part.Nodes,time,0) gid_io.WriteNodalResults(VELOCITY,cut_model_part.Nodes,time,0)
And that's it, the results are printed in the surfaces.
4. Example
Simulation using the Cutting Isosurface Application. The green layer represents the iso surface with 0 DISTANCE and the blue layer is the iso surface with VELOCITY_X equal to 0,5:
