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

Add range to sine function #595

Merged
merged 6 commits into from
Apr 21, 2020
Merged

Add range to sine function #595

merged 6 commits into from
Apr 21, 2020

Conversation

thiagordonho
Copy link
Contributor

Add range to the definition of a sine function thus allowing for the function to be specified only within this range. The value of the function is equal to zero at times that are outside of this range.

@codecov
Copy link

codecov bot commented Apr 7, 2020

Codecov Report

Merging #595 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #595   +/-   ##
========================================
  Coverage    96.82%   96.82%           
========================================
  Files          116      116           
  Lines        24846    24860   +14     
========================================
+ Hits         24055    24069   +14     
  Misses         791      791           
Impacted Files Coverage Δ
include/functions/sin_function.h 100.00% <ø> (ø)
src/functions/sin_function.cc 100.00% <100.00%> (ø)
tests/functions/sin_function_test.cc 96.30% <100.00%> (+0.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2283e0...cb5cc8e. Read the comment docs.

@kks32
Copy link
Contributor

kks32 commented Apr 8, 2020

I have the following questions:

  1. Is this to curtail the duration in which the sin function is applied?

  2. Could you provide an example input file in your description?

  3. Is the range function an optional argument?

  4. could we have either just xmin/xmax without specifying the other?

@@ -4,9 +4,17 @@ mpm::SinFunction::SinFunction(unsigned id, const Json& properties)
: mpm::FunctionBase(id, properties) {
x0_ = properties.at("x0");
a_ = properties.at("a");
if (properties.at("xrange").is_array() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this an optional argument?

if (properties.at("xrange").is_array() &&
properties.at("xrange").size() == 2) {
for (unsigned index = 0; index < 2; ++index)
xrange_[index] = properties.at("xrange").at(index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
xrange_[index] = properties.at("xrange").at(index);
xrange_.at(index) = properties.at("xrange").at(index);

} else
throw std::runtime_error(
"Cannot initialise sine function; x range is invalid");
if (properties.contains("xrange"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add { } to define range of the if-condition

}

// Return f(x) for a given x
double mpm::SinFunction::value(double x_input) const {
if ((x_input < xrange_[0]) || (x_input > xrange_[1])) return 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use .at()

@kks32 kks32 merged commit ce4008e into develop Apr 21, 2020
@kks32 kks32 deleted the math_functions/sine branch April 21, 2020 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants