34 #include <vtkCellLocator.h>
35 #include <vtkPointLocator.h>
36 #include <vtkUnstructuredGrid.h>
45 m_snapTimeRef (snapTimeRef),
47 m_filesBase (filesBase),
51 m_loadedSnapIdMin (0),
52 m_loadedSnapIdMax (0),
56 m_ptLocatorTolerance(1.e-8)
60 "Must pass a valid pointer to problem to create interpolator from data files"
67 while (not foundFile and n<7)
78 "Could not find the data files with base name " <<
m_filesBase <<
79 "***.vtk\n from which interpolation should be made.\n" <<
80 "Interpolation from files is available with vtk only."
106 if (std::isnan(itpxvals[i]) or std::isinf(itpxvals[i]))
115 corrected[vtkId] = w;
121 if (corrected.size()!=0)
123 for (
auto& [vtkId,w]: corrected)
159 auto reader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
163 auto pointLocator = vtkSmartPointer<vtkPointLocator>::New();
164 auto cellLocator = vtkSmartPointer<vtkCellLocator >::New();
165 pointLocator->SetDataSet(reader->GetOutput());
166 cellLocator ->SetDataSet(reader->GetOutput());
167 pointLocator->BuildLocator();
168 cellLocator ->BuildLocator();
170 CepsReal* xRef = ceps::newArray<CepsReal>(3);
175 for (
auto toParse: {dofs->getOwned(),dofs->getHalo()})
180 CepsReal* x = dof->getVertex()->getCoordinates().data();
181 vtkIdType refPtId = pointLocator->FindClosestPoint(x);
182 reader->GetOutput()->GetPoint(refPtId,xRef);
200 vtkGenericCell* g = vtkGenericCell::New();
201 auto refCellPtsIDs = vtkSmartPointer<vtkIdList>::New();
203 cellLocator->FindClosestPoint(x,cP,g,refCellID,subID,dist);
208 error = g->EvaluatePosition(x,cP,subID,xRef,dist,weights.data());
210 "Error while locating points of numerical solution mesh in reference mesh cells.\n"
211 " You can increase search distance with the \"convergence closest point tolerance\"\n"
212 " parameter in the input file"
215 reader->GetOutput()->GetCellPoints(refCellID,refCellPtsIDs);
225 for (vtkIdType j=0;j<g->GetNumberOfPoints();j++)
226 tmpW[refCellPtsIDs->GetId(j)] = weights[j];
243 std::stringstream ss;
245 <<
"-" << std::setfill(
'0') << std::setw(
m_nDigitsFile) << idSnap <<
".vtk";
264 for (
CepsUInt i=idMin; i<idMax; i++)
269 auto reader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
271 reader->SetReadAllScalars(1);
272 reader->SetReadAllFields(1);
275 vtkDataArray* array =
nullptr;
276 for (
CepsInt i=0; i<reader->GetOutput()->GetPointData()->GetNumberOfArrays(); i++)
278 array = reader->GetOutput()->GetPointData()->GetArray(i);
280 if (array->GetNumberOfComponents()==1)
287 vtkIdType nbData = array->GetNumberOfTuples();
289 for (vtkIdType ptId = 0; ptId < nbData; ++ptId)
290 array->GetTuple(ptId,&data[ptId]);
298 for (
CepsInt i=0; i<reader->GetOutput()->GetFieldData()->GetNumberOfArrays(); i++)
300 array = reader->GetOutput()->GetFieldData()->GetArray(i);
301 if (array->GetNumberOfComponents()==1 and array->GetNumberOfTuples()==1)
309 array->GetTuple(0,&data);
CepsBool areSameArray(const CepsArray< _Type, _N > &a, const CepsArray< _Type, _N > &b, const CepsReal error=1.)
Test equality of arrays, suitable for real numbers.
@ DofIndex
Use dof index to determine position.
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::basic_string< CepsChar > CepsString
C++ format string.
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
std::vector< _Type, _Alloc > CepsVector
C++ vector.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
float CepsReal
Need single precision floating point.
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
int32_t CepsInt
Need 32 bit integer.
Abstract Class for all numerical method (FE, FD, FV etc)
DistributedInfos< DegreeOfFreedom * > * getDistributedDofs() const
Get the stored Degree Of Freedom repartition.
Base class for creating PDEs to solve.
AbstractDiscretization * getSpatialDiscretization() const
Link to the spatial discretization (FE, FV, etc)
InputParameters * getParameters() const
Text parameters.
Unknown * getUnknown(const CepsString &label) const
Get an unknown by its name.
virtual CepsReal getStartTime() const
Returns 0. Here for compatibility.
virtual CepsReal getEndTime() const
Returns 0. Here for compatibility.
A degree of freedom for any kind of problem The dof can be associated to a geometrical element or not...
Functor that uses data from a collection of files to return a value at position x and time t.
CepsReal m_loadedTMax
Time of Max snapshot of currently loaded files.
CepsString getVtkFileName(CepsUInt i) const
Get full file name for snapshot i.
CepsUInt m_loadedSnapIdMax
Max snapshot ID of currently loaded files Loaded data, indexed by time, unknown id (array name in vtk...
virtual CepsReal eval(CepsStandardArgs args) final
Call operator to evaluate functor.
CepsEnum getFlags() const final
flag is Attribute only
CepsUInt m_loadedSnapIdMin
Min snapshot ID of currently loaded files.
CepsReal m_ptLocatorTolerance
Distance under which closest point search is tolerated (can be set in input file)
CepsUInt m_nDigitsFile
Number of digits of file number in collection of files.
FileInterpolatorSAFunc(AbstractPdeProblem *pb, CepsReal snapTimeRef, const CepsString &filesBase, CepsUInt tOrder=1)
Constructor with map. Flag is the expected flag of the coefficient used to interpolate.
void computeInterpolationWeights()
Computes the interpolation weights using geom locators.
void loadFilesForTime(CepsReal t)
Loads the appropriate files to perform time interpolation at time t.
CepsMap< CepsDofGlobalIndex, CepsMap< vtkIdType, CepsReal > > m_itpWeights
Precomputed interpolation weights. Built using point/cell locator.
AbstractPdeProblem * m_problem
Link to problem.
CepsUInt m_tOrder
Time interpolation order.
CepsReal m_loadedTMin
Time of Min snapshot of currently loaded files.
CepsVector< CepsMap< CepsUnknownIndex, CepsVector< CepsReal > > > m_loadedData
CepsVector< CepsMap< CepsUnknownIndex, CepsReal > > m_loadedData0D
Loaded data, indexed by time, unknown id (array name in vtk file)
CepsString m_filesBase
Base names of data files.
CepsReal m_snapTimeRef
Reference output period.
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
CepsUnknownIndex getIdentifier() const
Get the identifier of the unknown.
CepsReal interpolateLagrange(CepsReal x, const CepsVector< CepsReal > &f)
Computes the interpolate of f at point x. assumes f is given at equidistant points on [0,...
CepsString getDir(const CepsString &str)
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file....
CepsString toString(_Tp value)
Convert a given value to a string (input has to be compatible with std::to_string)
void destroyTabular(_Type &)
Destroy[delete] any type.
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
const _Type & min(const CepsVector< _Type, _Alloc > &vec)
Returns the minimum of the vector, const version.
CepsEnum getFlagsOf(ArraySAFunc< _Result > *f)
get functor options
CepsBool isNullPtr(_Type *ptr)
Tells if passed pointer is null.
void checkNanOrInf(CepsReal v, CepsString message="")
Stops if value is NaN or infty.
CepsString getBaseName(const CepsString &str)
Extracts the base of a file name, without path, nor extension. Ex: getBaseName("/path/to/myfile....
CepsBool fileExists(const CepsString &fileName, const CepsString &directory)
Structure used to pass arguments to SAFunc (see pde directory) The flags of the SAFunc allows extract...
CepsDofGlobalIndex dofId
dof index
CepsUnknownIndex unknownId
unknown index