33 #include <vtkDoubleArray.h> 34 #include <vtkPointData.h> 37 std::vector<int> _arrayIDs,
38 std::string transferType,
double targetGCI)
42 arrayIDs(
std::move(_arrayIDs)),
43 targetGCI(targetGCI) {
53 for (
int i = 0; i < numArr; ++i) {
57 std::string coarseName = name +
"f3";
58 std::string fineName = name +
"f2";
76 std::cout <<
"Refinement ratio from 2-to-1 is " <<
r21 <<
" " 77 <<
" and from 3-to-2 is " <<
r32 << std::endl;
82 for (
int i = 0; i <
diffF3F2.size(); ++i) {
84 for (
int j = 0; j <
diffF3F2[i].size(); ++j) {
88 int s = (f32_f21 > 0) - (f32_f21 < 0);
91 for (
int k = 0; k < 1000; ++k) {
92 p = std::fabs(log(std::fabs(f32_f21)) + q_p) / log(
r21);
93 q_p = log((pow(
r21, p) - s) / (pow(
r32, p) - s));
94 if (std::fabs(old_p - p) < 1e-16)
115 double relativeError =
diffF2F1[i][j] / std::sqrt(f1L2[i][j]);
134 double relativeError =
diffF3F2[i][j] / std::sqrt(f2L2[i][j]);
146 std::vector<std::vector<double>> res(
GCI_32.size());
147 for (
int i = 0; i <
GCI_32.size(); ++i) {
148 res[i].resize(
GCI_32[i].size());
149 for (
int j = 0; j <
GCI_32[i].size(); ++j) {
157 const std::string &ofname) {
159 for (
const auto &ratio : ratios) {
160 for (
double j : ratio) {
161 if (std::abs(j - 1) > 1) {
163 <<
"WARNING: Solutions are not in the asymptotic convergence range" 170 auto minmax = std::minmax_element(resolution.begin(), resolution.end());
171 double ave = (*minmax.first + *minmax.second) / 2;
177 f3, refined,
"Consistent Interpolation");
178 f3refinedTransfer->transferPointData(
arrayIDs);
188 std::vector<std::vector<double>> ratios(
GCI_21.size());
189 for (
int i = 0; i <
GCI_21.size(); ++i) {
190 ratios[i].resize(
GCI_21[i].size());
191 for (
int j = 0; j <
GCI_21[i].size(); ++j) {
204 std::vector<vtkSmartPointer<vtkDoubleArray>> fineDatas(numArr);
205 std::vector<vtkSmartPointer<vtkDoubleArray>> diffDatas(numArr);
206 std::vector<vtkSmartPointer<vtkDoubleArray>> richardsonDatas(numArr);
208 vtkSmartPointer<vtkPointData> finePD =
f1->
getDataSet()->GetPointData();
210 std::vector<std::string> names(numArr);
211 for (
int id = 0;
id < numArr; ++
id) {
213 vtkDoubleArray::SafeDownCast(finePD->GetArray(
realDiffIDs[
id]));
215 vtkDoubleArray::SafeDownCast(finePD->GetArray(
arrayIDs[
id]));
218 richardsonData->SetNumberOfComponents(
219 diffDatas[
id]->GetNumberOfComponents());
221 std::string name(finePD->GetArrayName(
arrayIDs[
id]));
222 name +=
"_richExtrap";
224 richardsonData->SetName(&name[0u]);
225 richardsonDatas[
id] = richardsonData;
229 for (
int id = 0;
id < numArr; ++
id) {
230 int numComponent = diffDatas[
id]->GetNumberOfComponents();
232 auto *fine_comps =
new double[numComponent];
233 fineDatas[
id]->GetTuple(i, fine_comps);
235 auto *diff_comps =
new double[numComponent];
236 diffDatas[
id]->GetTuple(i, diff_comps);
238 auto *val =
new double[numComponent];
239 for (
int j = 0; j < numComponent; ++j) {
240 double comp = fine_comps[j] +
244 richardsonDatas[
id]->SetTuple(i, val);
252 std::vector<int> richExtrapIDs(numArr);
253 for (
int id = 0;
id < numArr; ++
id) {
254 finePD->AddArray(richardsonDatas[
id]);
255 finePD->GetArray(names[
id].c_str(), richExtrapIDs[
id]);
259 f1,
f3,
"Consistent Interpolation");
264 meshBase *
mesh,
const std::vector<std::string> &newArrNames) {
267 std::vector<vtkSmartPointer<vtkDoubleArray>> fineDatas(numArr);
268 std::vector<vtkSmartPointer<vtkDoubleArray>> coarseDatas(numArr);
269 std::vector<vtkSmartPointer<vtkDoubleArray>> diffDatas(numArr);
270 std::vector<vtkSmartPointer<vtkDoubleArray>> fineDatasSqr(numArr);
271 std::vector<vtkSmartPointer<vtkDoubleArray>> realDiffDatas(numArr);
273 vtkSmartPointer<vtkPointData> finePD = mesh->
getDataSet()->GetPointData();
275 std::vector<std::string> names(numArr);
276 std::vector<std::string> names2(numArr);
277 std::vector<std::string> names3(numArr);
279 std::string diffSqrName, sqrName, diffName;
280 for (
int id = 0;
id < numArr; ++
id) {
282 vtkDoubleArray::SafeDownCast(finePD->GetArray(
arrayIDs[
id]));
284 vtkDoubleArray::SafeDownCast(finePD->GetArray(newArrNames[
id].c_str()));
287 vtkSmartPointer<vtkDoubleArray> diffData =
289 vtkSmartPointer<vtkDoubleArray> fineDataSqr =
291 vtkSmartPointer<vtkDoubleArray> realDiffData =
294 diffData->SetNumberOfComponents(fineDatas[
id]->GetNumberOfComponents());
296 std::string name(finePD->GetArrayName(
arrayIDs[
id]));
299 diffData->SetName(name.c_str());
300 diffDatas[
id] = diffData;
302 fineDataSqr->SetNumberOfComponents(fineDatas[
id]->GetNumberOfComponents());
304 std::string name2(finePD->GetArrayName(
arrayIDs[
id]));
307 fineDataSqr->SetName(name2.c_str());
308 fineDatasSqr[
id] = fineDataSqr;
310 realDiffData->SetNumberOfComponents(fineDatas[
id]->GetNumberOfComponents());
312 std::string name3(finePD->GetArrayName(
arrayIDs[
id]));
315 realDiffData->SetName(name3.c_str());
316 realDiffDatas[
id] = realDiffData;
320 for (
int id = 0;
id < numArr; ++
id) {
321 auto fineData = fineDatas[
id];
322 auto coarseData = coarseDatas[
id];
323 auto diffData = diffDatas[
id];
324 auto fineDataSqr = fineDatasSqr[
id];
325 auto realDiffData = realDiffDatas[
id];
327 int numComps = fineDatas[
id]->GetNumberOfComponents();
329 double *fine_comps =
new double[numComps];
330 double *coarse_comps =
new double[numComps];
331 double *diff =
new double[numComps];
332 double *fsqr =
new double[numComps];
333 double *realdiff =
new double[numComps];
335 for (
int i = 0; i < numPts; ++i) {
336 fineData->GetTuple(i, fine_comps);
337 coarseData->GetTuple(i, coarse_comps);
339 for (
int j = 0; j < numComps; ++j) {
340 double error = coarse_comps[j] - fine_comps[j];
341 diff[j] = error * error;
342 fsqr[j] = fine_comps[j] * fine_comps[j];
343 realdiff[j] = fine_comps[j] - coarse_comps[j];
346 diffData->SetTuple(i, diff);
347 fineDataSqr->SetTuple(i, fsqr);
348 realDiffData->SetTuple(i, realdiff);
351 delete[] coarse_comps;
357 for (
int id = 0;
id < numArr; ++
id) {
358 finePD->AddArray(diffDatas[
id]);
359 finePD->GetArray(names[
id].c_str(),
diffIDs[
id]);
360 finePD->AddArray(fineDatasSqr[
id]);
361 finePD->GetArray(names2[
id].c_str(),
relEIDs[
id]);
362 finePD->AddArray(realDiffDatas[
id]);
363 finePD->GetArray(names3[
id].c_str(),
realDiffIDs[
id]);
366 std::vector<std::vector<double>> diff_integral(
368 for (
auto &&i : diff_integral) {
369 for (
double &j : i) {
371 std::cout << j <<
" ";
373 std::cout << std::endl;
375 return diff_integral;
std::vector< int > diffIDs
array ids for differences^2 in solutions between meshes
void refineMesh(const std::string &method, int arrayID, double dev_mult, bool maxIsmin, double edge_scale, const std::string &ofname, bool transferData, double sizeFactor=1., bool constrainBoundary=false)
perform sizefield-based h-refinement.
A brief description of meshBase.
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
std::vector< std::vector< double > > diffF2F1
L2 norm of the difference in solution between f2 and f1.
const std::vector< int > arrayIDs
array ids for arrays to be considered in analysis
std::vector< std::string > f3ArrNames
std::vector< std::vector< double > > GCI_21
GCIs with respect to the finer mesh (f2)
std::vector< std::vector< double > > orderOfAccuracy
Order of accuracy (p) with respect to refinements f3-f2-f1.
static meshBase * Create(const std::string &fname)
Construct vtkMesh from filename.
meshBase * f1
meshes from least to most refined (f3 - coarsest, f2 - finer, f1 - finest)
std::vector< std::vector< double > > checkAsymptoticRange()
Check if grids are in asymptotic range of convergence based on the computed GCIs (GCI_32 and GCI_21)...
std::vector< std::vector< double > > computeGCI_21()
Compute the GCI with respect to the finer and finest grids.
std::vector< std::vector< double > > computeOrderOfAccuracy()
Compute order of accuracy.
vtkSmartPointer< vtkDataSet > getDataSet() const
get this meshes' dataSet
OrderOfAccuracy(meshBase *_f3, meshBase *_f2, meshBase *_f1, std::vector< int > _arrayIDs, std::string transferType="Consistent Interpolation", double targetGCI=1.1)
nemId_t getNumberOfPoints() const
return the number of points
vtkIdType id
id in .inp file
void computeMeshWithResolution(double gciStar, const std::string &ofname)
Refine the coarsest mesh based on the target GCI, write to file with name ofname. ...
std::vector< std::vector< double > > computeDiff(meshBase *mesh, const std::vector< std::string > &newArrNames)
std::vector< std::string > f2ArrNames
names of data arrays transferred from f3 to f2 and from f2 to f1
virtual void write() const
write the mesh to file named after the private var 'filename'.
std::shared_ptr< meshBase > mesh
std::vector< int > relEIDs
array ids for integral of solutions on the most refined mesh, used in computing relative discretizati...
void computeRichardsonExtrapolation()
std::vector< std::vector< double > > diffF3F2
L2 norm of the difference in solution between f3 and f2.
std::vector< std::vector< double > > integrateOverMesh(const std::vector< int > &arrayIDs)
integrate arrays in arrayIDs over the mesh.
std::vector< std::string > getNewArrayNames()
get new array names for use in transfer
static std::shared_ptr< TransferBase > CreateTransferObject(meshBase *srcmsh, meshBase *trgmsh, const std::string &method)
std::vector< std::vector< double > > computeGCI_32()
Compute the GCI with respect to the coarsest and finer grids.
double r32
effective grid refinement ratios
std::vector< std::vector< double > > GCI_32
GCIs with respect to the coarse mesh (f3)
std::vector< std::vector< double > > computeResolution(double gciStar)
Compute the grid resolution required to obtain the desired gci/level of accuracy for each component a...
std::vector< T > flatten(const std::vector< std::vector< T >> &v)
std::vector< int > realDiffIDs
array ids for actual difference data