Skip to content

Commit

Permalink
Merge pull request #10634 from KratosMultiphysics/cosim/tetra-line-da…
Browse files Browse the repository at this point in the history
…ta-transfer

[CoSimulationApplication] 3D domain (volume) - 1D domain (line) data transfer operator
  • Loading branch information
loumalouomega authored Oct 30, 2024
2 parents 0040ede + 88b7c62 commit 1e22ea3
Show file tree
Hide file tree
Showing 14 changed files with 3,312 additions and 0 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
// KRATOS / ___|___/ ___|(_)_ __ ___ _ _| | __ _| |_(_) ___ _ ___
// | | / _ \___ \| | '_ ` _ \| | | | |/ _` | __| |/ _ \| '_ |
// | |__| (_) |__) | | | | | | | |_| | | (_| | |_| | (_) | | | |
// \____\___/____/|_|_| |_| |_|\__,_|_|\__,_|\__|_|\___/|_| |_|
//
// License: BSD License
// license: CoSimulationApplication/license.txt
//
// Main authors: Vicente Mataix Ferrandiz
//

#pragma once

// System includes

// External includes

// Project includes
#include "includes/define.h"
#include "includes/model_part.h"
#include "includes/kratos_parameters.h"
#include "processes/process.h"

/* The mappers includes */
#include "spaces/ublas_space.h"
#include "mappers/mapper_flags.h"
#include "factories/mapper_factory.h"

namespace Kratos
{
///@addtogroup CoSimulationApplication
///@{

///@}
///@name Functions
///@{

///@}
///@name Kratos Classes
///@{

/**
* @class PointElement
* @ingroup CoSimulationApplication
* @brief Custom Point container to be used by the search
* @details It stores the pointer of a certain element
* @author Vicente Mataix Ferrandiz
*/
class PointElement
: public Point
{
public:

///@name Type Definitions
///@{

/// Base class definition
typedef Point BaseType;

/// Counted pointer of PointElement
KRATOS_CLASS_POINTER_DEFINITION( PointElement );

///@}
///@name Life Cycle
///@{

/// Default constructors
PointElement():
BaseType()
{}

PointElement(const double X, const double Y, const double Z)
: BaseType(X, Y, Z)
{}

PointElement(Element::Pointer pElement):
mpElement(pElement)
{
UpdatePoint();
}


///@}
///@name Operators
///@{

///@}
///@name Operations
///@{

/**
* @brief Returns the element associated to the point
* @return mpElement The reference to the element associated to the point
*/
Element::Pointer pGetElement()
{
return mpElement;
}

/**
* @brief This function updates the database, using as base for the coordinates the condition center
*/
void UpdatePoint()
{
noalias(this->Coordinates()) = mpElement->GetGeometry().Center().Coordinates();
}

private:
///@}
///@name Member Variables
///@{

Element::Pointer mpElement = nullptr; // The element instance

///@}

}; // Class PointElement

#define DEFINE_MAPPER_FACTORY_SERIAL \
using SparseSpace = UblasSpace<double, boost::numeric::ublas::compressed_matrix<double>, boost::numeric::ublas::vector<double>>; \
using DenseSpace = UblasSpace<double, DenseMatrix<double>, DenseVector<double>>; \
using MapperFactoryType = MapperFactory<SparseSpace, DenseSpace>; \
using MapperType = Mapper<SparseSpace, DenseSpace>;

/**
* @class DataTransfer3D1DProcess
* @ingroup CoSimulationApplication
* @brief This utility includes auxiliary methods to transfer from 3D domains to 1D domains and viceversa
* @author Vicente Mataix Ferrandiz
*/
class KRATOS_API(CO_SIMULATION_APPLICATION) DataTransfer3D1DProcess
: public Process
{
public:
///@name Type Definitions
///@{

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

/// Geometry definition
using GeometryType = Geometry<Node>;

// Define mapper factory
DEFINE_MAPPER_FACTORY_SERIAL

///@}
///@name Life Cycle
///@{

/// Default constructor.
DataTransfer3D1DProcess(
ModelPart& rFirstModelPart,
ModelPart& rSecondModelPart,
Parameters ThisParameters = Parameters(R"({})")
);


///@}
///@name Operators
///@{

void operator()()
{
Execute();
}

///@}
///@name Operations
///@{

/**
* @brief This method executes the process
*/
void Execute() override;

/**
* @brief This method provides the defaults parameters to avoid conflicts between the different constructors
*/
const Parameters GetDefaultParameters() const override;

///@}
private:
///@name Private member Variables
///@{

ModelPart& mr3DModelPart; /// The 3D model part
ModelPart& mr1DModelPart; /// The 1D model part
Parameters mThisParameters; /// The parameters containing the configuration
MapperType::Pointer mpMapper = nullptr; /// The mapper pointer
std::vector<const Variable<double>*> mOriginListVariables; /// The list of variables to be transferred (origin)
std::vector<const Variable<double>*> mDestinationListVariables; /// The list of variables to be transferred (destination)

///@}
///@name Private Operations
///@{

/**
* @brief This method interpolates from the 3D to the 1D
*/
void InterpolateFrom3Dto1D();

/**
* @brief This method interpolates from the 1D to the 3D
*/
void InterpolateFrom1Dto3D();

/**
* @brief This method computes the list of variables to interpolate
* @param rOriginListVariables The list of origin variables to interpolate
* @param rDestinationListVariables The list of destination variables to interpolate
*/
void GetVariablesList(
std::vector<const Variable<double>*>& rOriginListVariables,
std::vector<const Variable<double>*>& rDestinationListVariables
);

/**
* @brief This method computes maximum length of the elements
* @param rModelPart The model part to compute
* @return The maximum length
*/
static double GetMaxLength(const ModelPart& rModelPart);

///@}
}; // Class DataTransfer3D1DProcess

///@}

///@} addtogroup block

} // namespace Kratos.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// KRATOS / ___|___/ ___|(_)_ __ ___ _ _| | __ _| |_(_) ___ _ ___
// | | / _ \___ \| | '_ ` _ \| | | | |/ _` | __| |/ _ \| '_ |
// | |__| (_) |__) | | | | | | | |_| | | (_| | |_| | (_) | | | |
// \____\___/____/|_|_| |_| |_|\__,_|_|\__,_|\__|_|\___/|_| |_|
//
// License: BSD License
// license: CoSimulationApplication/license.txt
//
// Main authors:
//

