KratosFluidDynamicsApplication 10.4.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- KratosMultiphysics/.libs/KratosFluidDynamicsApplication.so +0 -0
- KratosMultiphysics/.libs/libKratosFluidDynamicsCore.dylib +4 -0
- KratosMultiphysics/FluidDynamicsApplication/__init__.py +11 -0
- KratosMultiphysics/FluidDynamicsApplication/adjoint_fluid_analysis.py +106 -0
- KratosMultiphysics/FluidDynamicsApplication/adjoint_fluid_solver.py +184 -0
- KratosMultiphysics/FluidDynamicsApplication/adjoint_monolithic_solver.py +224 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_boussinesq_force_process.py +44 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_compressible_navier_stokes_boundary_conditions_process.py +7 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_distance_modification_process.py +50 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_embedded_nodes_initialization_process.py +31 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_embedded_postprocess_process.py +28 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_inlet_process.py +69 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_mass_conservation_check_process.py +64 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_noslip_process.py +37 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_outlet_process.py +196 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_slip_process.py +52 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_two_fluids_inlet_process.py +164 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_two_fluids_inlet_process_mpi.py +49 -0
- KratosMultiphysics/FluidDynamicsApplication/apply_wall_law_process.py +166 -0
- KratosMultiphysics/FluidDynamicsApplication/axisymmetric_navier_stokes/generate_axisymmetric_navier_stokes_element.py +171 -0
- KratosMultiphysics/FluidDynamicsApplication/check_and_prepare_model_process_fluid.py +113 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/__init__.py +0 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/compressible_navier_stokes_symbolic_generator.py +526 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/generate_quadrilateral.py +21 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/generate_tetrahedron.py +21 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/generate_triangle.py +21 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/src/__init__.py +0 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/src/defines.py +39 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/src/generate_convective_flux.py +55 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/src/generate_diffusive_flux.py +192 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/src/generate_source_term.py +42 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/src/generate_stabilization_matrix.py +66 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/src/symbolic_geometry.py +164 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_navier_stokes/src/symbolic_parameters.py +33 -0
- KratosMultiphysics/FluidDynamicsApplication/compressible_slip_wall_process.py +174 -0
- KratosMultiphysics/FluidDynamicsApplication/compute_aerodynamic_coefficients_process.py +194 -0
- KratosMultiphysics/FluidDynamicsApplication/compute_body_fitted_flow_forces_and_moments_process.py +37 -0
- KratosMultiphysics/FluidDynamicsApplication/compute_cfl_process.py +32 -0
- KratosMultiphysics/FluidDynamicsApplication/compute_drag_process.py +34 -0
- KratosMultiphysics/FluidDynamicsApplication/compute_embedded_flow_forces_and_moments_process.py +37 -0
- KratosMultiphysics/FluidDynamicsApplication/compute_flow_forces_and_moments_process.py +144 -0
- KratosMultiphysics/FluidDynamicsApplication/compute_pressure_coefficient_process.py +8 -0
- KratosMultiphysics/FluidDynamicsApplication/compute_y_plus_process.py +15 -0
- KratosMultiphysics/FluidDynamicsApplication/cube_mesher.py +775 -0
- KratosMultiphysics/FluidDynamicsApplication/dynamic_smagorinsky_utilities.py +67 -0
- KratosMultiphysics/FluidDynamicsApplication/embedded_ausas_navier_stokes/generate_embedded_ausas_navier_stokes_element.py +231 -0
- KratosMultiphysics/FluidDynamicsApplication/finite_difference_sensitivity_utilities.py +268 -0
- KratosMultiphysics/FluidDynamicsApplication/flow_output_process.py +88 -0
- KratosMultiphysics/FluidDynamicsApplication/fluid_dynamics_analysis.py +98 -0
- KratosMultiphysics/FluidDynamicsApplication/fluid_dynamics_analysis_rve.py +253 -0
- KratosMultiphysics/FluidDynamicsApplication/fluid_solver.py +429 -0
- KratosMultiphysics/FluidDynamicsApplication/incompressible_navier_stokes_p2_p1_continuous/generate_incompressible_navier_stokes_p2_p1_continuous_element.py +206 -0
- KratosMultiphysics/FluidDynamicsApplication/integration_point_statistics_process.py +16 -0
- KratosMultiphysics/FluidDynamicsApplication/low_mach_navier_stokes/generate_low_mach_navier_stokes_element.py +240 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_ale_fluid_solver.py +110 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_compressible_explicit_solver.py +211 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_embedded_solver.py +698 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_low_mach_solver.py +301 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_monolithic_iga_solver.py +67 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_monolithic_solver.py +412 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_solver_fractionalstep.py +240 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_solver_vmsmonolithic.py +9 -0
- KratosMultiphysics/FluidDynamicsApplication/navier_stokes_two_fluids_solver.py +612 -0
- KratosMultiphysics/FluidDynamicsApplication/python_registry_lists.py +14 -0
- KratosMultiphysics/FluidDynamicsApplication/python_solvers_wrapper_adjoint_fluid.py +35 -0
- KratosMultiphysics/FluidDynamicsApplication/python_solvers_wrapper_fluid.py +85 -0
- KratosMultiphysics/FluidDynamicsApplication/read_distance_from_file.py +40 -0
- KratosMultiphysics/FluidDynamicsApplication/refine_embedded_object.py +92 -0
- KratosMultiphysics/FluidDynamicsApplication/response_function_output_process.py +70 -0
- KratosMultiphysics/FluidDynamicsApplication/stokes_solver_monolithic.py +193 -0
- KratosMultiphysics/FluidDynamicsApplication/trilinos_adjoint_monolithic_solver.py +103 -0
- KratosMultiphysics/FluidDynamicsApplication/trilinos_navier_stokes_embedded_solver.py +132 -0
- KratosMultiphysics/FluidDynamicsApplication/trilinos_navier_stokes_monolithic_solver.py +155 -0
- KratosMultiphysics/FluidDynamicsApplication/trilinos_navier_stokes_solver_fractionalstep.py +150 -0
- KratosMultiphysics/FluidDynamicsApplication/trilinos_navier_stokes_solver_vmsmonolithic.py +9 -0
- KratosMultiphysics/FluidDynamicsApplication/trilinos_navier_stokes_two_fluids_solver.py +204 -0
- KratosMultiphysics/FluidDynamicsApplication/two_fluid_navier_stokes/generate_two_fluid_navier_stokes.py +355 -0
- KratosMultiphysics/FluidDynamicsApplication/two_fluid_navier_stokes_fractional/generate_two_fluid_convection_fractional.py +164 -0
- KratosMultiphysics/FluidDynamicsApplication/two_fluid_navier_stokes_fractional/generate_two_fluid_navier_stokes_fractional.py +322 -0
- KratosMultiphysics/FluidDynamicsApplication/two_fluid_stokes/generate_stokes_twofluid_element.py +189 -0
- KratosMultiphysics/FluidDynamicsApplication/weakly_compressible_navier_stokes/generate_weakly_compressible_navier_stokes_element.py +306 -0
- kratosfluiddynamicsapplication-10.4.4.dist-info/METADATA +132 -0
- kratosfluiddynamicsapplication-10.4.4.dist-info/RECORD +88 -0
- kratosfluiddynamicsapplication-10.4.4.dist-info/WHEEL +6 -0
- kratosfluiddynamicsapplication.dylibs/libKratosCore.dylib +4 -0
- kratosfluiddynamicsapplication.dylibs/libgcc_s.1.1.dylib +0 -0
- kratosfluiddynamicsapplication.dylibs/libgomp.1.dylib +0 -0
- kratosfluiddynamicsapplication.dylibs/libstdc++.6.dylib +0 -0
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from KratosFluidDynamicsApplication import *
|
|
2
|
+
|
|
3
|
+
from KratosMultiphysics import _ImportApplication, python_registry_utilities
|
|
4
|
+
|
|
5
|
+
application = KratosFluidDynamicsApplication()
|
|
6
|
+
application_name = "KratosFluidDynamicsApplication"
|
|
7
|
+
|
|
8
|
+
_ImportApplication(application, application_name)
|
|
9
|
+
|
|
10
|
+
from . import python_registry_lists
|
|
11
|
+
python_registry_utilities.RegisterAll("KratosMultiphysics.FluidDynamicsApplication", python_registry_lists)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
|
|
2
|
+
import KratosMultiphysics as Kratos
|
|
3
|
+
import KratosMultiphysics.FluidDynamicsApplication as KFluid
|
|
4
|
+
|
|
5
|
+
from KratosMultiphysics.analysis_stage import AnalysisStage
|
|
6
|
+
from KratosMultiphysics.process_factory import KratosProcessFactory
|
|
7
|
+
from KratosMultiphysics.FluidDynamicsApplication import python_solvers_wrapper_adjoint_fluid
|
|
8
|
+
from KratosMultiphysics.FluidDynamicsApplication.fluid_dynamics_analysis import FluidDynamicsAnalysis
|
|
9
|
+
|
|
10
|
+
class AdjointFluidAnalysis(AnalysisStage):
|
|
11
|
+
'''Main script for adjoint sensitivity optimization in fluid dynamics simulations.'''
|
|
12
|
+
|
|
13
|
+
def __init__(self,model,parameters):
|
|
14
|
+
super().__init__(model, parameters)
|
|
15
|
+
|
|
16
|
+
problem_data = self.project_parameters["problem_data"]
|
|
17
|
+
|
|
18
|
+
# check that old input is not provided
|
|
19
|
+
if problem_data.Has("nsteps"):
|
|
20
|
+
raise Exception("'nsteps' is no longer supported. Use 'start_time' and 'end_time' instead")
|
|
21
|
+
if problem_data.Has("start_step"):
|
|
22
|
+
raise Exception("'start_step' is no longer supported. Use 'start_time' and 'end_time' instead")
|
|
23
|
+
if problem_data.Has("end_step"):
|
|
24
|
+
raise Exception("'end_step' is no longer supported. Use 'start_time' and 'end_time' instead")
|
|
25
|
+
|
|
26
|
+
# compute delta time
|
|
27
|
+
delta_time = self._GetSolver()._ComputeDeltaTime()
|
|
28
|
+
if delta_time >= 0.0:
|
|
29
|
+
raise Exception("Adjoints are solved in reverse in time. Hence, delta_time should be negative. [ delta_time = " + str(delta_time) + "].")
|
|
30
|
+
|
|
31
|
+
# update start time and end time. Adjoints are solved reverse in time,
|
|
32
|
+
# hence we include an additional time step at the end
|
|
33
|
+
# to properly initialize initial conditions for adjoint problem
|
|
34
|
+
# and start time is also shifted by one to keep the same number
|
|
35
|
+
# of steps
|
|
36
|
+
delta_time *= -1.0
|
|
37
|
+
self.start_time = problem_data["start_time"].GetDouble() + delta_time
|
|
38
|
+
self.end_time = problem_data["end_time"].GetDouble() + delta_time
|
|
39
|
+
|
|
40
|
+
# now set start_time, end_time of the problem_data bt flipping them
|
|
41
|
+
self.project_parameters["problem_data"]["start_time"].SetDouble(self.end_time)
|
|
42
|
+
self.project_parameters["problem_data"]["end_time"].SetDouble(self.start_time)
|
|
43
|
+
|
|
44
|
+
def Initialize(self):
|
|
45
|
+
super(AdjointFluidAnalysis, self).Initialize()
|
|
46
|
+
|
|
47
|
+
# dummy time step to correctly calculate DELTA_TIME
|
|
48
|
+
self._GetSolver().main_model_part.CloneTimeStep(self.time)
|
|
49
|
+
|
|
50
|
+
def _CreateSolver(self):
|
|
51
|
+
return python_solvers_wrapper_adjoint_fluid.CreateSolver(self.model, self.project_parameters)
|
|
52
|
+
|
|
53
|
+
def KeepAdvancingSolutionLoop(self):
|
|
54
|
+
"""This function specifies the stopping criteria for breaking the solution loop
|
|
55
|
+
Note that as the adjoint problem is solved backward in time, the stopping criteria is current time being larger than the start one
|
|
56
|
+
"""
|
|
57
|
+
return self.time > self.start_time
|
|
58
|
+
|
|
59
|
+
def _GetOrderOfProcessesInitialization(self):
|
|
60
|
+
return ["gravity",
|
|
61
|
+
"initial_conditions_process_list",
|
|
62
|
+
"boundary_conditions_process_list",
|
|
63
|
+
"auxiliar_process_list"]
|
|
64
|
+
|
|
65
|
+
def _GetSimulationName(self):
|
|
66
|
+
return self.__class__.__name__
|
|
67
|
+
|
|
68
|
+
if __name__ == '__main__':
|
|
69
|
+
from sys import argv
|
|
70
|
+
|
|
71
|
+
primal_parameter_file_name = None
|
|
72
|
+
adjoint_parameter_file_name = None
|
|
73
|
+
|
|
74
|
+
parameters = Kratos.Parameters(r'''{}''')
|
|
75
|
+
|
|
76
|
+
if len(argv) == 2:
|
|
77
|
+
adjoint_parameter_file_name = argv[1]
|
|
78
|
+
elif len(argv) == 3:
|
|
79
|
+
primal_parameter_file_name = argv[1]
|
|
80
|
+
adjoint_parameter_file_name = argv[2]
|
|
81
|
+
else:
|
|
82
|
+
err_msg = 'Unexpected amount of input arguments!\n'
|
|
83
|
+
err_msg += 'To run the primal fluid problem followed by the adjoint solution, provide both parameter files:\n'
|
|
84
|
+
err_msg += ' "python adjoint_fluid_analysis.py <primal-parameter-file>.json <adjoint-parameter-file>.json"\n'
|
|
85
|
+
err_msg += 'To run only the adjoint problem, provide only the adjoint parameter file:\n'
|
|
86
|
+
err_msg += ' "python adjoint_fluid_analysis.py <adjoint-parameter-file>.json"\n'
|
|
87
|
+
raise Exception(err_msg)
|
|
88
|
+
|
|
89
|
+
if primal_parameter_file_name is not None:
|
|
90
|
+
with open(primal_parameter_file_name,'r') as primal_parameter_file:
|
|
91
|
+
parameters.AddValue("primal_settings",Kratos.Parameters(primal_parameter_file.read()))
|
|
92
|
+
else:
|
|
93
|
+
parameters.AddEmptyValue("primal_settings")
|
|
94
|
+
|
|
95
|
+
with open(adjoint_parameter_file_name,'r') as adjoint_parameter_file:
|
|
96
|
+
parameters.AddValue("adjoint_settings", Kratos.Parameters(adjoint_parameter_file.read()))
|
|
97
|
+
|
|
98
|
+
model = Kratos.Model()
|
|
99
|
+
|
|
100
|
+
if primal_parameter_file_name is not None:
|
|
101
|
+
primal_simulation = FluidDynamicsAnalysis(model,parameters["primal_settings"])
|
|
102
|
+
primal_simulation.Run()
|
|
103
|
+
|
|
104
|
+
adjoint_model = Kratos.Model()
|
|
105
|
+
adjoint_simulation = AdjointFluidAnalysis(adjoint_model,parameters["adjoint_settings"])
|
|
106
|
+
adjoint_simulation.Run()
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Importing the Kratos Library
|
|
2
|
+
import KratosMultiphysics
|
|
3
|
+
# from KratosMultiphysics.python_solver import PythonSolver
|
|
4
|
+
|
|
5
|
+
import KratosMultiphysics.FluidDynamicsApplication as KratosCFD
|
|
6
|
+
from KratosMultiphysics.FluidDynamicsApplication.fluid_solver import FluidSolver
|
|
7
|
+
|
|
8
|
+
def CreateSolver(model, custom_settings):
|
|
9
|
+
return AdjointFluidSolver(model, custom_settings)
|
|
10
|
+
|
|
11
|
+
class AdjointFluidSolver(FluidSolver):
|
|
12
|
+
|
|
13
|
+
def __init__(self, model, settings):
|
|
14
|
+
super(AdjointFluidSolver,self).__init__(model, settings)
|
|
15
|
+
|
|
16
|
+
# Overwrite the default buffer size in base FluidSolver
|
|
17
|
+
# TODO: CHECK WHY THE DEFAULT BUFFER SIZE IS 2 IF THE DEFAULT TIME SCHEME IS BOSSAK
|
|
18
|
+
self.min_buffer_size = 2
|
|
19
|
+
|
|
20
|
+
def AddDofs(self):
|
|
21
|
+
dofs_to_add = []
|
|
22
|
+
dofs_to_add.append("ADJOINT_FLUID_VECTOR_1_X")
|
|
23
|
+
dofs_to_add.append("ADJOINT_FLUID_VECTOR_1_Y")
|
|
24
|
+
dofs_to_add.append("ADJOINT_FLUID_VECTOR_1_Z")
|
|
25
|
+
dofs_to_add.append("ADJOINT_FLUID_SCALAR_1")
|
|
26
|
+
KratosMultiphysics.VariableUtils.AddDofsList(dofs_to_add, self.main_model_part)
|
|
27
|
+
|
|
28
|
+
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, "Adjoint fluid solver DOFs added correctly.")
|
|
29
|
+
|
|
30
|
+
def GetDofsList(self):
|
|
31
|
+
dofs_list = []
|
|
32
|
+
dofs_list.append("ADJOINT_FLUID_VECTOR_1_X")
|
|
33
|
+
dofs_list.append("ADJOINT_FLUID_VECTOR_1_Y")
|
|
34
|
+
if self.settings["domain_size"].GetInt() == 3:
|
|
35
|
+
dofs_list.append("ADJOINT_FLUID_VECTOR_1_Z")
|
|
36
|
+
dofs_list.append("ADJOINT_FLUID_SCALAR_1")
|
|
37
|
+
|
|
38
|
+
return dofs_list
|
|
39
|
+
|
|
40
|
+
def InitializeSolutionStep(self):
|
|
41
|
+
self._GetSolutionStrategy().InitializeSolutionStep()
|
|
42
|
+
self.GetResponseFunction().InitializeSolutionStep()
|
|
43
|
+
self.GetSensitivityBuilder().InitializeSolutionStep()
|
|
44
|
+
|
|
45
|
+
def Predict(self):
|
|
46
|
+
self._GetSolutionStrategy().Predict()
|
|
47
|
+
|
|
48
|
+
def SolveSolutionStep(self):
|
|
49
|
+
return self._GetSolutionStrategy().SolveSolutionStep()
|
|
50
|
+
|
|
51
|
+
def FinalizeSolutionStep(self):
|
|
52
|
+
self._GetSolutionStrategy().FinalizeSolutionStep()
|
|
53
|
+
self.GetResponseFunction().FinalizeSolutionStep()
|
|
54
|
+
|
|
55
|
+
self.GetSensitivityBuilder().UpdateSensitivities()
|
|
56
|
+
self.GetSensitivityBuilder().FinalizeSolutionStep()
|
|
57
|
+
|
|
58
|
+
def Check(self):
|
|
59
|
+
self._GetSolutionStrategy().Check()
|
|
60
|
+
|
|
61
|
+
def _ReplaceElementsAndConditions(self):
|
|
62
|
+
## Get number of nodes and domain size
|
|
63
|
+
elem_num_nodes = self._GetElementNumNodes()
|
|
64
|
+
cond_num_nodes = self._GetConditionNumNodes()
|
|
65
|
+
domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]
|
|
66
|
+
|
|
67
|
+
## If there are no elements and/or conditions, default to triangles/tetra meshes to avoid breaking the ReplaceElementsAndConditionsProcess
|
|
68
|
+
## This only affects the input name (if there are no elements or conditions to replace, nothing is replaced).
|
|
69
|
+
if elem_num_nodes == 0:
|
|
70
|
+
elem_num_nodes = domain_size + 1
|
|
71
|
+
if cond_num_nodes == 0:
|
|
72
|
+
cond_num_nodes = domain_size
|
|
73
|
+
|
|
74
|
+
## Complete the element name
|
|
75
|
+
# TODO: EXPORT THE ADJOINT FOLLOWING THE CONVENTION. ONCE THIS IS DONE WE CAN USE THE FUNCTION IN THE BASE CLASS
|
|
76
|
+
if (self.element_name is not None):
|
|
77
|
+
new_elem_name = f"{self.element_name}{int(domain_size)}D{int(elem_num_nodes)}N"
|
|
78
|
+
else:
|
|
79
|
+
raise Exception("There is no element name. Define the self.element_name string variable in your derived solver.")
|
|
80
|
+
|
|
81
|
+
## Complete the condition name
|
|
82
|
+
if (self.condition_name is not None):
|
|
83
|
+
new_cond_name = self.condition_name + str(int(domain_size)) + "D" + str(int(cond_num_nodes)) + "N"
|
|
84
|
+
else:
|
|
85
|
+
raise Exception("There is no condition name. Define the self.condition_name string variable in your derived solver.")
|
|
86
|
+
|
|
87
|
+
## Set the element and condition names in the Json parameters
|
|
88
|
+
self.settings.AddValue("element_replace_settings", KratosMultiphysics.Parameters("""{}"""))
|
|
89
|
+
self.settings["element_replace_settings"].AddEmptyValue("element_name").SetString(new_elem_name)
|
|
90
|
+
self.settings["element_replace_settings"].AddEmptyValue("condition_name").SetString(new_cond_name)
|
|
91
|
+
|
|
92
|
+
## Call the replace elements and conditions process
|
|
93
|
+
KratosMultiphysics.ReplaceElementsAndConditionsProcess(self.main_model_part, self.settings["element_replace_settings"]).Execute()
|
|
94
|
+
|
|
95
|
+
def _ComputeDeltaTime(self):
|
|
96
|
+
"""This function returns the delta time
|
|
97
|
+
Note that the adjoint fluid analysis does not support the automatic time stepping
|
|
98
|
+
Also note that as it requires to go backwards in time, here we return minus the user time step
|
|
99
|
+
"""
|
|
100
|
+
if self.settings["time_stepping"]["automatic_time_step"].GetBool():
|
|
101
|
+
raise Exception("Automatic time stepping is not supported by adjoint fluid solver.")
|
|
102
|
+
|
|
103
|
+
delta_time = self.settings["time_stepping"]["time_step"].GetDouble()
|
|
104
|
+
if delta_time > 0.0:
|
|
105
|
+
# Expected positive time_step is reversed to advance backwards in time
|
|
106
|
+
delta_time *= -1.0
|
|
107
|
+
else:
|
|
108
|
+
# TODO: Remove this check after the backwards compatibility period
|
|
109
|
+
# In order to keep backwards compatibility, we throw a warning if a negative time_step is provided
|
|
110
|
+
KratosMultiphysics.Logger.PrintWarning("Setting a negative 'time_step' is no longer needed by 'AdjointFluidSolver'.")
|
|
111
|
+
|
|
112
|
+
return delta_time
|
|
113
|
+
|
|
114
|
+
def _SetNodalProperties(self):
|
|
115
|
+
# Get density and dynamic viscostity from the properties of the first element
|
|
116
|
+
for el in self.main_model_part.Elements:
|
|
117
|
+
rho = el.Properties.GetValue(KratosMultiphysics.DENSITY)
|
|
118
|
+
if rho <= 0.0:
|
|
119
|
+
raise Exception("DENSITY set to {0} in Properties {1}, positive number expected.".format(rho,el.Properties.Id))
|
|
120
|
+
dyn_viscosity = el.Properties.GetValue(KratosMultiphysics.DYNAMIC_VISCOSITY)
|
|
121
|
+
if dyn_viscosity <= 0.0:
|
|
122
|
+
raise Exception("DYNAMIC_VISCOSITY set to {0} in Properties {1}, positive number expected.".format(dyn_viscosity,el.Properties.Id))
|
|
123
|
+
kin_viscosity = dyn_viscosity / rho
|
|
124
|
+
break
|
|
125
|
+
else:
|
|
126
|
+
raise Exception("No fluid elements found in the main model part.")
|
|
127
|
+
# Transfer the obtained properties to the nodes
|
|
128
|
+
KratosMultiphysics.VariableUtils().SetVariable(KratosMultiphysics.DENSITY, rho, self.main_model_part.Nodes)
|
|
129
|
+
KratosMultiphysics.VariableUtils().SetVariable(KratosMultiphysics.VISCOSITY, kin_viscosity, self.main_model_part.Nodes)
|
|
130
|
+
|
|
131
|
+
def GetResponseFunction(self):
|
|
132
|
+
if not hasattr(self, '_response_function'):
|
|
133
|
+
self._response_function = self.__CreateResponseFunction()
|
|
134
|
+
return self._response_function
|
|
135
|
+
|
|
136
|
+
def __CreateResponseFunction(self):
|
|
137
|
+
domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]
|
|
138
|
+
response_type = self.settings["response_function_settings"]["response_type"].GetString()
|
|
139
|
+
if response_type == "drag":
|
|
140
|
+
if domain_size == 2:
|
|
141
|
+
response_function = KratosCFD.DragResponseFunction2D(
|
|
142
|
+
self.settings["response_function_settings"]["custom_settings"],
|
|
143
|
+
self.main_model_part)
|
|
144
|
+
elif domain_size == 3:
|
|
145
|
+
response_function = KratosCFD.DragResponseFunction3D(
|
|
146
|
+
self.settings["response_function_settings"]["custom_settings"],
|
|
147
|
+
self.main_model_part)
|
|
148
|
+
else:
|
|
149
|
+
raise Exception("Invalid DOMAIN_SIZE: " + str(domain_size))
|
|
150
|
+
elif response_type == "norm_square":
|
|
151
|
+
response_function = KratosCFD.VelocityPressureNormSquareResponseFunction(
|
|
152
|
+
self.settings["response_function_settings"]["custom_settings"],
|
|
153
|
+
self.model)
|
|
154
|
+
else:
|
|
155
|
+
raise Exception("Invalid response_type: " + response_type + ". Available response functions: \'drag\'.")
|
|
156
|
+
return response_function
|
|
157
|
+
|
|
158
|
+
def GetSensitivityBuilder(self):
|
|
159
|
+
if not hasattr(self, '_sensitivity_builder'):
|
|
160
|
+
self._sensitivity_builder = self.__CreateSensitivityBuilder()
|
|
161
|
+
return self._sensitivity_builder
|
|
162
|
+
|
|
163
|
+
def __CreateSensitivityBuilder(self):
|
|
164
|
+
response_function = self.GetResponseFunction()
|
|
165
|
+
time_scheme_settings = self.settings["scheme_settings"]
|
|
166
|
+
time_scheme_type = time_scheme_settings["scheme_type"].GetString()
|
|
167
|
+
|
|
168
|
+
domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]
|
|
169
|
+
# the schemes used in fluid supports SLIP conditions which rotates element/condition
|
|
170
|
+
# matrices based on nodal NORMAL. Hence, the consistent adjoints also need to
|
|
171
|
+
# rotate adjoint element/condition matrices accordingly and to compute derivatives
|
|
172
|
+
# of rotation matrices as well. Therefore, following schemes are used.
|
|
173
|
+
if (time_scheme_type == "steady"):
|
|
174
|
+
self.sensitivity_builder_scheme = KratosCFD.SimpleSteadySensitivityBuilderScheme(domain_size, domain_size + 1)
|
|
175
|
+
elif (time_scheme_type == "bossak"):
|
|
176
|
+
self.sensitivity_builder_scheme = KratosCFD.VelocityBossakSensitivityBuilderScheme(time_scheme_settings["alpha_bossak"].GetDouble(), domain_size, domain_size + 1)
|
|
177
|
+
|
|
178
|
+
sensitivity_builder = KratosMultiphysics.SensitivityBuilder(
|
|
179
|
+
self.settings["sensitivity_settings"],
|
|
180
|
+
self.main_model_part,
|
|
181
|
+
response_function,
|
|
182
|
+
self.sensitivity_builder_scheme
|
|
183
|
+
)
|
|
184
|
+
return sensitivity_builder
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Importing the Kratos Library
|
|
2
|
+
import KratosMultiphysics
|
|
3
|
+
from KratosMultiphysics.kratos_utilities import IssueDeprecationWarning
|
|
4
|
+
|
|
5
|
+
# Import applications
|
|
6
|
+
import KratosMultiphysics.FluidDynamicsApplication as KratosCFD
|
|
7
|
+
|
|
8
|
+
# Import base class file
|
|
9
|
+
from KratosMultiphysics.FluidDynamicsApplication.adjoint_fluid_solver import AdjointFluidSolver
|
|
10
|
+
|
|
11
|
+
class StabilizedAdjointFormulation(object):
|
|
12
|
+
"""Helper class to define stabilization-dependent parameters."""
|
|
13
|
+
def __init__(self,settings):
|
|
14
|
+
self.element_name = None
|
|
15
|
+
self.element_integrates_in_time = False
|
|
16
|
+
self.element_has_nodal_properties = False
|
|
17
|
+
self.process_data = {}
|
|
18
|
+
|
|
19
|
+
if settings.Has("element_type"):
|
|
20
|
+
formulation = settings["element_type"].GetString()
|
|
21
|
+
if formulation == "vms":
|
|
22
|
+
self._SetUpClassicAdjointVMS(settings)
|
|
23
|
+
elif formulation == "qsvms":
|
|
24
|
+
self._SetUpAdjointQSVMS(settings)
|
|
25
|
+
else:
|
|
26
|
+
print(settings)
|
|
27
|
+
raise RuntimeError("Argument \'element_type\' not found in stabilization settings.")
|
|
28
|
+
|
|
29
|
+
def SetProcessInfo(self,model_part):
|
|
30
|
+
for variable,value in self.process_data.items():
|
|
31
|
+
model_part.ProcessInfo[variable] = value
|
|
32
|
+
|
|
33
|
+
def _SetUpClassicAdjointVMS(self,settings):
|
|
34
|
+
IssueDeprecationWarning('StabilizedAdjointFormulation', 'Please use the "qsvms" formulation instead of "vms" formulation')
|
|
35
|
+
default_settings = KratosMultiphysics.Parameters(r"""{
|
|
36
|
+
"element_type": "vms",
|
|
37
|
+
"use_orthogonal_subscales": false,
|
|
38
|
+
"dynamic_tau" : 0.0
|
|
39
|
+
}""")
|
|
40
|
+
|
|
41
|
+
# if non-newtonian, there are some extra options
|
|
42
|
+
if settings.Has("non_newtonian_fluid_parameters"):
|
|
43
|
+
raise Exception("Adjoints are not yet supported for HerschelBulkleyVMS")
|
|
44
|
+
|
|
45
|
+
self.element_name = 'VMSAdjointElement'
|
|
46
|
+
|
|
47
|
+
settings.ValidateAndAssignDefaults(default_settings)
|
|
48
|
+
|
|
49
|
+
# set the nodal material properties flag
|
|
50
|
+
self.element_has_nodal_properties = True
|
|
51
|
+
|
|
52
|
+
self.process_data[KratosMultiphysics.DYNAMIC_TAU] = settings["dynamic_tau"].GetDouble()
|
|
53
|
+
use_oss = settings["use_orthogonal_subscales"].GetBool()
|
|
54
|
+
self.process_data[KratosMultiphysics.OSS_SWITCH] = int(use_oss)
|
|
55
|
+
|
|
56
|
+
def _SetUpAdjointQSVMS(self,settings):
|
|
57
|
+
default_settings = KratosMultiphysics.Parameters(r"""{
|
|
58
|
+
"element_type": "qsvms",
|
|
59
|
+
"use_orthogonal_subscales": false,
|
|
60
|
+
"dynamic_tau": 0.0,
|
|
61
|
+
"element_manages_time_integration": false
|
|
62
|
+
}""")
|
|
63
|
+
settings.ValidateAndAssignDefaults(default_settings)
|
|
64
|
+
|
|
65
|
+
if settings["element_manages_time_integration"].GetBool() == False:
|
|
66
|
+
self.element_name = "QSVMSAdjoint"
|
|
67
|
+
self.element_integrates_in_time = False
|
|
68
|
+
else:
|
|
69
|
+
raise Exception("Only bossak time integrations is supported with adjoints")
|
|
70
|
+
|
|
71
|
+
self.process_data[KratosMultiphysics.DYNAMIC_TAU] = settings["dynamic_tau"].GetDouble()
|
|
72
|
+
use_oss = settings["use_orthogonal_subscales"].GetBool()
|
|
73
|
+
self.process_data[KratosMultiphysics.OSS_SWITCH] = int(use_oss)
|
|
74
|
+
|
|
75
|
+
def CreateSolver(main_model_part, custom_settings):
|
|
76
|
+
return AdjointMonolithicSolver(main_model_part, custom_settings)
|
|
77
|
+
|
|
78
|
+
class AdjointMonolithicSolver(AdjointFluidSolver):
|
|
79
|
+
@classmethod
|
|
80
|
+
def GetDefaultParameters(cls):
|
|
81
|
+
# default settings string in json format
|
|
82
|
+
default_settings = KratosMultiphysics.Parameters("""
|
|
83
|
+
{
|
|
84
|
+
"solver_type" : "adjoint_monolithic_solver",
|
|
85
|
+
"model_part_name": "",
|
|
86
|
+
"domain_size": -1,
|
|
87
|
+
"scheme_settings" : {
|
|
88
|
+
"scheme_type" : "bossak"
|
|
89
|
+
},
|
|
90
|
+
"response_function_settings" : {
|
|
91
|
+
"response_type" : "drag"
|
|
92
|
+
},
|
|
93
|
+
"sensitivity_settings" : {},
|
|
94
|
+
"model_import_settings" : {
|
|
95
|
+
"input_type" : "mdpa",
|
|
96
|
+
"input_filename" : "unknown_name"
|
|
97
|
+
},
|
|
98
|
+
"enforce_element_and_conditions_replacement": true,
|
|
99
|
+
"material_import_settings": {
|
|
100
|
+
"materials_filename": ""
|
|
101
|
+
},
|
|
102
|
+
"linear_solver_settings" : {
|
|
103
|
+
"solver_type" : "amgcl"
|
|
104
|
+
},
|
|
105
|
+
"volume_model_part_name" : "volume_model_part",
|
|
106
|
+
"skin_parts" : [""],
|
|
107
|
+
"no_skin_parts" : [""],
|
|
108
|
+
"echo_level" : 0,
|
|
109
|
+
"time_stepping" : {
|
|
110
|
+
"automatic_time_step" : false,
|
|
111
|
+
"time_step" : -0.1
|
|
112
|
+
},
|
|
113
|
+
"consider_periodic_conditions": false,
|
|
114
|
+
"assign_neighbour_elements_to_conditions": true,
|
|
115
|
+
"formulation": {
|
|
116
|
+
"element_type": "qsvms"
|
|
117
|
+
}
|
|
118
|
+
}""")
|
|
119
|
+
|
|
120
|
+
default_settings.AddMissingParameters(super().GetDefaultParameters())
|
|
121
|
+
return default_settings
|
|
122
|
+
|
|
123
|
+
def __init__(self, model, custom_settings):
|
|
124
|
+
super().__init__(model,custom_settings)
|
|
125
|
+
self.element_has_nodal_properties = True
|
|
126
|
+
|
|
127
|
+
self._SetFormulation()
|
|
128
|
+
|
|
129
|
+
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, "Construction of AdjointMonolithicSolver finished.")
|
|
130
|
+
|
|
131
|
+
def AddVariables(self):
|
|
132
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.VELOCITY)
|
|
133
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.MESH_VELOCITY)
|
|
134
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.ACCELERATION)
|
|
135
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.PRESSURE)
|
|
136
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.NORMAL)
|
|
137
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosCFD.ADJOINT_FLUID_VECTOR_1)
|
|
138
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosCFD.ADJOINT_FLUID_VECTOR_2)
|
|
139
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosCFD.ADJOINT_FLUID_VECTOR_3)
|
|
140
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosCFD.AUX_ADJOINT_FLUID_VECTOR_1)
|
|
141
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosCFD.ADJOINT_FLUID_SCALAR_1)
|
|
142
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.VISCOSITY)
|
|
143
|
+
# TODO: Remove when old VMS elements are removed.
|
|
144
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.ADVPROJ)
|
|
145
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DIVPROJ)
|
|
146
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DENSITY)
|
|
147
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.BODY_FORCE)
|
|
148
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.EXTERNAL_PRESSURE)
|
|
149
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.SHAPE_SENSITIVITY)
|
|
150
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.NORMAL_SENSITIVITY)
|
|
151
|
+
|
|
152
|
+
if self.settings["consider_periodic_conditions"].GetBool() == True:
|
|
153
|
+
self.main_model_part.AddNodalSolutionStepVariable(KratosCFD.PATCH_INDEX)
|
|
154
|
+
|
|
155
|
+
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, "Adjoint fluid solver variables added correctly.")
|
|
156
|
+
|
|
157
|
+
def Initialize(self):
|
|
158
|
+
# If the solver requires an instance of the stabilized formulation class, set the process info variables
|
|
159
|
+
if hasattr(self, 'formulation'):
|
|
160
|
+
self.formulation.SetProcessInfo(self.GetComputingModelPart())
|
|
161
|
+
|
|
162
|
+
# Construct and set the solution strategy
|
|
163
|
+
solution_strategy = self._GetSolutionStrategy()
|
|
164
|
+
solution_strategy.SetEchoLevel(self.settings["echo_level"].GetInt())
|
|
165
|
+
|
|
166
|
+
# clear RELAXED_ACCELERATION if it is a steady adjoint problem
|
|
167
|
+
scheme_type = self.settings["scheme_settings"]["scheme_type"].GetString()
|
|
168
|
+
if (scheme_type == "steady"):
|
|
169
|
+
KratosMultiphysics.VariableUtils().SetNonHistoricalVariableToZero(KratosMultiphysics.RELAXED_ACCELERATION, self.main_model_part.Nodes)
|
|
170
|
+
|
|
171
|
+
# Initialize the strategy and adjoint utilities
|
|
172
|
+
solution_strategy.Initialize()
|
|
173
|
+
self.GetResponseFunction().Initialize()
|
|
174
|
+
self.GetSensitivityBuilder().Initialize()
|
|
175
|
+
|
|
176
|
+
domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]
|
|
177
|
+
KratosMultiphysics.NormalCalculationUtils().CalculateOnSimplex(self.main_model_part.Conditions, domain_size)
|
|
178
|
+
KratosMultiphysics.NormalCalculationUtils().CalculateNormalShapeDerivativesOnSimplex(self.main_model_part.Conditions, domain_size)
|
|
179
|
+
|
|
180
|
+
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, "Solver initialization finished.")
|
|
181
|
+
|
|
182
|
+
def _CreateScheme(self):
|
|
183
|
+
response_function = self.GetResponseFunction()
|
|
184
|
+
scheme_type = self.settings["scheme_settings"]["scheme_type"].GetString()
|
|
185
|
+
domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]
|
|
186
|
+
|
|
187
|
+
# the schemes used in fluid supports SLIP conditions which rotates element/condition
|
|
188
|
+
# matrices based on nodal NORMAL. Hence, the consistent adjoints also need to
|
|
189
|
+
# rotate adjoint element/condition matrices accordingly. Therefore, following
|
|
190
|
+
# schemes are used.
|
|
191
|
+
if scheme_type == "bossak":
|
|
192
|
+
scheme = KratosCFD.VelocityBossakAdjointScheme(self.settings["scheme_settings"], response_function, domain_size, domain_size + 1)
|
|
193
|
+
elif scheme_type == "steady":
|
|
194
|
+
scheme = KratosCFD.SimpleSteadyAdjointScheme(response_function, domain_size, domain_size + 1)
|
|
195
|
+
else:
|
|
196
|
+
raise Exception("Invalid scheme_type: " + scheme_type)
|
|
197
|
+
return scheme
|
|
198
|
+
|
|
199
|
+
def _CreateSolutionStrategy(self):
|
|
200
|
+
computing_model_part = self.GetComputingModelPart()
|
|
201
|
+
time_scheme = self._GetScheme()
|
|
202
|
+
builder_and_solver = self._GetBuilderAndSolver()
|
|
203
|
+
calculate_reaction_flag = False
|
|
204
|
+
reform_dof_set_at_each_step = False
|
|
205
|
+
calculate_norm_dx_flag = False
|
|
206
|
+
move_mesh_flag = False
|
|
207
|
+
return KratosMultiphysics.ResidualBasedLinearStrategy(
|
|
208
|
+
computing_model_part,
|
|
209
|
+
time_scheme,
|
|
210
|
+
builder_and_solver,
|
|
211
|
+
calculate_reaction_flag,
|
|
212
|
+
reform_dof_set_at_each_step,
|
|
213
|
+
calculate_norm_dx_flag,
|
|
214
|
+
move_mesh_flag)
|
|
215
|
+
|
|
216
|
+
def _SetFormulation(self):
|
|
217
|
+
self.formulation = StabilizedAdjointFormulation(self.settings["formulation"])
|
|
218
|
+
self.element_name = self.formulation.element_name
|
|
219
|
+
self.element_has_nodal_properties = self.formulation.element_has_nodal_properties
|
|
220
|
+
|
|
221
|
+
# TODO: at the moment, qs_vms with SLIP adjoints are not supported, only no slip is supported
|
|
222
|
+
# because AdjointMonolithicWallCondition is based on nodal nu, where as QSVMS is based on
|
|
223
|
+
# CLs. There need to update navier_stokes_wall_condition.h with adjoints
|
|
224
|
+
self.condition_name = "AdjointMonolithicWallCondition"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import KratosMultiphysics
|
|
2
|
+
import KratosMultiphysics.FluidDynamicsApplication as KratosFluid
|
|
3
|
+
|
|
4
|
+
def Factory(settings, Model):
|
|
5
|
+
if(type(settings) != KratosMultiphysics.Parameters):
|
|
6
|
+
raise Exception("expected input shall be a Parameters object, encapsulating a json string")
|
|
7
|
+
return ApplyBoussinesqForceProcess(Model, settings["Parameters"])
|
|
8
|
+
|
|
9
|
+
class ApplyBoussinesqForceProcess(KratosMultiphysics.Process):
|
|
10
|
+
|
|
11
|
+
def __init__(self, Model, settings):
|
|
12
|
+
|
|
13
|
+
KratosMultiphysics.Process.__init__(self)
|
|
14
|
+
|
|
15
|
+
# Check the default values
|
|
16
|
+
default_settings = KratosMultiphysics.Parameters( """
|
|
17
|
+
{
|
|
18
|
+
"model_part_name" : "CHOOSE_FLUID_MODELPART_NAME",
|
|
19
|
+
"gravity" : [0.0,0.0,0.0],
|
|
20
|
+
"ambient_temperature" : 273.0
|
|
21
|
+
} """ )
|
|
22
|
+
|
|
23
|
+
# Note: if the thermal expansion coefficient is not provided, it is computed as
|
|
24
|
+
# 1/AMBIENT_TEMPERATURE which is the usual assumption for perfect gases.
|
|
25
|
+
if (settings.Has("thermal_expansion_coefficient")):
|
|
26
|
+
default_settings.AddEmptyValue("thermal_expansion_coefficient").SetDouble(0.0)
|
|
27
|
+
|
|
28
|
+
settings.ValidateAndAssignDefaults(default_settings)
|
|
29
|
+
|
|
30
|
+
# Get the fluid model part from the Model container
|
|
31
|
+
self.fluid_model_part = Model[settings["model_part_name"].GetString()]
|
|
32
|
+
|
|
33
|
+
# Save the ambient temperature in the fluid model part ProcessInfo
|
|
34
|
+
ambient_temperature = settings["ambient_temperature"].GetDouble()
|
|
35
|
+
self.fluid_model_part.ProcessInfo.SetValue(KratosMultiphysics.AMBIENT_TEMPERATURE, ambient_temperature)
|
|
36
|
+
|
|
37
|
+
# Set the Boussinesq force process
|
|
38
|
+
self.BoussinesqForceProcess = KratosFluid.BoussinesqForceProcess(self.fluid_model_part, settings)
|
|
39
|
+
|
|
40
|
+
def ExecuteInitialize(self):
|
|
41
|
+
self.BoussinesqForceProcess.ExecuteInitialize()
|
|
42
|
+
|
|
43
|
+
def ExecuteInitializeSolutionStep(self):
|
|
44
|
+
self.BoussinesqForceProcess.ExecuteInitializeSolutionStep()
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import KratosMultiphysics
|
|
2
|
+
from KratosMultiphysics.FluidDynamicsApplication import ApplyCompressibleNavierStokesBoundaryConditionsProcess
|
|
3
|
+
|
|
4
|
+
def Factory(settings, Model):
|
|
5
|
+
if not isinstance(settings, KratosMultiphysics.Parameters):
|
|
6
|
+
raise Exception("expected input shall be a Parameters object, encapsulating a json string")
|
|
7
|
+
return ApplyCompressibleNavierStokesBoundaryConditionsProcess(Model, settings["Parameters"])
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import KratosMultiphysics
|
|
2
|
+
import KratosMultiphysics.FluidDynamicsApplication as KratosFluid
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
def Factory(settings, Model):
|
|
6
|
+
if(type(settings) != KratosMultiphysics.Parameters):
|
|
7
|
+
raise Exception("expected input shall be a Parameters object, encapsulating a json string")
|
|
8
|
+
return ApplyDistanceModificationProcess(Model, settings["Parameters"])
|
|
9
|
+
|
|
10
|
+
class ApplyDistanceModificationProcess(KratosMultiphysics.Process):
|
|
11
|
+
|
|
12
|
+
def __init__(self, Model, settings):
|
|
13
|
+
|
|
14
|
+
msg = "The python distance modification process is deprecated.\n"
|
|
15
|
+
msg += "Please use (or implement) the \'distance_modification_settings\' in the \'solver_settings\'.\n"
|
|
16
|
+
KratosMultiphysics.Logger.PrintWarning("ApplyDistanceModificationProcess",msg)
|
|
17
|
+
|
|
18
|
+
KratosMultiphysics.Process.__init__(self)
|
|
19
|
+
|
|
20
|
+
default_parameters = KratosMultiphysics.Parameters( """
|
|
21
|
+
{
|
|
22
|
+
"model_part_name" : "CHOOSE_FLUID_MODELPART_NAME",
|
|
23
|
+
"distance_threshold" : 0.01,
|
|
24
|
+
"continuous_distance" : true,
|
|
25
|
+
"check_at_each_time_step" : false,
|
|
26
|
+
"avoid_almost_empty_elements" : true,
|
|
27
|
+
"deactivate_full_negative_elements" : true,
|
|
28
|
+
"recover_original_distance_at_each_step" : false
|
|
29
|
+
} """ )
|
|
30
|
+
|
|
31
|
+
settings.ValidateAndAssignDefaults(default_parameters);
|
|
32
|
+
|
|
33
|
+
self.fluid_model_part = Model[settings["model_part_name"].GetString()]
|
|
34
|
+
self.DistanceModificationProcess = KratosFluid.DistanceModificationProcess(self.fluid_model_part, settings)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def ExecuteInitialize(self):
|
|
38
|
+
self.DistanceModificationProcess.ExecuteInitialize()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def ExecuteBeforeSolutionLoop(self):
|
|
42
|
+
self.DistanceModificationProcess.ExecuteBeforeSolutionLoop()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def ExecuteInitializeSolutionStep(self):
|
|
46
|
+
self.DistanceModificationProcess.ExecuteInitializeSolutionStep()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def ExecuteFinalizeSolutionStep(self):
|
|
50
|
+
self.DistanceModificationProcess.ExecuteFinalizeSolutionStep()
|