Skip to content

Commit

Permalink
Updated compressible examples files
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco1410 committed Nov 29, 2022
1 parent 818767e commit 0a47fc2
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 310 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 30 additions & 49 deletions fluid_dynamics/validation/compressible_sod_shock_tube/source/MainKratos.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,58 +1,39 @@
#!/usr/bin/env python

import time
import sys
import pathlib
import time
import importlib

import KratosMultiphysics
import KratosMultiphysics.FluidDynamicsApplication
from KratosMultiphysics.FluidDynamicsApplication.fluid_dynamics_analysis \
import FluidDynamicsAnalysis


def abs_filepath(relative_filepath: str) -> str:
return str(pathlib.Path(__file__).parent.resolve()) + "/" \
+ relative_filepath


class FluidDynamicsAnalysisCompressible(FluidDynamicsAnalysis):
"""
Modified FluidDynamicsAnalysis in order to:
- Print at the first step
- Force stdout to flush at regular intervals
"""
def CreateAnalysisStageWithFlushInstance(cls, global_model, parameters):
class AnalysisStageWithFlush(cls):

def __init__(self, model,project_parameters, flush_frequency=10.0):
super().__init__(model,project_parameters)
self.flush_frequency = flush_frequency
self.last_flush = time.time()
sys.stdout.flush()

def Flush(self):
if self.parallel_type == "OpenMP":
now = time.time()
if now - self.last_flush > self.flush_frequency:
sys.stdout.flush()
self.last_flush = now

return AnalysisStageWithFlush(global_model, parameters)

def __init__(self, model, parameters, flush_frequency=10.0):
super().__init__(model, parameters)
self.flush_frequency = flush_frequency
self.last_flush = time.time()
sys.stdout.flush()

def Initialize(self):
super().Initialize()
sys.stdout.flush()
self.OutputSolutionStep()

def OutputSolutionStep(self):
self.Flush()
super().OutputSolutionStep()

def Flush(self, force=False):
if not force and self.parallel_type != "OpenMP":
return

now = time.time()
if not force and (now - self.last_flush < self.flush_frequency):
return
if __name__ == "__main__":

sys.stdout.flush()
self.last_flush = now
with open("ProjectParameters.json", 'r') as parameter_file:
parameters = KratosMultiphysics.Parameters(parameter_file.read())

analysis_stage_module_name = parameters["analysis_stage"].GetString()
analysis_stage_class_name = analysis_stage_module_name.split('.')[-1]
analysis_stage_class_name = ''.join(x.title() for x in analysis_stage_class_name.split('_'))

if __name__ == "__main__":
with open(abs_filepath("ProjectParameters.json"), 'r') as parameter_file:
project_parameters = KratosMultiphysics.Parameters(parameter_file.read())
analysis_stage_module = importlib.import_module(analysis_stage_module_name)
analysis_stage_class = getattr(analysis_stage_module, analysis_stage_class_name)

