[cig-commits] r13862 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Tue Jan 13 03:12:08 PST 2009
Author: luis
Date: 2009-01-13 03:12:07 -0800 (Tue, 13 Jan 2009)
New Revision: 13862
Added:
cs/cigma/trunk/src/core_misc.cpp
cs/cigma/trunk/src/core_misc.h
Log:
Added source file for keeping misc functions before sorting them out.
Added: cs/cigma/trunk/src/core_misc.cpp
===================================================================
--- cs/cigma/trunk/src/core_misc.cpp (rev 0)
+++ cs/cigma/trunk/src/core_misc.cpp 2009-01-13 11:12:07 UTC (rev 13862)
@@ -0,0 +1,32 @@
+#include "core_misc.h"
+#include <iostream>
+#include <iomanip>
+#include <cassert>
+#include <cstdlib>
+#include <ctime>
+
+double pick_rand_from_interval(double a, double b)
+{
+ return a + (b - a) * rand() / (RAND_MAX + 1.0);
+}
+
+void random_point_in_box(double x[3], double minpt[3], double maxpt[3])
+{
+ const int dim = 3;
+ for (int i = 0; i < dim; i++)
+ {
+ assert(minpt[i] <= maxpt[i]);
+ x[i] = pick_from_interval(minpt[i], maxpt[i]);
+ }
+}
+
+void linspace(std::valarray<double>& x, double a, double b, int n)
+{
+ x.resize(n);
+ double dx = (b - a)/n;
+ for (int i = 0; i < n; i++)
+ {
+ x[i] = a + i * dx;
+ }
+}
+
Added: cs/cigma/trunk/src/core_misc.h
===================================================================
--- cs/cigma/trunk/src/core_misc.h (rev 0)
+++ cs/cigma/trunk/src/core_misc.h 2009-01-13 11:12:07 UTC (rev 13862)
@@ -0,0 +1,13 @@
+#ifndef CORE_MISC_H
+#define CORE_MISC_H
+
+// Miscellaneous functions
+
+#include <valarray>
+
+double pick_from_interval(double a, double b);
+void random_point_in_box(double x[3], double minpt[3], double maxpt[3]);
+
+void linspace(std::valarray<double>& x, double a, double b, int n);
+
+#endif
More information about the CIG-COMMITS
mailing list