-
Notifications
You must be signed in to change notification settings - Fork 2
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
WIP: Implement arbitrary field sequences #14
Open
TobiasKlemme
wants to merge
13
commits into
Neumann-A:dev
Choose a base branch
from
TobiasKlemme:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8d0772f
SequenceField changes
TobiasKlemme 8db9ff9
new sequence field
TobiasKlemme cc88803
new sequence field and megre
TobiasKlemme 7ecdad1
Corrected save_directory option for phantom generation
TobiasKlemme 258d11d
corrected typo
TobiasKlemme 599e769
first iteration of implemented sequence Field.
TobiasKlemme 6281398
added sequence field
TobiasKlemme 22f84ce
remove obsolete code
TobiasKlemme 3054151
Merge branch 'dev' of https://github.com/Neumann-A/StochasticPhysics …
TobiasKlemme 1d75005
removed obsolete code
TobiasKlemme 9f0590e
Update Particle_Simulation/app/StoPhysApp_MultiArch.cpp
TobiasKlemme 715535b
Update Particle_Simulation/app/InputParams.cpp
TobiasKlemme ad67907
Update SysMatFileGen.h
TobiasKlemme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
|
||
#ifndef INC_SequenceField_H | ||
#define INC_SequenceField_H | ||
///--------------------------------------------------------------------------------------------------- | ||
#pragma once | ||
|
||
#include <MyCEL/math/math_constants.h> | ||
|
||
#include <cmath> | ||
#include <exception> | ||
#include <type_traits> | ||
#include <variant> | ||
#include <vector> | ||
|
||
#include "Properties/FieldProperties.h" | ||
#include "SDEFramework/GeneralField.h" | ||
|
||
//Field Includes | ||
#include "Fields/ConstantField.h" | ||
#include "Fields/LissajousField.h" | ||
#include "Fields/ModulatedSincField.h" | ||
#include "Fields/RectangularField.h" | ||
#include "Fields/SincField.h" | ||
#include "Fields/SinusoidalField.h" | ||
#include "Fields/TriangularField.h" | ||
#include "Fields/ZeroField.h" | ||
|
||
template <class... Ts> | ||
struct SeqFieldOverload : Ts... | ||
{ | ||
using Ts::operator()...; | ||
}; | ||
template <class... Ts> | ||
SeqFieldOverload(Ts...) -> SeqFieldOverload<Ts...>; | ||
|
||
template <typename precision> | ||
class SequenceField : public GeneralField<SequenceField<precision>> | ||
{ | ||
public: | ||
using ThisClass = SequenceField<precision>; | ||
using Precision = precision; | ||
using Base = GeneralField<ThisClass>; | ||
using Traits = typename Base::Traits; | ||
using FieldProperties = typename Traits::FieldProperties; | ||
using FieldVector = typename Traits::FieldVector; | ||
using FieldParams = typename Traits::FieldParameters; | ||
|
||
template <SequenceFieldProp::ISequenceFields Field> | ||
using type = typename Selectors::SequenceFieldSelector<Field>::template FieldParameters<Precision>; | ||
|
||
template <SequenceFieldProp::ISequenceFields Field> | ||
using ExFieldtype = typename Selectors::SequenceFieldSelector<Field>::template FieldType<Precision>; | ||
|
||
using impl_field = std::variant<ZeroField<precision>, ConstantField<precision>, SinusoidalField<precision>, | ||
LissajousField<precision>, TriangularField<precision>, RectangularField<precision>, | ||
SincField<precision>, ModulatedSincField<precision>>; | ||
|
||
private: | ||
size_t step = 1; | ||
FieldParams params; | ||
std::vector<size_t> cumulatedSteps; | ||
std::vector<impl_field> exfield; | ||
|
||
protected: | ||
public: | ||
constexpr SequenceField(const typename Traits::FieldParameters &input) | ||
: params(input) | ||
{ | ||
size_t lastVal = 0; | ||
for (size_t i = 0; i < input.stepsPerField.size(); i++) { | ||
cumulatedSteps.push_back(input.stepsPerField[i] + lastVal); | ||
lastVal = cumulatedSteps[i]; | ||
} | ||
for (const auto &value : input.fields) { | ||
auto currentFieldVar = value.variant; | ||
|
||
std::visit( | ||
SeqFieldOverload{ | ||
[this](type<SequenceFieldProp::ISequenceFields::Field_Zero> & Fieldparams) { | ||
ExFieldtype<SequenceFieldProp::ISequenceFields::Field_Zero> seqfield(Fieldparams); | ||
impl_field tmp = seqfield; | ||
(this->exfield).push_back(tmp); | ||
}, | ||
[this](type<SequenceFieldProp::ISequenceFields::Field_Constant> &Fieldparams) { | ||
ExFieldtype<SequenceFieldProp::ISequenceFields::Field_Constant> seqfield(Fieldparams); | ||
impl_field tmp = seqfield; | ||
(this->exfield).push_back(tmp); | ||
}, | ||
[this](type<SequenceFieldProp::ISequenceFields::Field_Sinusoidal> &Fieldparams) { | ||
ExFieldtype<SequenceFieldProp::ISequenceFields::Field_Sinusoidal> seqfield(Fieldparams); | ||
impl_field tmp = seqfield; | ||
(this->exfield).push_back(tmp); | ||
}, | ||
[this](type<SequenceFieldProp::ISequenceFields::Field_Lissajous> &Fieldparams) { | ||
ExFieldtype<SequenceFieldProp::ISequenceFields::Field_Lissajous> seqfield(Fieldparams); | ||
impl_field tmp = seqfield; | ||
(this->exfield).push_back(tmp); | ||
}, | ||
[this](type<SequenceFieldProp::ISequenceFields::Field_Triangular> &Fieldparams) { | ||
ExFieldtype<SequenceFieldProp::ISequenceFields::Field_Triangular> seqfield(Fieldparams); | ||
impl_field tmp = seqfield; | ||
(this->exfield).push_back(tmp); | ||
}, | ||
[this](type<SequenceFieldProp::ISequenceFields::Field_Rectangular> &Fieldparams) { | ||
ExFieldtype<SequenceFieldProp::ISequenceFields::Field_Rectangular> seqfield(Fieldparams); | ||
impl_field tmp = seqfield; | ||
(this->exfield).push_back(tmp); | ||
}, | ||
[this](type<SequenceFieldProp::ISequenceFields::Field_Sinc> &Fieldparams) { | ||
ExFieldtype<SequenceFieldProp::ISequenceFields::Field_Sinc> seqfield(Fieldparams); | ||
impl_field tmp = seqfield; | ||
(this->exfield).push_back(tmp); | ||
}, | ||
[this](type<SequenceFieldProp::ISequenceFields::Field_Modsinc> &Fieldparams) { | ||
ExFieldtype<SequenceFieldProp::ISequenceFields::Field_Modsinc> seqfield(Fieldparams); | ||
impl_field tmp = seqfield; | ||
(this->exfield).push_back(tmp); | ||
}, | ||
}, | ||
currentFieldVar); | ||
} | ||
}; | ||
|
||
inline FieldVector getCurrentField(impl_field &field, const Precision &time) | ||
{ | ||
switch (field.index()) { | ||
case 0:{ | ||
return std::get<ZeroField<precision>>(field).getField(time); | ||
break;} | ||
case 1:{ | ||
return std::get<ConstantField<precision>>(field).getField(time); | ||
break;} | ||
case 2:{ | ||
return std::get<SinusoidalField<precision>>(field).getField(time); | ||
break;} | ||
case 3:{ | ||
return std::get<LissajousField<precision>>(field).getField(time); | ||
break;} | ||
case 4:{ | ||
return std::get<TriangularField<precision>>(field).getField(time); | ||
break;} | ||
case 5:{ | ||
return std::get<RectangularField<precision>>(field).getField(time); | ||
break;} | ||
case 6:{ | ||
return std::get<SincField<precision>>(field).getField(time); | ||
break;} | ||
case 7:{ | ||
return std::get<ModulatedSincField<precision>>(field).getField(time); | ||
break;} | ||
default: | ||
throw std::runtime_error{ "getCurrentField: unknown active variant type" }; | ||
break; | ||
} | ||
} | ||
constexpr SequenceField(const FieldProperties &pars) | ||
: SequenceField(pars.template getFieldParameters<Traits::Field_type>()){ | ||
|
||
}; | ||
|
||
inline FieldVector getField(const Precision &time) | ||
{ | ||
for (size_t i = 0; i < exfield.size(); i++) { | ||
if (step <= cumulatedSteps[i]) { | ||
step++; | ||
return getCurrentField(exfield[i], time); | ||
} | ||
else if (step > cumulatedSteps.back()) { | ||
step=2; | ||
return getField(time); | ||
} | ||
} | ||
throw std::runtime_error{ "no Valid field" }; | ||
} | ||
}; | ||
|
||
template <typename prec> | ||
class FieldTraits<SequenceField<prec>> | ||
{ | ||
public: | ||
using Precision = prec; | ||
using FieldProperties = Properties::FieldProperties<Precision>; | ||
using FieldVector = Eigen::Matrix<Precision, 3, 1>; | ||
using FieldVectorStdAllocator = std::allocator<FieldVector>; | ||
using FieldParameters = ::Properties::Fields::Sequence<Precision>; | ||
static constexpr auto Field_type = ::Properties::IField::Field_Sequence; | ||
}; | ||
|
||
#endif // INC_SequenceField_H | ||
// end of LissajousField.h | ||
///--------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to hpp file