Skip to content

Commit

Permalink
Pulled from feature branch for constraint investigation
Browse files Browse the repository at this point in the history
  • Loading branch information
the-florist committed Apr 16, 2024
2 parents 078e670 + 696adf6 commit 89e27e8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Examples/ScalarField/DiagnosticVariables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum
c_sfd,
c_sf2,
c_ch2,
c_Ham_abs_pbp,

c_a,
c_H,
Expand All @@ -34,6 +35,8 @@ static const std::array<std::string, NUM_DIAGNOSTIC_VARS> variable_names = {
"Phi",
"Pi",
"PhiSq",
"ChiSq",
"AbsHamPBP",

"ScaleFactor",
"HubbleFactor",
Expand Down
14 changes: 14 additions & 0 deletions Examples/ScalarField/Main_ScalarField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "GRParmParse.hpp"
#include "SetupFunctions.hpp"
#include "SimulationParameters.hpp"
#include "MultiLevelTask.hpp"

// Problem specific includes:
#include "ScalarFieldLevel.hpp"
Expand Down Expand Up @@ -53,6 +54,19 @@ int runGRChombo(int argc, char *argv[])
level->specificPostTimeStep();
};

// (!!) only un-comment one of the code blocks below
// at a time.

// call specificPostTimeStep at every time step
//MultiLevelTaskPtr<> call_task(task);
//call_task.execute(gr_amr);

// call specificPostTimeStep at some_interval
int some_interval = 1;
bool reverse_levels = true;
MultiLevelTaskPtr<> call_task(task, reverse_levels, some_interval);
gr_amr.schedule(call_task);

// Engage! Run the evolution
gr_amr.run(sim_params.stop_time, sim_params.max_steps);
gr_amr.conclude();
Expand Down
3 changes: 1 addition & 2 deletions Examples/ScalarField/MeansVars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class MeansVars
data_t Pi;
data_t chi;
data_t K;

data_t h11;
data_t Ham;

template <typename mapping_function_t>
void enum_mapping(mapping_function_t mapping_function);
Expand Down
4 changes: 3 additions & 1 deletion Examples/ScalarField/MeansVars.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ inline
data_t phisq = vars.phi*vars.phi;
data_t chisq = vars.chi*vars.chi;
data_t kin = vars.Pi*vars.Pi;
data_t hamabspbp = abs(vars.Ham);

//store class (Vars) variables as diagnostic variables on the grid
current_cell.store_vars(vars.phi, c_sf);
current_cell.store_vars(vars.Pi, c_sfd);
current_cell.store_vars(vars.chi, c_a);
current_cell.store_vars(vars.K, c_H);
current_cell.store_vars(hamabspbp, c_Ham_abs_pbp);
current_cell.store_vars(phisq, c_sf2);
current_cell.store_vars(chisq, c_ch2);
current_cell.store_vars(kin, c_kin);
Expand All @@ -50,7 +52,7 @@ inline
define_enum_mapping(mapping_function, c_Pi, Pi);
define_enum_mapping(mapping_function, c_chi, chi);
define_enum_mapping(mapping_function, c_K, K);
define_enum_mapping(mapping_function, c_h11, h11);
define_enum_mapping(mapping_function, c_Ham, Ham);
}

#endif /* MEANSVARS_IMPL_HPP_ */
11 changes: 5 additions & 6 deletions Examples/ScalarField/ScalarFieldLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ void ScalarFieldLevel::initialData()

pfield.clear_data();
pout() << "Calculating position ICs ended.\n";
// MayDay::Error("Calculating position ICs ended.");

std::vector<std::vector<double> > h(std::pow(N, 3.), std::vector<double>(6, 0.)); // input array memory allocation
std::vector<std::vector<double> > hdot(std::pow(N, 3.), std::vector<double>(6, 0.));
Expand All @@ -90,9 +89,7 @@ void ScalarFieldLevel::initialData()
make_compute_pack(InitialScalarData(m_p.initial_params)),
m_state_new, m_state_new, INCLUDE_GHOST_CELLS,disable_simd());

cout << "IC set-up ended.\n";

//MayDay::Error("Check for crash.");
pout() << "IC set-up ended.\n";

