Skip to content

Commit

Permalink
Merge pull request #12985 from KratosMultiphysics/siapp/sensors/exten…
Browse files Browse the repository at this point in the history
…d_strain_sensor_to_solids

[SIApp] Adding Strain Sensor test for solids
  • Loading branch information
sunethwarna authored Jan 8, 2025
2 parents 7e4c67e + afbe277 commit ae48108
Show file tree
Hide file tree
Showing 21 changed files with 1,252 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,40 @@

namespace Kratos
{
namespace AdjointSemiAnalyticBaseConditionHelperUtils
{
template <class TData>
void CalculateOnIntegrationPoints(
Condition& rPrimalCondition,
const Condition& rAdjointCondition,
const Variable<TData>& rVariable,
std::vector<TData>& rValues,
const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY

if (rAdjointCondition.Has(rVariable)) {
// Get result value for output
const auto& output_value = rAdjointCondition.GetValue(rVariable);

// Resize Output
const auto gauss_points_number = rAdjointCondition.GetGeometry().IntegrationPointsNumber(rAdjointCondition.GetIntegrationMethod());
if (rValues.size() != gauss_points_number) {
rValues.resize(gauss_points_number);
}

// Write scalar result value on all Gauss-Points
for (IndexType i = 0; i < gauss_points_number; ++i) {
rValues[i] = output_value;
}
}
else {
rPrimalCondition.CalculateOnIntegrationPoints(rVariable, rValues, rCurrentProcessInfo);
}

KRATOS_CATCH("");
}
} // namespace AdjointSemiAnalyticBaseConditionHelperUtils

template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::EquationIdVector(EquationIdVectorType& rResult, const ProcessInfo& rCurrentProcessInfo ) const
Expand Down Expand Up @@ -114,62 +148,74 @@ namespace Kratos

template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::CalculateOnIntegrationPoints(
const Variable<array_1d<double, 3 > >& rVariable, std::vector< array_1d<double, 3 > >& rOutput, const ProcessInfo& rCurrentProcessInfo)
const Variable<bool>& rVariable,
std::vector<bool>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY;

if (this->Has(rVariable)) {
// Get result value for output
const auto& output_value = this->GetValue(rVariable);

// Resize Output
const SizeType gauss_points_number = this->GetGeometry()
.IntegrationPointsNumber(this->GetIntegrationMethod());
if (rOutput.size() != gauss_points_number) {
rOutput.resize(gauss_points_number);
}

// Write result value on all Gauss-Points
for(IndexType i = 0; i < gauss_points_number; ++i) {
rOutput[i] = output_value;
}

}
else {
KRATOS_ERROR << "Unsupported output variable." << std::endl;
}
AdjointSemiAnalyticBaseConditionHelperUtils::CalculateOnIntegrationPoints(*mpPrimalCondition, *this, rVariable, rOutput, rCurrentProcessInfo);
}

KRATOS_CATCH("")
template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::CalculateOnIntegrationPoints(
const Variable<double>& rVariable,
std::vector<double>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointSemiAnalyticBaseConditionHelperUtils::CalculateOnIntegrationPoints(*mpPrimalCondition, *this, rVariable, rOutput, rCurrentProcessInfo);
}

template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::CalculateOnIntegrationPoints(
const Variable<double>& rVariable, std::vector<double>& rOutput, const ProcessInfo& rCurrentProcessInfo)
const Variable<array_1d<double, 3>>& rVariable,
std::vector<array_1d<double, 3>>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY;
AdjointSemiAnalyticBaseConditionHelperUtils::CalculateOnIntegrationPoints(*mpPrimalCondition, *this, rVariable, rOutput, rCurrentProcessInfo);
}

