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

Update example for diagnostic use and to give explicit example #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
98 changes: 98 additions & 0 deletions ChomboTools/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
BreakBeforeInheritanceComma: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

96 changes: 96 additions & 0 deletions ChomboTools/ReprocessFiles/CustomExtraction.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* GRChombo
* Copyright 2012 The GRChombo collaboration.
* Please refer to LICENSE in GRChombo's root directory.
*/

#ifndef CUSTOMEXTRACTION_HPP_
#define CUSTOMEXTRACTION_HPP_

#include "AMRInterpolator.hpp"
#include "InterpolationQuery.hpp"
#include "Lagrange.hpp"
#include "SimulationParametersBase.hpp"
#include "SmallDataIO.hpp"
#include "SphericalHarmonics.hpp"
#include "UserVariables.hpp"
#include <fstream>
#include <iostream>

//! The class allows extraction of the values of components at
//! specified points
class CustomExtraction
{
private:
//! Params for extraction
const int m_comp;
const int m_num_points;
const double m_L;
const std::array<double, CH_SPACEDIM> m_center;
const double m_dt;
const double m_time;

public:
//! The constructor
CustomExtraction(int a_comp, int a_num_points, double a_L,
std::array<double, CH_SPACEDIM> a_center, double a_dt,
double a_time)
: m_comp(a_comp), m_num_points(a_num_points), m_center(a_center),
m_L(a_L), m_dt(a_dt), m_time(a_time)
{
}

//! Destructor
~CustomExtraction() {}

//! Execute the query
void execute_query(AMRInterpolator<Lagrange<4>> *a_interpolator,
std::string a_file_prefix) const
{
CH_TIME("CustomExtraction::execute_query");
if (a_interpolator == nullptr)
{
MayDay::Error("Interpolator has not been initialised.");
}
std::vector<double> interp_var_data(m_num_points);
std::vector<double> interp_x(m_num_points);
std::vector<double> interp_y(m_num_points);
std::vector<double> interp_z(m_num_points);

// Work out the coordinates
// go out radially in diagonal dircetion to L/2
for (int idx = 0; idx < m_num_points; ++idx)
{
interp_x[idx] =
m_center[0] + (double(idx) / double(m_num_points) * 0.5 * m_L);
interp_y[idx] =
m_center[1] + (double(idx) / double(m_num_points) * 0.5 * m_L);
interp_z[idx] =
m_center[2] + (double(idx) / double(m_num_points) * 0.5 * m_L);
}

// set up the query
InterpolationQuery query(m_num_points);
query.setCoords(0, interp_x.data())
.setCoords(1, interp_y.data())
.setCoords(2, interp_z.data())
.addComp(m_comp, interp_var_data.data(), Derivative::LOCAL,
VariableType::evolution);

// submit the query
a_interpolator->interp(query);

// now write out
bool first_step = (m_time == 0.0);
double restart_time = 0.0;
SmallDataIO output_file(a_file_prefix, m_dt, m_time, restart_time,
SmallDataIO::APPEND, first_step);

if (first_step)
{
output_file.write_header_line({"r values"});
}
output_file.write_time_data_line(interp_var_data);
}
};

#endif /* CUSTOMEXTRACTION_HPP_ */
25 changes: 24 additions & 1 deletion ChomboTools/ReprocessFiles/ReprocessingLevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef REPROCESSINGLEVEL_HPP_
#define REPROCESSINGLEVEL_HPP_

#include "CustomExtraction.hpp"
#include "GRAMRLevel.hpp"

class ReprocessingLevel : public GRAMRLevel
Expand All @@ -22,8 +23,30 @@ class ReprocessingLevel : public GRAMRLevel
// Add code here to do what you need it to do on each level
// Note that if you want the AMRInterpolator you need to define it
// and set it here (currently it is just a nullptr)
pout() << "The time is " << m_time << " on level " << m_level
pout() << "The time is " << m_time << " on level " << m_level
<< ". Your wish is my command." << endl;

// as an example, on the coarsest level do a simple extraction
// (NB will still take data from finest level which covers the points)
if (m_level == 0)
{
// set up an interpolator
// pass the boundary params so that we can use symmetries if
// applicable
AMRInterpolator<Lagrange<4>> interpolator(
m_gr_amr, m_p.origin, m_p.dx, m_p.boundary_params,
m_p.verbosity);

// this should fill all ghosts including the boundary ones according
// to the conditions set in params.txt
interpolator.refresh();

// set up the query and execute it
int num_points = 4;
CustomExtraction extraction(c_chi, num_points, m_p.L, m_p.center,
m_dt, m_time);
extraction.execute_query(&interpolator, "outputs");
}
}

