Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions src/constraint_framework/4C_constraint_framework_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,11 @@ FOUR_C_NAMESPACE_OPEN
/*----------------------------------------------------------------------------*
*----------------------------------------------------------------------------*/
void Constraints::SubmodelEvaluator::LinearCoupledEquation::evaluate_equation(
Core::LinAlg::SparseMatrix& Q_dd, Core::LinAlg::SparseMatrix& Q_dL,
Core::LinAlg::SparseMatrix& Q_Ld, Core::LinAlg::Vector<double>& constraint_vector,
const Core::LinAlg::Vector<double>& D_np1)
Core::LinAlg::SparseMatrix& Q_Ld)
{
double constraintViolation = 0.;

// Iterate over the elements (coefficient, rowId, dofId) in equationData.
// Each element of equation data represents one term of the defined multipoint constraints
// The rowId is equivalent to the Number of the equation
for (const auto& [coefficient, rowId, dofId] : equation_data_)
{
// stiffness contribution
Q_dL.assemble(coefficient, dofId, rowId);
Q_Ld.assemble(coefficient, rowId, dofId);

// force contribution
constraintViolation = D_np1.get_values()[dofId] * coefficient;
constraint_vector.sum_into_global_values(1, &constraintViolation, &rowId);
}
// assemble the rows owned by this rank
for (const auto& [coefficient, row_id, dof_id] : equation_data_)
if (Q_Ld.row_map().my_gid(row_id)) Q_Ld.assemble(coefficient, row_id, dof_id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if drops rows that are not in the row map. For the periodic constraints this never happens. But for DESIGN POINT COUPLED DOF EQUATION CONDITIONS together with RVE_REFERENCE_POINTS: automatic it does happen.

FIX:

for (const auto& [coefficient, row_id, dof_id] : equation_data_)
{
    FOUR_C_ASSERT_ALWAYS(Q_Ld.row_map().my_gid(row_id),
        "Constraint equation row {} is not in the constraint row map and would "
        "be dropped.",
        row_id);
    Q_Ld.assemble(coefficient, row_id, dof_id);
  }

}
/*----------------------------------------------------------------------------*
*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -76,4 +62,4 @@ Constraints::SubmodelEvaluator::LinearCoupledEquation::LinearCoupledEquation(
}
/*----------------------------------------------------------------------------*
*----------------------------------------------------------------------------*/
FOUR_C_NAMESPACE_CLOSE
FOUR_C_NAMESPACE_CLOSE
18 changes: 4 additions & 14 deletions src/constraint_framework/4C_constraint_framework_equation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,11 @@ namespace Constraints::SubmodelEvaluator
//! Constructor
ConstraintEquationBase() = default;

/*! \brief Add the penalty stiffness contribution to the constraint_vector and the
* coupling-stiffness
/*! \brief Assemble this equation's terms into the coupling matrix \f$Q_{Ld}\f$
*
* @param [in] \f$Q_{dd}\f$ coupling-stiffnes matrix
* @param [in] \f$Q_{dL}\f$ coupling-stiffnes matrix
* @param [in] \f$Q_{Ld}\f$ coupling-stiffnes matrix
* @param [in] constraint_vector constraint vector
* @param [in] displacements \f$D_{n+1}\f$
* @param [in,out] Q_Ld coupling-stiffness matrix
*/
virtual void evaluate_equation(Core::LinAlg::SparseMatrix& Q_dd,
Core::LinAlg::SparseMatrix& Q_dL, Core::LinAlg::SparseMatrix& Q_Ld,
Core::LinAlg::Vector<double>& constraint_vector,
const Core::LinAlg::Vector<double>& D_np1) = 0;
virtual void evaluate_equation(Core::LinAlg::SparseMatrix& Q_Ld) = 0;

/*! \brief Return the number of constraints the object contains
*
Expand Down Expand Up @@ -82,9 +74,7 @@ namespace Constraints::SubmodelEvaluator
LinearCoupledEquation(int id, const std::vector<int>& dofs, std::vector<double> coefficients);

//! derived
void evaluate_equation(Core::LinAlg::SparseMatrix& Q_dd, Core::LinAlg::SparseMatrix& Q_dL,
Core::LinAlg::SparseMatrix& Q_Ld, Core::LinAlg::Vector<double>& constraint_vector,
const Core::LinAlg::Vector<double>& D_np1) override;
void evaluate_equation(Core::LinAlg::SparseMatrix& Q_Ld) override;

private:
//! Struct with Term data: Coef, RowID, DofID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ Constraints::SubmodelEvaluator::ConstraintBase::ConstraintBase()
constraint_parameter_list, "CONSTRAINT_ENFORCEMENT");
}

void Constraints::SubmodelEvaluator::ConstraintBase::set_owned_constraint_row_ids(
std::vector<int> row_ids)
{
owned_constraint_row_ids_ = std::move(row_ids);
use_explicit_constraint_row_ids_ = true;
}

bool Constraints::SubmodelEvaluator::ConstraintBase::evaluate_force_stiff(
const Core::LinAlg::Vector<double>& displacement_vector,
std::shared_ptr<Solid::TimeInt::BaseDataGlobalState>& global_state_ptr,
Expand Down Expand Up @@ -72,28 +79,34 @@ void Constraints::SubmodelEvaluator::ConstraintBase::evaluate_coupling_terms(
for (const auto& mpc : constraint_equations_)
ncon_ += mpc->get_number_of_constraint_equation_objects();

// ToDo: Add an offset to the constraint dof map.
n_condition_map_ = std::make_shared<Core::LinAlg::Map>(ncon_, 0, stiff_ptr_->get_comm());
if (!use_explicit_constraint_row_ids_)
{
n_condition_map_ = std::make_shared<Core::LinAlg::Map>(ncon_, 0, stiff_ptr_->get_comm());
}
else
{
n_condition_map_ =
std::make_shared<Core::LinAlg::Map>(-1, static_cast<int>(owned_constraint_row_ids_.size()),
owned_constraint_row_ids_.data(), 0, stiff_ptr_->get_comm());
}

// initialise all global coupling objects
constraint_residual_ = std::make_shared<Core::LinAlg::Vector<double>>(*n_condition_map_, true);
Q_Ld_ = std::make_shared<Core::LinAlg::SparseMatrix>(*n_condition_map_, 4);
Q_dL_ = std::make_shared<Core::LinAlg::SparseMatrix>(stiff_ptr_->row_map(), 4);
Q_dd_ = std::make_shared<Core::LinAlg::SparseMatrix>(stiff_ptr_->row_map(), 0);

// set Q_dd to zero as default
Q_dd_->zero();
// Evaluate the Constraint Pairs / equations objects

std::shared_ptr<const Core::LinAlg::Vector<double>> dis_np = gstate.get_dis_np();
for (const auto& obj : constraint_equations_)
{
obj->evaluate_equation(*Q_dd_, *Q_dL_, *Q_Ld_, *constraint_residual_, *dis_np);
}
Core::IO::cout(Core::IO::debug) << "Evaluated all constraint objects" << Core::IO::endl;
for (const auto& obj : constraint_equations_) obj->evaluate_equation(*Q_Ld_);

// Complete
Q_dd_->complete();
Q_Ld_->complete(stiff_ptr_->domain_map(), *n_condition_map_);

// Q_dL = Q_Ld^T
Q_dL_ = Core::LinAlg::matrix_transpose(*Q_Ld_);
Q_dL_->complete(*n_condition_map_, stiff_ptr_->domain_map());

// constraint residual r_L = Q_Ld * d
Q_Ld_->multiply(false, *dis_np, *constraint_residual_);
}
FOUR_C_NAMESPACE_CLOSE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "4C_structure_new_enum_lists.hpp"
#include "4C_structure_new_model_evaluator_generic.hpp"

#include <vector>

FOUR_C_NAMESPACE_OPEN

namespace Constraints::SubmodelEvaluator
Expand Down Expand Up @@ -58,6 +60,9 @@ namespace Constraints::SubmodelEvaluator
//! Return the Penalty-Parameter
double& get_penalty_parameter_ptr() { return penalty_parameter_; }

//! Set the constraint rows owned by this rank

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these actually row IDs in a matrix or the global IDs of DOFs, that are subject to a constraint?

void set_owned_constraint_row_ids(std::vector<int> row_ids);

//! Generate the runtime output
virtual void runtime_output_step_state(std::pair<double, int> output_time_and_step) {};

Expand All @@ -70,6 +75,12 @@ namespace Constraints::SubmodelEvaluator
//! Penalty parameter
double penalty_parameter_;

//! Constraint rows owned by this rank
std::vector<int> owned_constraint_row_ids_;

//! Use owned_constraint_row_ids_ for the constraint map
bool use_explicit_constraint_row_ids_ = false;

protected:
//! Vector containing all constraint equation objects
std::vector<std::shared_ptr<ConstraintEquationBase>> constraint_equations_;
Expand Down Expand Up @@ -99,4 +110,4 @@ namespace Constraints::SubmodelEvaluator
} // namespace Constraints::SubmodelEvaluator

FOUR_C_NAMESPACE_CLOSE
#endif
#endif
Loading
Loading