Skip to content

Commit f7da499

Browse files
Make potential_reduction_length optional
1 parent decfd2a commit f7da499

6 files changed

+36
-34
lines changed

src/beaminteraction/src/potential/4C_beaminteraction_potential_input.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ void BeamPotential::set_valid_parameters(std::map<std::string, Core::IO::InputSp
7373
"slave be assigned to beam elements?",
7474
.default_value = MasterSlaveChoice::smaller_eleGID_is_slave}));
7575

76-
// TODO add None as default value
77-
beampotential.specs.emplace_back(parameter<double>("POTENTIAL_REDUCTION_LENGTH",
78-
{.description = "Within this length of the master beam end point the potential is smoothly "
79-
"reduced to one half to account for infinitely long master beam surrogates.",
80-
.default_value = -1.0}));
76+
beampotential.specs.emplace_back(parameter<std::optional<double>>("POTENTIAL_REDUCTION_LENGTH",
77+
{.description =
78+
"Within this length of the master beam end point the potential is smoothly "
79+
"reduced to one half to account for infinitely long master beam surrogates."}));
8180

8281
beampotential.move_into_collection(list);
8382

src/beaminteraction/src/potential/4C_beaminteraction_potential_pair_beam_to_beam.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ void BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::
10681068
}
10691069

