Skip to content

Commit

Permalink
Use smart pointer source
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed May 7, 2024
1 parent 6c23b99 commit 98b6555
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 42 deletions.
12 changes: 6 additions & 6 deletions examples/faradayCageEtching/faradayCageEtching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include <psProcess.hpp>

template <typename NumericType, int D>
class FaradayCageSource : public raySource<NumericType, D> {
class FaradayCageSource : public raySource<NumericType> {
public:
FaradayCageSource(const NumericType xExtent, const NumericType yExtent,
const NumericType zPos, const NumericType gridDelta,
const NumericType angle)
: minPoint_{-xExtent / 2., -yExtent / 2.}, maxPoint_{xExtent / 2.,
yExtent / 2.},
zPos_(zPos), gridDelta_(gridDelta), angle_(angle * M_PI / 180.) {}
: minPoint_{-xExtent / 2., -yExtent / 2.},
maxPoint_{xExtent / 2., yExtent / 2.}, zPos_(zPos),
gridDelta_(gridDelta), angle_(angle * M_PI / 180.) {}

rayPair<rayTriple<NumericType>>
getOriginAndDirection(const size_t idx, rayRNG &RngState) const {
Expand Down Expand Up @@ -87,11 +87,11 @@ int main(int argc, char *argv[]) {
auto &modelParams = model->getParameters();

// faraday cage source setup
auto source = std::make_unique<FaradayCageSource<NumericType, D>>(
auto source = psSmartPointer<FaradayCageSource<NumericType, D>>::New(
params.get("xExtent"), params.get("yExtent"),
params.get("finHeight") + params.get("gridDelta") / 2.,
params.get("gridDelta"), params.get("angle"));
model->setSource(std::move(source));
model->setSource(source);
modelParams.tiltAngle = params.get("angle");

// process setup
Expand Down
16 changes: 8 additions & 8 deletions include/viennaps/psProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ template <typename NumericType, int D> class psProcess {
rayTracer.setCalculateFlux(false);
auto source = model->getSource();
if (source) {
rayTracer.setSource(std::move(source));
rayTracer.setSource(source);
psLogger::getInstance().addInfo("Using custom source.").print();
}
auto primaryDirection = model->getPrimaryDirection();
Expand All @@ -155,7 +155,7 @@ template <typename NumericType, int D> class psProcess {
rayTracer.setGeometry(points, normals, domain->getGrid().getGridDelta());
rayTracer.setMaterialIds(materialIds);

for (auto &particle : *model->getParticleTypes()) {
for (auto &particle : model->getParticleTypes()) {
rayTracer.setParticleType(particle);
rayTracer.apply();

Expand Down Expand Up @@ -260,7 +260,7 @@ template <typename NumericType, int D> class psProcess {
}

/* --------- Setup for ray tracing ----------- */
const bool useRayTracing = model->getParticleTypes() != nullptr;
const bool useRayTracing = !model->getParticleTypes().empty();

rayBoundaryCondition rayBoundaryCondition[D];
rayTrace<NumericType, D> rayTracer;
Expand All @@ -286,13 +286,13 @@ template <typename NumericType, int D> class psProcess {
rayTracer.setCalculateFlux(false);
auto source = model->getSource();
if (source) {
rayTracer.setSource(std::move(source));
rayTracer.setSource(source);
psLogger::getInstance().addInfo("Using custom source.").print();
}

// initialize particle data logs
particleDataLogs.resize(model->getParticleTypes()->size());
for (std::size_t i = 0; i < model->getParticleTypes()->size(); i++) {
particleDataLogs.resize(model->getParticleTypes().size());
for (std::size_t i = 0; i < model->getParticleTypes().size(); i++) {
int logSize = model->getParticleLogSize(i);
if (logSize > 0) {
particleDataLogs[i].data.resize(1);
Expand Down Expand Up @@ -366,7 +366,7 @@ template <typename NumericType, int D> class psProcess {
auto rates = psSmartPointer<psPointData<NumericType>>::New();

std::size_t particleIdx = 0;
for (auto &particle : *model->getParticleTypes()) {
for (auto &particle : model->getParticleTypes()) {
int dataLogSize = model->getParticleLogSize(particleIdx);
if (dataLogSize > 0) {
rayTracer.getDataLog().data.resize(1);
Expand Down Expand Up @@ -478,7 +478,7 @@ template <typename NumericType, int D> class psProcess {
}

std::size_t particleIdx = 0;
for (auto &particle : *model->getParticleTypes()) {
for (auto &particle : model->getParticleTypes()) {
int dataLogSize = model->getParticleLogSize(particleIdx);
if (dataLogSize > 0) {
rayTracer.getDataLog().data.resize(1);
Expand Down
41 changes: 13 additions & 28 deletions include/viennaps/psProcessModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ template <typename NumericType, int D> class psProcessModel {
using ParticleTypeList =
std::vector<std::unique_ptr<rayAbstractParticle<NumericType>>>;

psSmartPointer<ParticleTypeList> particles = nullptr;
std::unique_ptr<raySource<NumericType, D>> source;
ParticleTypeList particles;
psSmartPointer<raySource<NumericType>> source = nullptr;
std::vector<int> particleLogSize;
psSmartPointer<psSurfaceModel<NumericType>> surfaceModel = nullptr;
psSmartPointer<psAdvectionCallback<NumericType, D>> advectionCallback =
Expand All @@ -31,31 +31,21 @@ template <typename NumericType, int D> class psProcessModel {
public:
virtual ~psProcessModel() = default;

virtual psSmartPointer<ParticleTypeList> getParticleTypes() const {
return particles;
}
virtual psSmartPointer<psSurfaceModel<NumericType>> getSurfaceModel() const {
ParticleTypeList const &getParticleTypes() const { return particles; }
psSmartPointer<psSurfaceModel<NumericType>> getSurfaceModel() const {
return surfaceModel;
}
virtual psSmartPointer<psAdvectionCallback<NumericType, D>>
psSmartPointer<psAdvectionCallback<NumericType, D>>
getAdvectionCallback() const {
return advectionCallback;
}
virtual psSmartPointer<psGeometricModel<NumericType, D>>
getGeometricModel() const {
psSmartPointer<psGeometricModel<NumericType, D>> getGeometricModel() const {
return geometricModel;
}
virtual psSmartPointer<psVelocityField<NumericType>>
getVelocityField() const {
psSmartPointer<psVelocityField<NumericType>> getVelocityField() const {
return velocityField;
}
virtual std::unique_ptr<raySource<NumericType, D>> getSource() {
if (source) {
return std::move(source);
} else {
return nullptr;
}
}
psSmartPointer<raySource<NumericType>> getSource() { return source; }

/// Set a primary direction for the source distribution (tilted distribution).
virtual std::optional<std::array<NumericType, 3>>
Expand All @@ -81,21 +71,16 @@ template <typename NumericType, int D> class psProcessModel {
ParticleType> = lsConcepts::assignable>
void insertNextParticleType(std::unique_ptr<ParticleType> &passedParticle,
const int dataLogSize = 0) {
if (particles == nullptr) {
particles = psSmartPointer<ParticleTypeList>::New();
}
particles->push_back(passedParticle->clone());
particles.push_back(passedParticle->clone());
particleLogSize.push_back(dataLogSize);
}

void setSource(std::unique_ptr<raySource<NumericType, D>> passedSource) {
source = std::move(passedSource);
void setSource(psSmartPointer<raySource<NumericType>> passedSource) {
source = passedSource;
}

template <typename SurfaceModelType,
lsConcepts::IsBaseOf<psSurfaceModel<NumericType>,
SurfaceModelType> = lsConcepts::assignable>
void setSurfaceModel(psSmartPointer<SurfaceModelType> passedSurfaceModel) {
void setSurfaceModel(
psSmartPointer<psSurfaceModel<NumericType>> passedSurfaceModel) {
surfaceModel = std::dynamic_pointer_cast<psSurfaceModel<NumericType>>(
passedSurfaceModel);
}
Expand Down

0 comments on commit 98b6555

Please sign in to comment.