/*
Copyright 2025 Equinor ASA
This file is part of the Open Porous Media Project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see .
*/
#include
#include
#include
namespace Opm {
template
void SymmTensor::
operator+=(const T data)
{
std::for_each(this->data_.begin(), this->data_.end(),
[&data](auto& v) { v += data; });
}
template
void SymmTensor::
operator+=(const SymmTensor& data)
{
auto it = data.data_.begin();
std::for_each(this->data_.begin(), this->data_.end(),
[&it](auto& v) { v += *it++; });
}
template
void SymmTensor::
operator*=(const T value)
{
std::for_each(this->data_.begin(), this->data_.end(),
[&value](auto& v) { v *= value; });
}
template
void SymmTensor::reset()
{
this->data_.fill(T{0});
}
template
T SymmTensor::
trace() const
{
return (*this)[VoigtIndex::XX] +
(*this)[VoigtIndex::YY] +
(*this)[VoigtIndex::ZZ];
}
template
T SymmTensor::traction(const Dune::FieldVector& normal) const
{
T traction = 0.0;
constexpr auto& ind = Opm::SymmTensor::diag_indices;
for (std::size_t i = 0; i < 3; ++i){
traction += (*this)[ind[i]] * normal[i] * normal[i];
}
traction += T{2} * (*this)[VoigtIndex::YZ] * normal[0] * normal[1]; // xy*nx*ny;
traction += T{2} * (*this)[VoigtIndex::XZ] * normal[0] * normal[2]; // xz*nx*nz
traction += T{2} * (*this)[VoigtIndex::XY] * normal[1] * normal[2]; // yz*ny*nz
return traction;
}
template
SymmTensor&
SymmTensor::operator=(const T value)
{
this->data_.fill(value);
return *this;
}
template
SymmTensor operator*(const T2 value, SymmTensor t1)
{
t1 *= value;
return t1;
}
template
SymmTensor operator*(SymmTensor t1, const T2 value)
{
t1 *= value;
return t1;
}
template
SymmTensor operator+(SymmTensor t1, const SymmTensor& t2)
{
t1 += t2;
return t1;
}
#define INSTANTIATE_OPS(T1, T2) \
template SymmTensor operator*(const T2, SymmTensor); \
template SymmTensor operator*(SymmTensor, const T2);
#define INSTANTIATE_TYPE(T) \
template class SymmTensor; \
INSTANTIATE_OPS(T, T) \
INSTANTIATE_OPS(T, int) \
INSTANTIATE_OPS(T, unsigned) \
INSTANTIATE_OPS(T, std::size_t) \
template SymmTensor operator+(SymmTensor, const SymmTensor&);
INSTANTIATE_TYPE(double)
#if FLOW_INSTANTIATE_FLOAT
INSTANTIATE_TYPE(float)
#endif
} // namespace Opm