global_model = KratosMultiphysics.Model()
simulation = FluidDynamicsAnalysisCompressible(global_model, project_parameters)
simulation.Run()
global_model = KratosMultiphysics.Model()
simulation = CreateAnalysisStageWithFlushInstance(analysis_stage_class, global_model, parameters)
simulation.Run()
Original file line number Diff line number Diff line change
@@ -1,76 +1,40 @@
{
"problem_data": {
"problem_name": "sod_triangle",
"parallel_type": "OpenMP",
"echo_level": 5,
"start_time": 0.0,
"end_time": 0.16
},
"output_processes": {
"gid_output": [
{
"python_module": "gid_output_process",
"kratos_module": "KratosMultiphysics",
"process_name": "GiDOutputProcess",
"help": "This process writes postprocessing files for GiD",
"Parameters": {
"model_part_name": "FluidModelPart.fluid_computational_model_part",
"output_name": "sod",
"postprocess_parameters": {
"result_file_configuration": {
"gidpost_flags": {
"GiDPostMode": "GiD_PostBinary",
"WriteDeformedMeshFlag": "WriteDeformed",
"WriteConditionsFlag": "WriteConditions",
"MultiFileFlag": "SingleFile"
},
"file_label": "time",
"output_control_type": "time",
"output_interval": 0.05,
"body_output": true,
"node_output": false,
"skin_output": false,
"plane_output": [],
"nodal_results": ["MOMENTUM","DENSITY","TOTAL_ENERGY","PRESSURE","TEMPERATURE","VELOCITY", "NUMERICAL_ENTROPY"],
"gauss_point_results": ["SHOCK_SENSOR","THERMAL_SENSOR","SHEAR_SENSOR", "VELOCITY_DIVERGENCE"],
"nodal_nonhistorical_results": ["SOUND_VELOCITY", "ARTIFICIAL_MASS_DIFFUSIVITY", "ARTIFICIAL_BULK_VISCOSITY","ARTIFICIAL_DYNAMIC_VISCOSITY","ARTIFICIAL_CONDUCTIVITY","MACH"]
},
"point_data_configuration": []
}
}
}
]
},
"analysis_stage": "KratosMultiphysics.FluidDynamicsApplication.fluid_dynamics_analysis",
"problem_data" : {
"problem_name" : "sod_with_triangles",
"parallel_type" : "OpenMP",
"echo_level" : 0,
"start_time" : 0.0,
"end_time" : 0.1
},
"solver_settings": {
"model_part_name": "FluidModelPart",
"domain_size": 2,
"solver_type": "CompressibleExplicit",
"model_import_settings": {
"input_type": "mdpa",
"input_filename": "rectangle"
},
"material_import_settings": {
"materials_filename": "FluidMaterials.json"
},
"echo_level": 0,
"compute_reactions": false,
"shock_capturing_settings": {
"type" : "physics_based"
},
"time_scheme" : "RK3-TVD",
"use_oss": false,
"volume_model_part_name": "FluidParts_Fluid",
"skin_parts": ["Slip2D", "Boundaries-Left", "Boundaries-Right"],
"no_skin_parts": [],
"time_stepping": {
"automatic_time_step": true,
"CFL_number": 0.5,
"minimum_delta_time": 1e-8,
"maximum_delta_time": 0.01,
"Viscous_Fourier_number": -1,
"Thermal_Fourier_number": -1
},
"reform_dofs_at_each_step": false
"model_part_name" : "FluidModelPart",
"domain_size" : 2,
"solver_type" : "CompressibleExplicit",
"model_import_settings": {
"input_type": "mdpa",
"input_filename": "rectangle"
},
"material_import_settings": {
"materials_filename": "FluidMaterials.json"
},
"echo_level": 0,
"compute_reactions": false,
"shock_capturing_settings": {
"type" : "physics_based",
"Parameters" : {}
},
"time_scheme" : "RK4",
"use_oss": false,
"volume_model_part_name": "FluidParts_Fluid",
"skin_parts": ["Slip2D", "Boundaries-Left", "Boundaries-Right"],
"no_skin_parts": [],
"time_stepping": {
"automatic_time_step": true,
"minimum_delta_time" : 1e-8,
"CFL_number": 1.0
},
"reform_dofs_at_each_step": false
},
"processes": {
"initial_conditions_process_list":
Expand Down Expand Up @@ -141,5 +105,56 @@
}
],
"auxiliar_process_list": []
},
"output_processes": {
"gid_output": [
{
"python_module": "gid_output_process",
"kratos_module": "KratosMultiphysics",
"process_name": "GiDOutputProcess",
"help": "This process writes postprocessing files for GiD",
"Parameters": {
"model_part_name": "FluidModelPart.fluid_computational_model_part",
"output_name": "sod",
"postprocess_parameters": {
"result_file_configuration": {
"gidpost_flags": {
"GiDPostMode": "GiD_PostBinary",
"WriteDeformedMeshFlag": "WriteDeformed",
"WriteConditionsFlag": "WriteConditions",
"MultiFileFlag": "SingleFile"
},
"file_label": "time",
"output_control_type": "time",
"output_interval": 0.01,
"body_output": true,
"node_output": false,
"skin_output": false,
"plane_output": [],
"nodal_results": [
"MOMENTUM",
"DENSITY",
"TOTAL_ENERGY",
"PRESSURE",
"TEMPERATURE",
"VELOCITY"],
"gauss_point_results": [
"SHOCK_SENSOR",
"THERMAL_SENSOR",
"SHEAR_SENSOR",
"VELOCITY_DIVERGENCE"],
"nodal_nonhistorical_results": [
"SOUND_VELOCITY",
"ARTIFICIAL_MASS_DIFFUSIVITY",
"ARTIFICIAL_BULK_VISCOSITY",
"ARTIFICIAL_DYNAMIC_VISCOSITY",
"ARTIFICIAL_CONDUCTIVITY",
"MACH"]
},
"point_data_configuration": []
}
}
}
]
}
}
Loading

0 comments on commit 0a47fc2

Please sign in to comment.