OpenLB 1.7
Loading...
Searching...
No Matches
particleIoFunctions.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24
25/* This file contains functions for console and vtk output.
26 * Those include spefic and generic version.
27*/
28
29#ifndef PARTICLE_IO_FUNCTIONS_H
30#define PARTICLE_IO_FUNCTIONS_H
31
32
33namespace olb {
34
35namespace particles {
36
37namespace io {
38
40// -TODO:should most likely be implemented somewhere else)
41// -Also: using template recursion, the for loop could be discarded
42template<typename VECTOR>
43std::string strFormatVector(VECTOR vector, int strWidth=13)
44{
45 const int dim=vector.getDim();
46 std::stringstream stream;
47 stream << "(";
48 for( int iDim=0; iDim<dim-1; ++iDim ){
49 stream << std::setw(strWidth) << vector[iDim] << ", ";
50 }
51 stream << std::setw(strWidth) << vector[dim-1] << ")";
52 return stream.str();
53}
54
55
57template<typename T, typename PARTICLETYPE, bool multiOutput=access::providesParallelization<PARTICLETYPE>()>
59{
60 OstreamManager clout( std::cout, "Particle "+std::to_string(iP) );
61 clout.setMultiOutput(multiOutput);
62 clout << "================================================" << std::endl;
63 //Define output lambda expression
64 typedef std::function<bool(const std::type_info&,int,std::string)> FunctionType;
65 FunctionType printFunction = [](const std::type_info& typeInfo, int fieldSize, std::string fieldContentStr) {
66 OstreamManager clout( std::cout,"Field" );
67 clout << std::setw(45) << std::string(typeInfo.name()) << " (" << fieldSize << ") : " << fieldContentStr << std::endl;
68 return false; //resetField=false
69 };
70 //Call recursive field traversal function with lambda expression
72 printFunction, dynamicFieldGroups, iP );
73 clout << "================================================" << std::endl;
74 clout.setMultiOutput(false);
75}
76
77
79template<typename T, typename PARTICLETYPE, bool multiOutput=access::providesParallelization<PARTICLETYPE>()>
81{
82 using namespace descriptors;
83 constexpr unsigned D = PARTICLETYPE::d;
85 //Retrieve Data
86 Vector<T,D> position( particle.template getField<GENERAL,POSITION>() );
87 Vector<T,D> velocity( particle.template getField<MOBILITY,VELOCITY>() );
88 Vector<T,Drot> angularVelocity( particle.template getField<MOBILITY,ANG_VELOCITY>() );
89 Vector<T,Drot> angle( particle.template getField<SURFACE,ANGLE>() );
90 auto indicatorPtr = particle.template getField<SURFACE,SINDICATOR>();
91 //Print data
92 OstreamManager clout( std::cout,"Particle" );
93 clout.setMultiOutput(multiOutput);
94 clout << "================================================" << std::endl;
95 clout << "Position(m)= " << std::setw(13) << position << std::endl;
96 clout << "Velocity(m/s)= " << std::setw(13) << velocity << std::endl;
97 clout << "Ang. Velocity(m/s)= " << std::setw(13) << angularVelocity << std::endl;
98 clout << "Angle(rad)= " << std::setw(13) << angle << std::endl;
99 clout << "Indi Pos= " << std::setw(13) << indicatorPtr->getPos() << std::endl;
100 clout << "Indi Min= " << std::setw(13) << indicatorPtr->getMin() << std::endl;
101 clout << "Indi Max= " << std::setw(13) << indicatorPtr->getMax() << std::endl;
102 clout << "================================================" << std::endl;
103 clout.setMultiOutput(false);
104}
105
106
107
109template<typename T, typename PARTICLETYPE, bool multiOutput=access::providesParallelization<PARTICLETYPE>()>
110void printResolvedParticleInfo( Particle<T, PARTICLETYPE>& particle, const std::string& streamName="ParticleInfo" )
111{
112
113 //Set up environment
114 using namespace descriptors;
115 using namespace access;
116 constexpr unsigned D = PARTICLETYPE::d;
118
119 //Retrieve data
120 std::size_t particleLocalID = particle.getId();
121 const bool hasGlobalID = PARTICLETYPE::template providesNested<PARALLELIZATION,ID>();
122 auto indicatorPtr = particle.template getField<SURFACE,SINDICATOR>();
123 T sIndiCircumRadius = indicatorPtr->getCircumRadius();
124 T mass = particle.template getField<PHYSPROPERTIES,MASS>();
125 Vector<T,D> position( particle.template getField<GENERAL,POSITION>() );
126 Vector<T,D> velocity( particle.template getField<MOBILITY,VELOCITY>() );
127 Vector<T,Drot> angularVelocity( particle.template getField<MOBILITY,ANG_VELOCITY>() );
128 Vector<T,Drot> angle( particle.template getField<SURFACE,ANGLE>() );
129 Vector<T,D> force( particle.template getField<FORCING,FORCE>() );
130 Vector<T,D> acceleration( particle.template getField<MOBILITY,ACCELERATION_STRD>() );
131 Vector<T,Drot> angularAcceleration( particle.template getField<MOBILITY,ANG_ACC_STRD>() );
132 Vector<T,Drot> momentOfInertia( particle.template getField<PHYSPROPERTIES,MOFI>() );
133
134 //Translate angle from radian to degree
135 angle *= (180/M_PI);
136 angularVelocity *= (180/M_PI);
137 angularAcceleration *= (180/M_PI);
138
139 //Print data
140 OstreamManager clout( std::cout,streamName );
141 clout.setMultiOutput(multiOutput);
142 if constexpr(!hasGlobalID){
143 clout << "Particle " << "ID=" << particleLocalID;
144 } else {
145 std::size_t particleGlobalID = particle.template getField<PARALLELIZATION,ID>();
146 clout << "Particle " << "LokalID=" << particleLocalID << ", GlobalID=" << particleGlobalID;
147 }
148 if constexpr(providesActive<PARTICLETYPE>()){
149 bool active = isActive(particle);
150 clout << " (" << (active ? "active" : "idle") << ")";
151 }
152 clout << std::endl;
153 clout << " |Circum radius(m)= " << std::setw(13) << sIndiCircumRadius << std::endl;
154 clout << " |Mass(kg)= " << std::setw(13) << mass << std::endl;
155 clout << " |Position(m)= " << strFormatVector<Vector<T,D>>(position) << std::endl;
156 clout << " |Angle(°)= " << strFormatVector<Vector<T,Drot>>(angle) << std::endl;
157 clout << " |Velocity(m/s)= " << strFormatVector<Vector<T,D>>(velocity) << std::endl;
158 clout << " |Ang. Velocity(°/s)= " << strFormatVector<Vector<T,Drot>>(angularVelocity) << std::endl;
159 clout << " |Force(N)= " << strFormatVector<Vector<T,D>>(force) << std::endl;
160 clout << " |Acceleration(m/s^2)= " << strFormatVector<Vector<T,D>>(acceleration) << std::endl;
161 clout << " |Ang. acc.(°/s^2)= " << strFormatVector<Vector<T,Drot>>(angularAcceleration) << std::endl;
162 clout << " |Moment of inertia(kg m^2)= " << strFormatVector<Vector<T,Drot>>(momentOfInertia) << std::endl;
163 clout.setMultiOutput(false);
164}
165
166template<typename T, typename PARTICLETYPE, bool multiOutput=access::providesParallelization<PARTICLETYPE>()>
167void printSubgridParticleInfo( Particle<T, PARTICLETYPE>& particle, const std::string& streamName="ParticleInfo" )
168{
169
170 //Set up environment
171 using namespace descriptors;
172 using namespace access;
173 constexpr unsigned D = PARTICLETYPE::d;
174
175 //Retrieve data
176 std::size_t particleLocalID = particle.getId();
177 const bool hasGlobalID = PARTICLETYPE::template providesNested<PARALLELIZATION,ID>();
178 T radius = particle.template getField<PHYSPROPERTIES,RADIUS>();
179 T mass = particle.template getField<PHYSPROPERTIES,MASS>();
180 Vector<T,D> position( particle.template getField<GENERAL,POSITION>() );
181 Vector<T,D> velocity( particle.template getField<MOBILITY,VELOCITY>() );
182 Vector<T,D> force( particle.template getField<FORCING,FORCE>() );
183
184 //Print data
185 OstreamManager clout( std::cout,streamName );
186 clout.setMultiOutput(multiOutput);
187 if constexpr(!hasGlobalID){
188 clout << "Particle " << "ID=" << particleLocalID;
189 } else {
190 std::size_t particleGlobalID = particle.template getField<PARALLELIZATION,ID>();
191 clout << "Particle " << "LokalID=" << particleLocalID << ", GlobalID=" << particleGlobalID;
192 }
193 if constexpr(providesActive<PARTICLETYPE>()){
194 bool active = isActive(particle);
195 clout << " (" << (active ? "active" : "idle") << ")";
196 }
197 clout << std::endl;
198 clout << " |Radius(m)= " << std::setw(13) << radius << std::endl;
199 clout << " |Mass(kg)= " << std::setw(13) << mass << std::endl;
200 clout << " |Position(m)= " << strFormatVector<Vector<T,D>>(position) << std::endl;
201 clout << " |Velocity(m/s)= " << strFormatVector<Vector<T,D>>(velocity) << std::endl;
202 clout << " |Force(N)= " << strFormatVector<Vector<T,D>>(force) << std::endl;
203 clout.setMultiOutput(false);
204}
205
207template<typename T, typename PARTICLETYPE, bool multiOutput=access::providesParallelization<PARTICLETYPE>()>
209{
210 using namespace descriptors;
211 constexpr unsigned D = PARTICLETYPE::d;
212 /* constexpr unsigned Drot = utilities::dimensions::convert<D>::rotation; */
213 //Retrieve Data
214 Vector<T,D> position( particle.template getField<GENERAL,POSITION>() );
215 Vector<T,D> velocity( particle.template getField<MOBILITY,VELOCITY>() );
216 bool activity( particle.template getField<DYNBEHAVIOUR,ACTIVE>() );
217 //Print data
218 OstreamManager clout( std::cout,"Particle" );
219 clout.setMultiOutput(multiOutput);
220 clout << "================================================" << std::endl;
221 clout << "Position(m)= " << std::setw(13) << position << std::endl;
222 clout << "Velocity(m/s)= " << std::setw(13) << velocity << std::endl;
223 clout << "Active= " << std::setw(13) << activity << std::endl;
224 clout << "================================================" << std::endl;
225 clout.setMultiOutput(false);
226}
227
228
229
230
231
232} //namespace io
233
234} //namespace particles
235
236} //namespace olb
237
238#endif
#define M_PI
Storage for dynamic field groups (Prototype for ParticleSystem)
class for marking output with some text
void setMultiOutput(bool b)
enable message output for all MPI processes, disabled by default
Plain old scalar vector.
Definition vector.h:47
std::size_t getId() const
Return memory ID of the currently represented particle.
Definition particle.hh:67
void printResolvedParticleInfo(Particle< T, PARTICLETYPE > &particle, const std::string &streamName="ParticleInfo")
Printing method adapted to the original output.
void printGenericParticleInfo(DynamicFieldGroupsD< T, typename PARTICLETYPE::fields_t > &dynamicFieldGroups, std::size_t iP)
Generic printing method for particles, which automatically traverses through all provided fields.
void printSubgridParticleInfo(Particle< T, PARTICLETYPE > &particle, const std::string &streamName="ParticleInfo")
void printSubgridParticleInfoSimple(Particle< T, PARTICLETYPE > &particle)
Simple printing method for subgrid particles.
void printResolvedParticleInfoSimple(Particle< T, PARTICLETYPE > &particle)
Simple printing method for resolved particles.
std::string strFormatVector(VECTOR vector, int strWidth=13)
Generic vector print method.
Top level namespace for all of OpenLB.
Traversal of nested field contents for output and initialization.
Converts dimensions by deriving from given cartesian dimension D.