// System includes

// External includes

// Project includes
#include "includes/define.h"
#include "custom_python/add_custom_processes_to_python.h"
#include "custom_processes/data_transfer_3D_1D_process.h"

namespace Kratos::Python{

void AddCustomProcessesToPython(pybind11::module& m)
{
namespace py = pybind11;

py::class_< DataTransfer3D1DProcess, DataTransfer3D1DProcess::Pointer, Process>(m, "DataTransfer3D1DProcess")
.def(py::init<ModelPart&, ModelPart&>())
.def(py::init<ModelPart&, ModelPart&, Parameters>())
;
}

} // namespace Kratos::Python.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// KRATOS / ___|___/ ___|(_)_ __ ___ _ _| | __ _| |_(_) ___ _ ___
// | | / _ \___ \| | '_ ` _ \| | | | |/ _` | __| |/ _ \| '_ |
// | |__| (_) |__) | | | | | | | |_| | | (_| | |_| | (_) | | | |
// \____\___/____/|_|_| |_| |_|\__,_|_|\__,_|\__|_|\___/|_| |_|
//
// License: BSD License
// license: CoSimulationApplication/license.txt
//
// Main authors:
//

#pragma once

// System includes
#include <pybind11/pybind11.h>

// External includes

// Project includes
#include "includes/define.h"

namespace Kratos::Python {

void AddCustomProcessesToPython(pybind11::module& m);

} // namespace Kratos::Python.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "custom_python/add_co_sim_io_to_python.h"
#include "custom_python/add_custom_io_to_python.h"
#include "custom_python/add_custom_utilities_to_python.h"
#include "custom_python/add_custom_processes_to_python.h"

namespace Kratos::Python {

Expand All @@ -39,6 +40,7 @@ PYBIND11_MODULE(KratosCoSimulationApplication,m)
AddCoSimIOToPython(m);
AddCustomIOToPython(m);
AddCustomUtilitiesToPython(m);
AddCustomProcessesToPython(m);

KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, SCALAR_DISPLACEMENT );
KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, SCALAR_ROOT_POINT_DISPLACEMENT );
Expand Down
Loading

0 comments on commit 1e22ea3

Please sign in to comment.