-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
256 additions
and
310 deletions.
There are no files selected for viewing
Binary file modified
BIN
+1.67 KB
(120%)
fluid_dynamics/validation/compressible_sod_shock_tube/data/density.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.34 KB
(120%)
fluid_dynamics/validation/compressible_sod_shock_tube/data/pressure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.86 KB
(120%)
fluid_dynamics/validation/compressible_sod_shock_tube/data/velocity.png
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
79
fluid_dynamics/validation/compressible_sod_shock_tube/source/MainKratos.py
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.