Skip to content

Commit decfd2a

Browse files
Make cutoff_radius optional
1 parent 716ec20 commit decfd2a

6 files changed

+29
-24
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,22 @@ void BeamPotential::set_valid_parameters(std::map<std::string, Core::IO::InputSp
3535
{.description = "prefactor(s) $k_i$ of potential law $\\Phi(r) = \\sum_i (k_i * r^{-m_i})$.",
3636
.default_value = "0.0"}));
3737

38+
// TODO remove default value
3839
beampotential.specs.emplace_back(parameter<BeamPotential::Type>("TYPE",
3940
{.description = "Type of potential interaction: surface (default) or volume potential",
4041
.default_value = BeamPotential::Type::surface}));
4142

43+
// TODO remove default value
4244
beampotential.specs.emplace_back(parameter<BeamPotential::Strategy>("STRATEGY",
4345
{.description = "strategy to evaluate interaction potential: double/single length specific, "
4446
"small/large separation approximation, ...",
4547
.default_value = BeamPotential::Strategy::double_length_specific_large_separations}));
4648

47-
beampotential.specs.emplace_back(parameter<double>("CUTOFF_RADIUS",
49+
beampotential.specs.emplace_back(parameter<std::optional<double>>("CUTOFF_RADIUS",
4850
{.description =
49-
"Neglect all potential contributions at separation largerthan this cutoff radius",
50-
.default_value = -1.0}));
51+
"Neglect all potential contributions at separation largerthan this cutoff radius"}));
5152

53+
// TODO subgroup regularization
5254
beampotential.specs.emplace_back(parameter<BeamPotential::RegularizationType>(
5355
"REGULARIZATION_TYPE", {.description = "Type of regularization applied to the force law",
5456
.default_value = BeamPotential::RegularizationType::none}));
@@ -71,6 +73,7 @@ void BeamPotential::set_valid_parameters(std::map<std::string, Core::IO::InputSp
7173
"slave be assigned to beam elements?",
7274
.default_value = MasterSlaveChoice::smaller_eleGID_is_slave}));
7375

