Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve for psi-1 in XCTS system #5684

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Elliptic/DiscontinuousGalerkin/DgOperator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
* u^* &= \frac{1}{2} \left(u^\mathrm{int} + u^\mathrm{ext}\right) \\
* (n_i F^i)^* &= \frac{1}{2} n_i \left(
* F^i_\mathrm{int} + F^i_\mathrm{ext} \right)
* - \sigma n_i F^i(n_j (u^\mathrm{int} - u^\mathrm{ext})) \right)
* - \sigma n_i F^i(n_j (u^\mathrm{int} - u^\mathrm{ext}))
* \f}
*
* Note that \f$n_i\f$ denotes the face normal on the "interior" side of the
Expand Down
4 changes: 3 additions & 1 deletion src/Elliptic/Executables/Xcts/SolveXcts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ struct Metavariables {
using analytic_solution_fields = tmpl::append<typename system::primal_fields,
typename system::primal_fluxes>;
using spacetime_quantities_compute = Xcts::Tags::SpacetimeQuantitiesCompute<
tmpl::list<gr::Tags::HamiltonianConstraint<DataVector>,
tmpl::list<Xcts::Tags::ConformalFactor<DataVector>,
Xcts::Tags::LapseTimesConformalFactor<DataVector>,
gr::Tags::HamiltonianConstraint<DataVector>,
gr::Tags::MomentumConstraint<DataVector, 3>,
gr::Tags::SpatialMetric<DataVector, 3>,
gr::Tags::Lapse<DataVector>, gr::Tags::Shift<DataVector, 3>,
Expand Down
95 changes: 53 additions & 42 deletions src/Elliptic/Systems/Xcts/BoundaryConditions/ApparentHorizon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ void negative_expansion_quantities(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional, random line] there are a lot of divisions by the conformal factor. I'm not sure if it matters because this is a BC, but it may be possible to factor those out and do only one. Probably doesn't matter, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't profiled this recently, but I'll keep this in mind when doing a round of optimizations 👍 Not much use to do this blindly I think.

template <Xcts::Geometry ConformalGeometry>
void apparent_horizon_impl(
const gsl::not_null<Scalar<DataVector>*> conformal_factor,
const gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
const gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
const gsl::not_null<Scalar<DataVector>*>
lapse_times_conformal_factor_minus_one,
const gsl::not_null<tnsr::I<DataVector, 3>*> shift_excess,
const gsl::not_null<Scalar<DataVector>*> n_dot_conformal_factor_gradient,
const gsl::not_null<Scalar<DataVector>*>
Expand Down Expand Up @@ -259,12 +260,13 @@ void apparent_horizon_impl(
// Shift
{
if (solution_for_negative_expansion.has_value()) {
get(beta_orthogonal) /= square(get(*conformal_factor));
get(beta_orthogonal) /= square(get(*conformal_factor_minus_one) + 1.);
} else {
get(beta_orthogonal) = 0.;
}
get(beta_orthogonal) +=
get(*lapse_times_conformal_factor) / cube(get(*conformal_factor));
(get(*lapse_times_conformal_factor_minus_one) + 1.) /
cube(get(*conformal_factor_minus_one) + 1.);
for (size_t i = 0; i < 3; ++i) {
shift_excess->get(i) = -get(beta_orthogonal) * face_normal_raised.get(i) -
shift_background.get(i);
Expand Down Expand Up @@ -292,10 +294,12 @@ void apparent_horizon_impl(
}
// At this point we're done with `face_normal_raised`, so we can re-purpose
// the memory buffer.
get(*n_dot_conformal_factor_gradient) *= -0.25 * get(*conformal_factor);
get(*n_dot_conformal_factor_gradient) *=
-0.25 * (get(*conformal_factor_minus_one) + 1.);
if (solution_for_negative_expansion.has_value()) {
get(*n_dot_conformal_factor_gradient) -=
0.25 * cube(get(*conformal_factor)) * get(expansion_of_solution);
0.25 * cube(get(*conformal_factor_minus_one) + 1.) *
get(expansion_of_solution);
}
{
tnsr::I<DataVector, 3>& n_dot_longitudinal_shift =
Expand All @@ -311,21 +315,23 @@ void apparent_horizon_impl(
normal_dot_flux(make_not_null(&nn_dot_longitudinal_shift), face_normal,
n_dot_longitudinal_shift);
get(*n_dot_conformal_factor_gradient) +=
-get(extrinsic_curvature_trace) * cube(get(*conformal_factor)) / 6. +
pow<4>(get(*conformal_factor)) / 8. /
get(*lapse_times_conformal_factor) * get(nn_dot_longitudinal_shift);
-get(extrinsic_curvature_trace) *
cube(get(*conformal_factor_minus_one) + 1.) / 6. +
pow<4>(get(*conformal_factor_minus_one) + 1.) / 8. /
(get(*lapse_times_conformal_factor_minus_one) + 1.) *
get(nn_dot_longitudinal_shift);
}

// Lapse
if (solution_for_lapse.has_value()) {
*lapse_times_conformal_factor = call_with_dynamic_type<
*lapse_times_conformal_factor_minus_one = call_with_dynamic_type<
Scalar<DataVector>, Xcts::Solutions::all_analytic_solutions>(
solution_for_lapse.value().get(),
[&x](const auto* const local_solution) {
return get<Xcts::Tags::LapseTimesConformalFactor<DataVector>>(
return get<Xcts::Tags::LapseTimesConformalFactorMinusOne<DataVector>>(
local_solution->variables(
x, tmpl::list<
Xcts::Tags::LapseTimesConformalFactor<DataVector>>{}));
x, tmpl::list<Xcts::Tags::LapseTimesConformalFactorMinusOne<
DataVector>>{}));
});
} else {
get(*n_dot_lapse_times_conformal_factor_gradient) = 0.;
Expand Down Expand Up @@ -357,8 +363,8 @@ void linearized_apparent_horizon_impl(
const tnsr::I<DataVector, 3>& x_offcenter,
const Scalar<DataVector>& extrinsic_curvature_trace,
const tnsr::II<DataVector, 3>& longitudinal_shift_background,
const Scalar<DataVector>& conformal_factor,
const Scalar<DataVector>& lapse_times_conformal_factor,
const Scalar<DataVector>& conformal_factor_minus_one,
const Scalar<DataVector>& lapse_times_conformal_factor_minus_one,
const tnsr::I<DataVector, 3>& n_dot_longitudinal_shift_excess,
[[maybe_unused]] const std::optional<
std::reference_wrapper<const tnsr::II<DataVector, 3>>>
Expand Down Expand Up @@ -404,14 +410,16 @@ void linearized_apparent_horizon_impl(
{
if (solution_for_negative_expansion.has_value()) {
get(beta_orthogonal_correction) *=
-2. * get(*conformal_factor_correction) / cube(get(conformal_factor));
-2. * get(*conformal_factor_correction) /
cube(get(conformal_factor_minus_one) + 1.);
} else {
get(beta_orthogonal_correction) = 0.;
}
get(beta_orthogonal_correction) +=
get(*lapse_times_conformal_factor_correction) /
cube(get(conformal_factor)) -
3. * get(lapse_times_conformal_factor) / pow<4>(get(conformal_factor)) *
cube(get(conformal_factor_minus_one) + 1.) -
3. * (get(lapse_times_conformal_factor_minus_one) + 1.) /
pow<4>(get(conformal_factor_minus_one) + 1.) *
get(*conformal_factor_correction);
for (size_t i = 0; i < 3; ++i) {
shift_correction->get(i) =
Expand Down Expand Up @@ -440,8 +448,8 @@ void linearized_apparent_horizon_impl(
-0.25 * get(*conformal_factor_correction);
if (solution_for_negative_expansion.has_value()) {
get(*n_dot_conformal_factor_gradient_correction) -=
0.75 * square(get(conformal_factor)) * get(expansion_of_solution) *
get(*conformal_factor_correction);
0.75 * square(get(conformal_factor_minus_one) + 1.) *
get(expansion_of_solution) * get(*conformal_factor_correction);
}
{
tnsr::I<DataVector, 3>& n_dot_longitudinal_shift =
Expand All @@ -456,13 +464,14 @@ void linearized_apparent_horizon_impl(
normal_dot_flux(make_not_null(&nn_dot_longitudinal_shift), face_normal,
n_dot_longitudinal_shift);
get(*n_dot_conformal_factor_gradient_correction) +=
-0.5 * get(extrinsic_curvature_trace) * square(get(conformal_factor)) *
-0.5 * get(extrinsic_curvature_trace) *
square(get(conformal_factor_minus_one) + 1.) *
get(*conformal_factor_correction) +
0.5 * pow<3>(get(conformal_factor)) /
get(lapse_times_conformal_factor) * get(nn_dot_longitudinal_shift) *
get(*conformal_factor_correction) -
0.125 * pow<4>(get(conformal_factor)) /
square(get(lapse_times_conformal_factor)) *
0.5 * pow<3>(get(conformal_factor_minus_one) + 1.) /
(get(lapse_times_conformal_factor_minus_one) + 1.) *
get(nn_dot_longitudinal_shift) * get(*conformal_factor_correction) -
0.125 * pow<4>(get(conformal_factor_minus_one) + 1.) /
square(get(lapse_times_conformal_factor_minus_one) + 1.) *
get(nn_dot_longitudinal_shift) *
get(*lapse_times_conformal_factor_correction);
}
Expand All @@ -472,8 +481,8 @@ void linearized_apparent_horizon_impl(
normal_dot_flux(make_not_null(&nn_dot_longitudinal_shift_correction),
face_normal, *n_dot_longitudinal_shift_correction);
get(*n_dot_conformal_factor_gradient_correction) +=
0.125 * pow<4>(get(conformal_factor)) /
get(lapse_times_conformal_factor) *
0.125 * pow<4>(get(conformal_factor_minus_one) + 1.) /
(get(lapse_times_conformal_factor_minus_one) + 1.) *
get(nn_dot_longitudinal_shift_correction);
}

Expand All @@ -488,8 +497,9 @@ void linearized_apparent_horizon_impl(

template <Xcts::Geometry ConformalGeometry>
void ApparentHorizon<ConformalGeometry>::apply(
const gsl::not_null<Scalar<DataVector>*> conformal_factor,
const gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
const gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
const gsl::not_null<Scalar<DataVector>*>
lapse_times_conformal_factor_minus_one,
const gsl::not_null<tnsr::I<DataVector, 3>*> shift_excess,
const gsl::not_null<Scalar<DataVector>*> n_dot_conformal_factor_gradient,
const gsl::not_null<Scalar<DataVector>*>
Expand All @@ -504,8 +514,8 @@ void ApparentHorizon<ConformalGeometry>::apply(
const tnsr::I<DataVector, 3>& shift_background,
const tnsr::II<DataVector, 3>& longitudinal_shift_background) const {
apparent_horizon_impl<ConformalGeometry>(
conformal_factor, lapse_times_conformal_factor, shift_excess,
n_dot_conformal_factor_gradient,
conformal_factor_minus_one, lapse_times_conformal_factor_minus_one,
shift_excess, n_dot_conformal_factor_gradient,
n_dot_lapse_times_conformal_factor_gradient,
n_dot_longitudinal_shift_excess, center_, rotation_, solution_for_lapse_,
solution_for_negative_expansion_, face_normal,
Expand All @@ -516,8 +526,9 @@ void ApparentHorizon<ConformalGeometry>::apply(

template <Xcts::Geometry ConformalGeometry>
void ApparentHorizon<ConformalGeometry>::apply(
const gsl::not_null<Scalar<DataVector>*> conformal_factor,
const gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
const gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
const gsl::not_null<Scalar<DataVector>*>
lapse_times_conformal_factor_minus_one,
const gsl::not_null<tnsr::I<DataVector, 3>*> shift_excess,
const gsl::not_null<Scalar<DataVector>*> n_dot_conformal_factor_gradient,
const gsl::not_null<Scalar<DataVector>*>
Expand All @@ -534,8 +545,8 @@ void ApparentHorizon<ConformalGeometry>::apply(
const tnsr::II<DataVector, 3>& inv_conformal_metric,
const tnsr::Ijj<DataVector, 3>& conformal_christoffel_second_kind) const {
apparent_horizon_impl<ConformalGeometry>(
conformal_factor, lapse_times_conformal_factor, shift_excess,
n_dot_conformal_factor_gradient,
conformal_factor_minus_one, lapse_times_conformal_factor_minus_one,
shift_excess, n_dot_conformal_factor_gradient,
n_dot_lapse_times_conformal_factor_gradient,
n_dot_longitudinal_shift_excess, center_, rotation_, solution_for_lapse_,
solution_for_negative_expansion_, face_normal,
Expand Down Expand Up @@ -563,8 +574,8 @@ void ApparentHorizon<ConformalGeometry>::apply_linearized(
const tnsr::I<DataVector, 3>& x,
const Scalar<DataVector>& extrinsic_curvature_trace,
const tnsr::II<DataVector, 3>& longitudinal_shift_background,
const Scalar<DataVector>& conformal_factor,
const Scalar<DataVector>& lapse_times_conformal_factor,
const Scalar<DataVector>& conformal_factor_minus_one,
const Scalar<DataVector>& lapse_times_conformal_factor_minus_one,
const tnsr::I<DataVector, 3>& n_dot_longitudinal_shift_excess) const {
linearized_apparent_horizon_impl<ConformalGeometry>(
conformal_factor_correction, lapse_times_conformal_factor_correction,
Expand All @@ -574,7 +585,7 @@ void ApparentHorizon<ConformalGeometry>::apply_linearized(
solution_for_negative_expansion_, face_normal,
deriv_unnormalized_face_normal, face_normal_magnitude, x,
extrinsic_curvature_trace, longitudinal_shift_background,
conformal_factor, lapse_times_conformal_factor,
conformal_factor_minus_one, lapse_times_conformal_factor_minus_one,
n_dot_longitudinal_shift_excess, std::nullopt, std::nullopt);
}

Expand All @@ -596,8 +607,8 @@ void ApparentHorizon<ConformalGeometry>::apply_linearized(
const tnsr::I<DataVector, 3>& x,
const Scalar<DataVector>& extrinsic_curvature_trace,
const tnsr::II<DataVector, 3>& longitudinal_shift_background,
const Scalar<DataVector>& conformal_factor,
const Scalar<DataVector>& lapse_times_conformal_factor,
const Scalar<DataVector>& conformal_factor_minus_one,
const Scalar<DataVector>& lapse_times_conformal_factor_minus_one,
const tnsr::I<DataVector, 3>& n_dot_longitudinal_shift_excess,
const tnsr::II<DataVector, 3>& inv_conformal_metric,
const tnsr::Ijj<DataVector, 3>& conformal_christoffel_second_kind) const {
Expand All @@ -609,7 +620,7 @@ void ApparentHorizon<ConformalGeometry>::apply_linearized(
solution_for_negative_expansion_, face_normal,
deriv_unnormalized_face_normal, face_normal_magnitude, x,
extrinsic_curvature_trace, longitudinal_shift_background,
conformal_factor, lapse_times_conformal_factor,
conformal_factor_minus_one, lapse_times_conformal_factor_minus_one,
n_dot_longitudinal_shift_excess, inv_conformal_metric,
conformal_christoffel_second_kind);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Elliptic/Systems/Xcts/BoundaryConditions/ApparentHorizon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ class ApparentHorizon
using volume_tags = tmpl::list<>;

void apply(
gsl::not_null<Scalar<DataVector>*> conformal_factor,
gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor_minus_one,
gsl::not_null<tnsr::I<DataVector, 3>*> shift_excess,
gsl::not_null<Scalar<DataVector>*> n_dot_conformal_factor_gradient,
gsl::not_null<Scalar<DataVector>*>
Expand All @@ -247,8 +247,8 @@ class ApparentHorizon
const tnsr::II<DataVector, 3>& longitudinal_shift_background) const;

void apply(
gsl::not_null<Scalar<DataVector>*> conformal_factor,
gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor_minus_one,
gsl::not_null<tnsr::I<DataVector, 3>*> shift_excess,
gsl::not_null<Scalar<DataVector>*> n_dot_conformal_factor_gradient,
gsl::not_null<Scalar<DataVector>*>
Expand All @@ -275,8 +275,8 @@ class ApparentHorizon
gr::Tags::TraceExtrinsicCurvature<DataVector>,
Tags::LongitudinalShiftBackgroundMinusDtConformalMetric<DataVector, 3,
Frame::Inertial>,
Tags::ConformalFactor<DataVector>,
Tags::LapseTimesConformalFactor<DataVector>,
Tags::ConformalFactorMinusOne<DataVector>,
Tags::LapseTimesConformalFactorMinusOne<DataVector>,
::Tags::NormalDotFlux<Tags::ShiftExcess<DataVector, 3, Frame::Inertial>>,
tmpl::conditional_t<ConformalGeometry == Xcts::Geometry::Curved,
tmpl::list<Tags::InverseConformalMetric<
Expand All @@ -303,8 +303,8 @@ class ApparentHorizon
const tnsr::I<DataVector, 3>& x,
const Scalar<DataVector>& extrinsic_curvature_trace,
const tnsr::II<DataVector, 3>& longitudinal_shift_background,
const Scalar<DataVector>& conformal_factor,
const Scalar<DataVector>& lapse_times_conformal_factor,
const Scalar<DataVector>& conformal_factor_minus_one,
const Scalar<DataVector>& lapse_times_conformal_factor_minus_one,
const tnsr::I<DataVector, 3>& n_dot_longitudinal_shift_excess) const;

void apply_linearized(
Expand All @@ -324,8 +324,8 @@ class ApparentHorizon
const tnsr::I<DataVector, 3>& x,
const Scalar<DataVector>& extrinsic_curvature_trace,
const tnsr::II<DataVector, 3>& longitudinal_shift_background,
const Scalar<DataVector>& conformal_factor,
const Scalar<DataVector>& lapse_times_conformal_factor,
const Scalar<DataVector>& conformal_factor_minus_one,
const Scalar<DataVector>& lapse_times_conformal_factor_minus_one,
const tnsr::I<DataVector, 3>& n_dot_longitudinal_shift_excess,
const tnsr::II<DataVector, 3>& inv_conformal_metric,
const tnsr::Ijj<DataVector, 3>& conformal_christoffel_second_kind) const;
Expand Down
22 changes: 12 additions & 10 deletions src/Elliptic/Systems/Xcts/BoundaryConditions/Flatness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,39 @@ namespace Xcts::BoundaryConditions {

template <>
void Flatness<Xcts::Equations::Hamiltonian>::apply(
const gsl::not_null<Scalar<DataVector>*> conformal_factor,
const gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
const gsl::not_null<Scalar<DataVector>*>
/*n_dot_conformal_factor_gradient*/) {
get(*conformal_factor) = 1.;
get(*conformal_factor_minus_one) = 0.;
}

template <>
void Flatness<Xcts::Equations::HamiltonianAndLapse>::apply(
const gsl::not_null<Scalar<DataVector>*> conformal_factor,
const gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
const gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
const gsl::not_null<Scalar<DataVector>*>
lapse_times_conformal_factor_minus_one,
const gsl::not_null<Scalar<DataVector>*>
/*n_dot_conformal_factor_gradient*/,
const gsl::not_null<Scalar<DataVector>*>
/*n_dot_lapse_times_conformal_factor_gradient*/) {
get(*conformal_factor) = 1.;
get(*lapse_times_conformal_factor) = 1.;
get(*conformal_factor_minus_one) = 0.;
get(*lapse_times_conformal_factor_minus_one) = 0.;
}

template <>
void Flatness<Xcts::Equations::HamiltonianLapseAndShift>::apply(
const gsl::not_null<Scalar<DataVector>*> conformal_factor,
const gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
const gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
const gsl::not_null<Scalar<DataVector>*>
lapse_times_conformal_factor_minus_one,
const gsl::not_null<tnsr::I<DataVector, 3>*> shift_excess,
const gsl::not_null<Scalar<DataVector>*>
/*n_dot_conformal_factor_gradient*/,
const gsl::not_null<Scalar<DataVector>*>
/*n_dot_lapse_times_conformal_factor_gradient*/,
const gsl::not_null<tnsr::I<DataVector, 3>*>
/*n_dot_longitudinal_shift_excess*/) {
get(*conformal_factor) = 1.;
get(*lapse_times_conformal_factor) = 1.;
get(*conformal_factor_minus_one) = 0.;
get(*lapse_times_conformal_factor_minus_one) = 0.;
std::fill(shift_excess->begin(), shift_excess->end(), 0.);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Elliptic/Systems/Xcts/BoundaryConditions/Flatness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ class Flatness : public elliptic::BoundaryConditions::BoundaryCondition<3> {
using volume_tags = tmpl::list<>;

static void apply(
gsl::not_null<Scalar<DataVector>*> conformal_factor,
gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
gsl::not_null<Scalar<DataVector>*> n_dot_conformal_factor_gradient);

static void apply(
gsl::not_null<Scalar<DataVector>*> conformal_factor,
gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor_minus_one,
gsl::not_null<Scalar<DataVector>*> n_dot_conformal_factor_gradient,
gsl::not_null<Scalar<DataVector>*>
n_dot_lapse_times_conformal_factor_gradient);

static void apply(
gsl::not_null<Scalar<DataVector>*> conformal_factor,
gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor,
gsl::not_null<Scalar<DataVector>*> conformal_factor_minus_one,
gsl::not_null<Scalar<DataVector>*> lapse_times_conformal_factor_minus_one,
gsl::not_null<tnsr::I<DataVector, 3>*> shift_excess,
gsl::not_null<Scalar<DataVector>*> n_dot_conformal_factor_gradient,
gsl::not_null<Scalar<DataVector>*>
Expand Down
Loading
Loading