ASL  0.1.7
Advanced Simulation Library
multicomponent_flow.cc

Example: Multicomponent flow

/*
* Advanced Simulation Library <http://asl.org.il>
*
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
*
*
* This file is part of Advanced Simulation Library (ASL).
*
* ASL is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* ASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <utilities/aslParametersManager.h>
#include <math/aslTemplates.h>
#include <aslGeomInc.h>
#include <aslDataInc.h>
#include <acl/aclGenerators.h>
#include <writers/aslVTKFormatWriters.h>
#include <num/aslLBGK.h>
#include <num/aslLBGKBC.h>
#include <utilities/aslTimer.h>
#include <num/aslFDAdvectionDiffusion.h>
#include <num/aslBasicBC.h>
// typedef to switch to double precision
//typedef double FlT;
typedef float FlT;
using asl::AVec;
{
private:
void init();
public:
void load(int argc, char * argv[]);
};
appParamsManager("multicomponent_flow", "0.1"),
size(3),
dx(0.0005, "dx", "space step"),
dt(1., "dt", "time step"),
tSimulation(2e-3, "simulation_time", "simulation time"),
tOutput(1e-4, "output_interval", "output interval"),
nu(4e-8/1.6, "nu", "viscosity"),
tubeL(0.25, "tubeL", "tube's length"),
tubeD(0.05, "tubeD", "tube's diameter"),
pumpL(0.025, "pumpL", "pump's length"),
pumpD(0.03, "pumpD", "pump's diameter"),
component1InVel(0.16, "component1_in_velocity", "flow velocity in the component1 input"),
component2InVel(0.08, "component2_in_velocity", "flow velocity in the component2 input"),
component3InVel(0.1, "component3_in_velocity", "flow velocity in the component3 input")
{
}
void Parameters::load(int argc, char * argv[])
{
appParamsManager.load(argc, argv);
init();
}
{
nuNum = nu.v() * dt.v() / dx.v() / dx.v();
size[0] = tubeD.v() / dx.v() + 1;
size[1] = (tubeD.v() + 2 * pumpL.v()) / dx.v() + 1;
size[2] = tubeL.v() / dx.v() + 1;
}
void Parameters::init()
{
if (tubeD.v() < pumpD.v())
asl::errorMessage("Tube's diameter is smaller than pump's diameter");
}
// Generate geometry of the mixer (cross-coupled pipes)
{
asl::SPDistanceFunction mixerGeometry;
asl::AVec<double> orientation(asl::makeAVec(0., 0., 1.));
asl::AVec<double> center(asl::AVec<double>(params.size) * .5 * params.dx.v());
mixerGeometry = generateDFCylinderInf(params.tubeD.v() / 2., orientation,
center);
orientation[1] = 1.0;
orientation[2] = 0.0;
center[2] = params.pumpD.v() * 1.5;
mixerGeometry = mixerGeometry | generateDFCylinderInf(params.pumpD.v() / 2.,
orientation, center);
return asl::normalize(-(mixerGeometry) | asl::generateDFInBlock(block, 0),
params.dx.v());
}
int main(int argc, char *argv[])
{
Parameters params;
params.load(argc, argv);
cout << "Data initialization..." << endl;
asl::Block block(params.size, params.dx.v());
auto mcfMapMem(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
asl::initData(mcfMapMem, generateMixer(block, params));
auto component1Frac(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
asl::initData(component1Frac, 0);
auto component3Frac(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
asl::initData(component3Frac, 0);
cout << "Finished" << endl;
cout << "Numerics initialization..." << endl;
auto templ(&asl::d3q15());
asl::SPLBGK lbgk(new asl::LBGK(block,
templ));
lbgk->init();
lbgkUtil->initF(acl::generateVEConstant(.0, .0, .0));
auto flowVel(lbgk->getVelocity());
auto nmcomponent1(asl::generateFDAdvectionDiffusion(component1Frac, 0.01,
flowVel, templ, true));
nmcomponent1->init();
auto nmcomponent3(asl::generateFDAdvectionDiffusion(component3Frac, 0.01,
flowVel, templ));
nmcomponent3->init();
std::vector<asl::SPNumMethod> bc;
std::vector<asl::SPNumMethod> bcV;
std::vector<asl::SPNumMethod> bcDif;
bc.push_back(generateBCNoSlip(lbgk, mcfMapMem));
bc.push_back(generateBCConstantPressure(lbgk, 1., {asl::ZE}));
bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
makeAVec(0., 0., params.component2InVel.v()),
{asl::Z0}));
bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
makeAVec(0., -params.component1InVel.v(), 0.),
{asl::YE}));
bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
makeAVec(0., params.component3InVel.v(), 0.),
{asl::Y0}));
bcDif.push_back(generateBCNoSlipVel(lbgk, mcfMapMem));
bc.push_back(generateBCConstantGradient(component1Frac, 0., mcfMapMem, templ));
bc.push_back(generateBCConstantGradient(component3Frac, 0., mcfMapMem, templ));
bc.push_back(generateBCConstantValue(component1Frac, 1., {asl::YE}));
bc.push_back(generateBCConstantValue(component3Frac, 0., {asl::YE, asl::Z0, asl::ZE}));
bc.push_back(generateBCConstantValue(component1Frac, 0., {asl::Y0, asl::Z0, asl::ZE}));
bc.push_back(generateBCConstantValue(component3Frac, 1., {asl::Y0}));
// bc.push_back(generateBCConstantGradient(component1Frac, 0.,templ, {asl::ZE}));
// bc.push_back(generateBCConstantGradient(component3Frac, 0.,templ, {asl::ZE}));
initAll(bc);
initAll(bcDif);
initAll(bcV);
cout << "Finished" << endl;
cout << "Computing..." << endl;
asl::Timer timer;
asl::WriterVTKXML writer("multicomponent_flow");
writer.addScalars("map", *mcfMapMem);
writer.addScalars("component1", *component1Frac);
writer.addScalars("component3", *component3Frac);
writer.addScalars("rho", *lbgk->getRho());
writer.addVector("v", *flowVel);
executeAll(bcDif);
executeAll(bcV);
writer.write();
timer.start();
for (unsigned int i(1); i < 10001; ++i)
{
lbgk->execute();
executeAll(bcDif);
nmcomponent1->execute();
nmcomponent3->execute();
if (!(i%100))
{
timer.stop();
cout << i << "/10000; time left (estimated): " << timer.estimatedRemainder(double(i)/10000.) << endl;
executeAll(bcV);
writer.write();
timer.start();
}
}
timer.stop();
cout << "Finished" << endl;
cout << "Computation statistic:" << endl;
cout << "Real Time = " << timer.realTime() << "; Processor Time = "
<< timer.processorTime() << "; Processor Load = "
<< timer.processorLoad() * 100 << "%" << endl;
return 0;
}
asl::generateDFInBlock
SPDistanceFunction generateDFInBlock(const Block &b, unsigned int nG)
generates map corresponding to external (ghost) part of the block
asl::generateDFCylinderInf
SPDistanceFunction generateDFCylinderInf(double r, const AVec< double > &l, const AVec< double > &c)
generates infinite cylinder
asl::Timer::processorLoad
const double processorLoad() const
Definition: aslTimer.h:47
FlT
float FlT
Definition: multicomponent_flow.cc:43
asl::generateBCConstantValue
SPBCond generateBCConstantValue(SPAbstractDataWithGhostNodes d, double v, const std::vector< SlicesNames > &sl)
Bondary condition that puts fixed value in each point.
asl::Timer::stop
void stop()
Definition: aslTimer.h:44
asl::LBGK
Numerical method for fluid flow.
Definition: aslLBGK.h:77
Parameters::appParamsManager
asl::ApplicationParametersManager appParamsManager
Definition: acousticWaves.cc:49
asl::WriterVTKXML
Definition: aslVTKFormatWriters.h:41
Parameters::size
asl::Block::DV size
Definition: acousticWaves.cc:51
asl::generateBCNoSlipVel
SPNumMethod generateBCNoSlipVel(SPLBGK nmU, SPAbstractDataWithGhostNodes map)
asl::Timer::start
void start()
Definition: aslTimer.h:43
Parameters::component2InVel
asl::Parameter< double > component2InVel
Definition: multicomponent_flow.cc:71
asl::Timer
Definition: aslTimer.h:34
Parameters::Parameters
Parameters()
Definition: acousticWaves.cc:78
main
int main(int argc, char *argv[])
Definition: multicomponent_flow.cc:145
asl::AVec::makeAVec
AVec< T > makeAVec(T a1)
Definition: aslVectorsDynamicLength.h:176
asl::generateBCConstantPressureVelocity
SPBCond generateBCConstantPressureVelocity(SPLBGK nm, double p, AVec<> v, const std::vector< SlicesNames > &sl)
Parameters::dt
asl::UValue< double > dt
Definition: acousticWaves.cc:68
Parameters::component1InVel
asl::Parameter< double > component1InVel
Definition: multicomponent_flow.cc:72
Parameters::pumpD
asl::Parameter< double > pumpD
Definition: multicomponent_flow.cc:69
asl::SPLBGKUtilities
std::shared_ptr< LBGKUtilities > SPLBGKUtilities
Definition: aslLBGK.h:161
asl::generateFDAdvectionDiffusion
SPFDAdvectionDiffusion generateFDAdvectionDiffusion(SPDataWithGhostNodesACLData c, double diffustionCoeff, SPAbstractDataWithGhostNodes v, const VectorTemplate *vt, bool compressibilityCorrection=false)
asl::dx
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
asl::ApplicationParametersManager::load
void load(int argc, char *argv[])
generateMixer
asl::SPDistanceFunction generateMixer(asl::Block &block, Parameters &params)
Definition: multicomponent_flow.cc:126
asl::Parameter< double >
asl::Z0
@ Z0
Definition: aslBCond.h:309
asl::Timer::estimatedRemainder
const double estimatedRemainder(double completeness)
Returns estimated time till finishing current task based on its current completeness [0....
Definition: aslTimer.h:52
asl::UValue< double >
asl::YE
@ YE
Definition: aslBCond.h:309
Parameters::tubeL
asl::Parameter< double > tubeL
Definition: acousticWaves.cc:57
asl::SPLBGK
std::shared_ptr< LBGK > SPLBGK
Definition: aslLBGK.h:133
asl::generateBCNoSlip
SPBCond generateBCNoSlip(SPLBGK nm, const std::vector< SlicesNames > &sl)
Parameters::tOutput
asl::Parameter< double > tOutput
Definition: acousticWaves.cc:66
asl::initAll
void initAll(std::vector< T * > &v)
Definition: aslNumMethod.h:67
Parameters::load
void load(int argc, char *argv[])
Definition: acousticWaves.cc:99
asl::LBGKUtilities
contains different kernels for preprocessing and posprocessing of data used by LBGK
Definition: aslLBGK.h:137
asl::UValue::v
const T & v() const
Definition: aslUValue.h:43
asl::Block
Definition: aslBlocks.h:56
Parameters
Definition: acousticWaves.cc:43
asl::Parameter::v
const T & v() const
Definition: aslParametersManager.h:179
asl::initData
void initData(SPAbstractData d, double a)
acl::generateVEConstant
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
asl::Y0
@ Y0
Definition: aslBCond.h:309
Parameters::nuNum
asl::UValue< double > nuNum
Definition: multicomponent_flow.cc:64
asl::errorMessage
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
asl::ApplicationParametersManager
Definition: aslParametersManager.h:158
Parameters::tSimulation
asl::Parameter< double > tSimulation
Definition: acousticWaves.cc:65
asl::makeAVec
AVec< T > makeAVec(T a1)
Definition: aslVectorsDynamicLength.h:176
asl::d3q15
const VectorTemplate & d3q15()
Vector template.
Parameters::tubeD
asl::Parameter< double > tubeD
Definition: multicomponent_flow.cc:67
Parameters::component3InVel
asl::Parameter< double > component3InVel
Definition: multicomponent_flow.cc:73
Parameters::pumpL
asl::Parameter< double > pumpL
Definition: multicomponent_flow.cc:68
asl::Timer::realTime
const double realTime() const
Definition: aslTimer.h:45
asl::SPDistanceFunction
std::shared_ptr< DistanceFunction > SPDistanceFunction
Definition: aslGeomInc.h:44
Parameters::updateNumValues
void updateNumValues()
Definition: acousticWaves.cc:107
asl::executeAll
void executeAll(std::vector< T * > &v)
Definition: aslNumMethod.h:55
asl::Timer::processorTime
const double processorTime() const
Definition: aslTimer.h:46
asl::ZE
@ ZE
Definition: aslBCond.h:309
asl::AVec
Definition: aslDataInc.h:34
Parameters::dx
asl::Parameter< double > dx
Definition: acousticWaves.cc:53
asl::generateBCConstantPressure
SPBCond generateBCConstantPressure(SPLBGK nm, double p, const std::vector< SlicesNames > &sl)
asl::generateBCConstantGradient
SPBCond generateBCConstantGradient(SPAbstractDataWithGhostNodes d, double v, const VectorTemplate *const t, const std::vector< SlicesNames > &sl)
Bondary condition that makes fixed gradient.
Parameters::nu
asl::Parameter< double > nu
Definition: multicomponent_flow.cc:63
asl::normalize
SPDistanceFunction normalize(SPDistanceFunction a, double dx)