-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding specialized ASPH H advance options (fixShape and radialOnly),
and creating a special H time advance policy. Note when using these options the ASPH idealH does not require the Voronoi (big time savings).
- Loading branch information
Showing
8 changed files
with
375 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
//---------------------------------Spheral++----------------------------------// | ||
// IncrementASPHHtensor | ||
// | ||
// Specialized version of FieldUpdatePolicy for time integrating the H tensor. | ||
// | ||
// Created by JMO, Mon Oct 7 13:31:02 PDT 2024 | ||
//----------------------------------------------------------------------------// | ||
#include "IncrementASPHHtensor.hh" | ||
#include "DataBase/State.hh" | ||
#include "DataBase/StateDerivatives.hh" | ||
#include "Field/Field.hh" | ||
#include "Hydro/HydroFieldNames.hh" | ||
#include "Utilities/rotationMatrix.hh" | ||
#include "Utilities/GeometricUtilities.hh" | ||
#include "Utilities/DBC.hh" | ||
|
||
namespace Spheral { | ||
|
||
//------------------------------------------------------------------------------ | ||
// Constructor | ||
//------------------------------------------------------------------------------ | ||
template<typename Dimension> | ||
IncrementASPHHtensor<Dimension>:: | ||
IncrementASPHHtensor(const Scalar hmin, | ||
const Scalar hmax, | ||
const Scalar hminratio, | ||
const bool fixShape, | ||
const bool radialOnly): | ||
FieldUpdatePolicy<Dimension>(), | ||
mhmin(hmin), | ||
mhmax(hmax), | ||
mhminratio(hminratio), | ||
mFixShape(fixShape), | ||
mRadialOnly(radialOnly) { | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// Update the field. | ||
//------------------------------------------------------------------------------ | ||
template<typename Dimension> | ||
void | ||
IncrementASPHHtensor<Dimension>:: | ||
update(const KeyType& key, | ||
State<Dimension>& state, | ||
StateDerivatives<Dimension>& derivs, | ||
const double multiplier, | ||
const double t, | ||
const double dt) { | ||
|
||
// Get the field name portion of the key. | ||
KeyType fieldKey, nodeListKey; | ||
StateBase<Dimension>::splitFieldKey(key, fieldKey, nodeListKey); | ||
CHECK(fieldKey == HydroFieldNames::H); | ||
|
||
const auto hminInv = 1.0/mhmin; | ||
const auto hmaxInv = 1.0/mhmax; | ||
|
||
// Get the state we're updating. | ||
auto& H = state.field(key, SymTensor::zero); | ||
const auto& DHDt = derivs.field(prefix() + StateBase<Dimension>::buildFieldKey(HydroFieldNames::H, nodeListKey), SymTensor::zero); | ||
const auto& pos = state.field(StateBase<Dimension>::buildFieldKey(HydroFieldNames::position, nodeListKey), Vector::zero); // Only needed if we're using radial scaling | ||
|
||
// Walk the nodes and update H (with limiting) | ||
const auto n = H.numInternalElements(); | ||
#pragma omp parallel for | ||
for (auto i = 0u; i < n; ++i) { | ||
|
||
// Check for special update rules | ||
if (mFixShape) { | ||
|
||
// Fix the shape (only volume scaling allowed) | ||
|
||
auto fi = Dimension::rootnu((H(i) + multiplier*DHDt(i)).Determinant()/H(i).Determinant()); | ||
H(i) *= fi; | ||
|
||
} else if (mRadialOnly) { | ||
|
||
// Force only the radial component of H to be scaled | ||
const auto nhat = pos(i).unitVector(); | ||
const auto T = rotationMatrix(nhat); | ||
H(i).rotationalTransform(T); // Should have one eigenvector aligned with the x' axis in this frame | ||
auto DHDti = DHDt(i); | ||
DHDti.rotationalTransform(T); | ||
H(i)[0] += multiplier * DHDti[0]; | ||
H(i).rotationalTransform(T.Transpose()); | ||
|
||
} else { | ||
|
||
H(i) += multiplier * DHDt(i); | ||
|
||
} | ||
|
||
// Apply limiting | ||
const auto hev = H(i).eigenVectors(); | ||
const auto hminEffInv = min(hminInv, max(hmaxInv, hev.eigenValues.minElement())/mhminratio); | ||
H(i) = constructSymTensorWithBoundedDiagonal(hev.eigenValues, hmaxInv, hminEffInv); | ||
H(i).rotationalTransform(hev.eigenVectors); | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// Equivalence operator. | ||
//------------------------------------------------------------------------------ | ||
template<typename Dimension> | ||
inline | ||
bool | ||
IncrementASPHHtensor<Dimension>:: | ||
operator==(const UpdatePolicyBase<Dimension>& rhs) const { | ||
const auto rhsPtr = dynamic_cast<const IncrementASPHHtensor<Dimension>*>(&rhs); | ||
if (rhsPtr == nullptr) return false; | ||
|
||
// Ok, now do we agree on min & max? | ||
return (hmin() == rhsPtr->hmin() and | ||
hmax() == rhsPtr->hmax() and | ||
hminratio() == rhsPtr->hminratio() and | ||
fixShape() == rhsPtr->fixShape() and | ||
radialOnly() == rhsPtr->radialOnly()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//---------------------------------Spheral++----------------------------------// | ||
// IncrementASPHHtensor | ||
// | ||
// Specialized version of FieldUpdatePolicy for time integrating the H tensor. | ||
// | ||
// Created by JMO, Mon Oct 7 13:31:02 PDT 2024 | ||
//----------------------------------------------------------------------------// | ||
#ifndef __Spheral_IncrementASPHHtensor_hh__ | ||
#define __Spheral_IncrementASPHHtensor_hh__ | ||
|
||
#include "DataBase/FieldUpdatePolicy.hh" | ||
|
||
namespace Spheral { | ||
|
||
// Forward declarations. | ||
template<typename Dimension> class StateDerivatives; | ||
|
||
template<typename Dimension> | ||
class IncrementASPHHtensor: public FieldUpdatePolicy<Dimension> { | ||
public: | ||
//--------------------------- Public Interface ---------------------------// | ||
// Useful typedefs | ||
using KeyType = typename FieldUpdatePolicy<Dimension>::KeyType; | ||
using Scalar = typename Dimension::Scalar; | ||
using Vector = typename Dimension::Vector; | ||
using SymTensor = typename Dimension::SymTensor; | ||
|
||
// Constructors, destructor. | ||
IncrementASPHHtensor(const Scalar hmin, | ||
const Scalar hmax, | ||
const Scalar hminratio, | ||
const bool fixShape, | ||
const bool radialOnly); | ||
virtual ~IncrementASPHHtensor() {} | ||
IncrementASPHHtensor(const IncrementASPHHtensor& rhs) = delete; | ||
IncrementASPHHtensor& operator=(const IncrementASPHHtensor& rhs) = delete; | ||
|
||
// Overload the methods describing how to update Fields. | ||
virtual void update(const KeyType& key, | ||
State<Dimension>& state, | ||
StateDerivatives<Dimension>& derivs, | ||
const double multiplier, | ||
const double t, | ||
const double dt) override; | ||
|
||
// Access the min and max's. | ||
Scalar hmin() const { return mhmin; } | ||
Scalar hmax() const { return mhmax; } | ||
Scalar hminratio() const { return mhminratio; } | ||
bool fixShape() const { return mFixShape; } | ||
bool radialOnly() const { return mRadialOnly; } | ||
|
||
// Equivalence. | ||
virtual bool operator==(const UpdatePolicyBase<Dimension>& rhs) const override; | ||
|
||
static const std::string prefix() { return "delta "; } | ||
|
||
private: | ||
//--------------------------- Private Interface ---------------------------// | ||
Scalar mhmin, mhmax, mhminratio; | ||
bool mFixShape, mRadialOnly; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
text = """ | ||
//------------------------------------------------------------------------------ | ||
// Explicit instantiation. | ||
//------------------------------------------------------------------------------ | ||
#include "SmoothingScale/IncrementASPHHtensor.cc" | ||
#include "Geometry/Dimension.hh" | ||
namespace Spheral { | ||
template class IncrementASPHHtensor<Dim<%(ndim)s>>; | ||
} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters