Skip to content

Commit

Permalink
Revert local flags
Browse files Browse the repository at this point in the history
  • Loading branch information
loumalouomega committed Mar 4, 2024
1 parent aa6571e commit eb20a06
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ This algorithm defines 4 lambda functions for calculating the distance of nodes

- **`distance_lambda_non_historica_save_skin`**: Performs the same operations as `distance_lambda_historical_save_skin` but for non-historical variables.

These lambdas functions will be chosen depending on the flags `HISTORICAL_VALUE` and `SAVE_DISTANCE_IN_SKIN`, one of the four lambda functions is selected for execution. This decision dictates whether historical or non-historical variables are used and whether distances are saved in the skin model part.
These lambdas functions will be chosen depending on the flags `mHistoricalValue` and `mSaveDistanceInSkin`, one of the four lambda functions is selected for execution. This decision dictates whether historical or non-historical variables are used and whether distances are saved in the skin model part.

If the `SAVE_DISTANCE_IN_SKIN` flag is set, initializes the distance variable to zero for all elements or conditions in the skin model part.
If the `mSaveDistanceInSkin` flag is set, initializes the distance variable to zero for all elements or conditions in the skin model part.

Both lambda functions take the following parameters:
- `Nodes`: A reference to the container holding the nodes for which distances will be calculated.
Expand All @@ -61,8 +61,8 @@ The selected lambda function is then applied to calculate the distances for all
> A warning is issued if both elements and conditions are found in the skin model part, indicating that elements will be considered for the distance calculation.
#### Flags
- `HISTORICAL_VALUE`: Determines whether historical or non-historical variables are used for distance calculations.
- `SAVE_DISTANCE_IN_SKIN`: Indicates whether the calculated distances should be saved back to the skin model part, updating the values if the new distance is greater than the existing one.
- `mHistoricalValue`: Determines whether historical or non-historical variables are used for distance calculations.
- `mSaveDistanceInSkin`: Indicates whether the calculated distances should be saved back to the skin model part, updating the values if the new distance is greater than the existing one.

## Parameters & Defaults

Expand Down
29 changes: 11 additions & 18 deletions kratos/processes/calculate_nodal_distance_to_skin_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,25 @@

