1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2014 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 // Authors: Alessandro Tasora, Radu Serban
13 // =============================================================================
14
15 #include "chrono/motion_functions/ChFunction_Sigma.h"
16
17 namespace chrono {
18
19 // Register into the object factory, to enable run-time dynamic creation and persistence
CH_FACTORY_REGISTER(ChFunction_Sigma)20 CH_FACTORY_REGISTER(ChFunction_Sigma)
21
22 ChFunction_Sigma::ChFunction_Sigma(const ChFunction_Sigma& other) {
23 amp = other.amp;
24 start = other.start;
25 end = other.end;
26 }
27
Estimate_x_range(double & xmin,double & xmax) const28 void ChFunction_Sigma::Estimate_x_range(double& xmin, double& xmax) const {
29 double mdx = end - start;
30 xmin = start + mdx * 0.1;
31 xmax = end - mdx * 0.1;
32 }
33
Get_y(double x) const34 double ChFunction_Sigma::Get_y(double x) const {
35 double ret;
36 double A = (end - start);
37 if (x < start)
38 return 0;
39 if (x > end)
40 return amp;
41 else {
42 ret = amp * ((3 * (pow(((x - start) / A), 2))) - 2 * (pow(((x - start) / A), 3)));
43 }
44 return ret;
45 }
46
Get_y_dx(double x) const47 double ChFunction_Sigma::Get_y_dx(double x) const {
48 double ret;
49 double A = (end - start);
50 if ((x < start) || (x > end))
51 ret = 0;
52 else {
53 ret = amp * (6 * ((x - start) / pow(A, 2)) - 6 * (pow((x - start), 2) / pow(A, 3)));
54 }
55 return ret;
56 }
57
Get_y_dxdx(double x) const58 double ChFunction_Sigma::Get_y_dxdx(double x) const {
59 double ret;
60 double A = (end - start);
61 if ((x < start) || (x > end))
62 ret = 0;
63 else {
64 ret = amp * (6 * (1 / pow(A, 2)) - 12 * ((x - start) / pow(A, 3)));
65 }
66 return ret;
67 }
68
ArchiveOUT(ChArchiveOut & marchive)69 void ChFunction_Sigma::ArchiveOUT(ChArchiveOut& marchive) {
70 // version number
71 marchive.VersionWrite<ChFunction_Sigma>();
72 // serialize parent class
73 ChFunction::ArchiveOUT(marchive);
74 // serialize all member data:
75 marchive << CHNVP(amp);
76 marchive << CHNVP(start);
77 marchive << CHNVP(end);
78 }
79
ArchiveIN(ChArchiveIn & marchive)80 void ChFunction_Sigma::ArchiveIN(ChArchiveIn& marchive) {
81 // version number
82 /*int version =*/ marchive.VersionRead<ChFunction_Sigma>();
83 // deserialize parent class
84 ChFunction::ArchiveIN(marchive);
85 // stream in all member data:
86 marchive >> CHNVP(amp);
87 marchive >> CHNVP(start);
88 marchive >> CHNVP(end);
89 }
90
91 } // end namespace chrono
92