Skip to content

Commit

Permalink
Rename for z4c consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
hlim88 committed Oct 25, 2023
1 parent d37e45d commit f196a8f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 13 deletions.
31 changes: 20 additions & 11 deletions src/Z4c/Z4c.cpp → src/Z4c/z4c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,36 @@ Author : Hyun Lim
#include "phoebus_utils/robust.hpp"

// Z4c header to contain some utils including FD computations
#include "Z4c.hpp"
#include "z4c.hpp"

using namespace parthenon::package::prelude;
using parthenon::AllReduce;
using parthenon::MetadataFlag;



// TODO : Do I need this?
namespace Z4c {
namespace z4c {

std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
auto Z4c = std::make_shared<StateDescriptor>("Z4c");
Params &params = Z4c->AllParams();
auto z4c = std::make_shared<StateDescriptor>("z4c");
Params &params = z4c->AllParams();

bool enable_Z4c = pin->GetOrAddBoolean("Z4c", "enabled", false);
params.Add("enable_Z4c", enable_Z4c);
bool enable_z4c = pin->GetOrAddBoolean("z4c", "enabled", false);
params.Add("enable_z4c", enable_Z4c);
if (!enable_z4c) return z4c;

return Z4c
// Add vars
Metadata m_constraint_scalar({Metadata::Cell, Metadata::Metadata::Derived, Metadata::OneCopy});
Metadata m_constraint_vector({Metadata::Cell, Metadata::Metadata::Derived, Metadata::OneCopy}, std::vector<int>{3});
z4c->AddField<constraint::H>(m_constraint_scalar);
z4c->AddField<constraint::M>(m_constraint_vector);

Metadata m_evolution_rank2({Metadata::Cell, Metadata::Metadata::Derived, Metadata::OneCopy}, std::vector<int>{3,3});
z4c->AddField<evolution::At>(m_evolution_rank2);



return z4c
}

#endif //PHOEBUS_UNIT_TEST

}//namespace Z4c
}//namespace z4c
25 changes: 24 additions & 1 deletion src/Z4c/Z4c.hpp → src/Z4c/z4c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,32 @@ Author : Hyun Lim
#define Z4C_HPP_

#include "fd_compute.hpp"
#include "Z4c_eqn.cpp"
#include "z4c_eqn.cpp"

//TODO : Link to Phoebus
#include <parthenon/package.hpp>

#define VARIABLE(ns, varname) \
struct varname : public parthenon::variable_names::base_t<false> { \
template <class... Ts> \
KOKKOS_INLINE_FUNCTION varname(Ts &&...args) \
: parthenon::variable_names::base_t<false>(std::forward<Ts>(args)...) {} \
static std::string name() { return #ns "." #varname; } \
}

namespace z4c { // fix consistencty with namespace everywhere
namespace constraint{
VARIABLE(z4c.c, H);
VARIABLE(z4c.c, M);
} // constraint
namespace evolution{
VARIABLE(z4c.c, At);
} // evolution

// Prototype for package init
std::shared_ptr<parthenon::StateDescriptor> Initialize(ParameterInput *pin);

} // z4c

// Some precomputation
// compute spatial determinant of a 3x3 matrix
Expand Down
23 changes: 23 additions & 0 deletions src/Z4c/Z4c_eqn.cpp → src/Z4c/z4c_eqn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ void Z4c::ADMConstraints(
SetZ4cAliases(u_z4c, z4c);
#endif

//TODO : make better
constexpr size_t scratch_level = 1; // can be 0, 1, or 2. Depends on hardware. 0 is lower level cache usually. 2 is highest level (maybe main memory?)
// gets allocation size for scratch memory for rank 2 tensor along pencil in i
const auto scratch_size = parthenon::ScratchPad3D<Real>::shmem_size(NDIM, NDIM, Ni) /* + more sizes if desired */;

// make loop...
parthenon::par_for_outer(DEFAULT_OUTER_LOOP_PATTERN, "loop name", DevExecSpace(),
// scratch declarations
scratch_size, scratch_level,
// loop bounds
0, nblocks-1, kb.s, kb.e,
// lambda capture
KOKKOS_LAMBDA(parthenon::team_member_t member, const int b, const int k) {
// loop body

// request scratch memory. Can now be used as a multid array.
ScratchPad3D<Real> ginverse(member.team_scratch(scratch_level), NDIM, NDIM, Ni);
// can keep declaring scratch arrays up to as much memory as requested in scratch_size above

// do stuff...
});


ILOOP2(k,j) {
// -----------------------------------------------------------------------------------
// derivatives
Expand Down
2 changes: 1 addition & 1 deletion src/Z4c/Z4c_utils.cpp → src/Z4c/z4c_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Author : Hyun Lim
#include "phoebus_utils/robust.hpp"

// Z4c header to contain some utils including FD computations
#include "Z4c.hpp"
#include "z4c.hpp"

// Some macro
// TODO : maybe define different way?
Expand Down

0 comments on commit f196a8f

Please sign in to comment.