NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
TransferDriver.C
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #include "Drivers/TransferDriver.H"
30 
31 #include <iostream>
32 #include <string>
33 #include <utility>
34 
35 #include "Transfer/FETransfer.H"
36 #ifdef HAVE_IMPACT
38 #endif
39 #ifdef HAVE_SUPERMESH
41 #endif
42 #include "AuxiliaryFunctions.H"
43 
44 namespace NEM {
45 namespace DRV {
46 
47 TransferDriver::Files::Files(std::string source, std::string target,
48  std::string output)
49  : sourceMeshFile(std::move(source)),
50  targetMeshFile(std::move(target)),
51  outputMeshFile(std::move(output)) {}
52 
53 TransferDriver::Opts::Opts(std::string method, bool checkQuality)
54  : method(std::move(method)), checkQuality(checkQuality) {}
55 
57  : files_(std::move(files)), opts_(std::move(opts)) {
58  std::cout << "TransferDriver created" << std::endl;
59 }
60 
61 TransferDriver::TransferDriver() : TransferDriver({{}, {}, {}}, {{}, {}}) {}
62 
64  std::shared_ptr<meshBase> source{
66  std::shared_ptr<meshBase> target{
68  std::cout << "TransferDriver created" << std::endl;
69 
70  nemAux::Timer T;
71  T.start();
72  source->setCheckQuality(this->opts_.checkQuality);
73  // source->transfer(target, method, arrayNames);
75  source.get(), target.get(), this->opts_.method);
76  if (this->opts_.arrayNames) {
77  transfer->transferPointData(
78  source->getArrayIDs(this->opts_.arrayNames.value()),
79  source->getNewArrayNames());
80  } else {
81  transfer->run(source->getNewArrayNames());
82  }
83  source->write("new.vtu");
84  T.stop();
85 
86  std::cout << "Time spent transferring data (ms) " << T.elapsed() << std::endl;
87 
88  target->write(this->files_.outputMeshFile);
89 }
90 
92 
93 void TransferDriver::setFiles(Files files) { this->files_ = std::move(files); }
94 
96 
97 void TransferDriver::setOpts(Opts opts) { this->opts_ = std::move(opts); }
98 
100  std::cout << "TransferDriver destroyed" << std::endl;
101 }
102 
103 jsoncons::string_view TransferDriver::getProgramType() const {
104  return programType;
105 }
106 
107 std::shared_ptr<TransferBase> TransferDriver::CreateTransferObject(
108  meshBase *srcmsh, meshBase *trgmsh, const std::string &method) {
109  if (method == "Consistent Interpolation") {
110  return FETransfer::CreateShared(srcmsh, trgmsh);
111  }
112 #ifdef HAVE_IMPACT
113  else if (method == "Conservative Surface Transfer") {
114  return ConservativeSurfaceTransfer::CreateShared(srcmsh, trgmsh);
115  }
116 #endif
117 #ifdef HAVE_SUPERMESH
118  else if (method == "Conservative Volume Transfer") {
119  return ConservativeVolumeTransfer::CreateShared(srcmsh, trgmsh);
120  }
121 #endif
122  else {
123  std::cerr << "Method " << method << " is not supported." << std::endl;
124  std::cerr << "Supported methods are : " << std::endl;
125  std::cerr << "1) Consistent Interpolation" << std::endl;
126 #ifdef HAVE_IMPACT
127  std::cerr << "2) Conservative Surface Transfer" << std::endl;
128 #endif
129 #ifdef HAVE_SUPERMESH
130  std::cerr << "3) Conservative Volume Transfer" << std::endl;
131 #endif
132  exit(1);
133  }
134 }
135 
136 } // namespace DRV
137 } // namespace NEM
void setOpts(Opts opts)
jsoncons::string_view getProgramType() const override
const Files & getFiles() const
void execute() const override
Run the workflow represented by the driver.
A brief description of meshBase.
Definition: meshBase.H:64
static std::shared_ptr< ConservativeVolumeTransfer > CreateShared(meshBase *_source, meshBase *_target)
STL namespace.
static std::shared_ptr< ConservativeSurfaceTransfer > CreateShared(meshBase *_source, meshBase *_target)
static meshBase * Create(const std::string &fname)
Construct vtkMesh from filename.
Definition: meshBase.C:78
void setFiles(Files files)
static std::shared_ptr< FETransfer > CreateShared(meshBase *source, meshBase *target)
Definition: FETransfer.H:49
const Opts & getOpts() const
jsoncons::optional< std::vector< std::string > > arrayNames
static std::shared_ptr< TransferBase > CreateTransferObject(meshBase *srcmsh, meshBase *trgmsh, const std::string &method)
static constexpr const char * programType