-
Notifications
You must be signed in to change notification settings - Fork 84
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 math function from file #692 #701
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -762,16 +762,43 @@ bool mpm::MPMBase<Tdim>::initialise_math_functions(const Json& math_functions) { | |
const std::string function_type = | ||
function_props["type"].template get<std::string>(); | ||
|
||
// Initiate another function_prop to be passed | ||
auto function_props_update = function_props; | ||
|
||
// Create a file reader | ||
const std::string io_type = | ||
io_->json_object("mesh")["io_type"].template get<std::string>(); | ||
auto reader = Factory<mpm::IOMesh<Tdim>>::instance()->create(io_type); | ||
|
||
// Math function is specified in a file, replace function_props_update | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Read files in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I have tried to use in the beginning, and you requested CSV. Can we agree on which one to use now before I make more changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not asking you to revert back, this is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, so still CSV but within |
||
if (function_props.find("file") != function_props.end()) { | ||
std::string math_file = | ||
function_props.at("file").template get<std::string>(); | ||
auto math_function_values = | ||
reader->read_math_function(io_->file_name(math_file)); | ||
|
||
// Make separate arrays | ||
std::vector<double> xvalues; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having separate vectors makes it decoupled between x and y values, use a vector of arrays instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
std::vector<double> fxvalues; | ||
for (const auto& math_function_value : math_function_values) { | ||
xvalues.emplace_back(std::get<0>(math_function_value)); | ||
fxvalues.emplace_back(std::get<1>(math_function_value)); | ||
} | ||
|
||
function_props_update["xvalues"] = xvalues; | ||
function_props_update["fxvalues"] = fxvalues; | ||
} | ||
|
||
// Create a new function from JSON object | ||
auto function = | ||
Factory<mpm::FunctionBase, unsigned, const Json&>::instance()->create( | ||
function_type, std::move(function_id), function_props); | ||
|
||
// Add material to list | ||
// Add math function to list | ||
auto insert_status = | ||
math_functions_.insert(std::make_pair(function->id(), function)); | ||
|
||
// If insert material failed | ||
// If insert math function failed | ||
if (!insert_status.second) { | ||
status = false; | ||
throw std::runtime_error( | ||
|
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.
Why do we need this?