10701070
if (params()->strategy() == BeamPotential::Strategy::single_length_specific_small_separations &&
1071-
params()->potential_reduction_length() != -1.0)
1071+
params()->potential_reduction_length().has_value())
10721072
{
10731073
FOUR_C_THROW(
10741074
"The potential reduction strategy is currently not implemented for the beam interaction "
@@ -1084,20 +1084,20 @@ void BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::
10841084
const std::optional<double> cutoff_radius = params()->cutoff_radius();
10851085

10861086
// get potential reduction length
1087-
const double potential_reduction_length = params()->potential_reduction_length();
1087+
const std::optional<double> potential_reduction_length = params()->potential_reduction_length();
10881088

10891089
// get length from current master beam element to beam edge
10901090
double length_prior_left = 0.0;
10911091
double length_prior_right = 0.0;
10921092

1093-
if (potential_reduction_length > 0.0)
1093+
if (potential_reduction_length.has_value())
10941094
{
10951095
std::tie(length_prior_left, length_prior_right) =
10961096
params()->ele_gid_prior_length_map_.at(element2()->id());
10971097

10981098
if ((length_prior_left >= 0.0) && (length_prior_right >= 0.0) &&
1099-
((ele2length_ - 2 * potential_reduction_length + length_prior_left + length_prior_right) <
1100-
0.0))
1099+
((ele2length_ - 2 * potential_reduction_length.value() + length_prior_left +
1100+
length_prior_right) < 0.0))
11011101
{
11021102
FOUR_C_THROW(
11031103
"ERROR: Master beam endpoint reduction strategy would interfere on current master beam "
@@ -3029,8 +3029,8 @@ bool BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues,
30293029
Core::LinAlg::Matrix<1, 3, T> const& xi_master_partial_r_slave,
30303030
Core::LinAlg::Matrix<1, 3, T> const& xi_master_partial_r_master,
30313031
Core::LinAlg::Matrix<1, 3, T> const& xi_master_partial_r_xi_master,
3032-
double potential_reduction_length, double length_prior_right, double length_prior_left,
3033-
T& interaction_potential_GP,
3032+
std::optional<double> potential_reduction_length, double length_prior_right,
3033+
double length_prior_left, T& interaction_potential_GP,
30343034
Core::LinAlg::Matrix<1, numnodes * numnodalvalues, double> const& N_i_slave,
30353035
Core::LinAlg::Matrix<1, numnodes * numnodalvalues, double> const& N_i_xi_slave,
30363036
Core::LinAlg::Matrix<1, numnodes * numnodalvalues, T> const& N_i_master,
@@ -3227,35 +3227,37 @@ bool BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues,
32273227
}
32283228

32293229
// determine potential reduction factor for master beam endpoint strategy
3230-
if (potential_reduction_length > 0.0)
3230+
if (potential_reduction_length.has_value())
32313231
{
32323232
T left_length_to_edge = length_prior_left + ele2length_ * 0.5 * (1 + xi_master);
32333233
T right_length_to_edge = length_prior_right + ele2length_ * 0.5 * (1 - xi_master);
32343234
T length_to_edge = -1.0;
32353235
bool right_node = false;
32363236

32373237
// determine potential reduction factor (master beam can only consist of one element!)
3238-
if (left_length_to_edge < potential_reduction_length)
3238+
if (left_length_to_edge < potential_reduction_length.value())
32393239
{
32403240
potential_reduction_factor_GP =
3241-
0.5 - 0.5 * std::cos(M_PI * left_length_to_edge / potential_reduction_length);
3241+
0.5 - 0.5 * std::cos(M_PI * left_length_to_edge / potential_reduction_length.value());
32423242
length_to_edge = left_length_to_edge;
32433243
}
3244-
else if (right_length_to_edge < potential_reduction_length)
3244+
else if (right_length_to_edge < potential_reduction_length.value())
32453245
{
32463246
potential_reduction_factor_GP =
3247-
0.5 - 0.5 * std::cos(M_PI * right_length_to_edge / potential_reduction_length);
3247+
0.5 - 0.5 * std::cos(M_PI * right_length_to_edge / potential_reduction_length.value());
32483248
length_to_edge = right_length_to_edge;
32493249
right_node = true;
32503250
}
32513251

3252-
if ((length_to_edge < potential_reduction_length) && (length_to_edge != -1.0))
3252+
if ((length_to_edge < potential_reduction_length.value()) && (length_to_edge != -1.0))
32533253
{
3254-
pot_red_fac_deriv_l_edge = 0.5 * M_PI / potential_reduction_length *
3255-
std::sin(M_PI * length_to_edge / potential_reduction_length);
3256-
pot_red_fac_2ndderiv_l_edge = 0.5 * M_PI * M_PI /
3257-
(potential_reduction_length * potential_reduction_length) *
3258-
std::cos(M_PI * length_to_edge / potential_reduction_length);
3254+
pot_red_fac_deriv_l_edge =
3255+
0.5 * M_PI / potential_reduction_length.value() *
3256+
std::sin(M_PI * length_to_edge / potential_reduction_length.value());
3257+
pot_red_fac_2ndderiv_l_edge =
3258+
0.5 * M_PI * M_PI /
3259+
(potential_reduction_length.value() * potential_reduction_length.value()) *
3260+
std::cos(M_PI * length_to_edge / potential_reduction_length.value());
32593261
}
32603262

32613263
l_edge_deriv_xi_master = 0.5 * ele2length_;

src/beaminteraction/src/potential/4C_beaminteraction_potential_pair_beam_to_beam.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ namespace BeamInteraction
284284
Core::LinAlg::Matrix<1, 3, T> const& xi_master_partial_r_slave,
285285
Core::LinAlg::Matrix<1, 3, T> const& xi_master_partial_r_master,
286286
Core::LinAlg::Matrix<1, 3, T> const& xi_master_partial_r_xi_master,
287-
double potential_reduction_length, double length_prior_right, double length_prior_left,
288-
T& interaction_potential_GP,
287+
std::optional<double> potential_reduction_length, double length_prior_right,
288+
double length_prior_left, T& interaction_potential_GP,
289289
Core::LinAlg::Matrix<1, numnodes * numnodalvalues, double> const& N_i_slave,
290290
Core::LinAlg::Matrix<1, numnodes * numnodalvalues, double> const& N_i_xi_slave,
291291
Core::LinAlg::Matrix<1, numnodes * numnodalvalues, T> const& N_i_master,

src/beaminteraction/src/potential/4C_beaminteraction_potential_params.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BeamInteraction::BeamPotentialParams::BeamPotentialParams()
3636
choice_master_slave_(BeamPotential::MasterSlaveChoice::vague),
3737
visualization_output_(false),
3838
params_runtime_visualization_output_btb_potential_(nullptr),
39-
potential_reduction_length_(0.0)
39+
potential_reduction_length_(std::nullopt)
4040
{
4141
// empty constructor
4242
}
@@ -121,7 +121,7 @@ void BeamInteraction::BeamPotentialParams::init(const double restart_time)
121121
/****************************************************************************/
122122
cutoff_radius_ = beam_potential_params_list.get<std::optional<double>>("CUTOFF_RADIUS");
123123

124-
if (cutoff_radius_.has_value() && cutoff_radius_.value() <= 0.0)
124+
if (cutoff_radius_.has_value() and cutoff_radius_.value() <= 0.0)
125125
FOUR_C_THROW("Invalid cutoff radius! Must be positive value or null to deactivate.");
126126

127127
/****************************************************************************/
@@ -189,10 +189,11 @@ void BeamInteraction::BeamPotentialParams::init(const double restart_time)
189189

190190
/****************************************************************************/
191191
potential_reduction_length_ =
192-
beam_potential_params_list.get<double>("POTENTIAL_REDUCTION_LENGTH");
192+
beam_potential_params_list.get<std::optional<double>>("POTENTIAL_REDUCTION_LENGTH");
193193

194-
if (potential_reduction_length_ != -1.0 and potential_reduction_length_ <= 0.0)
195-
FOUR_C_THROW("Invalid potential reduction length! Must be positive value or -1 to deactivate.");
194+
if (potential_reduction_length_.has_value() and potential_reduction_length_.value() <= 0.0)
195+
FOUR_C_THROW(
196+
"Invalid potential reduction length! Must be positive value or none to deactivate.");
196197

197198
isinit_ = true;
198199
}

src/beaminteraction/src/potential/4C_beaminteraction_potential_params.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ namespace BeamInteraction
131131
return params_runtime_visualization_output_btb_potential_;
132132
}
133133

134-
inline double potential_reduction_length() const
134+
inline std::optional<double> potential_reduction_length() const
135135
{
136136
throw_error_if_not_init_and_setup();
137137
return potential_reduction_length_;
@@ -191,7 +191,7 @@ namespace BeamInteraction
191191
//! within this length starting from the master beam end point the potential is smoothly
192192
//! reduced to zero to account for infinitely long master beam surrogates and enable an
193193
//! axial pull-off force.
194-
double potential_reduction_length_;
194+
std::optional<double> potential_reduction_length_;
195195
};
196196

197197
} // namespace BeamInteraction

src/beaminteraction/src/potential/4C_beaminteraction_potential_submodel_evaluator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void BeamInteraction::SUBMODELEVALUATOR::BeamPotential::post_setup()
143143
{
144144
check_init_setup();
145145

146-
if (beam_potential_params().potential_reduction_length() != -1.0)
146+
if (beam_potential_params().potential_reduction_length().has_value())
147147
setup_potential_reduction_strategy();
148148

149149
nearby_elements_map_.clear();
@@ -599,7 +599,7 @@ void BeamInteraction::SUBMODELEVALUATOR::BeamPotential::post_read_restart()
599599
{
600600
check_init_setup();
601601

602-
if (beam_potential_params().potential_reduction_length() != -1.0)
602+
if (beam_potential_params().potential_reduction_length().has_value())
603603
setup_potential_reduction_strategy();
604604

605605
nearby_elements_map_.clear();

0 commit comments

Comments
 (0)