76+
// TODO add None as default value
7477
beampotential.specs.emplace_back(parameter<double>("POTENTIAL_REDUCTION_LENGTH",
7578
{.description = "Within this length of the master beam end point the potential is smoothly "
7679
"reduced to one half to account for infinitely long master beam surrogates.",

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ bool BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::eval
102102
const std::vector<Core::Conditions::Condition*> linechargeconds, const double k, const double m)
103103
{
104104
// no need to evaluate this pair in case of separation by far larger than cutoff or prefactor zero
105-
if ((params()->cutoff_radius() != -1.0 and
105+
if ((params()->cutoff_radius().has_value() and
106106
are_elements_much_more_separated_than_cutoff_distance()) or
107107
k == 0.0)
108108
return false;
@@ -203,7 +203,7 @@ void BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::
203203
set_automatic_differentiation_variables_if_required(ele1pos_, ele2pos_);
204204

205205
// get cutoff radius
206-
const double cutoff_radius = params()->cutoff_radius();
206+
const std::optional<double> cutoff_radius = params()->cutoff_radius();
207207

208208
// number of integration segments per element
209209
const unsigned int num_integration_segments = params()->number_integration_segments();
@@ -354,7 +354,8 @@ void BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::
354354
norm_dist = Core::FADUtils::vector_norm(dist);
355355

356356
// check cutoff criterion: if specified, contributions are neglected at larger separation
357-
if (cutoff_radius != -1.0 and Core::FADUtils::cast_to_double(norm_dist) > cutoff_radius)
357+
if (cutoff_radius.has_value() and
358+
Core::FADUtils::cast_to_double(norm_dist) > cutoff_radius.value())
358359
continue;
359360

360361
// auxiliary variables to store pre-calculated common terms
@@ -575,7 +576,7 @@ void BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::
575576
set_automatic_differentiation_variables_if_required(ele1pos_, ele2pos_);
576577

577578
// get cutoff radius
578-
const double cutoff_radius = params()->cutoff_radius();
579+
const std::optional<double> cutoff_radius = params()->cutoff_radius();
579580

580581
// get regularization type and separation
581582
const BeamPotential::RegularizationType regularization_type = params()->regularization_type();
@@ -775,7 +776,8 @@ void BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::
775776
}
776777

777778
// check cutoff criterion: if specified, contributions are neglected at larger separation
778-
if (cutoff_radius != -1.0 and Core::FADUtils::cast_to_double(norm_dist) > cutoff_radius)
779+
if (cutoff_radius.has_value() and
780+
Core::FADUtils::cast_to_double(norm_dist) > cutoff_radius.value())
779781
continue;
780782

781783
gap = norm_dist - radius1_ - radius2_;
@@ -1079,7 +1081,7 @@ void BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::
10791081
"potential requires the beam radii to be identical!");
10801082

10811083
// get cutoff radius
1082-
const double cutoff_radius = params()->cutoff_radius();
1084+
const std::optional<double> cutoff_radius = params()->cutoff_radius();
10831085

10841086
// get potential reduction length
10851087
const double potential_reduction_length = params()->potential_reduction_length();
@@ -1358,7 +1360,8 @@ void BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues, T>::
13581360
}
13591361

13601362
// check cutoff criterion: if specified, contributions are neglected at larger separation
1361-
if (cutoff_radius != -1.0 and Core::FADUtils::cast_to_double(norm_dist_ul) > cutoff_radius)
1363+
if (cutoff_radius.has_value() and
1364+
Core::FADUtils::cast_to_double(norm_dist_ul) > cutoff_radius.value())
13621365
{
13631366
continue;
13641367
}
@@ -3800,10 +3803,8 @@ bool BeamInteraction::BeamToBeamPotentialPair<numnodes, numnodalvalues,
38003803
element2_spherical_box_radius;
38013804

38023805

3803-
if (estimated_minimal_centerline_separation > safety_factor * params()->cutoff_radius())
3804-
return true;
3805-
else
3806-
return false;
3806+
return (
3807+
estimated_minimal_centerline_separation > safety_factor * params()->cutoff_radius().value());
38073808
}
38083809

38093810
// explicit template instantiations

src/beaminteraction/src/potential/4C_beaminteraction_potential_pair_beam_to_sphere.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void BeamInteraction::BeamToSpherePotentialPair<numnodes,
215215
numnodalvalues>::evaluate_fpotand_stiffpot_large_sep_approx()
216216
{
217217
// get cutoff radius
218-
const double cutoff_radius = params()->cutoff_radius();
218+
const std::optional<double> cutoff_radius = params()->cutoff_radius();
219219

220220
// Set gauss integration rule
221221
Core::FE::GaussRule1D gaussrule = get_gauss_rule();
@@ -298,7 +298,8 @@ void BeamInteraction::BeamToSpherePotentialPair<numnodes,
298298
norm_dist = Core::FADUtils::vector_norm<3>(dist);
299299

300300
// check cutoff criterion: if specified, contributions are neglected at larger separation
301-
if (cutoff_radius != -1.0 and Core::FADUtils::cast_to_double(norm_dist) > cutoff_radius)
301+
if (cutoff_radius.has_value() and
302+
Core::FADUtils::cast_to_double(norm_dist) > cutoff_radius.value())
302303
continue;
303304

304305
// auxiliary variables to store pre-calculated common terms

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ BeamInteraction::BeamPotentialParams::BeamPotentialParams()
2727
pot_law_prefactors_(nullptr),
2828
potential_type_(BeamPotential::Type::vague),
2929
strategy_(BeamPotential::Strategy::vague),
30-
cutoff_radius_(0.0),
30+
cutoff_radius_(std::nullopt),
3131
regularization_type_(BeamPotential::RegularizationType::none),
3232
regularization_separation_(0.0),
3333
num_integration_segments_(-1),
@@ -119,10 +119,10 @@ void BeamInteraction::BeamPotentialParams::init(const double restart_time)
119119
}
120120

121121
/****************************************************************************/
122-
cutoff_radius_ = beam_potential_params_list.get<double>("CUTOFF_RADIUS");
122+
cutoff_radius_ = beam_potential_params_list.get<std::optional<double>>("CUTOFF_RADIUS");
123123

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

127127
/****************************************************************************/
128128
regularization_type_ = Teuchos::getIntegralValue<BeamPotential::RegularizationType>(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace BeamInteraction
7474
return strategy_;
7575
}
7676

77-
inline double cutoff_radius() const
77+
inline std::optional<double> cutoff_radius() const
7878
{
7979
throw_error_if_not_init_and_setup();
8080
return cutoff_radius_;
@@ -160,7 +160,7 @@ namespace BeamInteraction
160160
enum BeamPotential::Strategy strategy_;
161161

162162
//! neglect all contributions at separation larger than this cutoff radius
163-
double cutoff_radius_;
163+
std::optional<double> cutoff_radius_;
164164

165165
//! type of regularization to use for force law at separations below specified separation
166166
enum BeamPotential::RegularizationType regularization_type_;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,9 @@ void BeamInteraction::SUBMODELEVALUATOR::BeamPotential::get_half_interaction_dis
647647
{
648648
check_init_setup();
649649

650-
if (beam_potential_params().cutoff_radius() > 0.0)
650+
if (beam_potential_params().cutoff_radius().has_value())
651651
{
652-
half_interaction_distance = 0.5 * beam_potential_params().cutoff_radius();
652+
half_interaction_distance = 0.5 * beam_potential_params().cutoff_radius().value();
653653

654654
if (g_state().get_my_rank() == 0)
655655
Core::IO::cout(Core::IO::verbose) << " beam potential half interaction distance "

0 commit comments

Comments
 (0)