if (this->Has(rVariable)) {
// Get result value for output
const auto& output_value = this->GetValue(rVariable);
template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::CalculateOnIntegrationPoints(
const Variable<array_1d<double, 4>>& rVariable,
std::vector<array_1d<double, 4>>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointSemiAnalyticBaseConditionHelperUtils::CalculateOnIntegrationPoints(*mpPrimalCondition, *this, rVariable, rOutput, rCurrentProcessInfo);
}

// Resize Output
const SizeType gauss_points_number = this->GetGeometry()
.IntegrationPointsNumber(this->GetIntegrationMethod());
if (rOutput.size() != gauss_points_number) {
rOutput.resize(gauss_points_number);
}
template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::CalculateOnIntegrationPoints(
const Variable<array_1d<double, 6>>& rVariable,
std::vector<array_1d<double, 6>>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointSemiAnalyticBaseConditionHelperUtils::CalculateOnIntegrationPoints(*mpPrimalCondition, *this, rVariable, rOutput, rCurrentProcessInfo);
}

// Write result value on all Gauss-Points
for(IndexType i = 0; i < gauss_points_number; ++i) {
rOutput[i] = output_value;
}
template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::CalculateOnIntegrationPoints(
const Variable<array_1d<double, 9>>& rVariable,
std::vector<array_1d<double, 9>>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointSemiAnalyticBaseConditionHelperUtils::CalculateOnIntegrationPoints(*mpPrimalCondition, *this, rVariable, rOutput, rCurrentProcessInfo);
}

}
else {
KRATOS_ERROR << "Unsupported output variable." << std::endl;
}
template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::CalculateOnIntegrationPoints(
const Variable<Vector>& rVariable,
std::vector<Vector>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointSemiAnalyticBaseConditionHelperUtils::CalculateOnIntegrationPoints(*mpPrimalCondition, *this, rVariable, rOutput, rCurrentProcessInfo);
}

KRATOS_CATCH("")
template <class TPrimalCondition>
void AdjointSemiAnalyticBaseCondition<TPrimalCondition>::CalculateOnIntegrationPoints(
const Variable<Matrix>& rVariable,
std::vector<Matrix>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointSemiAnalyticBaseConditionHelperUtils::CalculateOnIntegrationPoints(*mpPrimalCondition, *this, rVariable, rOutput, rCurrentProcessInfo);
}

template <class TPrimalCondition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,46 @@ class AdjointSemiAnalyticBaseCondition
KRATOS_ERROR << "Calculate of the adjoint base condition is called!" << std::endl;
}


