32 #include <vtkCellData.h> 33 #include <vtkPointData.h> 43 using nemAux::operator*;
46 bool _maxIsmin,
const std::string &arrName)
47 : ds(_ds), dev_mult(_dev_mult), maxIsmin(_maxIsmin), sizeFactor(1.) {
49 int numArr =
ds->GetPointData()->GetNumberOfArrays();
50 if (arrayID >= numArr) {
51 std::cerr <<
"ERROR: arrayID is out of bounds\n";
52 std::cerr <<
"There are " << numArr <<
" point data arrays" << std::endl;
54 }
else if (numArr < 1) {
55 std::cerr <<
"no point data found" << std::endl;
59 if (arrName !=
"Z2ErrorSF")
da =
ds->GetPointData()->GetArray(arrayID);
61 std::string array_name =
ds->GetPointData()->GetArrayName(arrayID);
62 sfname = array_name.append(arrName);
65 vtkSmartPointer<vtkCellData> cd =
ds->GetCellData();
66 if (cd->GetNumberOfArrays()) {
67 for (
int i = 0; i < cd->GetNumberOfArrays(); ++i) {
68 std::string currname = cd->GetArrayName(i);
70 std::cout <<
"Found size field identifier in cell data: " << currname
72 std::cout <<
"Removing " << currname <<
" from dataSet" << std::endl;
73 ds->GetCellData()->RemoveArray(i);
79 std::cout <<
"SizeFieldBase constructed" << std::endl;
83 const std::string &method,
int arrayID,
84 double _dev_mult,
bool _maxIsmin,
87 if (method ==
"value") {
88 sf =
new ValSizeField(_dataSet, arrayID, _dev_mult, _maxIsmin);
89 }
else if (method ==
"gradient") {
90 sf =
new GradSizeField(_dataSet, arrayID, _dev_mult, _maxIsmin);
91 }
else if (method ==
"Z2 Error Estimator") {
94 std::cerr <<
"Specified method " << method <<
" is not supported\n";
95 std::cerr <<
"Available methods are gradient, value and error" << std::endl;
104 vtkDataSet *_dataSet,
const std::string &method,
int arrayID,
105 double _dev_mult,
bool _maxIsmin,
double _sizeFactor,
int _order) {
107 _dataSet, method, arrayID, _dev_mult, _maxIsmin, _sizeFactor, _order));
113 std::cout <<
"Size Factor = " <<
sizeFactor << std::endl;
115 std::vector<double> lengths(
ds->GetNumberOfCells());
116 for (vtkIdType i = 0; i <
ds->GetNumberOfCells(); ++i)
117 lengths[i] = std::sqrt(
ds->GetCell(i)->GetLength2());
122 lengthminmax[1] = lengthminmax[0];
124 lengthminmax[1] *= 0.65;
125 lengthminmax[0] -= lengthminmax[0] / 2.;
128 std::cout <<
"Min Elm Length Scale : " << lengthminmax[0] <<
"\n" 129 <<
"Max Elm Length Scale : " << lengthminmax[1] << std::endl;
138 std::vector<bool> cells2Refine =
141 std::vector<double> values_norm = (1. / meanStdev[0]) * values;
153 std::ofstream elmLst;
154 elmLst.open(
"refineCellList.csv");
155 if (!elmLst.good()) {
156 std::cerr <<
"Error opening the stream for refinement list." << std::endl;
159 bool isFirstElmIdx =
true;
160 for (
int i = 0; i < values.size(); ++i) {
161 if (!cells2Refine[i])
162 values[i] = lengthminmax[1];
167 isFirstElmIdx =
false;
void scale_vec_to_range(std::vector< T > &x, const std::vector< T > &xminmax, const std::vector< T > &yminmax)
virtual void computeSizeField(vtkDataArray *da)=0
static std::unique_ptr< SizeFieldBase > CreateUnique(vtkDataSet *_dataSet, const std::string &method, int arrayID, double _dev_mult, bool _maxIsmin, double _sizeFactor=1.0, int _order=1)
std::vector< T > getMinMax(const std::vector< T > &x)
vtkSmartPointer< vtkDataSet > ds
std::vector< T > getMeanStdev(const std::vector< T > &x)
std::vector< bool > cellsToRefineMaxdev(const std::vector< T > &values, T dev)
void reciprocal_vec(std::vector< T > &x)
vtkSmartPointer< vtkDataArray > da
static SizeFieldBase * Create(vtkDataSet *_dataSet, const std::string &method, int arrayID, double _dev_mult, bool _maxIsmin, double _sizeFactor=1.0, int _order=1)
void mutateValues(std::vector< double > &values) const
bool hasZero(const std::vector< T > &x)
void setSizeFactor(double sf)