fillAllGhosts();
BoxLoops::loop(GammaCalculator(m_dx), m_state_new, m_state_new,
Expand Down Expand Up @@ -197,6 +194,7 @@ void ScalarFieldLevel::specificPostTimeStep()
double H = -amr_reductions.sum(c_H)/vol/3.;

double hambar = amr_reductions.sum(c_Ham)/vol;
double hamabspbpSum = amr_reductions.sum(c_Ham_abs_pbp)/vol;
double mombar = amr_reductions.sum(c_Mom)/vol;
double habsbar = amr_reductions.sum(c_Ham_abs_terms)/vol;
double mabsbar = amr_reductions.sum(c_Mom_abs_terms)/vol;
Expand All @@ -222,7 +220,8 @@ void ScalarFieldLevel::specificPostTimeStep()
if(first_step)
{
means_file.write_header_line({"Scalar field mean","Scalar field variance","Pi mean","Scale factor","Conformal factor variance","Hubble factor",
"Kinetic ED","Potential ED","First SRP","Second SRP","Avg Ham constr","Avg Mom constr","Avg Ham abs term","Avg Mom abs term","Avg lapse"});
"Kinetic ED","Potential ED","First SRP","Second SRP","Avg Ham constr","Avg |Ham| constr (point by point)","Avg Mom constr",
"Avg Ham abs term","Avg Mom abs term","Avg lapse"});
}
means_file.write_time_data_line({phibar, phivar, pibar, a, chivar, H, kinb, potb, epsilon, delta, hambar, mombar, habsbar, mabsbar, lapse});
means_file.write_time_data_line({phibar, phivar, pibar, a, chivar, H, kinb, potb, epsilon, delta, hambar, hamabspbpSum, mombar, habsbar, mabsbar, lapse});
}
16 changes: 8 additions & 8 deletions Source/InitialConditions/ScalarFields/RandomField.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
{
kstar = 32.*(2.*M_PI/m_params.L);
epsilon = 0.05;
H0 = 0.204692;//-3.0*sqrt((8.0 * M_PI/3.0/m_params.m_pl/m_params.m_pl)
//*(0.5*m_params.velocity*m_params.velocity + 0.5*pow(m_params.m * m_params.amplitude, 2.0)));
H0 = -3.0*sqrt((8.0 * M_PI/3.0/m_params.m_pl/m_params.m_pl)
*(0.5*m_params.velocity*m_params.velocity + 0.5*pow(m_params.m * m_params.amplitude, 2.0)));
norm = pow(m_params.N, 3.);

calc_spectrum();
Expand Down Expand Up @@ -197,8 +197,8 @@ void RandomField::calc_spectrum()

// Start of with random numbers filling the entire array
// Real parts of h+, hx and hij
hplus[k + (N/2+1)*(j + N*i)][0] = find_rayleigh_factor(kmag, m_spec_type, sigma_dist(engine), 0);// * cos(theta_dist(engine));
hcross[k + (N/2+1)*(j + N*i)][0] = find_rayleigh_factor(kmag, m_spec_type, sigma_dist(engine), 0);// * cos(theta_dist(engine));
hplus[k + (N/2+1)*(j + N*i)][0] = find_rayleigh_factor(kmag, m_spec_type, sigma_dist(engine), 0) * cos(theta_dist(engine));
hcross[k + (N/2+1)*(j + N*i)][0] = find_rayleigh_factor(kmag, m_spec_type, sigma_dist(engine), 0) * cos(theta_dist(engine));

calc_transferse_vectors(i, j, k, mhat, nhat);

Expand All @@ -218,8 +218,8 @@ void RandomField::calc_spectrum()
// Else, fill the imaginary part of each field appropriately
else
{
hplus[k + (N/2+1)*(j + N*i)][1] = find_rayleigh_factor(kmag, m_spec_type, sigma_dist(engine), 1);// * sin(theta_dist(engine));
hcross[k + (N/2+1)*(j + N*i)][1] = find_rayleigh_factor(kmag, m_spec_type, sigma_dist(engine), 1);// * sin(theta_dist(engine));
hplus[k + (N/2+1)*(j + N*i)][1] = find_rayleigh_factor(kmag, m_spec_type, sigma_dist(engine), 1) * sin(theta_dist(engine));
hcross[k + (N/2+1)*(j + N*i)][1] = find_rayleigh_factor(kmag, m_spec_type, sigma_dist(engine), 1) * sin(theta_dist(engine));
for (int l=0; l<3; l++) for (int p=0; p<3; p++)
{
hk[lut[l][p]][k + (N/2+1)*(j + N*i)][1] = ((mhat[l]*mhat[p] - nhat[l]*nhat[p]) * hplus[k + (N/2+1)*(j + N*i)][1]
Expand All @@ -246,7 +246,7 @@ void RandomField::calc_spectrum()
}

hkprint.close();
MayDay::Error("Printed file for comparison with stand-alone IC generator.");
//MayDay::Error("Printed file for comparison with stand-alone IC generator.");

pout() << "Moving to configuration space.\n";

Expand Down Expand Up @@ -310,7 +310,7 @@ double RandomField::find_rayleigh_factor(double km, std::string spec_type, doubl
}

// Apply the tanh window function and the uniform draw
windowed_value *= 0.5 * (1.0 - tanh(epsilon * (km - kstar)));// * sqrt(-2. * log(uniform_draw));
windowed_value *= 0.5 * (1.0 - tanh(epsilon * (km - kstar))) * sqrt(-2. * log(uniform_draw));
return windowed_value;
}

Expand Down

0 comments on commit 89e27e8

Please sign in to comment.