void CalculateOnIntegrationPoints(const Variable<double>& rVariable,
std::vector<double>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(const Variable<array_1d<double, 3 > >& rVariable,
std::vector< array_1d<double, 3 > >& Output,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(const Variable<Vector >& rVariable,
std::vector< Vector >& Output,
const ProcessInfo& rCurrentProcessInfo) override
{
KRATOS_ERROR << "CalculateOnIntegrationPoints of the adjoint base condition is called!" << std::endl;
}

void CalculateOnIntegrationPoints(const Variable<Matrix >& rVariable,
std::vector< Matrix >& Output,
const ProcessInfo& rCurrentProcessInfo) override
{
KRATOS_ERROR << "CalculateOnIntegrationPoints of the adjoint base condition is called!" << std::endl;
}
// Results calculation on integration points
void CalculateOnIntegrationPoints(
const Variable<bool>& rVariable,
std::vector<bool>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(
const Variable<double>& rVariable,
std::vector<double>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(
const Variable<array_1d<double, 3>>& rVariable,
std::vector<array_1d<double, 3>>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(
const Variable<array_1d<double, 4>>& rVariable,
std::vector<array_1d<double, 4>>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(
const Variable<array_1d<double, 6>>& rVariable,
std::vector<array_1d<double, 6>>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(
const Variable<array_1d<double, 9>>& rVariable,
std::vector<array_1d<double, 9>>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(
const Variable<Vector>& rVariable,
std::vector<Vector>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

void CalculateOnIntegrationPoints(
const Variable<Matrix>& rVariable,
std::vector<Matrix>& rOutput,
const ProcessInfo& rCurrentProcessInfo) override;

int Check( const ProcessInfo& rCurrentProcessInfo ) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,42 @@
namespace Kratos
{

namespace AdjointFiniteDifferenceBaseElementHelperUtils
{

template <class TData>
void CalculateOnIntegrationPoints(
Element& rPrimalElement,
const Element& rAdjointElement,
const Variable<TData>& rVariable,
std::vector<TData>& rValues,
const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY

if (rAdjointElement.Has(rVariable)) {
// Get result value for output
const auto& output_value = rAdjointElement.GetValue(rVariable);

// Resize Output
const SizeType gauss_points_number = rAdjointElement.GetGeometry().IntegrationPointsNumber(rAdjointElement.GetIntegrationMethod());
if (rValues.size() != gauss_points_number) {
rValues.resize(gauss_points_number);
}

// Write scalar result value on all Gauss-Points
for (IndexType i = 0; i < gauss_points_number; ++i) {
rValues[i] = output_value;
}
}
else {
rPrimalElement.CalculateOnIntegrationPoints(rVariable, rValues, rCurrentProcessInfo);
}

KRATOS_CATCH("");
}
} // namespace AdjointFiniteDifferenceBaseElementHelperUtils

template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::EquationIdVector(EquationIdVectorType& rResult,
const ProcessInfo& rCurrentProcessInfo) const
Expand Down Expand Up @@ -194,60 +230,75 @@ void AdjointFiniteDifferencingBaseElement<TPrimalElement>::Calculate(const Varia
}

template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(const Variable<double>& rVariable,
std::vector<double>& rValues,
const ProcessInfo& rCurrentProcessInfo)
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(
const Variable<bool>& rVariable,
std::vector<bool>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY;

if(this->Has(rVariable))
{
// Get result value for output
const double& output_value = this->GetValue(rVariable);

// Resize Output
const SizeType gauss_points_number = this->GetGeometry()
.IntegrationPointsNumber(this->GetIntegrationMethod());
if (rValues.size() != gauss_points_number)
rValues.resize(gauss_points_number);

// Write scalar result value on all Gauss-Points
for(IndexType i = 0; i < gauss_points_number; ++i)
rValues[i] = output_value;
}
else
KRATOS_ERROR << "Unsupported output variable." << std::endl;
AdjointFiniteDifferenceBaseElementHelperUtils::CalculateOnIntegrationPoints(*mpPrimalElement, *this, rVariable, rOutput, rCurrentProcessInfo);
}

KRATOS_CATCH("")
template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(
const Variable<double>& rVariable,
std::vector<double>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointFiniteDifferenceBaseElementHelperUtils::CalculateOnIntegrationPoints(*mpPrimalElement, *this, rVariable, rOutput, rCurrentProcessInfo);
}

template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(
const Variable<array_1d<double, 3 > >& rVariable, std::vector< array_1d<double, 3 > >& rOutput, const ProcessInfo& rCurrentProcessInfo)
const Variable<array_1d<double, 3>>& rVariable,
std::vector<array_1d<double, 3>>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY;
AdjointFiniteDifferenceBaseElementHelperUtils::CalculateOnIntegrationPoints(*mpPrimalElement, *this, rVariable, rOutput, rCurrentProcessInfo);
}

if(this->Has(rVariable)) {
// Get result value for output
const auto& output_value = this->GetValue(rVariable);
template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(
const Variable<array_1d<double, 4>>& rVariable,
std::vector<array_1d<double, 4>>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointFiniteDifferenceBaseElementHelperUtils::CalculateOnIntegrationPoints(*mpPrimalElement, *this, rVariable, rOutput, rCurrentProcessInfo);
}

// Resize Output
const SizeType gauss_points_number = this->GetGeometry()
.IntegrationPointsNumber(this->GetIntegrationMethod());
if (rOutput.size() != gauss_points_number) {
rOutput.resize(gauss_points_number);
}
template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(
const Variable<array_1d<double, 6>>& rVariable,
std::vector<array_1d<double, 6>>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointFiniteDifferenceBaseElementHelperUtils::CalculateOnIntegrationPoints(*mpPrimalElement, *this, rVariable, rOutput, rCurrentProcessInfo);
}

// Write scalar result value on all Gauss-Points
for(IndexType i = 0; i < gauss_points_number; ++i) {
rOutput[i] = output_value;
}
template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(
const Variable<array_1d<double, 9>>& rVariable,
std::vector<array_1d<double, 9>>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointFiniteDifferenceBaseElementHelperUtils::CalculateOnIntegrationPoints(*mpPrimalElement, *this, rVariable, rOutput, rCurrentProcessInfo);
}

} else {
KRATOS_ERROR << "Unsupported output variable." << std::endl;
}
template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(
const Variable<Vector>& rVariable,
std::vector<Vector>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointFiniteDifferenceBaseElementHelperUtils::CalculateOnIntegrationPoints(*mpPrimalElement, *this, rVariable, rOutput, rCurrentProcessInfo);
}

KRATOS_CATCH("")
template <class TPrimalElement>
void AdjointFiniteDifferencingBaseElement<TPrimalElement>::CalculateOnIntegrationPoints(
const Variable<Matrix>& rVariable,
std::vector<Matrix>& rOutput,
const ProcessInfo& rCurrentProcessInfo)
{
AdjointFiniteDifferenceBaseElementHelperUtils::CalculateOnIntegrationPoints(*mpPrimalElement, *this, rVariable, rOutput, rCurrentProcessInfo);
}

template <class TPrimalElement>
Expand Down
Loading

0 comments on commit ae48108

Please sign in to comment.