namespace Kratos
{
/// Local Flags
KRATOS_CREATE_LOCAL_FLAG( CalculateNodalDistanceToSkinProcess, HISTORICAL_VALUE, 0 );
KRATOS_CREATE_LOCAL_FLAG( CalculateNodalDistanceToSkinProcess, SAVE_DISTANCE_IN_SKIN, 1 );

/***********************************************************************************/
/***********************************************************************************/

CalculateNodalDistanceToSkinProcess::CalculateNodalDistanceToSkinProcess(
ModelPart& rVolumeModelPart,
ModelPart& rSkinModelPart,
const bool HistoricalVariable,
const std::string& rDistanceVariableName,
const bool SaveDistanceInSkin
) : mrVolumeModelPart(rVolumeModelPart),
mrSkinModelPart(rSkinModelPart)
mrSkinModelPart(rSkinModelPart),
mHistoricalValue(HistoricalVariable),
mSaveDistanceInSkin(SaveDistanceInSkin)
{
// Assign distance variable
if (rDistanceVariableName != "") {
mpDistanceVariable = &KratosComponents<Variable<double>>::Get(rDistanceVariableName);
}

// Setting flags
this->Set(HISTORICAL_VALUE, HistoricalVariable);
// If SaveDistanceInSkin is true we can not use parallel algorithms and therefore a warning will be raised
KRATOS_WARNING_IF("CalculateNodalDistanceToSkinProcess", SaveDistanceInSkin) << "SaveDistanceInSkin is true, therefore the parallel algorithms will not be used." << std::endl;
this->Set(SAVE_DISTANCE_IN_SKIN, SaveDistanceInSkin);
KRATOS_WARNING_IF("CalculateNodalDistanceToSkinProcess", mSaveDistanceInSkin) << "SaveDistanceInSkin is true, therefore the parallel algorithms will not be used." << std::endl;

// Check it is serial
KRATOS_ERROR_IF(mrVolumeModelPart.IsDistributed()) << "Distributed computation still not supported. Please update implementation as soon as MPI search is merged. See https://github.com/KratosMultiphysics/Kratos/pull/11719" << std::endl;
Expand All @@ -70,15 +63,15 @@ CalculateNodalDistanceToSkinProcess::CalculateNodalDistanceToSkinProcess(
// If historical or non-historical variables
const std::string database = ThisParameters["distance_database"].GetString();
if (database == "nodal_historical") {
this->Set(HISTORICAL_VALUE, true);
mHistoricalValue = true;
} else if (database == "nodal_non_historical") {
this->Set(HISTORICAL_VALUE, false);
mHistoricalValue = false;
} else {
KRATOS_ERROR << "Only options are nodal_historical and nodal_non_historical, provided is: " << database << std::endl;
}

// Save distance in skin flag
this->Set(SAVE_DISTANCE_IN_SKIN, ThisParameters["save_distance_in_skin"].GetBool());
mSaveDistanceInSkin = ThisParameters["save_distance_in_skin"].GetBool();

// Assign distance variable
mpDistanceVariable = &KratosComponents<Variable<double>>::Get(ThisParameters["distance_variable"].GetString());
Expand Down Expand Up @@ -136,7 +129,7 @@ void CalculateNodalDistanceToSkinProcess::Execute()
};

// Call lambda depending on the flags
const auto* p_distance_lambda = this->Is(HISTORICAL_VALUE) ? (this->Is(SAVE_DISTANCE_IN_SKIN) ? &distance_lambda_historical_save_skin : &distance_lambda_historical) : (this->Is(SAVE_DISTANCE_IN_SKIN) ? &distance_lambda_non_historica_save_skin : &distance_lambda_non_historical);
const auto* p_distance_lambda = mHistoricalValue ? (mSaveDistanceInSkin ? &distance_lambda_historical_save_skin : &distance_lambda_historical) : (mSaveDistanceInSkin ? &distance_lambda_non_historica_save_skin : &distance_lambda_non_historical);

// First try to detect if elements or conditions
const std::size_t number_of_elements_skin = mrSkinModelPart.NumberOfElements();
Expand All @@ -146,7 +139,7 @@ void CalculateNodalDistanceToSkinProcess::Execute()
GeometricalObjectsBins bins(mrSkinModelPart.ElementsBegin(), mrSkinModelPart.ElementsEnd());

// Set to zero in skin if required
if (this->Is(SAVE_DISTANCE_IN_SKIN)) {
if (mSaveDistanceInSkin) {
VariableUtils().SetNonHistoricalVariableToZero(*mpDistanceVariable, mrSkinModelPart.Elements());
}

Expand All @@ -156,7 +149,7 @@ void CalculateNodalDistanceToSkinProcess::Execute()
GeometricalObjectsBins bins(mrSkinModelPart.ConditionsBegin(), mrSkinModelPart.ConditionsEnd());

// Set to zero in skin if required
if (this->Is(SAVE_DISTANCE_IN_SKIN)) {
if (mSaveDistanceInSkin) {
VariableUtils().SetNonHistoricalVariableToZero(*mpDistanceVariable, mrSkinModelPart.Conditions());
}

Expand Down Expand Up @@ -203,7 +196,7 @@ void CalculateNodalDistanceToSkinProcess::PrintInfo(std::ostream& rOStream) cons

void CalculateNodalDistanceToSkinProcess::PrintData(std::ostream& rOStream) const
{
rOStream << "Volume model part:\n" << mrVolumeModelPart << "\nSkin model part:\n" << mrSkinModelPart << "\nHistorical variable: " << std::boolalpha << this->Is(HISTORICAL_VALUE) << "\nSave distance in skin: " << std::boolalpha << this->Is(SAVE_DISTANCE_IN_SKIN) << "\nDistance variable: " << mpDistanceVariable->Name() << std::endl;
rOStream << "Volume model part:\n" << mrVolumeModelPart << "\nSkin model part:\n" << mrSkinModelPart << "\nHistorical variable: " << std::boolalpha << mHistoricalValue << "\nSave distance in skin: " << std::boolalpha << mSaveDistanceInSkin << "\nDistance variable: " << mpDistanceVariable->Name() << std::endl;
}

} // namespace Kratos.
10 changes: 6 additions & 4 deletions kratos/processes/calculate_nodal_distance_to_skin_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ class KRATOS_API(KRATOS_CORE) CalculateNodalDistanceToSkinProcess
///@name Type Definitions
///@{

/// Local Flags
KRATOS_DEFINE_LOCAL_FLAG( HISTORICAL_VALUE ); /// This flag is used in order to check if the values are historical
KRATOS_DEFINE_LOCAL_FLAG( SAVE_DISTANCE_IN_SKIN ); /// This flag is used in order to save the highest distance in the found geometries of the skin

/// Pointer definition of CalculateNodalDistanceToSkinProcess
KRATOS_CLASS_POINTER_DEFINITION(CalculateNodalDistanceToSkinProcess);

Expand Down Expand Up @@ -149,6 +145,12 @@ class KRATOS_API(KRATOS_CORE) CalculateNodalDistanceToSkinProcess
/// Pointer to the distance variable.
const Variable<double>* mpDistanceVariable = &DISTANCE;

/// This flag is used in order to check if the values are historical
bool mHistoricalValue = true;

/// This flag is used in order to save the highest distance in the found geometries of the skin
bool mSaveDistanceInSkin = false;

///@}
///@name Private Operators
///@{
Expand Down

0 comments on commit eb20a06

Please sign in to comment.