v0.14.0
Functions | Variables
scaling_method.cpp File Reference

Testing interface for reading and writing CSV files containing time series data. More...

#include <MoFEM.hpp>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "...\n\n"
 

Detailed Description

Testing interface for reading and writing CSV files containing time series data.

Definition in file scaling_method.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 13 of file scaling_method.cpp.

13  {
14 
15  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
16  const std::string delimiter = "(\\s*,\\s*|\\s+)"; // comma or space
17  std::string file_name = "scalar_data.csv";
18  std::vector<double> scalar_values = {1.1, 2.4, 3.6, 4.1, 3.1,
19  5.1, 9.1, 10.5, 11.2, 15.3};
20  try {
21  auto time_scale = std::make_shared<TimeScale>(file_name, delimiter);
22  auto time_scale_linear_scaling = std::make_shared<TimeScale>();
23  for (int i = 1; i <= scalar_values.size(); i++) {
24  if (std::fabs(time_scale->getScale(double(i)) - scalar_values[i - 1]) >
25  std::numeric_limits<double>::epsilon()) {
26  SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
27  "Validation for data scaling from csv "
28  "failed for time: %f value: %f",
29  double(i), time_scale->getScale(i));
30  }
31  }
32  double time1 = 3.0;
33  double time0 = 2.0;
34  double scale1 = scalar_values[2];
35  double scale0 = scalar_values[1];
36  double input_time = 2.5;
37  double interp_t = (input_time - time0) / (time1 - time0);
38  double expected_scale = scale0 + (scale1 - scale0) * interp_t;
39  double actual_scale = time_scale->getScale(2.5);
40  if (std::fabs(expected_scale - actual_scale) >
41  std::numeric_limits<double>::epsilon()) {
42  SETERRQ2(
43  PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
44  "Validation for data scaling from csv failed for time: %f value: %f",
45  2.5, time_scale->getScale(2.5));
46  }
47  double time_out_of_range_1 = 11.0;
48  double time_out_of_range_2 = -1.0;
49  if (std::fabs(time_scale->getScale(time_out_of_range_2)) >
50  std::numeric_limits<double>::epsilon()) {
51  SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
52  "Validation for data scaling from csv failed for time: %f "
53  "value: %f",
54  -1.0, time_scale->getScale(-1.0));
55  }
56  if (std::fabs(time_scale->getScale(time_out_of_range_1) - 15.3) >
57  std::numeric_limits<double>::epsilon()) {
58  SETERRQ2(
59  PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
60  "Validation for data scaling from csv failed for time: %f value: %f",
61  11.0, time_scale->getScale(11.0));
62  }
63  for (int i = 1; i <= scalar_values.size(); i++) {
64  if (std::fabs(time_scale_linear_scaling->getScale(double(i)) -
65  double(i)) > std::numeric_limits<double>::epsilon()) {
66  SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
67  "Validation for linear scaling from csv failed for time: %f "
68  "value: %f",
69  double(i), time_scale->getScale(i));
70  }
71  }
72  }
74 
76 
77  return 0;
78 }

Variable Documentation

◆ help

char help[] = "...\n\n"
static

Definition at line 11 of file scaling_method.cpp.

MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
help
static char help[]
Definition: scaling_method.cpp:11
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40