<commit_before>// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2014 projectchrono.org
// All right reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// Authors: <NAME>, <NAME>
// =============================================================================
//
// Test for the rotational spring damper
//
// Recall that Irrlicht uses a left-hand frame, so everything is rendered with
// left and right flipped.
//
// =============================================================================

#include <ostream>
#include <fstream>
#include <math.h>

#include "chrono/core/ChFileutils.h"
#include "chrono/physics/ChSystem.h"
#include "chrono/physics/ChBody.h"
#include "chrono/utils/ChUtilsInputOutput.h"
#include "chrono/utils/ChUtilsValidation.h"

#include "chrono_irrlicht/ChIrrApp.h"

#include "ChronoValidation_config.h"

using namespace chrono;
using namespace irr;


// =============================================================================
// Local variables
//
static const std::string val_dir = "../RESULTS/";
static const std::string out_dir = val_dir + "rotspring_force/";
static const std::string ref_dir = "rotspring_force/";

// =============================================================================

// Functor class for a custom rotaional spring constant modifier (function of position only)
  class ChFunction_CustomSpring : public ChFunction
  {
  public:
    ChFunction* new_Duplicate() {return new ChFunction_CustomSpring;} 

    double Get_y(double x)
    {
      double spring_coef = 50;
      double spring_nonlin_coef = 10;

      return spring_coef + spring_nonlin_coef * fabs(x);
    }
  };

// =============================================================================
// Prototypes of local functions
//
bool TestRotSpring(const ChVector<>& jointLoc, const ChQuaternion<>& jointRot,
                  const int customSpringType,
                  double simTimeStep, double outTimeStep,
                  const std::string& testName, bool animate, bool save);
bool ValidateReference(const std::string& testName, const std::string& what, double tolerance);
bool ValidateConstraints(const std::string& testName, double tolerance);
bool ValidateEnergy(const std::string& testName, double tolerance);
utils::CSV_writer OutStream();

// =============================================================================
//
// Main driver function for running the simulation and validating the results.
//
int main(int argc, char* argv[])
{
  bool animate = (argc > 1);
  bool save = (argc > 2);

  // Set the path to the Chrono data folder
  SetChronoDataPath(CHRONO_DATA_DIR);

  // Create output directory (if it does not already exist)
  if (ChFileutils::MakeDirectory(val_dir.c_str()) < 0) {
    std::cout << "Error creating directory " << val_dir << std::endl;
    return 1;
  }
  if (ChFileutils::MakeDirectory(out_dir.c_str()) < 0) {
    std::cout << "Error creating directory " << out_dir << std::endl;
    return 1;
  }

  // Set the simulation and output step sizes
  double sim_step = 5e-4;
  double out_step = 1e-2;

  std::string test_name;
  bool test_passed = true;

  // Case 1 - Revolute Joint at the origin and aligned with the global Y axis.
  // Since the axis of rotation of a revolute joint is the Z-axis, the joint
  // must be rotated -pi/2 about the global X-axis.<commit_msg>Reduce step size in test_rotspring.<commit_after>// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2014 projectchrono.org
// All right reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// Authors: <NAME>, <NAME>
// =============================================================================
//
// Test for the rotational spring damper
//
// Recall that Irrlicht uses a left-hand frame, so everything is rendered with
// left and right flipped.
//
// =============================================================================

#include <ostream>
#include <fstream>
#include <math.h>

#include "chrono/core/ChFileutils.h"
#include "chrono/physics/ChSystem.h"
#include "chrono/physics/ChBody.h"
#include "chrono/utils/ChUtilsInputOutput.h"
#include "chrono/utils/ChUtilsValidation.h"

#include "chrono_irrlicht/ChIrrApp.h"

#include "ChronoValidation_config.h"

using namespace chrono;
using namespace irr;


// =============================================================================
// Local variables
//
static const std::string val_dir = "../RESULTS/";
static const std::string out_dir = val_dir + "rotspring_force/";
static const std::string ref_dir = "rotspring_force/";

// =============================================================================

// Functor class for a custom rotaional spring constant modifier (function of position only)
  class ChFunction_CustomSpring : public ChFunction
  {
  public:
    ChFunction* new_Duplicate() {return new ChFunction_CustomSpring;} 

    double Get_y(double x)
    {
      double spring_coef = 50;
      double spring_nonlin_coef = 10;

      return spring_coef + spring_nonlin_coef * fabs(x);
    }
  };

// =============================================================================
// Prototypes of local functions
//
bool TestRotSpring(const ChVector<>& jointLoc, const ChQuaternion<>& jointRot,
                  const int customSpringType,
                  double simTimeStep, double outTimeStep,
                  const std::string& testName, bool animate, bool save);
bool ValidateReference(const std::string& testName, const std::string& what, double tolerance);
bool ValidateConstraints(const std::string& testName, double tolerance);
bool ValidateEnergy(const std::string& testName, double tolerance);
utils::CSV_writer OutStream();

// =============================================================================
//
// Main driver function for running the simulation and validating the results.
//
int main(int argc, char* argv[])
{
  bool animate = (argc > 1);
  bool save = (argc > 2);

  // Set the path to the Chrono data folder
  SetChronoDataPath(CHRONO_DATA_DIR);

  // Create output directory (if it does not already exist)
  if (ChFileutils::MakeDirectory(val_dir.c_str()) < 0) {
    std::cout << "Error creating directory " << val_dir << std::endl;
    return 1;
  }
  if (ChFileutils::MakeDirectory(out_dir.c_str()) < 0) {
    std::cout << "Error creating directory " << out_dir << std::endl;
    return 1;
  }

  // Set the simulation and output step sizes
  double sim_step = 2e-4;
  double out_step = 1e-2;

  std::string test_name;
  bool test_passed = true;

  // Case 1 - Revolute Joint at the origin and aligned with the global Y axis.
  // Since the axis of rotation of a revolute joint is the Z-axis, the joint
  // must be rotated -pi/2 about the global X-axis.
{'fraction_non_alphanumeric': 0.26226619680130114, 'fraction_numerical': 0.005421523448088913, 'mean_word_length': 4.354862119013062, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1971746', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1919, 'n_words': 625}