22 #include <LbmLib/include/Field.hpp>
23 #include <LbmLib/include/nodes/EulerianPoint.hpp>
24 #include <LbmLib/include/nodes/GeometryNode.hpp>
25 #include <LbmLib/include/solver/ForceSolver.hpp>
26 #include <LbmLib/include/solver/ForceStructs.hpp>
27 #include <UtilLib/include/Exception.hpp>
43 std::shared_ptr<nodes::GeometryNode> >& nodes) {
44 std::vector< std::shared_ptr<AbstractForceStruct> > tempforcevector;
46 const size_t nodes_length = nodes.size();
47 typedef std::map<unsigned int, std::shared_ptr<nodes::GeometryNode> >::const_iterator temp_map_it;
48 std::vector<temp_map_it> helper_nodes;
51 auto nodes_it = nodes.begin();
56 helper_nodes.push_back(nodes_it++);
60 #pragma omp parallel for schedule(static)
61 for (
size_t it=0; it<nodes_length; ++it) {
65 auto forcemap_length = this->forcemap_.size();
66 std::vector<map_forcestruct::iterator> helper_forcemap;
69 auto forcemap_it = this->forcemap_.begin();
73 helper_forcemap.push_back(forcemap_it++);
77 # pragma omp parallel for schedule(static)
81 for (
auto in : helper_forcemap[it]->second) {
82 in->calculateForce(nodes);
90 std::ifstream fileStream;
91 fileStream.open(filename);
92 if (fileStream.is_open()) {
94 while (std::getline(fileStream, line)) {
95 std::stringstream lineStream(line);
97 if (line.at(0) !=
'#') {
102 lbm_fail(
"Cannot find the force solver file.");
109 unsigned int type, nodeid;
110 std::stringstream copyforcedescriptor(forcedescriptor->str());
111 copyforcedescriptor >> type >> nodeid;
114 this->forcemap_[nodeid].push_back(LbmLib::solver::ForceStructs::loadForceType0(forcedescriptor));
115 }
else if (type == 1) {
117 this->forcemap_[nodeid].push_back(LbmLib::solver::ForceStructs::loadForceType1(forcedescriptor));
118 }
else if (type == 2) {
120 this->forcemap_[nodeid].push_back(LbmLib::solver::ForceStructs::loadForceType2(forcedescriptor));
121 }
else if (type == 3) {
123 this->forcemap_[nodeid].push_back(LbmLib::solver::ForceStructs::loadForceType3(forcedescriptor));
124 }
else if (type == 4) {
126 this->forcemap_[nodeid].push_back(LbmLib::solver::ForceStructs::loadForceType4(forcedescriptor));
127 }
else if (type == 5) {
129 this->forcemap_[nodeid].push_back(LbmLib::solver::ForceStructs::loadForceType5(forcedescriptor));
130 }
else if (type == 6) {
132 this->forcemap_[nodeid].push_back(LbmLib::solver::ForceStructs::loadForceType6(forcedescriptor));
133 }
else if (type == 7) {
135 this->forcemap_[nodeid].push_back(LbmLib::solver::ForceStructs::loadForceType7(forcedescriptor));
137 lbm_fail(
"Invalid force solver type found.");
142 std::ofstream fileStream;
143 fileStream.open(filename);
144 if (fileStream.is_open()) {
145 for (
auto it1=this->forcemap_.begin();
146 it1!=this->forcemap_.end();
148 for (
auto it2 : it1->second) {
149 it2->writeForceStruct(&fileStream);
154 "Problem to open the output file for the force solver");
160 for (
auto it : this->forcemap_) {
162 assert(it.second.size()==0 &&
"ForceSolver::deleteAllForces: couldn't clear forcemap_");
164 this->forcemap_.clear();
165 assert(this->forcemap_.size()==0 &&
"ForceSolver::deleteAllForces: couldn't clear forcemap_");
171 const auto forcemap_length = this->forcemap_.size();
173 std::vector<map_forcestruct::iterator> helper_map;
174 auto map_it = this->forcemap_.begin();
180 helper_map.push_back(map_it++);
191 helper_map[j]->second.erase( std::remove_if(helper_map[j]->second.begin(),
192 helper_map[j]->second.end(),
193 [forcetype](std::shared_ptr<AbstractForceStruct> force){
194 if (force->getType() == forcetype) {
201 helper_map[j]->second.end()
207 const unsigned int nodeid)
210 assert(forcevector.size()==0 &&
"ForceSolver::getForcesOfNode: non-empty forcevector");
212 if ( this->forcemap_.find(nodeid) == this->forcemap_.end() ) {
215 forcevector.insert(forcevector.end(),
216 this->forcemap_[nodeid].begin(),
217 this->forcemap_[nodeid].end()
225 return this->forcemap_;
void deleteForceType(const unsigned int forcetype)
reset all forces
~ForceSolver()
The destructor.
vec_shptr_forcestruct getForcesOfNode(vec_shptr_forcestruct &forcevector, const unsigned int nodeid)
get all forces of nodeid
ForceSolver()
The constructor.
void writeForceSolver(const std::string &filename) const
writes the forces to the file
void addForce(std::stringstream *const forcedescriptor)
add a force
const map_forcestruct getAllForces() const
getAllForces returns the entire map {nodeid, AbstractForceStruct}
void loadForceFile(const std::string &filename)
loading of the force solver
void deleteAllForces()
reset all forces
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the Force