virtual void specificEvalRHS(GRLevelData &a_soln, GRLevelData &a_rhs,
Expand Down
8 changes: 4 additions & 4 deletions ChomboTools/ReprocessFiles/ReprocessingTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
#endif

// General includes:
#include "parstream.H" //Gives us pout()
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sys/time.h>
#include "parstream.H" //Gives us pout()
using std::endl;

// Problem specific includes:
#include "AMRInterpolator.hpp"
#include "DefaultLevelFactory.hpp"
#include "GRAMR.hpp"
#include "ReprocessingLevel.hpp"
#include "InterpolationQuery.hpp"
#include "Lagrange.hpp"
#include "ReprocessingLevel.hpp"
#include "SetupFunctions.hpp"
#include "SimulationParameters.hpp"
#include "UserVariables.hpp"
Expand Down Expand Up @@ -61,8 +61,8 @@ int runReprocessingTool(int argc, char *argv[])
std::ostringstream current_file;
current_file << std::setw(6) << std::setfill('0')
<< ifile * sim_params.checkpoint_interval;
std::string restart_file(sim_params.checkpoint_prefix + current_file.str() +
".3d.hdf5");
std::string restart_file(sim_params.checkpoint_prefix +
current_file.str() + ".3d.hdf5");
HDF5Handle handle(restart_file, HDF5Handle::OPEN_RDONLY);
gr_amr.setupForRestart(handle);
handle.close();
Expand Down
8 changes: 1 addition & 7 deletions ChomboTools/ReprocessFiles/SimulationParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#define SIMULATIONPARAMETERS_HPP_

// General includes
#include "GRParmParse.hpp"
#include "ChomboParameters.hpp"
#include "GRParmParse.hpp"

class SimulationParameters : public ChomboParameters
{
Expand All @@ -26,15 +26,9 @@ class SimulationParameters : public ChomboParameters
pp.get("num_files", num_files);
pp.get("start_file", start_file);
pp.get("checkpoint_interval", checkpoint_interval);

// extraction params
dx.fill(coarsest_dx);
origin.fill(coarsest_dx / 2.0);
}

int num_files, start_file, checkpoint_interval;
std::array<double, CH_SPACEDIM> origin,
dx; // location of coarsest origin and dx
};

#endif /* SIMULATIONPARAMETERS_HPP_ */
76 changes: 12 additions & 64 deletions ChomboTools/ReprocessFiles/UserVariables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,27 @@
#ifndef USERVARIABLES_HPP
#define USERVARIABLES_HPP

#include "EmptyDiagnosticVariables.hpp"
#include <array>
#include <string>

// assign an enum to each variable
// if restarting from plot files you should put the plot vars here in the order
// in which you added them to the plot files, so this may not match your ACTUAL
// UserVariables.hpp file. For the purposes of this tool, all vars are treated
// as evolution ones since we use the checkpoint restart feature
enum
{
c_chi,

c_h11,
c_h12,
c_h13,
c_h22,
c_h23,
c_h33,

c_K,

c_A11,
c_A12,
c_A13,
c_A22,
c_A23,
c_A33,

c_Theta,

c_Gamma1,
c_Gamma2,
c_Gamma3,

c_lapse,

c_shift1,
c_shift2,
c_shift3,

c_B1,
c_B2,
c_B3,

c_phi, // matter field added
c_Pi, //(minus) conjugate momentum

c_Ham,

c_Mom1,
c_Mom2,
c_Mom3,

c_rho,
NUM_VARS
};

namespace UserVariables
{
static constexpr char const *variable_names[NUM_VARS] = {
"chi",

"h11", "h12", "h13", "h22", "h23", "h33",

"K",

"A11", "A12", "A13", "A22", "A23", "A33",

"Theta",

"Gamma1", "Gamma2", "Gamma3",

"lapse",

"shift1", "shift2", "shift3",

"B1", "B2", "B3",

"phi", "Pi",

"Ham", "Mom1", "Mom2", "Mom3"};
static const std::array<std::string, NUM_VARS> variable_names = {"chi", "rho"};
}

#include "UserVariables.inc.hpp"

#endif /* USERVARIABLES_HPP */
Loading