Skip to content

Commit

Permalink
[PL] Use string views avoiding a temporary strings
Browse files Browse the repository at this point in the history
  • Loading branch information
endJunction committed Jan 18, 2024
1 parent 0a333b1 commit a88ea31
Show file tree
Hide file tree
Showing 25 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion ProcessLib/HydroMechanics/HydroMechanicsFEM-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
int DisplacementDim>
std::size_t HydroMechanicsLocalAssembler<
ShapeFunctionDisplacement, ShapeFunctionPressure,
DisplacementDim>::setIPDataInitialConditions(std::string const& name,
DisplacementDim>::setIPDataInitialConditions(std::string_view const name,
double const* values,
int const integration_order)
{
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/HydroMechanics/HydroMechanicsFEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class HydroMechanicsLocalAssembler

/// Returns number of read integration points.
std::size_t setIPDataInitialConditions(
std::string const& name,
std::string_view const name,
double const* values,
int const integration_order) override;

Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/HydroMechanics/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct LocalAssemblerInterface : public ProcessLib::LocalAssemblerInterface,
public NumLib::ExtrapolatableElement
{
virtual std::size_t setIPDataInitialConditions(
std::string const& name, double const* values,
std::string_view const name, double const* values,
int const integration_order) = 0;

virtual std::vector<double> getSigma() const = 0;
Expand Down
11 changes: 5 additions & 6 deletions ProcessLib/LargeDeformation/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct LargeDeformationLocalAssemblerInterface
output_data_.resize(n_integration_points);
}
/// Returns number of read integration points.
std::size_t setIPDataInitialConditions(std::string const& name,
std::size_t setIPDataInitialConditions(std::string_view name,
double const* values,
int const integration_order)
{
Expand All @@ -77,17 +77,16 @@ struct LargeDeformationLocalAssemblerInterface

if (name.starts_with("material_state_variable_"))
{
std::string const variable_name = name.substr(24, name.size() - 24);
name.remove_prefix(24);

auto const& internal_variables =
solid_material_.getInternalVariables();
if (auto const iv = std::find_if(
begin(internal_variables), end(internal_variables),
[&variable_name](auto const& iv)
{ return iv.name == variable_name; });
[&name](auto const& iv) { return iv.name == name; });
iv != end(internal_variables))
{
DBUG("Setting material state variable '{:s}'", variable_name);
DBUG("Setting material state variable '{:s}'", name);
return ProcessLib::
setIntegrationPointDataMaterialStateVariables(
values, material_states_,
Expand All @@ -99,7 +98,7 @@ struct LargeDeformationLocalAssemblerInterface
WARN(
"Could not find variable {:s} in solid material model's "
"internal variables.",
variable_name);
name);
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions ProcessLib/Reflection/ReflectionSetIPData.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void setIPData(double const* values,
// Returns true if IP have been set, false otherwise.
template <int dim, typename IPData, typename Accessor_CurrentLevelFromIPData,
typename Class, typename Accessor>
bool setIPDataIfNameMatches(std::string const& name, double const* values,
bool setIPDataIfNameMatches(std::string_view const name, double const* values,
std::vector<IPData>& ip_data_vector,
Accessor_CurrentLevelFromIPData const& accessor,
ReflectionData<Class, Accessor> const& refl_data)
Expand Down Expand Up @@ -112,7 +112,7 @@ bool setIPDataIfNameMatches(std::string const& name, double const* values,
template <int dim, typename IPData, typename Accessor_CurrentLevelFromIPData,
typename... Classes, typename... Accessors, std::size_t... Idcs>
bool reflectSetIPData(
std::string const& name, double const* values,
std::string_view const name, double const* values,
std::vector<IPData>& ip_data_vector,
Accessor_CurrentLevelFromIPData const& accessor,
std::tuple<ReflectionData<Classes, Accessors>...> const& refl_data,
Expand All @@ -128,7 +128,7 @@ bool reflectSetIPData(
template <int dim, typename IPData, typename Accessor_CurrentLevelFromIPData,
typename... Classes, typename... Accessors>
bool reflectSetIPData(
std::string const& name, double const* values,
std::string_view const name, double const* values,
std::vector<IPData>& ip_data_vector,
Accessor_CurrentLevelFromIPData const& accessor,
std::tuple<ReflectionData<Classes, Accessors>...> const& refl_data)
Expand All @@ -149,7 +149,7 @@ bool reflectSetIPData(
* \return The number of integration points.
*/
template <int dim, typename IPData>
std::size_t reflectSetIPData(std::string const& name, double const* values,
std::size_t reflectSetIPData(std::string_view const name, double const* values,
std::vector<IPData>& ip_data_vector)
{
detail::reflectSetIPData<dim>(
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/RichardsMechanics/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct LocalAssemblerInterface : public ProcessLib::LocalAssemblerInterface,
public NumLib::ExtrapolatableElement
{
virtual std::size_t setIPDataInitialConditions(
std::string const& name, double const* values,
std::string_view const name, double const* values,
int const integration_order) = 0;

virtual std::vector<double> getSigma() const = 0;
Expand Down
15 changes: 7 additions & 8 deletions ProcessLib/RichardsMechanics/RichardsMechanicsFEM-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
int DisplacementDim>
std::size_t RichardsMechanicsLocalAssembler<
ShapeFunctionDisplacement, ShapeFunctionPressure,
DisplacementDim>::setIPDataInitialConditions(std::string const& name,
DisplacementDim>::setIPDataInitialConditions(std::string_view name,
double const* values,
int const integration_order)
{
Expand Down Expand Up @@ -250,27 +250,26 @@ std::size_t RichardsMechanicsLocalAssembler<
}
if (name.starts_with("material_state_variable_"))
{
std::string const variable_name = name.substr(24, name.size() - 24);
name.remove_prefix(24);

// Using first ip data for solid material. TODO (naumov) move solid
// material into element, store only material state in IPs.
auto const& internal_variables =
_ip_data[0].solid_material.getInternalVariables();
if (auto const iv =
std::find_if(begin(internal_variables), end(internal_variables),
[&variable_name](auto const& iv)
{ return iv.name == variable_name; });
if (auto const iv = std::find_if(
begin(internal_variables), end(internal_variables),
[&name](auto const& iv) { return iv.name == name; });
iv != end(internal_variables))
{
DBUG("Setting material state variable '{:s}'", variable_name);
DBUG("Setting material state variable '{:s}'", name);
return ProcessLib::setIntegrationPointDataMaterialStateVariables(
values, _ip_data, &IpData::material_state_variables,
iv->reference);
}

ERR("Could not find variable {:s} in solid material model's internal "
"variables.",
variable_name);
name);
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/RichardsMechanics/RichardsMechanicsFEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class RichardsMechanicsLocalAssembler

/// \return the number of read integration points.
std::size_t setIPDataInitialConditions(
std::string const& name,
std::string_view const name,
double const* values,
int const integration_order) override;

Expand Down
11 changes: 5 additions & 6 deletions ProcessLib/SmallDeformation/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct SmallDeformationLocalAssemblerInterface
output_data_.resize(n_integration_points);
}
/// Returns number of read integration points.
std::size_t setIPDataInitialConditions(std::string const& name,
std::size_t setIPDataInitialConditions(std::string_view name,
double const* values,
int const integration_order)
{
Expand All @@ -80,17 +80,16 @@ struct SmallDeformationLocalAssemblerInterface

if (name.starts_with("material_state_variable_"))
{
std::string const variable_name = name.substr(24, name.size() - 24);
name.remove_prefix(24);

auto const& internal_variables =
solid_material_.getInternalVariables();
if (auto const iv = std::find_if(
begin(internal_variables), end(internal_variables),
[&variable_name](auto const& iv)
{ return iv.name == variable_name; });
[&name](auto const& iv) { return iv.name == name; });
iv != end(internal_variables))
{
DBUG("Setting material state variable '{:s}'", variable_name);
DBUG("Setting material state variable '{:s}'", name);
return ProcessLib::
setIntegrationPointDataMaterialStateVariables(
values, material_states_,
Expand All @@ -102,7 +101,7 @@ struct SmallDeformationLocalAssemblerInterface
WARN(
"Could not find variable {:s} in solid material model's "
"internal variables.",
variable_name);
name);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct SmallDeformationNonlocalLocalAssemblerInterface
public NumLib::ExtrapolatableElement
{
virtual std::size_t setIPDataInitialConditions(
std::string const& name, double const* values,
std::string_view const name, double const* values,
int const integration_order) = 0;

virtual void setIPDataInitialConditionsFromCellData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class SmallDeformationNonlocalLocalAssembler
}
}

std::size_t setIPDataInitialConditions(std::string const& name,
std::size_t setIPDataInitialConditions(std::string_view const name,
double const* values,
int const integration_order) override
{
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/TH2M/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct LocalAssemblerInterface : public ProcessLib::LocalAssemblerInterface,
public NumLib::ExtrapolatableElement
{
virtual std::size_t setIPDataInitialConditions(
std::string const& name, double const* values,
std::string_view name, double const* values,
int const integration_order) = 0;

virtual std::vector<double> getSigma() const = 0;
Expand Down
16 changes: 8 additions & 8 deletions ProcessLib/TH2M/TH2MFEM-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
int DisplacementDim>
std::size_t TH2MLocalAssembler<
ShapeFunctionDisplacement, ShapeFunctionPressure,
DisplacementDim>::setIPDataInitialConditions(std::string const& name,
DisplacementDim>::setIPDataInitialConditions(std::string_view name,
double const* values,
int const integration_order)
{
Expand Down Expand Up @@ -897,19 +897,19 @@ std::size_t TH2MLocalAssembler<
}
if (name.starts_with("material_state_variable_"))
{
std::string const variable_name = name.substr(24, name.size() - 24);
name.remove_prefix(24);
DBUG("Setting material state variable '{:s}'", name);

// Using first ip data for solid material. TODO (naumov) move solid
// material into element, store only material state in IPs.
auto const& internal_variables =
_ip_data[0].solid_material.getInternalVariables();
if (auto const iv =
std::find_if(begin(internal_variables), end(internal_variables),
[&variable_name](auto const& iv)
{ return iv.name == variable_name; });
if (auto const iv = std::find_if(
begin(internal_variables), end(internal_variables),
[&name](auto const& iv) { return iv.name == name; });
iv != end(internal_variables))
{
DBUG("Setting material state variable '{:s}'", variable_name);
DBUG("Setting material state variable '{:s}'", name);
return ProcessLib::setIntegrationPointDataMaterialStateVariables(
values, _ip_data, &IpData::material_state_variables,
iv->reference);
Expand All @@ -918,7 +918,7 @@ std::size_t TH2MLocalAssembler<
WARN(
"Could not find variable {:s} in solid material model's "
"internal variables.",
variable_name);
name);
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/TH2M/TH2MFEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TH2MLocalAssembler : public LocalAssemblerInterface<DisplacementDim>
private:
/// \return the number of read integration points.
std::size_t setIPDataInitialConditions(
std::string const& name,
std::string_view const name,
double const* values,
int const integration_order) override;

Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/ThermoHydroMechanics/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct LocalAssemblerInterface : public ProcessLib::LocalAssemblerInterface,
public NumLib::ExtrapolatableElement
{
virtual std::size_t setIPDataInitialConditions(
std::string const& name, double const* values,
std::string_view const name, double const* values,
int const integration_order) = 0;

virtual std::vector<double> getSigma() const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ template <typename ShapeFunctionDisplacement, typename ShapeFunctionPressure,
int DisplacementDim>
std::size_t ThermoHydroMechanicsLocalAssembler<
ShapeFunctionDisplacement, ShapeFunctionPressure,
DisplacementDim>::setIPDataInitialConditions(std::string const& name,
DisplacementDim>::setIPDataInitialConditions(std::string_view const name,
double const* values,
int const integration_order)
{
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsFEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ThermoHydroMechanicsLocalAssembler : public LocalAssemblerInterface

/// Returns number of read integration points.
std::size_t setIPDataInitialConditions(
std::string const& name,
std::string_view const name,
double const* values,
int const integration_order) override;

Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/ThermoMechanics/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct ThermoMechanicsLocalAssemblerInterface
public NumLib::ExtrapolatableElement
{
virtual std::size_t setIPDataInitialConditions(
std::string const& name, double const* values,
std::string_view const name, double const* values,
int const integration_order) = 0;

virtual std::vector<double> getSigma() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/ThermoMechanics/ThermoMechanicsFEM-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ThermoMechanicsLocalAssembler<ShapeFunction, DisplacementDim>::

template <typename ShapeFunction, int DisplacementDim>
std::size_t ThermoMechanicsLocalAssembler<ShapeFunction, DisplacementDim>::
setIPDataInitialConditions(std::string const& name,
setIPDataInitialConditions(std::string_view const name,
double const* values,
int const integration_order)
{
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ThermoMechanicsLocalAssembler

/// Returns number of read integration points.
std::size_t setIPDataInitialConditions(
std::string const& name,
std::string_view const name,
double const* values,
int const integration_order) override;

Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/ThermoRichardsFlow/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct LocalAssemblerInterface : public ProcessLib::LocalAssemblerInterface,
public NumLib::ExtrapolatableElement
{
virtual std::size_t setIPDataInitialConditions(
std::string const& name, double const* values,
std::string_view const name, double const* values,
int const integration_order) = 0;

virtual std::vector<double> const& getIntPtDarcyVelocity(
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/ThermoRichardsFlow/ThermoRichardsFlowFEM-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ThermoRichardsFlowLocalAssembler<ShapeFunction, GlobalDim>::

template <typename ShapeFunction, int GlobalDim>
std::size_t ThermoRichardsFlowLocalAssembler<ShapeFunction, GlobalDim>::
setIPDataInitialConditions(std::string const& name,
setIPDataInitialConditions(std::string_view const name,
double const* values,
int const integration_order)
{
Expand Down
2 changes: 1 addition & 1 deletion ProcessLib/ThermoRichardsFlow/ThermoRichardsFlowFEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ThermoRichardsFlowLocalAssembler : public LocalAssemblerInterface

/// \return the number of read integration points.
std::size_t setIPDataInitialConditions(
std::string const& name,
std::string_view const name,
double const* values,
int const integration_order) override;

Expand Down
9 changes: 4 additions & 5 deletions ProcessLib/ThermoRichardsMechanics/LocalAssemblerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct LocalAssemblerInterface : public ProcessLib::LocalAssemblerInterface,
}
}

std::size_t setIPDataInitialConditions(std::string const& name,
std::size_t setIPDataInitialConditions(std::string_view name,
double const* values,
int const integration_order)
{
Expand Down Expand Up @@ -83,17 +83,16 @@ struct LocalAssemblerInterface : public ProcessLib::LocalAssemblerInterface,
// reflectWithName function also supports only a single return value.
if (name.starts_with("material_state_variable_"))
{
std::string const variable_name = name.substr(24, name.size() - 24);
name.remove_prefix(24);

auto const& internal_variables =
solid_material_.getInternalVariables();
if (auto const iv = std::find_if(
begin(internal_variables), end(internal_variables),
[&variable_name](auto const& iv)
{ return iv.name == variable_name; });
[&name](auto const& iv) { return iv.name == name; });
iv != end(internal_variables))
{
DBUG("Setting material state variable '{:s}'", variable_name);
DBUG("Setting material state variable '{:s}'", name);
return ProcessLib::
setIntegrationPointDataMaterialStateVariables(
values, material_states_,
Expand Down
Loading

0 comments on commit a88ea31

Please sign in to comment.