C++ main module for emicrom Package  1.0
EMM_OperatorsTest.hpp
Go to the documentation of this file.
1 #ifndef EMM_OperatorsTest_HPP
2 #define EMM_OperatorsTest_HPP
3 
4 #include "EMM_Array.h"
5 
6 template <class T>
8  EMM_Array<T> array;
9  EMM_Array<T> arrayRef;
10  tString dataName;
11  tUIndex i,n;
12  tDimension dim;
13  const T * values;
14  tBoolean ok=true;
15  tReal errMax=0,err;
16  if (!op.getDataField(d,dataName,n,dim,values)) return CORE_Object::getRealInfinity();
17  array.setValues(n*dim,values);
18  array.saveToFile(fn+".txt");
19  indexMax=0;
20  if (arrayRef.loadFromFile(fn+"_ref.txt")) {
21  ok = ok && (array.getSize()==arrayRef.getSize());
22  if (!ok) cout << "reference array & array "<<fn<<" have not same size.\n";
23  if (ok) {
24  errMax=0;
25  for (i=0;i<array.getSize();i++) {
26  err=(fabs(arrayRef[i])>1)?fabs(1.-array[i]/arrayRef[i]):fabs(array[i]-arrayRef[i]);
27  if (errMax<err) {
28  errMax=err;
29  indexMax=i;
30  if (errMax>1.e-4) cout <<"Warning "<<array[indexMax]<<" != "<<arrayRef[indexMax]<<" err="<<errMax<<"\n";
31  }
32  }
33 
34  }
35  }else {
36  cout << "impossible to read "<<fn<<"_ref.txt"<<"\n";
37  ok=false;
38  }
39 
40  if (!ok) errMax=CORE_Object::getRealInfinity();
41  return errMax;
42 }
43 
44 #endif
const tUIndex & getSize() const
return the size of the array for reading
Definition: CORE_Array.h:1018
static tReal getRealInfinity()
get the infinity value
Definition: CORE_Object.h:633
#define tUSInt
Definition: types.h:28
#define tBoolean
Definition: types.h:139
virtual tBoolean getDataField(const tUSInt &index, tString &dataName, tUIndex &n, tDimension &dim, const float *&values) const
get the data field at index for saving data in vtk,txt,... files.
Definition: EMM_Operator.h:180
#define tDimension
Definition: EMM_Types.h:10
tBoolean loadFromFile(const tString &fileName)
load the steady array from file
Definition: EMM_Array.hpp:116
tBoolean saveToFile(const tString &fileName) const
save the steady array into file
Definition: EMM_Array.hpp:10
void setValues(const tUIndex &n, const Q *v)
set the values of the array by copying the n first values of pointer v
Definition: CORE_Array.h:445
static tReal compareDiscretizedData(const tUSInt &d, const tString &fn, const EMM_MagneticExcitationOperator &op, tUIndex &indexMax)
Definition: EMM_OperatorsTest.hpp:7
#define tUIndex
Definition: types.h:126
#define tString
Definition: types.h:135
This class is an operator of a E-MicromM package wich compute a magnetic excitation operator...
Definition: EMM_MagneticExcitationOperator.h:15
This class describes a general array.
Definition: EMM_Array.h:18
#define tReal
Definition: types.h:118