Skip to content

Commit

Permalink
Merge branch 'master' into core/save-distance-skin-in-CalculateNodalD…
Browse files Browse the repository at this point in the history
…istanceToSkinProcess
  • Loading branch information
loumalouomega committed Mar 5, 2024
2 parents eb20a06 + f653329 commit f8199f1
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 377 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align=center><img height="72.125%" width="72.125%" src="https://raw.githubusercontent.com/KratosMultiphysics/Documentation/master/Wiki_files/Home/kratos.png"></p>

[![License][license-image]][license] [![C++][c++-image]][c++standard] [![Github CI][Nightly-Build]][Nightly-link] [![DOI][DOI-image]][DOI] [![GitHub stars][stars-image]][stars] [![Twitter][twitter-image]][twitter] [![YouTube](https://badges.aleen42.com/src/youtube.svg)]([https://youtu.be/VlJ71kzcn9Y](https://www.youtube.com/@kratosmultiphysics3578))
[![License][license-image]][license] [![C++][c++-image]][c++standard] [![Github CI][Nightly-Build]][Nightly-link] [![DOI][DOI-image]][DOI] [![GitHub stars][stars-image]][stars] [![Twitter][twitter-image]][twitter] [![Youtube][youtube-image]][youtube]

[![Release][release-image]][releases]
<a href="https://github.com/KratosMultiphysics/Kratos/releases/latest"><img src="https://img.shields.io/github/release-date/KratosMultiphysics/Kratos?label="></a>
Expand All @@ -10,7 +10,7 @@
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/KratosMultiphysics.svg)](https://pypi.org/project/KratosMultiphysics/)
[![Downloads](https://pepy.tech/badge/KratosMultiphysics/month)](https://pepy.tech/project/KratosMultiphysics)

[release-image]: https://img.shields.io/badge/release-9.3-green.svg?style=flat
[release-image]: https://img.shields.io/badge/release-9.4-green.svg?style=flat
[releases]: https://github.com/KratosMultiphysics/Kratos/releases

[license-image]: https://img.shields.io/badge/license-BSD-green.svg?style=flat
Expand All @@ -31,6 +31,9 @@
[twitter-image]: https://img.shields.io/twitter/follow/kratosmultiphys.svg?label=Follow&style=social
[twitter]: https://twitter.com/kratosmultiphys

[youtube-image]: https://badges.aleen42.com/src/youtube.svg
[youtube]:https://www.youtube.com/@kratosmultiphysics3578

_KRATOS Multiphysics_ ("Kratos") is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface. More in [Overview](https://github.com/KratosMultiphysics/Kratos/wiki/Overview)

**Kratos** is **free** under BSD-4 [license](https://github.com/KratosMultiphysics/Kratos/wiki/Licence) and can be used even in comercial softwares as it is. Many of its main applications are also free and BSD-4 licensed but each derived application can have its own propietary license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import kratos core and applications
import KratosMultiphysics
import KratosMultiphysics.EigenSolversApplication as KratosEigen
import KratosMultiphysics.StructuralMechanicsApplication as KratosStructural
import KratosMultiphysics.DamApplication as KratosDam
import KratosMultiphysics.PoromechanicsApplication as KratosPoro
Expand Down Expand Up @@ -69,7 +68,7 @@ def AddVariables(self):


def GetMinimumBufferSize(self):
return 2;
return 2


def AddDofs(self):
Expand Down
6 changes: 0 additions & 6 deletions applications/EigenSolversApplication/CMakeLists.txt

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions docs/pages/Kratos/For_Users/How_To_Get_Kratos/Binaries.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Getting Kratos Binaries for Linux
keywords:
keywords:
tags: [Getting-Kratos-Binaries-for-Linux.md]
sidebar: kratos_for_users
summary:
summary:
---

# Pip Install
Expand Down Expand Up @@ -35,7 +35,6 @@ The following Kratos Pakcages ara avaialable
- KratosPoromechanicsApplication;
- KratosFSIApplication;
- KratosSwimmingDEMApplication;
- KratosEigenSolversApplication;
- KratosLinearSolversApplication;
- KratosConstitutiveLawsApplication;
- KratosDelaunayMeshingApplication;
Expand Down
199 changes: 199 additions & 0 deletions kratos/processes/apply_constant_vectorvalue_process.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Riccardo Rossi
//
//

// System includes

// External includes

// Project includes
#include "includes/model_part.h"
#include "processes/apply_constant_vectorvalue_process.h"

namespace Kratos
{

KRATOS_CREATE_LOCAL_FLAG(ApplyConstantVectorValueProcess,X_COMPONENT_FIXED, 0);
KRATOS_CREATE_LOCAL_FLAG(ApplyConstantVectorValueProcess,Y_COMPONENT_FIXED, 1);
KRATOS_CREATE_LOCAL_FLAG(ApplyConstantVectorValueProcess,Z_COMPONENT_FIXED, 2);

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

ApplyConstantVectorValueProcess::ApplyConstantVectorValueProcess(ModelPart& rModelPart,
Parameters parameters
) : Process(Flags()),
mrModelPart(rModelPart)
{
KRATOS_TRY

// Get defaults parameters
Parameters default_parameters = GetDefaultParameters();

// Some values need to be mandatorily prescribed since no meaningful default Value exist. For this reason try accessing to them
// So that an error is thrown if they don't exist
KRATOS_ERROR_IF(parameters["direction"].IsArray() && parameters["direction"].size() != 3) << "direction vector is not a vector or it does not have size 3. Direction vector currently passed" << parameters.PrettyPrintJsonString() << std::endl;
KRATOS_ERROR_IF_NOT(parameters["modulus"].IsNumber()) << "modulus shall be a number. Parameter list in which is included is :" << parameters.PrettyPrintJsonString() << std::endl;
KRATOS_ERROR_IF_NOT(parameters["variable_name"].IsString()) << "variable_name shall be a String. Parameter list in which is included is :" << parameters.PrettyPrintJsonString() << std::endl;
KRATOS_ERROR_IF_NOT(parameters["model_part_name"].IsString()) << "model_part_name shall be a String. Parameter list in which is included is :" << parameters.PrettyPrintJsonString() << std::endl;

// Validate against defaults -- this also ensures no type mismatch
parameters.ValidateAndAssignDefaults(default_parameters);

// Read from the parameters and assign to the values
mMeshId = parameters["mesh_id"].GetInt();

this->Set(X_COMPONENT_FIXED, parameters["is_fixed_x"].GetBool());
this->Set(Y_COMPONENT_FIXED, parameters["is_fixed_y"].GetBool());
this->Set(Z_COMPONENT_FIXED, parameters["is_fixed_z"].GetBool());

// Get the modulus and variable name
mVariableName = parameters["variable_name"].GetString();
mModulus = parameters["modulus"].GetDouble();

mDirection.resize(3,false);
mDirection[0] = parameters["direction"][0].GetDouble();
mDirection[1] = parameters["direction"][1].GetDouble();
mDirection[2] = parameters["direction"][2].GetDouble();

const double dim_norm = norm_2(mDirection);
KRATOS_ERROR_IF(dim_norm < 1e-20) << " Norm of direction given is approximately zero. Please give a direction vector with a non zero norm : current Value of direction vector = " << mDirection << std::endl;

// Normalize the direction
mDirection /= dim_norm;

const bool has_variable = KratosComponents<Variable<array_1d<double,3>>>::Has(mVariableName);
KRATOS_ERROR_IF_NOT(has_variable) << "Not defined the variable " << mVariableName << std::endl;
const Variable<array_1d<double,3> >& r_variable = KratosComponents< Variable<array_1d<double,3>>>::Get(mVariableName);

KRATOS_ERROR_IF(mMeshId >= rModelPart.NumberOfMeshes()) << "Mesh does not exist in rModelPart: mesh id is --> " << mMeshId << std::endl;

KRATOS_ERROR_IF_NOT(rModelPart.GetNodalSolutionStepVariablesList().Has(r_variable)) << "Trying to fix a variable that is not in the rModelPart - variable: " << mVariableName << std::endl;

KRATOS_ERROR_IF(mDirection.size() != 3) << "Direction vector is expected to have size 3. Direction vector currently passed " << mDirection << std::endl;

KRATOS_ERROR_IF_NOT(KratosComponents<Variable<double>>::Has(mVariableName+ "_X")) << "Not defined the variable " << mVariableName+ "_X" << std::endl;
KRATOS_ERROR_IF_NOT(KratosComponents<Variable<double>>::Has(mVariableName+ "_Y")) << "Not defined the variable " << mVariableName+ "_Y" << std::endl;
KRATOS_ERROR_IF_NOT(KratosComponents<Variable<double>>::Has(mVariableName+ "_Z")) << "Not defined the variable " << mVariableName+ "_Z" << std::endl;

KRATOS_CATCH("");
}

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

ApplyConstantVectorValueProcess::ApplyConstantVectorValueProcess(
ModelPart& rModelPart,
const Variable<array_1d<double, 3>>& rVariable,
const double Modulus,
const Vector& Direction,
std::size_t MeshId,
const Flags Options
) : Process(Options) ,
mrModelPart(rModelPart),
mModulus(Modulus),
mDirection(Direction),
mMeshId(MeshId)
{
KRATOS_TRY;

KRATOS_ERROR_IF_NOT(this->IsDefined(X_COMPONENT_FIXED) ) << "Please specify if component x is to be fixed or not (flag X_COMPONENT_FIXED)" << std::endl;
KRATOS_ERROR_IF_NOT(this->IsDefined(Y_COMPONENT_FIXED) ) << "Please specify if component y is to be fixed or not (flag Y_COMPONENT_FIXED)" << std::endl;
KRATOS_ERROR_IF_NOT(this->IsDefined(Z_COMPONENT_FIXED) ) << "Please specify if the variable is to be fixed or not (flag Z_COMPONENT_FIXED)" << std::endl;

mVariableName = rVariable.Name();

KRATOS_ERROR_IF(mMeshId >= rModelPart.NumberOfMeshes()) << "Mesh does not exist in rModelPart: mesh id is --> " << mMeshId << std::endl;

KRATOS_ERROR_IF_NOT(rModelPart.GetNodalSolutionStepVariablesList().Has(rVariable)) << "Trying to fix a variable that is not in the rModelPart - variable: " << mVariableName << std::endl;

KRATOS_ERROR_IF(mDirection.size() != 3) << "Direction vector is expected to have size 3. Direction vector currently passed " << mDirection << std::endl;

KRATOS_ERROR_IF_NOT(KratosComponents<Variable<double>>::Has(mVariableName+ "_X")) << "Not defined the variable " << mVariableName+ "_X" << std::endl;
KRATOS_ERROR_IF_NOT(KratosComponents<Variable<double>>::Has(mVariableName+ "_Y")) << "Not defined the variable " << mVariableName+ "_Y" << std::endl;
KRATOS_ERROR_IF_NOT(KratosComponents<Variable<double>>::Has(mVariableName+ "_Z")) << "Not defined the variable " << mVariableName+ "_Z" << std::endl;

KRATOS_CATCH("");
}

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

void ApplyConstantVectorValueProcess::ExecuteInitialize()
{
// Compute the Value to be applied
const array_1d<double,3> values = mModulus * mDirection;

// Retrieve the variables
const Variable<double>& r_variable_x = KratosComponents<Variable<double>>::Get(mVariableName + std::string("_X"));
const Variable<double>& r_variable_y = KratosComponents<Variable<double>>::Get(mVariableName + std::string("_Y"));
const Variable<double>& r_variable_z = KratosComponents<Variable<double>>::Get(mVariableName + std::string("_Z"));

// Apply the values
InternalApplyValue(r_variable_x, this->Is(X_COMPONENT_FIXED), values[0]);
InternalApplyValue(r_variable_y, this->Is(Y_COMPONENT_FIXED), values[1]);
InternalApplyValue(r_variable_z, this->Is(Z_COMPONENT_FIXED), values[2]);
}

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

void ApplyConstantVectorValueProcess::InternalApplyValue(
const Variable<double>& rVariable,
const bool ToBeFixed,
const double Value
)
{
// Get the number of nodes in the model part
const std::size_t number_of_nodes = mrModelPart.GetMesh(mMeshId).Nodes().size();

// Check if there are nodes in the model part
if(number_of_nodes != 0) {
// Get an iterator to the beginning of the nodes
auto it_begin = mrModelPart.GetMesh(mMeshId).NodesBegin();

// Check if the dofs are there (on the first node). Throw an error if trying to fix a variable that was not allocated
KRATOS_ERROR_IF(ToBeFixed && (it_begin->HasDofFor(rVariable) == false)) << "Trying to fix a dofs which was not allocated. Variable is --> " << rVariable.Name() << std::endl;

// Iterate over all nodes in the model part
block_for_each(mrModelPart.GetMesh(mMeshId).Nodes(), [&](Node& rNode){
// Fix the variable if needed
if(ToBeFixed) {
rNode.Fix(rVariable);
}
// Assign the constant value to the variable for the node
rNode.FastGetSolutionStepValue(rVariable) = Value;
});
}
}

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

const Parameters ApplyConstantVectorValueProcess::GetDefaultParameters() const
{
Parameters default_settings(R"({
"model_part_name":"PLEASE_CHOOSE_MODEL_PART_NAME",
"mesh_id" : 0,
"variable_name" : "PLEASE_PRESCRIBE_VARIABLE_NAME",
"is_fixed_x" : false,
"is_fixed_y" : false,
"is_fixed_z" : false,
"modulus" : 1.0,
"direction" : [1.0, 0.0, 0.0]
})");
return default_settings;
}

} // namespace Kratos.


Loading

0 comments on commit f8199f1

Please sign in to comment.