From 9757fb016dd6f7f02b2daa5577b33a97a80f5dbd Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Fri, 16 Jan 2026 09:23:49 +0100 Subject: [PATCH 01/10] add LIFT_COEFFICIENT to CFD variables --- kratos/includes/cfd_variables.h | 1 + kratos/python/add_cfd_variables_to_python.cpp | 1 + kratos/sources/cfd_variables.cpp | 2 ++ 3 files changed, 4 insertions(+) diff --git a/kratos/includes/cfd_variables.h b/kratos/includes/cfd_variables.h index e7d7894e4141..b7c2ad655d08 100644 --- a/kratos/includes/cfd_variables.h +++ b/kratos/includes/cfd_variables.h @@ -47,6 +47,7 @@ namespace Kratos KRATOS_DEFINE_VARIABLE( double, TURBULENT_VISCOSITY ) KRATOS_DEFINE_VARIABLE( double, Y_WALL) KRATOS_DEFINE_VARIABLE( double, PRESSURE_COEFFICIENT) + KRATOS_DEFINE_VARIABLE( double, LIFT_COEFFICIENT) KRATOS_DEFINE_VARIABLE( double, ARTIFICIAL_MASS_DIFFUSIVITY) KRATOS_DEFINE_VARIABLE( double, ARTIFICIAL_CONDUCTIVITY) KRATOS_DEFINE_VARIABLE( double, ARTIFICIAL_BULK_VISCOSITY) diff --git a/kratos/python/add_cfd_variables_to_python.cpp b/kratos/python/add_cfd_variables_to_python.cpp index 35b85743614a..dc3cd1cc2634 100644 --- a/kratos/python/add_cfd_variables_to_python.cpp +++ b/kratos/python/add_cfd_variables_to_python.cpp @@ -42,6 +42,7 @@ namespace Kratos::Python KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, TURBULENT_VISCOSITY ); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, Y_WALL); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, PRESSURE_COEFFICIENT); + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LIFT_COEFFICIENT); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ARTIFICIAL_MASS_DIFFUSIVITY); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ARTIFICIAL_CONDUCTIVITY); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ARTIFICIAL_BULK_VISCOSITY); diff --git a/kratos/sources/cfd_variables.cpp b/kratos/sources/cfd_variables.cpp index fea78674488f..97b2d05ee3fb 100644 --- a/kratos/sources/cfd_variables.cpp +++ b/kratos/sources/cfd_variables.cpp @@ -37,6 +37,7 @@ KRATOS_CREATE_VARIABLE( double, MOLECULAR_VISCOSITY ) KRATOS_CREATE_VARIABLE( double, TURBULENT_VISCOSITY ) KRATOS_CREATE_VARIABLE( double, Y_WALL) KRATOS_CREATE_VARIABLE( double, PRESSURE_COEFFICIENT) +KRATOS_CREATE_VARIABLE( double, LIFT_COEFFICIENT) KRATOS_CREATE_VARIABLE( double, ARTIFICIAL_MASS_DIFFUSIVITY) KRATOS_CREATE_VARIABLE( double, ARTIFICIAL_CONDUCTIVITY) KRATOS_CREATE_VARIABLE( double, ARTIFICIAL_BULK_VISCOSITY) @@ -76,6 +77,7 @@ void KratosApplication::RegisterCFDVariables() KRATOS_REGISTER_VARIABLE( ARTIFICIAL_BULK_VISCOSITY ) KRATOS_REGISTER_VARIABLE( ARTIFICIAL_DYNAMIC_VISCOSITY ) KRATOS_REGISTER_VARIABLE( PRESSURE_COEFFICIENT ) + KRATOS_REGISTER_VARIABLE( LIFT_COEFFICIENT ) KRATOS_REGISTER_VARIABLE( OSS_SWITCH ) // Legacy variables From 5bdc562297e0d0cced85cdb6f88e619f2b671d36 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Fri, 16 Jan 2026 09:26:09 +0100 Subject: [PATCH 02/10] add compute lift coefficient process --- .../compute_lift_coefficient_process.cpp | 145 +++++++++++++ .../compute_lift_coefficient_process.h | 191 ++++++++++++++++++ .../add_custom_processes_to_python.cpp | 5 + .../compute_lift_coefficient_process.py | 8 + 4 files changed, 349 insertions(+) create mode 100644 applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.cpp create mode 100644 applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.h create mode 100644 applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.cpp b/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.cpp new file mode 100644 index 000000000000..b01bdcc832fb --- /dev/null +++ b/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.cpp @@ -0,0 +1,145 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Eduard Gómez +// +// + +// System includes + +// External includes + +// Project includes + +// Application includes +#include "compute_lift_coefficient_process.h" +#include "fluid_dynamics_application_variables.h" +#include "utilities/variable_utils.h" + + +namespace Kratos +{ + +ComputeLiftCoefficientProcess::ComputeLiftCoefficientProcess( + Model &rModel, + Parameters Params) + : Process(), + mrModelPart(rModel.GetModelPart(Params["model_part_name"].GetString())) +{ + // Check default settings + KRATOS_TRY + + Params.ValidateAndAssignDefaults(GetDefaultParameters()); + + ReadFreestreamValues(Params); + + KRATOS_CATCH("") +} + + +const Parameters ComputeLiftCoefficientProcess::GetDefaultParameters() const +{ + return Parameters( R"( + { + "model_part_name" : "PLEASE_PROVIDE_A_MODELPART_NAME", + "reference_surface" : 0.0, + "angle_of_attack" : 0.0 + })" ); +} + +void ComputeLiftCoefficientProcess::ReadFreestreamValues(const Parameters& rParams) +{ + constexpr double tol = 1e-12; + + KRATOS_ERROR_IF_NOT(rParams.Has("reference_surface")) + << "Missing required parameter 'reference_surface'."; + + mReference_Surface = rParams["reference_surface"].GetDouble(); + KRATOS_ERROR_IF(std::abs(mReference_Surface) <= tol) + << "Invalid value for 'reference_surface' = " << mReference_Surface + << ". It must be non-zero."; + + KRATOS_ERROR_IF_NOT(rParams.Has("angle_of_attack")) + << "Missing required parameter 'angle_of_attack'."; + + mAngle_of_Attack = rParams["angle_of_attack"].GetDouble(); +} + + +void ComputeLiftCoefficientProcess::ExecuteBeforeOutputStep() +{ + Execute(); +} + + +void ComputeLiftCoefficientProcess::Execute() +{ + KRATOS_TRY; + + double angle_rad = mAngle_of_Attack*3.14159/(180); + std::vector e_lift(3); // direction of the lift + e_lift[0] = std::sin(angle_rad)*-1; + e_lift[1] = 0; + e_lift[2] = std::cos(angle_rad); + + + double C_L = 0.0; + double S = 0.0; + double S_w = 0.0; + + for (auto it_cond = mrModelPart.ConditionsBegin(); it_cond != mrModelPart.ConditionsEnd(); ++it_cond) + { + auto& r_geometry = it_cond->GetGeometry(); + const auto integration_method = it_cond->GetIntegrationMethod(); + const auto& r_integration_points = r_geometry.IntegrationPoints(integration_method); + const auto& r_shape_funct = r_geometry.ShapeFunctionsValues(integration_method); + + double cp_integrated = 0.0; + + // Loop integration points + for (unsigned int gp = 0; gp < r_integration_points.size(); ++gp) + { + const double weight = r_integration_points[gp].Weight(); + + // Cp at integration point + double cp_gp = 0.0; + for (unsigned int i_node = 0; i_node < r_geometry.PointsNumber(); ++i_node) + { + const double cp_node = r_geometry[i_node].GetValue(PRESSURE_COEFFICIENT); + cp_gp += r_shape_funct(gp, i_node) * cp_node; + } + + S += r_geometry.DeterminantOfJacobian(gp, integration_method); + S_w += weight * r_geometry.DeterminantOfJacobian(gp, integration_method); + cp_integrated += cp_gp * weight * r_geometry.DeterminantOfJacobian(gp, integration_method); + } + + + // Normal of the element + array_1d normal_el; + normal_el = r_geometry.Normal(r_geometry.Center()); // Non unit vector! + double norm = std::sqrt(normal_el[0]*normal_el[0] + normal_el[1]*normal_el[1] + normal_el[2]*normal_el[2]); + normal_el /= norm; + + const double lift_projection = normal_el[0] * e_lift[0] + normal_el[1] * e_lift[1] + normal_el[2] * e_lift[2]; + + C_L -= cp_integrated * lift_projection; + } + + C_L = C_L/mReference_Surface; + mrModelPart.SetValue(LIFT_COEFFICIENT, C_L); + std::cout << "S_w: " << S_w << std::endl; + std::cout << "S: " << S << std::endl; + std::cout << "C_L: " << C_L << std::endl; + KRATOS_CATCH(""); + +} + + +} \ No newline at end of file diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.h b/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.h new file mode 100644 index 000000000000..3cfbbc70b956 --- /dev/null +++ b/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.h @@ -0,0 +1,191 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Eduard Gómez +// +// + +#ifndef KRATOS_COMPUTE_LIFT_COEFFICIENT_PROCESS_H +#define KRATOS_COMPUTE_LIFT_COEFFICIENT_PROCESS_H + +// System includes +#include +#include + +// External includes + +// Project includes +#include "includes/model_part.h" +#include "includes/define.h" +#include "processes/process.h" +#include "includes/kratos_parameters.h" + +// Application includes + + +namespace Kratos +{ +///@addtogroup FluidDynamicsApplication +///@{ + +///@name Kratos Globals +///@{ + +///@} +///@name Type Definitions +///@{ + + +///@} +///@name Enum's +///@{ + +///@} +///@name Functions +///@{ + +///@} +///@name Kratos Classes +///@{ + +/// This process computes the lift coefficient as a function of reference fluid properties +class KRATOS_API(FLUID_DYNAMICS_APPLICATION) ComputeLiftCoefficientProcess : public Process +{ +public: + ///@name Type Definitions + ///@{ + using NodeType = ModelPart::NodeType; + + /// Pointer definition of ComputeLiftCoefficientProcess + KRATOS_CLASS_POINTER_DEFINITION(ComputeLiftCoefficientProcess); + + ///@} + ///@name Life Cycle + ///@{ + + /// Constructor with Kratos model + ComputeLiftCoefficientProcess( + Model& rModel, + Parameters Params); + + /// Destructor. + ~ComputeLiftCoefficientProcess() override {} + + ///@} + ///@name Operators + ///@{ + + ///@} + ///@name Operations + ///@{ + + const Parameters GetDefaultParameters() const override; + + void Execute() override; + + void ExecuteBeforeOutputStep() override; + + ///@} + ///@name Access + ///@{ + + ///@} + ///@name Inquiry + ///@{ + + ///@} + ///@name Input and output + ///@{ + + /// Turn back information as a string. + std::string Info() const override + { + std::stringstream buffer; + buffer << "ComputeLiftCoefficientProcess" ; + return buffer.str(); + } + + /// Print information about this object. + void PrintInfo(std::ostream& rOStream) const override {rOStream << "ComputeLiftCoefficientProcess";} + + /// Print object's data. + void PrintData(std::ostream& rOStream) const override {} + + + ///@} + ///@name Friends + ///@{ + + ///@} + +private: + ///@name Static Member Variables + ///@{ + + ///@} + ///@name Member Variables + ///@{ + + ModelPart& mrModelPart; + double mAngle_of_Attack = 0.0; // Angle of attack + double mReference_Surface = 0.0; // Reference surface + std::function mGetPressureCoefficient; + + ///@} + ///@name Private Operators + ///@{ + + ///@} + ///@name Private Operations + ///@{ + + void ReadFreestreamValues(const Parameters& Params); + + ///@} + ///@name Private Access + ///@{ + + + ///@} + ///@name Private Inquiry + ///@{ + + + ///@} + ///@name Un accessible methods + ///@{ + + /// Default constructor. + ComputeLiftCoefficientProcess() = delete; + + /// Assignment operator. + ComputeLiftCoefficientProcess& operator=(ComputeLiftCoefficientProcess const& rOther) = delete; + + /// Copy constructor. + ComputeLiftCoefficientProcess(ComputeLiftCoefficientProcess const& rOther) = delete; + + ///@} + +}; // Class ComputeLiftCoefficientProcess + +///@} +///@name Type Definitions +///@{ + +///@} +///@name Input and output +///@{ + +///@} + +///@} addtogroup block + +}; // namespace Kratos. + +#endif // KRATOS_COMUTE_LIFT_COEFFICIENT_PROCESS_H diff --git a/applications/FluidDynamicsApplication/custom_python/add_custom_processes_to_python.cpp b/applications/FluidDynamicsApplication/custom_python/add_custom_processes_to_python.cpp index e85de405bee5..161f29230af9 100644 --- a/applications/FluidDynamicsApplication/custom_python/add_custom_processes_to_python.cpp +++ b/applications/FluidDynamicsApplication/custom_python/add_custom_processes_to_python.cpp @@ -28,6 +28,7 @@ #include "custom_processes/boussinesq_force_process.h" #include "custom_processes/calculate_levelset_consistent_nodal_gradient_process.h" #include "custom_processes/compute_pressure_coefficient_process.h" +#include "custom_processes/compute_lift_coefficient_process.h" #include "custom_processes/distance_modification_process.h" #include "custom_processes/distance_smoothing_process.h" #include "custom_processes/embedded_nodes_initialization_process.h" @@ -181,6 +182,10 @@ void AddCustomProcessesToPython(pybind11::module& m) .def(py::init()) ; + py::class_(m, "ComputeLiftCoefficientProcess") + .def(py::init()) + ; + py::class_(m, "ComputeYPlusProcess") .def(py::init()) ; diff --git a/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py b/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py new file mode 100644 index 000000000000..d893c876cb8f --- /dev/null +++ b/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py @@ -0,0 +1,8 @@ +import KratosMultiphysics +from KratosMultiphysics.FluidDynamicsApplication import ComputeLiftCoefficientProcess + + +def Factory(settings, Model): + if not isinstance(settings, KratosMultiphysics.Parameters): + raise Exception("expected input shall be a Parameters object, encapsulating a json string") + return ComputeLiftCoefficientProcess(Model, settings["Parameters"]) From ec6b03784b161d264200ceca0856a9fd05c877a1 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Fri, 16 Jan 2026 17:17:54 +0100 Subject: [PATCH 03/10] remove the variables from the core --- kratos/includes/cfd_variables.h | 1 - kratos/python/add_cfd_variables_to_python.cpp | 1 - kratos/sources/cfd_variables.cpp | 2 -- 3 files changed, 4 deletions(-) diff --git a/kratos/includes/cfd_variables.h b/kratos/includes/cfd_variables.h index b7c2ad655d08..e7d7894e4141 100644 --- a/kratos/includes/cfd_variables.h +++ b/kratos/includes/cfd_variables.h @@ -47,7 +47,6 @@ namespace Kratos KRATOS_DEFINE_VARIABLE( double, TURBULENT_VISCOSITY ) KRATOS_DEFINE_VARIABLE( double, Y_WALL) KRATOS_DEFINE_VARIABLE( double, PRESSURE_COEFFICIENT) - KRATOS_DEFINE_VARIABLE( double, LIFT_COEFFICIENT) KRATOS_DEFINE_VARIABLE( double, ARTIFICIAL_MASS_DIFFUSIVITY) KRATOS_DEFINE_VARIABLE( double, ARTIFICIAL_CONDUCTIVITY) KRATOS_DEFINE_VARIABLE( double, ARTIFICIAL_BULK_VISCOSITY) diff --git a/kratos/python/add_cfd_variables_to_python.cpp b/kratos/python/add_cfd_variables_to_python.cpp index dc3cd1cc2634..35b85743614a 100644 --- a/kratos/python/add_cfd_variables_to_python.cpp +++ b/kratos/python/add_cfd_variables_to_python.cpp @@ -42,7 +42,6 @@ namespace Kratos::Python KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, TURBULENT_VISCOSITY ); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, Y_WALL); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, PRESSURE_COEFFICIENT); - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LIFT_COEFFICIENT); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ARTIFICIAL_MASS_DIFFUSIVITY); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ARTIFICIAL_CONDUCTIVITY); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ARTIFICIAL_BULK_VISCOSITY); diff --git a/kratos/sources/cfd_variables.cpp b/kratos/sources/cfd_variables.cpp index 97b2d05ee3fb..fea78674488f 100644 --- a/kratos/sources/cfd_variables.cpp +++ b/kratos/sources/cfd_variables.cpp @@ -37,7 +37,6 @@ KRATOS_CREATE_VARIABLE( double, MOLECULAR_VISCOSITY ) KRATOS_CREATE_VARIABLE( double, TURBULENT_VISCOSITY ) KRATOS_CREATE_VARIABLE( double, Y_WALL) KRATOS_CREATE_VARIABLE( double, PRESSURE_COEFFICIENT) -KRATOS_CREATE_VARIABLE( double, LIFT_COEFFICIENT) KRATOS_CREATE_VARIABLE( double, ARTIFICIAL_MASS_DIFFUSIVITY) KRATOS_CREATE_VARIABLE( double, ARTIFICIAL_CONDUCTIVITY) KRATOS_CREATE_VARIABLE( double, ARTIFICIAL_BULK_VISCOSITY) @@ -77,7 +76,6 @@ void KratosApplication::RegisterCFDVariables() KRATOS_REGISTER_VARIABLE( ARTIFICIAL_BULK_VISCOSITY ) KRATOS_REGISTER_VARIABLE( ARTIFICIAL_DYNAMIC_VISCOSITY ) KRATOS_REGISTER_VARIABLE( PRESSURE_COEFFICIENT ) - KRATOS_REGISTER_VARIABLE( LIFT_COEFFICIENT ) KRATOS_REGISTER_VARIABLE( OSS_SWITCH ) // Legacy variables From 152a2c9b6b5b41d69e8276b939ed4531472c5e5b Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Fri, 16 Jan 2026 17:20:25 +0100 Subject: [PATCH 04/10] add the variables to the cfd application --- .../custom_python/fluid_dynamics_python_application.cpp | 8 ++++++++ .../fluid_dynamics_application_variables.cpp | 7 +++++++ .../fluid_dynamics_application_variables.h | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/applications/FluidDynamicsApplication/custom_python/fluid_dynamics_python_application.cpp b/applications/FluidDynamicsApplication/custom_python/fluid_dynamics_python_application.cpp index 81d1d7c493e0..bdca9db22258 100644 --- a/applications/FluidDynamicsApplication/custom_python/fluid_dynamics_python_application.cpp +++ b/applications/FluidDynamicsApplication/custom_python/fluid_dynamics_python_application.cpp @@ -148,6 +148,14 @@ PYBIND11_MODULE(KratosFluidDynamicsApplication,m) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m,SPECTRAL_RADIUS_LIMIT) KRATOS_REGISTER_IN_PYTHON_3D_VARIABLE_WITH_COMPONENTS(m, INLET_NORMAL); KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, Y_PLUS) + + // Aerodynamic coefficients + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LIFT_COEFFICIENT); + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, DRAG_COEFFICIENT); + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LATERAL_FORCE_COEFFICIENT); + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ROLLING_MOMENT_COEFFICIENT); + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, PITCHING_MOMENT_COEFFICIENT); + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, YAWING_MOMENT_COEFFICIENT); } diff --git a/applications/FluidDynamicsApplication/fluid_dynamics_application_variables.cpp b/applications/FluidDynamicsApplication/fluid_dynamics_application_variables.cpp index d91f92fa0625..e9c2d62a6273 100644 --- a/applications/FluidDynamicsApplication/fluid_dynamics_application_variables.cpp +++ b/applications/FluidDynamicsApplication/fluid_dynamics_application_variables.cpp @@ -134,4 +134,11 @@ KRATOS_CREATE_VARIABLE( double, DISTANCE_CORRECTION ) KRATOS_CREATE_VARIABLE( double, Y_PLUS ) +// Aerodynamic coefficients +KRATOS_CREATE_VARIABLE( double, LIFT_COEFFICIENT ) +KRATOS_CREATE_VARIABLE( double, DRAG_COEFFICIENT ) +KRATOS_CREATE_VARIABLE( double, LATERAL_FORCE_COEFFICIENT ) +KRATOS_CREATE_VARIABLE( double, ROLLING_MOMENT_COEFFICIENT ) +KRATOS_CREATE_VARIABLE( double, PITCHING_MOMENT_COEFFICIENT ) +KRATOS_CREATE_VARIABLE( double, YAWING_MOMENT_COEFFICIENT ) } diff --git a/applications/FluidDynamicsApplication/fluid_dynamics_application_variables.h b/applications/FluidDynamicsApplication/fluid_dynamics_application_variables.h index 378e41fabf49..0b8043347431 100644 --- a/applications/FluidDynamicsApplication/fluid_dynamics_application_variables.h +++ b/applications/FluidDynamicsApplication/fluid_dynamics_application_variables.h @@ -142,4 +142,12 @@ KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, bool, MOMENTUM_C KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, double, DISTANCE_CORRECTION ) KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, double, Y_PLUS ) + +// Aerodynamic coefficients +KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, double, LIFT_COEFFICIENT ) +KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, double, DRAG_COEFFICIENT ) +KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, double, LATERAL_FORCE_COEFFICIENT ) +KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, double, ROLLING_MOMENT_COEFFICIENT ) +KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, double, PITCHING_MOMENT_COEFFICIENT ) +KRATOS_DEFINE_APPLICATION_VARIABLE( FLUID_DYNAMICS_APPLICATION, double, YAWING_MOMENT_COEFFICIENT ) } From 8b6382e168d2773cca44396a83119192d60eedc1 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 19 Jan 2026 11:07:59 +0100 Subject: [PATCH 05/10] change process name to compute aerodynamic coefficients --- ...mpute_aerodynamic_coefficients_process.cpp | 195 ++++++++++++++++++ ...compute_aerodynamic_coefficients_process.h | 194 +++++++++++++++++ .../add_custom_processes_to_python.cpp | 4 +- .../compute_lift_coefficient_process.py | 4 +- 4 files changed, 393 insertions(+), 4 deletions(-) create mode 100644 applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.cpp create mode 100644 applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.cpp b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.cpp new file mode 100644 index 000000000000..896b4e1cef42 --- /dev/null +++ b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.cpp @@ -0,0 +1,195 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Juan I. Camarotti +// +// + +// System includes + +// External includes + +// Project includes + +// Application includes +#include "compute_aerodynamic_coefficients_process.h" +#include "fluid_dynamics_application_variables.h" +#include "utilities/variable_utils.h" + + +namespace Kratos +{ + +ComputeAerodynamicCoefficientsProcess::ComputeAerodynamicCoefficientsProcess( + Model &rModel, + Parameters Params) + : Process(), + mrModelPart(rModel.GetModelPart(Params["model_part_name"].GetString())) +{ + // Check default settings + KRATOS_TRY + + Params.ValidateAndAssignDefaults(GetDefaultParameters()); + + ReadFreestreamValues(Params); + + KRATOS_CATCH("") +} + + +const Parameters ComputeAerodynamicCoefficientsProcess::GetDefaultParameters() const +{ + return Parameters( R"( + { + "model_part_name" : "PLEASE_PROVIDE_A_MODELPART_NAME", + "reference_surface" : 0.0, + "reference_chord" : 1.0, + "reference_span" : 1.0, + "moment_reference_point" : [0.0, 0.0, 0.0], + "freestream_dynamic_pressure" : 1.0, + "angle_of_attack" : 0.0, + "sideslip_angle" : 0.0 + })" ); +} + +void ComputeAerodynamicCoefficientsProcess::ReadFreestreamValues(const Parameters& rParams) +{ + constexpr double tol = 1e-12; + + mReference_Surface = rParams["reference_surface"].GetDouble(); + KRATOS_ERROR_IF(std::abs(mReference_Surface) <= tol) + << "Invalid value for 'reference_surface' = " << mReference_Surface << "."; + + mReference_Chord = rParams["reference_chord"].GetDouble(); + KRATOS_ERROR_IF(std::abs(mReference_Chord) <= tol) + << "Invalid value for 'reference_chord' = " << mReference_Chord << "."; + + mReference_Span = rParams["reference_span"].GetDouble(); + KRATOS_ERROR_IF(std::abs(mReference_Span) <= tol) + << "Invalid value for 'reference_span' = " << mReference_Span << "."; + + mQInf = rParams["freestream_dynamic_pressure"].GetDouble(); + KRATOS_ERROR_IF(std::abs(mQInf) <= tol) + << "Invalid value for 'freestream_dynamic_pressure' = " << mQInf << "."; + + mAngleOfAttack = rParams["angle_of_attack"].GetDouble(); + mSideslipAngle = rParams["sideslip_angle"].GetDouble(); + + const auto& r_mrp = rParams["moment_reference_point"]; + KRATOS_ERROR_IF_NOT(r_mrp.IsArray() && r_mrp.size() == 3) + << "'moment_reference_point' must be an array of size 3."; + mMomentReferencePoint[0] = r_mrp[0].GetDouble(); + mMomentReferencePoint[1] = r_mrp[1].GetDouble(); + mMomentReferencePoint[2] = r_mrp[2].GetDouble(); +} + + +void ComputeAerodynamicCoefficientsProcess::ExecuteBeforeOutputStep() +{ + Execute(); +} + + +void ComputeAerodynamicCoefficientsProcess::Execute() +{ + KRATOS_TRY; + + // Build wind axes from alpha (AoA) and beta (sideslip) + const double alpha = mAngleOfAttack * Globals::Pi / 180.0; + const double beta = mSideslipAngle * Globals::Pi / 180.0; + + // Wind-x (drag axis): freestream direction (unit) + array_1d e_drag = ZeroVector(3); + e_drag[0] = std::cos(alpha) * std::cos(beta); + e_drag[1] = std::sin(beta); + e_drag[2] = std::sin(alpha) * std::cos(beta); + + const double n_drag = norm_2(e_drag); + KRATOS_ERROR_IF(n_drag < 1e-15) << "Invalid wind axis: e_drag near zero."; + e_drag /= n_drag; + + // Build a reference "up" vector to construct orthonormal basis + array_1d up = ZeroVector(3); + up[0] = 0.0; up[1] = 0.0; up[2] = 1.0; + if (std::abs(inner_prod(e_drag, up)) > 0.99) { + up[0] = 0.0; up[1] = 1.0; up[2] = 0.0; + } + + // Wind-y (side axis) + array_1d e_side = MathUtils::CrossProduct(up, e_drag); + const double n_side = norm_2(e_side); + KRATOS_ERROR_IF(n_side < 1e-15) << "Invalid wind axis: e_side near zero."; + e_side /= n_side; + + // Wind-z (lift axis) + array_1d e_lift = MathUtils::CrossProduct(e_drag, e_side); + const double n_lift = norm_2(e_lift); + KRATOS_ERROR_IF(n_lift < 1e-15) << "Invalid wind axis: e_lift near zero."; + e_lift /= n_lift; + + // Accumulate aerodynamic force and moment from nodal reactions + array_1d F_aero = ZeroVector(3); + array_1d M_aero = ZeroVector(3); + + for (auto& r_node : mrModelPart.Nodes()) + { + KRATOS_ERROR_IF_NOT(r_node.SolutionStepsDataHas(REACTION)) + << "Node " << r_node.Id() << " does not have REACTION in SolutionStepData."; + + const array_1d& r_R = r_node.FastGetSolutionStepValue(REACTION); + const array_1d f_node = -r_R; + + F_aero += f_node; + + array_1d r = r_node.Coordinates() - mMomentReferencePoint; + M_aero += MathUtils::CrossProduct(r, f_node); + } + + // Projections in wind axes + const double D = inner_prod(F_aero, e_drag); // drag + const double Y = inner_prod(F_aero, e_side); // side force + const double L = inner_prod(F_aero, e_lift); // lift + + const double Mx = inner_prod(M_aero, e_drag); // moment about wind-x (roll in wind frame) + const double My = inner_prod(M_aero, e_side); // moment about wind-y (pitch in wind frame) + const double Mz = inner_prod(M_aero, e_lift); // moment about wind-z (yaw in wind frame) + + // Denominator for non-dimensional coefficients + const double denom_F = mQInf * mReference_Surface; + + KRATOS_ERROR_IF(std::abs(denom_F) < 1e-15) << "Invalid denominator q_inf*S_ref."; + + const double C_D = D / denom_F; + const double C_Y = Y / denom_F; + const double C_L = L / denom_F; + + const double C_l = Mx / (denom_F * mReference_Span); + const double C_m = My / (denom_F * mReference_Chord); + const double C_n = Mz / (denom_F * mReference_Span); + + // Store on ModelPart + mrModelPart.SetValue(LIFT_COEFFICIENT, C_L); + mrModelPart.SetValue(DRAG_COEFFICIENT, C_D); + mrModelPart.SetValue(LATERAL_FORCE_COEFFICIENT, C_Y); + + mrModelPart.SetValue(ROLLING_MOMENT_COEFFICIENT, C_l); + mrModelPart.SetValue(PITCHING_MOMENT_COEFFICIENT, C_m); + mrModelPart.SetValue(YAWING_MOMENT_COEFFICIENT, C_n); + + std::cout << "Aero coeffs from nodal reactions | " + << "alpha=" << mAngleOfAttack << " deg, beta=" << mSideslipAngle << " deg : " + << "CL=" << C_L << ", CD=" << C_D << ", CY=" << C_Y + << ", Cl=" << C_l << ", Cm=" << C_m << ", Cn=" << C_n + << std::endl; + + KRATOS_CATCH(""); +} + + +} \ No newline at end of file diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h new file mode 100644 index 000000000000..5956004e52c4 --- /dev/null +++ b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h @@ -0,0 +1,194 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Juan I. Camarotti +// +// + +#ifndef KRATOS_COMPUTE_AERODYNAMIC_COEFFICIENTS_PROCESS_H +#define KRATOS_COMPUTE_AERODYNAMIC_COEFFICIENTS_PROCESS_H + +// System includes + +// External includes + +// Project includes +#include "includes/model_part.h" +#include "includes/define.h" +#include "processes/process.h" +#include "includes/kratos_parameters.h" + +// Application includes + + +namespace Kratos +{ +///@addtogroup FluidDynamicsApplication +///@{ + +///@name Kratos Globals +///@{ + +///@} +///@name Type Definitions +///@{ + + +///@} +///@name Enum's +///@{ + +///@} +///@name Functions +///@{ + +///@} +///@name Kratos Classes +///@{ + +/// This process computes the lift coefficient as a function of reference fluid properties +class KRATOS_API(FLUID_DYNAMICS_APPLICATION) ComputeAerodynamicCoefficientsProcess : public Process +{ +public: + ///@name Type Definitions + ///@{ + using NodeType = ModelPart::NodeType; + + /// Pointer definition of ComputeAerodynamicCoefficientsProcess + KRATOS_CLASS_POINTER_DEFINITION(ComputeAerodynamicCoefficientsProcess); + + ///@} + ///@name Life Cycle + ///@{ + + /// Constructor with Kratos model + ComputeAerodynamicCoefficientsProcess( + Model& rModel, + Parameters Params); + + /// Destructor. + ~ComputeAerodynamicCoefficientsProcess() override {} + + ///@} + ///@name Operators + ///@{ + + ///@} + ///@name Operations + ///@{ + + const Parameters GetDefaultParameters() const override; + + void Execute() override; + + void ExecuteBeforeOutputStep() override; + + ///@} + ///@name Access + ///@{ + + ///@} + ///@name Inquiry + ///@{ + + ///@} + ///@name Input and output + ///@{ + + /// Turn back information as a string. + std::string Info() const override + { + std::stringstream buffer; + buffer << "ComputeAerodynamicCoefficientsProcess" ; + return buffer.str(); + } + + /// Print information about this object. + void PrintInfo(std::ostream& rOStream) const override {rOStream << "ComputeAerodynamicCoefficientsProcess";} + + /// Print object's data. + void PrintData(std::ostream& rOStream) const override {} + + + ///@} + ///@name Friends + ///@{ + + ///@} + +private: + ///@name Static Member Variables + ///@{ + + ///@} + ///@name Member Variables + ///@{ + + ModelPart& mrModelPart; + double mReference_Surface = 0.0; + double mReference_Chord = 1.0; + double mReference_Span = 1.0; + double mQInf = 1.0; + array_1d mMomentReferencePoint = ZeroVector(3); + double mAngleOfAttack = 0.0; + double mSideslipAngle = 0.0; + std::function mGetPressureCoefficient; + + ///@} + ///@name Private Operators + ///@{ + + ///@} + ///@name Private Operations + ///@{ + + void ReadFreestreamValues(const Parameters& Params); + + ///@} + ///@name Private Access + ///@{ + + + ///@} + ///@name Private Inquiry + ///@{ + + + ///@} + ///@name Un accessible methods + ///@{ + + /// Default constructor. + ComputeAerodynamicCoefficientsProcess() = delete; + + /// Assignment operator. + ComputeAerodynamicCoefficientsProcess& operator=(ComputeAerodynamicCoefficientsProcess const& rOther) = delete; + + /// Copy constructor. + ComputeAerodynamicCoefficientsProcess(ComputeAerodynamicCoefficientsProcess const& rOther) = delete; + + ///@} + +}; // Class ComputeAerodynamicCoefficientsProcess + +///@} +///@name Type Definitions +///@{ + +///@} +///@name Input and output +///@{ + +///@} + +///@} addtogroup block + +}; // namespace Kratos. + +#endif // KRATOS_COMPUTE_AERODYNAMIC_COEFFICIENTS_PROCESS_H diff --git a/applications/FluidDynamicsApplication/custom_python/add_custom_processes_to_python.cpp b/applications/FluidDynamicsApplication/custom_python/add_custom_processes_to_python.cpp index 161f29230af9..c1b49b9848ca 100644 --- a/applications/FluidDynamicsApplication/custom_python/add_custom_processes_to_python.cpp +++ b/applications/FluidDynamicsApplication/custom_python/add_custom_processes_to_python.cpp @@ -28,7 +28,7 @@ #include "custom_processes/boussinesq_force_process.h" #include "custom_processes/calculate_levelset_consistent_nodal_gradient_process.h" #include "custom_processes/compute_pressure_coefficient_process.h" -#include "custom_processes/compute_lift_coefficient_process.h" +#include "custom_processes/compute_aerodynamic_coefficients_process.h" #include "custom_processes/distance_modification_process.h" #include "custom_processes/distance_smoothing_process.h" #include "custom_processes/embedded_nodes_initialization_process.h" @@ -182,7 +182,7 @@ void AddCustomProcessesToPython(pybind11::module& m) .def(py::init()) ; - py::class_(m, "ComputeLiftCoefficientProcess") + py::class_(m, "ComputeAerodynamicCoefficientsProcess") .def(py::init()) ; diff --git a/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py b/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py index d893c876cb8f..98acc52ecbea 100644 --- a/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py +++ b/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py @@ -1,8 +1,8 @@ import KratosMultiphysics -from KratosMultiphysics.FluidDynamicsApplication import ComputeLiftCoefficientProcess +from KratosMultiphysics.FluidDynamicsApplication import ComputeAerodynamicCoefficientsProcess def Factory(settings, Model): if not isinstance(settings, KratosMultiphysics.Parameters): raise Exception("expected input shall be a Parameters object, encapsulating a json string") - return ComputeLiftCoefficientProcess(Model, settings["Parameters"]) + return ComputeAerodynamicCoefficientsProcess(Model, settings["Parameters"]) From 103b589f256026d9e9aa8b72d503e6c47cd9b46b Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 19 Jan 2026 11:52:42 +0100 Subject: [PATCH 06/10] change python process name --- .../compute_aerodynamic_coefficients_process.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 applications/FluidDynamicsApplication/python_scripts/compute_aerodynamic_coefficients_process.py diff --git a/applications/FluidDynamicsApplication/python_scripts/compute_aerodynamic_coefficients_process.py b/applications/FluidDynamicsApplication/python_scripts/compute_aerodynamic_coefficients_process.py new file mode 100644 index 000000000000..98acc52ecbea --- /dev/null +++ b/applications/FluidDynamicsApplication/python_scripts/compute_aerodynamic_coefficients_process.py @@ -0,0 +1,8 @@ +import KratosMultiphysics +from KratosMultiphysics.FluidDynamicsApplication import ComputeAerodynamicCoefficientsProcess + + +def Factory(settings, Model): + if not isinstance(settings, KratosMultiphysics.Parameters): + raise Exception("expected input shall be a Parameters object, encapsulating a json string") + return ComputeAerodynamicCoefficientsProcess(Model, settings["Parameters"]) From 9cf3c687a27d24983347876bb718022990acb7c1 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 19 Jan 2026 12:21:48 +0100 Subject: [PATCH 07/10] erase the old process --- .../compute_lift_coefficient_process.cpp | 145 ------------- .../compute_lift_coefficient_process.h | 191 ------------------ .../compute_lift_coefficient_process.py | 8 - 3 files changed, 344 deletions(-) delete mode 100644 applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.cpp delete mode 100644 applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.h delete mode 100644 applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.cpp b/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.cpp deleted file mode 100644 index b01bdcc832fb..000000000000 --- a/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// | / | -// ' / __| _` | __| _ \ __| -// . \ | ( | | ( |\__ ` -// _|\_\_| \__,_|\__|\___/ ____/ -// Multi-Physics -// -// License: BSD License -// Kratos default license: kratos/license.txt -// -// Main authors: Eduard Gómez -// -// - -// System includes - -// External includes - -// Project includes - -// Application includes -#include "compute_lift_coefficient_process.h" -#include "fluid_dynamics_application_variables.h" -#include "utilities/variable_utils.h" - - -namespace Kratos -{ - -ComputeLiftCoefficientProcess::ComputeLiftCoefficientProcess( - Model &rModel, - Parameters Params) - : Process(), - mrModelPart(rModel.GetModelPart(Params["model_part_name"].GetString())) -{ - // Check default settings - KRATOS_TRY - - Params.ValidateAndAssignDefaults(GetDefaultParameters()); - - ReadFreestreamValues(Params); - - KRATOS_CATCH("") -} - - -const Parameters ComputeLiftCoefficientProcess::GetDefaultParameters() const -{ - return Parameters( R"( - { - "model_part_name" : "PLEASE_PROVIDE_A_MODELPART_NAME", - "reference_surface" : 0.0, - "angle_of_attack" : 0.0 - })" ); -} - -void ComputeLiftCoefficientProcess::ReadFreestreamValues(const Parameters& rParams) -{ - constexpr double tol = 1e-12; - - KRATOS_ERROR_IF_NOT(rParams.Has("reference_surface")) - << "Missing required parameter 'reference_surface'."; - - mReference_Surface = rParams["reference_surface"].GetDouble(); - KRATOS_ERROR_IF(std::abs(mReference_Surface) <= tol) - << "Invalid value for 'reference_surface' = " << mReference_Surface - << ". It must be non-zero."; - - KRATOS_ERROR_IF_NOT(rParams.Has("angle_of_attack")) - << "Missing required parameter 'angle_of_attack'."; - - mAngle_of_Attack = rParams["angle_of_attack"].GetDouble(); -} - - -void ComputeLiftCoefficientProcess::ExecuteBeforeOutputStep() -{ - Execute(); -} - - -void ComputeLiftCoefficientProcess::Execute() -{ - KRATOS_TRY; - - double angle_rad = mAngle_of_Attack*3.14159/(180); - std::vector e_lift(3); // direction of the lift - e_lift[0] = std::sin(angle_rad)*-1; - e_lift[1] = 0; - e_lift[2] = std::cos(angle_rad); - - - double C_L = 0.0; - double S = 0.0; - double S_w = 0.0; - - for (auto it_cond = mrModelPart.ConditionsBegin(); it_cond != mrModelPart.ConditionsEnd(); ++it_cond) - { - auto& r_geometry = it_cond->GetGeometry(); - const auto integration_method = it_cond->GetIntegrationMethod(); - const auto& r_integration_points = r_geometry.IntegrationPoints(integration_method); - const auto& r_shape_funct = r_geometry.ShapeFunctionsValues(integration_method); - - double cp_integrated = 0.0; - - // Loop integration points - for (unsigned int gp = 0; gp < r_integration_points.size(); ++gp) - { - const double weight = r_integration_points[gp].Weight(); - - // Cp at integration point - double cp_gp = 0.0; - for (unsigned int i_node = 0; i_node < r_geometry.PointsNumber(); ++i_node) - { - const double cp_node = r_geometry[i_node].GetValue(PRESSURE_COEFFICIENT); - cp_gp += r_shape_funct(gp, i_node) * cp_node; - } - - S += r_geometry.DeterminantOfJacobian(gp, integration_method); - S_w += weight * r_geometry.DeterminantOfJacobian(gp, integration_method); - cp_integrated += cp_gp * weight * r_geometry.DeterminantOfJacobian(gp, integration_method); - } - - - // Normal of the element - array_1d normal_el; - normal_el = r_geometry.Normal(r_geometry.Center()); // Non unit vector! - double norm = std::sqrt(normal_el[0]*normal_el[0] + normal_el[1]*normal_el[1] + normal_el[2]*normal_el[2]); - normal_el /= norm; - - const double lift_projection = normal_el[0] * e_lift[0] + normal_el[1] * e_lift[1] + normal_el[2] * e_lift[2]; - - C_L -= cp_integrated * lift_projection; - } - - C_L = C_L/mReference_Surface; - mrModelPart.SetValue(LIFT_COEFFICIENT, C_L); - std::cout << "S_w: " << S_w << std::endl; - std::cout << "S: " << S << std::endl; - std::cout << "C_L: " << C_L << std::endl; - KRATOS_CATCH(""); - -} - - -} \ No newline at end of file diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.h b/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.h deleted file mode 100644 index 3cfbbc70b956..000000000000 --- a/applications/FluidDynamicsApplication/custom_processes/compute_lift_coefficient_process.h +++ /dev/null @@ -1,191 +0,0 @@ -// | / | -// ' / __| _` | __| _ \ __| -// . \ | ( | | ( |\__ ` -// _|\_\_| \__,_|\__|\___/ ____/ -// Multi-Physics -// -// License: BSD License -// Kratos default license: kratos/license.txt -// -// Main authors: Eduard Gómez -// -// - -#ifndef KRATOS_COMPUTE_LIFT_COEFFICIENT_PROCESS_H -#define KRATOS_COMPUTE_LIFT_COEFFICIENT_PROCESS_H - -// System includes -#include -#include - -// External includes - -// Project includes -#include "includes/model_part.h" -#include "includes/define.h" -#include "processes/process.h" -#include "includes/kratos_parameters.h" - -// Application includes - - -namespace Kratos -{ -///@addtogroup FluidDynamicsApplication -///@{ - -///@name Kratos Globals -///@{ - -///@} -///@name Type Definitions -///@{ - - -///@} -///@name Enum's -///@{ - -///@} -///@name Functions -///@{ - -///@} -///@name Kratos Classes -///@{ - -/// This process computes the lift coefficient as a function of reference fluid properties -class KRATOS_API(FLUID_DYNAMICS_APPLICATION) ComputeLiftCoefficientProcess : public Process -{ -public: - ///@name Type Definitions - ///@{ - using NodeType = ModelPart::NodeType; - - /// Pointer definition of ComputeLiftCoefficientProcess - KRATOS_CLASS_POINTER_DEFINITION(ComputeLiftCoefficientProcess); - - ///@} - ///@name Life Cycle - ///@{ - - /// Constructor with Kratos model - ComputeLiftCoefficientProcess( - Model& rModel, - Parameters Params); - - /// Destructor. - ~ComputeLiftCoefficientProcess() override {} - - ///@} - ///@name Operators - ///@{ - - ///@} - ///@name Operations - ///@{ - - const Parameters GetDefaultParameters() const override; - - void Execute() override; - - void ExecuteBeforeOutputStep() override; - - ///@} - ///@name Access - ///@{ - - ///@} - ///@name Inquiry - ///@{ - - ///@} - ///@name Input and output - ///@{ - - /// Turn back information as a string. - std::string Info() const override - { - std::stringstream buffer; - buffer << "ComputeLiftCoefficientProcess" ; - return buffer.str(); - } - - /// Print information about this object. - void PrintInfo(std::ostream& rOStream) const override {rOStream << "ComputeLiftCoefficientProcess";} - - /// Print object's data. - void PrintData(std::ostream& rOStream) const override {} - - - ///@} - ///@name Friends - ///@{ - - ///@} - -private: - ///@name Static Member Variables - ///@{ - - ///@} - ///@name Member Variables - ///@{ - - ModelPart& mrModelPart; - double mAngle_of_Attack = 0.0; // Angle of attack - double mReference_Surface = 0.0; // Reference surface - std::function mGetPressureCoefficient; - - ///@} - ///@name Private Operators - ///@{ - - ///@} - ///@name Private Operations - ///@{ - - void ReadFreestreamValues(const Parameters& Params); - - ///@} - ///@name Private Access - ///@{ - - - ///@} - ///@name Private Inquiry - ///@{ - - - ///@} - ///@name Un accessible methods - ///@{ - - /// Default constructor. - ComputeLiftCoefficientProcess() = delete; - - /// Assignment operator. - ComputeLiftCoefficientProcess& operator=(ComputeLiftCoefficientProcess const& rOther) = delete; - - /// Copy constructor. - ComputeLiftCoefficientProcess(ComputeLiftCoefficientProcess const& rOther) = delete; - - ///@} - -}; // Class ComputeLiftCoefficientProcess - -///@} -///@name Type Definitions -///@{ - -///@} -///@name Input and output -///@{ - -///@} - -///@} addtogroup block - -}; // namespace Kratos. - -#endif // KRATOS_COMUTE_LIFT_COEFFICIENT_PROCESS_H diff --git a/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py b/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py deleted file mode 100644 index 98acc52ecbea..000000000000 --- a/applications/FluidDynamicsApplication/python_scripts/compute_lift_coefficient_process.py +++ /dev/null @@ -1,8 +0,0 @@ -import KratosMultiphysics -from KratosMultiphysics.FluidDynamicsApplication import ComputeAerodynamicCoefficientsProcess - - -def Factory(settings, Model): - if not isinstance(settings, KratosMultiphysics.Parameters): - raise Exception("expected input shall be a Parameters object, encapsulating a json string") - return ComputeAerodynamicCoefficientsProcess(Model, settings["Parameters"]) From e8b005c6bcba2fdb9c893b02d760701c5f27ef76 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 19 Jan 2026 12:24:01 +0100 Subject: [PATCH 08/10] change function name --- .../compute_aerodynamic_coefficients_process.cpp | 4 ++-- .../compute_aerodynamic_coefficients_process.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.cpp b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.cpp index 896b4e1cef42..08ddc31b73a7 100644 --- a/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.cpp +++ b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.cpp @@ -37,7 +37,7 @@ ComputeAerodynamicCoefficientsProcess::ComputeAerodynamicCoefficientsProcess( Params.ValidateAndAssignDefaults(GetDefaultParameters()); - ReadFreestreamValues(Params); + ReadProcessParameters(Params); KRATOS_CATCH("") } @@ -58,7 +58,7 @@ const Parameters ComputeAerodynamicCoefficientsProcess::GetDefaultParameters() c })" ); } -void ComputeAerodynamicCoefficientsProcess::ReadFreestreamValues(const Parameters& rParams) +void ComputeAerodynamicCoefficientsProcess::ReadProcessParameters(const Parameters& rParams) { constexpr double tol = 1e-12; diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h index 5956004e52c4..58659ebfc2b6 100644 --- a/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h +++ b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h @@ -148,7 +148,7 @@ class KRATOS_API(FLUID_DYNAMICS_APPLICATION) ComputeAerodynamicCoefficientsProce ///@name Private Operations ///@{ - void ReadFreestreamValues(const Parameters& Params); + void ReadProcessParameters(const Parameters& Params); ///@} ///@name Private Access From 50b0df012c5d45977c0c210cfbefd3694293c505 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 19 Jan 2026 15:55:22 +0100 Subject: [PATCH 09/10] register the variables correctly --- .../fluid_dynamics_application.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/applications/FluidDynamicsApplication/fluid_dynamics_application.cpp b/applications/FluidDynamicsApplication/fluid_dynamics_application.cpp index b44ac8900fcb..4a6ed7000340 100644 --- a/applications/FluidDynamicsApplication/fluid_dynamics_application.cpp +++ b/applications/FluidDynamicsApplication/fluid_dynamics_application.cpp @@ -311,6 +311,15 @@ void KratosFluidDynamicsApplication::Register() { KRATOS_REGISTER_VARIABLE( Y_PLUS ) + // Aerodynamic coefficients + KRATOS_REGISTER_VARIABLE( LIFT_COEFFICIENT ) + KRATOS_REGISTER_VARIABLE( DRAG_COEFFICIENT ) + KRATOS_REGISTER_VARIABLE( LATERAL_FORCE_COEFFICIENT ) + KRATOS_REGISTER_VARIABLE( ROLLING_MOMENT_COEFFICIENT ) + KRATOS_REGISTER_VARIABLE( PITCHING_MOMENT_COEFFICIENT ) + KRATOS_REGISTER_VARIABLE( YAWING_MOMENT_COEFFICIENT ) + + // Register Elements KRATOS_REGISTER_ELEMENT("VMS2D3N",mVMS2D); //this is the name the element should have according to the naming convention KRATOS_REGISTER_ELEMENT("VMS3D4N",mVMS3D); //this is the name the element should have according to the naming convention From 7444093cf4f2080b9aad8fd4965e325bd0ed7f80 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 19 Jan 2026 15:55:33 +0100 Subject: [PATCH 10/10] erase the std::function --- .../custom_processes/compute_aerodynamic_coefficients_process.h | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h index 58659ebfc2b6..67a6674cb1ff 100644 --- a/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h +++ b/applications/FluidDynamicsApplication/custom_processes/compute_aerodynamic_coefficients_process.h @@ -138,7 +138,6 @@ class KRATOS_API(FLUID_DYNAMICS_APPLICATION) ComputeAerodynamicCoefficientsProce array_1d mMomentReferencePoint = ZeroVector(3); double mAngleOfAttack = 0.0; double mSideslipAngle = 0.0; - std::function mGetPressureCoefficient; ///@} ///@name Private Operators