Skip to content

Commit

Permalink
Changes requested by #321 PR.
Browse files Browse the repository at this point in the history
* Removed friend classes from unit tests

Extra:
* change a var. name in plasticity: from m_one_minus_integrating_factor to m_oneMinusIntegratingFactor
  • Loading branch information
ravil committed Apr 15, 2021
1 parent c6dcce2 commit 415b998
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 149 deletions.
60 changes: 30 additions & 30 deletions src/Initializer/BatchRecorders/DynamicRuptureRecorder.cpp
Expand Up @@ -20,29 +20,28 @@ void DynamicRuptureRecorder::recordDofsTimeEvaluation() {
real* idofsPlus = static_cast<real *>(currentLayer->getScratchpadMemory(currentHandler->idofsPlusOnDevice));
real* idofsMinus = static_cast<real *>(currentLayer->getScratchpadMemory(currentHandler->idofsMinusOnDevice));

if (currentLayer->getNumberOfCells()) {
std::vector<real *> timeDerivativePlusPtrs{};
std::vector<real *> timeDerivativeMinusPtrs{};
std::vector<real *> idofsPlusPtrs{};
std::vector<real *> idofsMinusPtrs{};
const auto size = currentLayer->getNumberOfCells();
if (size > 0) {
std::vector<real *> timeDerivativePlusPtrs(size, nullptr);
std::vector<real *> timeDerivativeMinusPtrs(size, nullptr);
std::vector<real *> idofsPlusPtrs(size, nullptr);
std::vector<real *> idofsMinusPtrs(size, nullptr);

const size_t idofsSize = tensor::Q::size();
for (unsigned face = 0; face < currentLayer->getNumberOfCells(); ++face) {
timeDerivativePlusPtrs.push_back(timeDerivativePlus[face]);
timeDerivativeMinusPtrs.push_back(timeDerivativeMinus[face]);
idofsPlusPtrs.push_back(&idofsPlus[face * idofsSize]);
idofsMinusPtrs.push_back(&idofsMinus[face * idofsSize]);
for (unsigned faceId = 0; faceId < size; ++faceId) {
timeDerivativePlusPtrs[faceId] = timeDerivativePlus[faceId];
timeDerivativeMinusPtrs[faceId] = timeDerivativeMinus[faceId];
idofsPlusPtrs[faceId] = &idofsPlus[faceId * idofsSize];
idofsMinusPtrs[faceId] = &idofsMinus[faceId * idofsSize];
}

if (!idofsPlusPtrs.empty()) {
ConditionalKey key(*KernelNames::DrTime);
checkKey(key);
ConditionalKey key(*KernelNames::DrTime);
checkKey(key);

(*currentTable)[key].content[*EntityId::DrDerivativesPlus] = new BatchPointers(timeDerivativePlusPtrs);
(*currentTable)[key].content[*EntityId::DrDerivativesMinus] = new BatchPointers(timeDerivativeMinusPtrs);
(*currentTable)[key].content[*EntityId::DrIdofsPlus] = new BatchPointers(idofsPlusPtrs);
(*currentTable)[key].content[*EntityId::DrIdofsMinus] = new BatchPointers(idofsMinusPtrs);
}
(*currentTable)[key].content[*EntityId::DrDerivativesPlus] = new BatchPointers(timeDerivativePlusPtrs);
(*currentTable)[key].content[*EntityId::DrDerivativesMinus] = new BatchPointers(timeDerivativeMinusPtrs);
(*currentTable)[key].content[*EntityId::DrIdofsPlus] = new BatchPointers(idofsPlusPtrs);
(*currentTable)[key].content[*EntityId::DrIdofsMinus] = new BatchPointers(idofsMinusPtrs);
}
}

Expand All @@ -59,7 +58,8 @@ void DynamicRuptureRecorder::recordSpaceInterpolation() {
DRGodunovData* godunovData = currentLayer->var(currentHandler->godunovData);
DRFaceInformation* faceInfo = currentLayer->var(currentHandler->faceInformation);

if (currentLayer->getNumberOfCells()) {
const auto size = currentLayer->getNumberOfCells();
if (size > 0) {
std::array<std::vector<real *>, *FaceId::Count> QInterpolatedPlusPtr {};
std::array<std::vector<real *>, *FaceId::Count> idofsPlusPtr {};
std::array<std::vector<real *>, *FaceId::Count> TinvTPlusPtr {};
Expand All @@ -71,17 +71,17 @@ void DynamicRuptureRecorder::recordSpaceInterpolation() {
const size_t QInterpolatedSize = CONVERGENCE_ORDER * tensor::QInterpolated::size();
const size_t idofsSize = tensor::Q::size();

for (unsigned face = 0; face < currentLayer->getNumberOfCells(); ++face) {
const auto plusSide = faceInfo[face].plusSide;
QInterpolatedPlusPtr[plusSide].push_back(&QInterpolatedPlus[face * QInterpolatedSize]);
idofsPlusPtr[plusSide].push_back(&idofsPlus[face * idofsSize]);
TinvTPlusPtr[plusSide].push_back((&godunovData[face])->TinvT);

const auto minusSide = faceInfo[face].minusSide;
const auto faceRelation = faceInfo[face].faceRelation;
QInterpolatedMinusPtr[minusSide][faceRelation].push_back(&QInterpolatedMinus[face * QInterpolatedSize]);
idofsMinusPtr[minusSide][faceRelation].push_back(&idofsMinus[face * idofsSize]);
TinvTMinusPtr[minusSide][faceRelation].push_back((&godunovData[face])->TinvT);
for (unsigned faceId = 0; faceId < size; ++faceId) {
const auto plusSide = faceInfo[faceId].plusSide;
QInterpolatedPlusPtr[plusSide].push_back(&QInterpolatedPlus[faceId * QInterpolatedSize]);
idofsPlusPtr[plusSide].push_back(&idofsPlus[faceId * idofsSize]);
TinvTPlusPtr[plusSide].push_back((&godunovData[faceId])->TinvT);

const auto minusSide = faceInfo[faceId].minusSide;
const auto faceRelation = faceInfo[faceId].faceRelation;
QInterpolatedMinusPtr[minusSide][faceRelation].push_back(&QInterpolatedMinus[faceId * QInterpolatedSize]);
idofsMinusPtr[minusSide][faceRelation].push_back(&idofsMinus[faceId * idofsSize]);
TinvTMinusPtr[minusSide][faceRelation].push_back((&godunovData[faceId])->TinvT);
}

for (unsigned side = 0; side < 4; ++side) {
Expand Down
39 changes: 25 additions & 14 deletions src/Initializer/BatchRecorders/LocalIntegrationRecorder.cpp
Expand Up @@ -28,25 +28,28 @@ void LocalIntegrationRecorder::recordTimeAndVolumeIntegrals() {
real *idofsScratch = static_cast<real *>(currentLayer->getScratchpadMemory(currentHandler->idofsScratch));
real *derivativesScratch = static_cast<real *>(currentLayer->getScratchpadMemory(currentHandler->derivativesScratch));

if (currentLayer->getNumberOfCells()) {
std::vector<real *> dofsPtrs{};
std::vector<real *> starPtrs{};
const auto size = currentLayer->getNumberOfCells();
if (size > 0) {
std::vector<real *> dofsPtrs(size, nullptr);
std::vector<real *> starPtrs(size, nullptr);
std::vector<real *> idofsPtrs{};
std::vector<real *> dQPtrs{};
std::vector<real *> dQPtrs(size, nullptr);
std::vector<real *> ltsBuffers{};
std::vector<real *> idofsForLtsBuffers{};

idofsPtrs.reserve(size);

real **derivatives = currentLayer->var(currentHandler->derivatives);
real **buffers = currentLayer->var(currentHandler->buffers);

for (unsigned cell = 0; cell < currentLayer->getNumberOfCells(); ++cell) {
for (unsigned cell = 0; cell < size; ++cell) {
auto data = currentLoader->entry(cell);

// dofs
dofsPtrs.push_back(static_cast<real *>(data.dofs));
dofsPtrs[cell] = static_cast<real *>(data.dofs);

// idofs
real *nextIdofPtr = &idofsScratch[idofsAddressCounter];
real *nextIdofPtr = &idofsScratch[integratedDofsAddressCounter];
bool isBuffersProvided = ((data.cellInformation.ltsSetup >> 8) % 2) == 1;
bool isLtsBuffers = ((data.cellInformation.ltsSetup >> 10) % 2) == 1;

Expand All @@ -60,7 +63,7 @@ void LocalIntegrationRecorder::recordTimeAndVolumeIntegrals() {
ltsBuffers.push_back(buffers[cell]);

idofsAddressRegistry[cell] = nextIdofPtr;
idofsAddressCounter += tensor::I::size();
integratedDofsAddressCounter += tensor::I::size();
} else {
// gts buffers have to be always overridden
idofsPtrs.push_back(buffers[cell]);
Expand All @@ -69,22 +72,24 @@ void LocalIntegrationRecorder::recordTimeAndVolumeIntegrals() {
} else {
idofsPtrs.push_back(nextIdofPtr);
idofsAddressRegistry[cell] = nextIdofPtr;
idofsAddressCounter += tensor::I::size();
integratedDofsAddressCounter += tensor::I::size();
}

// stars
starPtrs.push_back(static_cast<real *>(data.localIntegrationOnDevice.starMatrices[0]));
starPtrs[cell] = static_cast<real *>(data.localIntegrationOnDevice.starMatrices[0]);

// derivatives
bool isDerivativesProvided = ((data.cellInformation.ltsSetup >> 9) % 2) == 1;
if (isDerivativesProvided) {
dQPtrs.push_back(derivatives[cell]);
dQPtrs[cell] = derivatives[cell];

} else {
dQPtrs.push_back(&derivativesScratch[derivativesAddressCounter]);
dQPtrs[cell] = &derivativesScratch[derivativesAddressCounter];
derivativesAddressCounter += yateto::computeFamilySize<tensor::dQ>();
}
}
// just to be sure that we took all branches while filling in idofsPtrs vector
assert(dofsPtrs.size() == idofsPtrs.size());

ConditionalKey key(KernelNames::Time || KernelNames::Volume);
checkKey(key);
Expand All @@ -106,12 +111,17 @@ void LocalIntegrationRecorder::recordTimeAndVolumeIntegrals() {


void LocalIntegrationRecorder::recordLocalFluxIntegral() {
const auto size = currentLayer->getNumberOfCells();
for (unsigned face = 0; face < 4; ++face) {
std::vector<real *> idofsPtrs{};
std::vector<real *> dofsPtrs{};
std::vector<real *> aplusTPtrs{};

for (unsigned cell = 0; cell < currentLayer->getNumberOfCells(); ++cell) {
idofsPtrs.reserve(size);
dofsPtrs.reserve(size);
aplusTPtrs.reserve(size);

for (unsigned cell = 0; cell < size; ++cell) {
auto data = currentLoader->entry(cell);

// no element local contribution in the case of dynamic rupture boundary conditions
Expand Down Expand Up @@ -141,7 +151,8 @@ void LocalIntegrationRecorder::recordDisplacements() {

// NOTE: velocity components are between 6th and 8th columns
constexpr unsigned OFFSET_TO_VELOCITIES = 6 * seissol::tensor::I::Shape[0];
for (unsigned cell = 0; cell < currentLayer->getNumberOfCells(); ++cell) {
const auto size = currentLayer->getNumberOfCells();
for (unsigned cell = 0; cell < size; ++cell) {
if (displacements[cell] != nullptr) {
real *iVelocity = &idofsAddressRegistry[cell][OFFSET_TO_VELOCITIES];
iVelocitiesPtrs.push_back(iVelocity);
Expand Down
14 changes: 8 additions & 6 deletions src/Initializer/BatchRecorders/NeighIntegrationRecorder.cpp
Expand Up @@ -23,13 +23,14 @@ void NeighIntegrationRecorder::recordDofsTimeEvaluation() {
real *(*faceNeighbors)[4] = currentLayer->var(currentHandler->faceNeighbors);
real *idofsScratch = static_cast<real *>(currentLayer->getScratchpadMemory(currentHandler->idofsScratch));

if (currentLayer->getNumberOfCells()) {
const auto size = currentLayer->getNumberOfCells();
if (size > 0) {
std::vector<real *> ltsIDofsPtrs{};
std::vector<real *> ltsDerivativesPtrs{};
std::vector<real *> gtsDerivativesPtrs{};
std::vector<real *> gtsIDofsPtrs{};

for (unsigned cell = 0; cell < currentLayer->getNumberOfCells(); ++cell) {
for (unsigned cell = 0; cell < size; ++cell) {
auto data = currentLoader->entry(cell);

for (unsigned face = 0; face < 4; ++face) {
Expand All @@ -47,7 +48,7 @@ void NeighIntegrationRecorder::recordDofsTimeEvaluation() {
bool isNeighbProvidesDerivatives = ((data.cellInformation.ltsSetup >> face) % 2) == 1;

if (isNeighbProvidesDerivatives) {
real *NextTempIDofsPtr = &idofsScratch[idofsAddressCounter];
real *NextTempIDofsPtr = &idofsScratch[integratedDofsAddressCounter];

bool isGtsNeigbour = ((data.cellInformation.ltsSetup >> (face + 4)) % 2) == 1;
if (isGtsNeigbour) {
Expand All @@ -61,7 +62,7 @@ void NeighIntegrationRecorder::recordDofsTimeEvaluation() {
ltsIDofsPtrs.push_back(NextTempIDofsPtr);
ltsDerivativesPtrs.push_back(neighbourBuffer);
}
idofsAddressCounter += tensor::I::size();
integratedDofsAddressCounter += tensor::I::size();
} else {
idofsAddressRegistry[neighbourBuffer] = neighbourBuffer;
}
Expand Down Expand Up @@ -101,12 +102,13 @@ void NeighIntegrationRecorder::recordNeighbourFluxIntegrals() {

CellDRMapping(*drMapping)[4] = currentLayer->var(currentHandler->drMapping);

for (unsigned cell = 0; cell < currentLayer->getNumberOfCells(); ++cell) {
const auto size = currentLayer->getNumberOfCells();
for (unsigned cell = 0; cell < size; ++cell) {
auto data = currentLoader->entry(cell);
for (unsigned int face = 0; face < 4; face++) {
switch (data.cellInformation.faceTypes[face]) {
case FaceType::regular:
// Fallthrough intended
[[fallthrough]];
case FaceType::periodic: {
// compute face type relation

Expand Down
36 changes: 18 additions & 18 deletions src/Initializer/BatchRecorders/PlasticityRecorder.cpp
Expand Up @@ -14,27 +14,27 @@ void PlasticityRecorder::record(LTS &handler, Layer &layer) {
real(*pstrains)[7] = currentLayer->var(currentHandler->pstrain);
size_t nodalStressTensorCounter = 0;
real *scratchMem = static_cast<real *>(currentLayer->getScratchpadMemory(currentHandler->idofsScratch));
if (currentLayer->getNumberOfCells()) {
std::vector<real *> dofsPtrs{};
std::vector<real *> qstressNodalPtrs{};
std::vector<real *> pstransPtrs{};
std::vector<real *> initialLoadPtrs{};
const auto size = currentLayer->getNumberOfCells();
if (size > 0) {
std::vector<real *> dofsPtrs(size, nullptr);
std::vector<real *> qstressNodalPtrs(size, nullptr);
std::vector<real *> pstransPtrs(size, nullptr);
std::vector<real *> initialLoadPtrs(size, nullptr);

for (unsigned cell = 0; cell < currentLayer->getNumberOfCells(); ++cell) {
for (unsigned cell = 0; cell < size; ++cell) {
auto data = currentLoader->entry(cell);
dofsPtrs.push_back(static_cast<real *>(data.dofs));
qstressNodalPtrs.push_back(&scratchMem[nodalStressTensorCounter]);
dofsPtrs[cell] = static_cast<real *>(data.dofs);
qstressNodalPtrs[cell] = &scratchMem[nodalStressTensorCounter];
nodalStressTensorCounter += tensor::QStressNodal::size();
pstransPtrs.push_back(static_cast<real *>(pstrains[cell]));
initialLoadPtrs.push_back(static_cast<real *>(data.plasticity.initialLoading));
}
if (!dofsPtrs.empty()) {
ConditionalKey key(*KernelNames::Plasticity);
checkKey(key);
(*currentTable)[key].content[*EntityId::Dofs] = new BatchPointers(dofsPtrs);
(*currentTable)[key].content[*EntityId::NodalStressTensor] = new BatchPointers(qstressNodalPtrs);
(*currentTable)[key].content[*EntityId::Pstrains] = new BatchPointers(pstransPtrs);
(*currentTable)[key].content[*EntityId::InitialLoad] = new BatchPointers(initialLoadPtrs);
pstransPtrs[cell] = static_cast<real *>(pstrains[cell]);
initialLoadPtrs[cell] = static_cast<real *>(data.plasticity.initialLoading);
}

ConditionalKey key(*KernelNames::Plasticity);
checkKey(key);
(*currentTable)[key].content[*EntityId::Dofs] = new BatchPointers(dofsPtrs);
(*currentTable)[key].content[*EntityId::NodalStressTensor] = new BatchPointers(qstressNodalPtrs);
(*currentTable)[key].content[*EntityId::Pstrains] = new BatchPointers(pstransPtrs);
(*currentTable)[key].content[*EntityId::InitialLoad] = new BatchPointers(initialLoadPtrs);
}
}
8 changes: 4 additions & 4 deletions src/Initializer/BatchRecorders/Recorders.h
Expand Up @@ -76,7 +76,7 @@ class LocalIntegrationRecorder : public AbstractRecorder<seissol::initializers::
private:
void setUpContext(LTS &handler, Layer &layer, kernels::LocalData::Loader &loader) {
currentLoader = &loader;
idofsAddressCounter = 0;
integratedDofsAddressCounter = 0;
derivativesAddressCounter = 0;
AbstractRecorder::setUpContext(handler, layer);
}
Expand All @@ -86,7 +86,7 @@ class LocalIntegrationRecorder : public AbstractRecorder<seissol::initializers::
void recordLocalFluxIntegral();
void recordDisplacements();
std::unordered_map<size_t, real *> idofsAddressRegistry{};
size_t idofsAddressCounter{0};
size_t integratedDofsAddressCounter{0};
size_t derivativesAddressCounter{0};
};

Expand All @@ -97,14 +97,14 @@ class NeighIntegrationRecorder : public AbstractRecorder<seissol::initializers::
private:
void setUpContext(LTS &handler, Layer &layer, kernels::NeighborData::Loader &loader) {
currentLoader = &loader;
idofsAddressCounter = 0;
integratedDofsAddressCounter = 0;
AbstractRecorder::setUpContext(handler, layer);
}
void recordDofsTimeEvaluation();
void recordNeighbourFluxIntegrals();
kernels::NeighborData::Loader *currentLoader{nullptr};
std::unordered_map<real *, real *> idofsAddressRegistry{};
size_t idofsAddressCounter{0};
size_t integratedDofsAddressCounter{0};
};


Expand Down
4 changes: 2 additions & 2 deletions src/Kernels/DeviceAux/PlasticityAux.h
Expand Up @@ -17,7 +17,7 @@ void saveFirstModes(real *firstModes,
void adjustDeviatoricTensors(real **nodalStressTensors,
int *isAdjustableVector,
const PlasticityData *plasticity,
double one_minus_integrating_factor,
double oneMinusIntegratingFactor,
size_t numElements);

void adjustModalStresses(real **modalStressTensors,
Expand All @@ -31,7 +31,7 @@ void computePstrains(real **pstrains,
const real **modalStressTensors,
const real *firsModes,
const PlasticityData *plasticity,
double one_minus_integrating_factor,
double oneMinusIntegratingFactor,
double timeStepWidth,
double T_v,
size_t numElements);
Expand Down

0 comments on commit 415b998

Please sign in to comment.