Commit de35b61d authored by Tomáš Jakubec's avatar Tomáš Jakubec
Browse files

Update using the new data write functionality.

parent 536c9eae
......@@ -148,8 +148,8 @@ private:
public:
template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
static void writeToStream(std::ostream& ost, MeshDataContainer<T, Dimensions...>& data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) {
using type = T;//typename std::remove_reference<decltype(data.template getDataByDim<MeshDimension>())>::type::DataType;
static_assert (Detail::has_default_traits<type>::value, "The class T must have defined traits for example using macro MAKE_ATTRIBUTE_TRAIT in header Traits.h");
//using type = T;//typename std::remove_reference<decltype(data.template getDataByDim<MeshDimension>())>::type::DataType;
//static_assert (Detail::has_default_traits<type>::value, "The class T must have defined traits for example using macro MAKE_ATTRIBUTE_TRAIT in header Traits.h");
ost << "CELL_DATA " << writer.getNumberOfCells() << std::endl;
MeshDataIterator<MeshDataContainer<T, Dimensions...>::size() - 1>::writeToStream(ost, data, writer);
}
......
......@@ -18,16 +18,23 @@ using namespace std;
struct CellData {
double T = 300;
double invVol;
};
struct CompData {
double T = 300;
};
MAKE_NAMED_ATTRIBUTE_TRAIT(CompData, "Temperature", T);
struct FaceData {
double volOverDist;
};
void heatFlow(UnstructuredMesh<3,size_t, double, 12> mesh,
MeshDataContainer<std::tuple<CellData, FaceData>, 3,2>& data,
MeshDataContainer<CompData, 3>& compData,
MeshDataContainer<double, 3>& outDeltas) {
for (double& dT : outDeltas.getDataByPos<0>()){
......@@ -38,14 +45,14 @@ void heatFlow(UnstructuredMesh<3,size_t, double, 12> mesh,
double lT = 1000;
bool lIn = false;
if(!((face.getCellLeftIndex() & BOUNDARY_INDEX(size_t)) == BOUNDARY_INDEX(size_t))){
lT = data.getDataByDim<3>().at(face.getCellLeftIndex()).T;
lT = compData.getDataByDim<3>().at(face.getCellLeftIndex()).T;
lIn = true;
}
double rT = 1000;
bool rIn = false;
if(!((face.getCellRightIndex() & BOUNDARY_INDEX(size_t)) == BOUNDARY_INDEX(size_t))){
rT = data.getDataByDim<3>().at(face.getCellRightIndex()).T;
rT = compData.getDataByDim<3>().at(face.getCellRightIndex()).T;
rIn = true;
}
......@@ -61,6 +68,7 @@ void heatFlow(UnstructuredMesh<3,size_t, double, 12> mesh,
void explicitUpdate(UnstructuredMesh<3,size_t, double, 12> mesh,
MeshDataContainer<std::tuple<CellData, FaceData>, 3,2>& data,
MeshDataContainer<CompData, 3>& compData,
double tau,
double startTime,
double finalT){
......@@ -68,11 +76,12 @@ void explicitUpdate(UnstructuredMesh<3,size_t, double, 12> mesh,
double time = startTime;
while (time < finalT) {
heatFlow(mesh, data, K1);
heatFlow(mesh, data, compData, K1);
for (size_t i = 0; i < mesh.getCells().size(); i++){
auto& cellData = data.getDataByDim<3>().at(i);
cellData.T += cellData.invVol * tau * K1.getDataByDim<3>().at(i);
auto& _compData = compData.getDataByPos<0>().at(i);
_compData.T += cellData.invVol * tau * K1.getDataByDim<3>().at(i);
}
cout << "time: " << time << "\r";
time += tau;
......@@ -82,6 +91,25 @@ void explicitUpdate(UnstructuredMesh<3,size_t, double, 12> mesh,
void exportData(std::string filename,
VTKMeshWriter<3, size_t, double>& writer,
double time,
UnstructuredMesh<3, size_t, double, 12>& mesh,
MeshDataContainer<CompData, 3>& compData) {
ofstream ofile(filename + "_" + to_string(time) + ".vtk");
writer.writeHeader(ofile, "HC_test"s + to_string(time));
writer.writeToStream(ofile, mesh, MeshDataContainer<MeshNativeType<3>::ElementType, 3>(mesh, MeshNativeType<3>::POLYHEDRON));
VTKMeshDataWriter<3> dataWriter;
dataWriter.writeToStream(ofile, compData, writer);
ofile.close();
DBGMSG("Data eported");
}
void testHeatConduction() {
UnstructuredMesh<3, size_t, double, 12> mesh;
FPMAMeshReader<3> reader;
......@@ -100,14 +128,16 @@ void testHeatConduction() {
auto dists = ComputeCellsDistance(mesh);
MeshDataContainer<std::tuple<CellData, FaceData>, 3,2> compData(mesh);
MeshDataContainer<std::tuple<CellData, FaceData>, 3,2> meshData(mesh);
MeshDataContainer<CompData, 3> compData(mesh);
for (auto& face : mesh.getFaces()) {
compData.at(face).volOverDist = measures.at(face) / dists.at(face);
meshData.at(face).volOverDist = measures.at(face) / dists.at(face);
}
for (auto& cell : mesh.getCells()) {
compData.at(cell).invVol = 1.0 / measures.at(cell);
meshData.at(cell).invVol = 1.0 / measures.at(cell);
}
double startTime = 0.0, finalTime = 1e-2, tau = 1e-5;
......@@ -122,21 +152,23 @@ void testHeatConduction() {
explicitUpdate(mesh,
meshData,
compData,
tau,
startTime,
finalTime);
exportData("Heatcond_test",
writer,
finalTime,
startTime,
mesh,
compData);
startTime = finalTime;
finalTime *= 2;
explicitUpdate(mesh,
meshData,
compData,
tau,
startTime,
......@@ -144,10 +176,12 @@ void testHeatConduction() {
exportData("Heatcond_test",
writer,
finalTime,
startTime,
mesh,
compData);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment