Skip to content

Commit

Permalink
feat: Add option to write Lagrange multipliers to output files
Browse files Browse the repository at this point in the history
  • Loading branch information
gouarin committed Oct 11, 2024
1 parent c3da4d7 commit e9004d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/scopi/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@ namespace scopi
*/
std::string filename;
/**
* @brief Whether to write the velocity and the rotation velocity of the particles in the output files.
* @brief Specifies if particle speed and rotation rate are to be written to output files.
*
* Default value is false.
*/
bool write_velocity;
/**
* @brief Specifies if Lagrange multipliers are to be written to output files.
*
* Default value is false.
*/
bool write_lagrange_multiplier;
/**
* @brief true for binary output files, false for text files.
*
Expand Down
6 changes: 6 additions & 0 deletions include/scopi/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,15 @@ namespace scopi

json_output["contacts"] = {};

const auto& lambda = m_optim_solver.lagrange_multiplier();
std::size_t ic = 0;
for (const auto& c : contacts)
{
json_output["contacts"].push_back(c.to_json());
if (m_params.write_lagrange_multiplier)
{
json_output["contacts"].back()["lagrange multiplier"] = xt::view(lambda, ic++);
}
}

if (m_params.binary_output)
Expand Down
2 changes: 2 additions & 0 deletions src/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace scopi
, path(std::filesystem::current_path() / "Results")
, filename("scopi_objects")
, write_velocity(false)
, write_lagrange_multiplier(false)
, binary_output(false)
{
}
Expand All @@ -22,6 +23,7 @@ namespace scopi
opt->add_option("--filename", filename, "Name of the outputs")->capture_default_str();
opt->add_option("--freq", output_frequency, "Output frequency (in iterations)")->capture_default_str();
opt->add_flag("--write-velocity", write_velocity, "Write the velocity of objects")->capture_default_str();
opt->add_flag("--write-lagrange-multiplier", write_lagrange_multiplier, "Write the Lagrange multiplier for each contact")->capture_default_str();
opt->add_flag("--binary-output", binary_output, "Write bson output file instead of json")->capture_default_str();
}
}
Expand Down

0 comments on commit e9004d1

Please sign in to comment.