acousticWaves.cc
Go to the documentation of this file.
/*
* 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 <aslDataInc.h>
#include <acl/aclGenerators.h>
#include <writers/aslVTKFormatWriters.h>
#include <num/aslFDElasticity.h>
#include <num/aslFDElasticityBC.h>
#include <num/aslBasicBC.h>
#include <utilities/aslTimer.h>
#include <utilities/aslParametersManager.h>
#include <math/aslTemplates.h>
#include <aslGeomInc.h>
typedef float FlT;
//typedef asl::UValue<FlT> Param;
class Parameters
{
private:
void init();
public:
asl::ApplicationParametersManager appParamsManager;
asl::Block::DV size;
asl::Parameter<double> dx;
asl::Parameter<double> bulkModulus;
asl::Parameter<double> shearModulus;
asl::Parameter<double> rho;
asl::Parameter<double> tubeL;
asl::Parameter<double> tubeDEx;
asl::Parameter<double> tubeDIn;
asl::Parameter<double> hole1Pos;
asl::Parameter<double> hole2Pos;
asl::Parameter<double> hole1D;
asl::Parameter<double> hole2D;
asl::Parameter<double> tSimulation;
asl::Parameter<double> tOutput;
asl::UValue<double> dt;
asl::UValue<double> bulkMNum;
asl::UValue<double> shearMNum;
void load(int argc, char * argv[]);
Parameters();
void updateNumValues();
};
Parameters::Parameters():
appParamsManager("acousticWaves", "0.1"),
size(3),
dx(1e-3,"dx", "dx"),
bulkModulus(160e9,"bulk_modulus", "bulk modulus"),
shearModulus(79e9,"shear_modulus", "shear modulus"),
rho(7800,"rho", "density"),
tubeL(.2,"tube_length", "pipe length" "m"),
tubeDEx(0.021, "tube_diameter_external", "external pipe diameter" "m"),
// tubeDIn(0.0157,"tube_diameter_internal", "internal pipe diameter" "m"),
tubeDIn(0.0107,"tube_diameter_internal", "internal pipe diameter" "m"),
hole1Pos(0.1,"hole_1_position", "position of first hole" "m"),
hole2Pos(0.15,"hole_2_position", "position of second hole" "m"),
hole1D(15e-3,"hole_1_diameter", "diameter of first hole" "m"),
hole2D(15e-3,"hole_2_diameter", "diameter of second hole" "m"),
tSimulation(8e-5, "simulation_time", "simulation time"),
tOutput(1e-6, "output_interval", "output interval")
{
}
void Parameters::load(int argc, char * argv[])
{
appParamsManager.load(argc, argv);
init();
}
void Parameters::updateNumValues()
{
double vs(sqrt((bulkModulus.v()+2.*shearModulus.v())/rho.v()));
dt=dx.v()/vs*.1;
cout << vs << "; " << dx.v() << "; " << dt.v() << endl;
bulkMNum = bulkModulus.v()/rho.v()/dx.v()/dx.v();
shearMNum = shearModulus.v()/rho.v()/dx.v()/dx.v();
size = asl::makeAVec(tubeL.v() / dx.v() + 1,
tubeDEx.v() / dx.v() + 1,
tubeDEx.v() / dx.v() + 1);
}
void Parameters::init()
{
// if (tubeD.v() < pumpD.v())
// asl::errorMessage("Tube's diameter is smaller than pump's diameter");
updateNumValues();
}
asl::SPDistanceFunction generatePipe(asl::Block & block, Parameters &params)
{
asl::SPDistanceFunction pipeGeometry;
asl::AVec<double> orientation(asl::makeAVec(1., 0., 0.));
asl::AVec<double> lVec(asl::makeAVec(params.tubeL.v()+2.*params.dx.v(), 0., 0.));
asl::AVec<double> h1Orientation(asl::makeAVec(0., 1., 0.));
asl::AVec<double> h2Orientation(asl::makeAVec(0., 0., 1.));
asl::AVec<double> center(asl::AVec<double>(params.size)*.5*params.dx.v());
double wallMid((params.tubeDEx.v()+params.tubeDIn.v())*.25);
double wallTh((params.tubeDEx.v())*.5);
asl::AVec<double> h1Center(center - (center*orientation)*orientation +
params.hole1Pos.v()*orientation +
h1Orientation*wallMid);
asl::AVec<double> h2Center(center - (center*orientation)*orientation +
params.hole2Pos.v()*orientation +
h2Orientation*wallMid);
pipeGeometry = asl::generateDFCylinder(params.tubeDEx.v() / 2., lVec, center) &
(-asl::generateDFCylinderInf(params.tubeDIn.v() / 2., orientation, center));
pipeGeometry = pipeGeometry &
(-asl::generateDFCylinder(params.hole1D.v() / 2., h1Orientation * wallTh, h1Center));
pipeGeometry = pipeGeometry &
(-asl::generateDFCylinder(params.hole2D.v() / 2., h2Orientation * wallTh, h2Center));
return asl::normalize(-pipeGeometry, params.dx.v());
}
asl::AVec<float> getAmplitude(double it)
{
float a(it<200. ? 1.-cos(it*6.28/200.) : 0);
return asl::makeAVec(a,0.f,0.f);
}
int main(int argc, char* argv[])
{
Parameters params;
params.load(argc, argv);
std::cout << "Data initialization... " << flush;
asl::Block block(params.size, params.dx.v());
auto displacement(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u));
asl::initData(displacement, asl::makeAVec(0.,0.,0.));
auto mapMem(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
asl::initData(mapMem, generatePipe(block, params));
asl::WriterVTKXML writer(params.appParamsManager.getDir() + "acousticWaves");
writer.addScalars("map", *mapMem);
writer.addVector("displacement", *displacement);
writer.write();
std::cout << "Finished" << endl;
std::cout << "Numerics initialization... " << flush;
auto elasticity(generateFDElasticityRelax(displacement,
params.bulkMNum.v(),
params.shearMNum.v(),
params.dt.v(),
&asl::d3q19()));
/* auto elasticity(generateFDElasticity(displacement,
params.bulkMNum.v(),
params.shearMNum.v(),
params.dt.v(),
&asl::d3q19()));*/
elasticity->setDumpingFactor(acl::generateVEConstant(.9999));
elasticity->init();
std::vector<asl::SPNumMethod> bc;
bc.push_back(generateBCZeroStress(elasticity, mapMem));
// bc.push_back(generateBCConstantGradient(displacement,asl::makeAVec(0.,0.,0.),mapMem,&asl::d3q19()));
// bc.push_back(generateBCConstantGradient(elasticity->getPressureData(),0.,mapMem,&asl::d3q19()));
// bc.push_back(generateBCZeroStressP(elasticity, mapMem));
asl::UValue<asl::AVec<float>> pres(asl::makeAVec(0.f,0.f,0.f));
bc.push_back(asl::generateBCConstantValue(displacement, pres, {asl::X0}));
initAll(bc);
std::cout << "Finished" << endl;
std::cout << "Computing..." << endl;
asl::Timer timer;
executeAll(bc);
timer.start();
double tOutPrev(0);
cout << params.dt.v() << endl;
for (double t(0); t < params.tSimulation.v(); t+=params.dt.v())
{
elasticity->execute();
pres=getAmplitude(t/params.dt.v());
executeAll(bc);
if(t - params.tOutput.v()>=tOutPrev)
{
timer.stop();
tOutPrev=t;
cout << t << "/" << params.tSimulation.v() << "; time left (estimated): " << timer.estimatedRemainder(t/params.tSimulation.v()) << endl;
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;
}
getAmplitude
asl::AVec< float > getAmplitude(double it)
Definition: acousticWaves.cc:153
main
int main(int argc, char *argv[])
Definition: acousticWaves.cc:160
FlT
float FlT
Definition: acousticWaves.cc:40
generatePipe
asl::SPDistanceFunction generatePipe(asl::Block &block, Parameters &params)
Definition: acousticWaves.cc:127
Parameters
Definition: acousticWaves.cc:44
Parameters::tubeL
asl::Parameter< double > tubeL
Definition: acousticWaves.cc:57
Parameters::bulkModulus
asl::Parameter< double > bulkModulus
Definition: acousticWaves.cc:54
Parameters::tubeDIn
asl::Parameter< double > tubeDIn
Definition: acousticWaves.cc:59
Parameters::tOutput
asl::Parameter< double > tOutput
Definition: acousticWaves.cc:66
Parameters::tSimulation
asl::Parameter< double > tSimulation
Definition: acousticWaves.cc:65
Parameters::hole2Pos
asl::Parameter< double > hole2Pos
Definition: acousticWaves.cc:61
Parameters::shearModulus
asl::Parameter< double > shearModulus
Definition: acousticWaves.cc:55
Parameters::bulkMNum
asl::UValue< double > bulkMNum
Definition: acousticWaves.cc:69
Parameters::size
asl::Block::DV size
Definition: acousticWaves.cc:51
Parameters::dt
asl::UValue< double > dt
Definition: acousticWaves.cc:68
Parameters::tubeDEx
asl::Parameter< double > tubeDEx
Definition: acousticWaves.cc:58
Parameters::dx
asl::Parameter< double > dx
Definition: acousticWaves.cc:53
Parameters::hole2D
asl::Parameter< double > hole2D
Definition: acousticWaves.cc:63
Parameters::appParamsManager
asl::ApplicationParametersManager appParamsManager
Definition: acousticWaves.cc:49
Parameters::updateNumValues
void updateNumValues()
Definition: acousticWaves.cc:107
Parameters::hole1D
asl::Parameter< double > hole1D
Definition: acousticWaves.cc:62
Parameters::rho
asl::Parameter< double > rho
Definition: acousticWaves.cc:56
Parameters::hole1Pos
asl::Parameter< double > hole1Pos
Definition: acousticWaves.cc:60
Parameters::Parameters
Parameters()
Definition: acousticWaves.cc:78
Parameters::shearMNum
asl::UValue< double > shearMNum
Definition: acousticWaves.cc:70
Parameters::load
void load(int argc, char *argv[])
Definition: acousticWaves.cc:99
asl::AVec< int >
asl::ApplicationParametersManager
Definition: aslParametersManager.h:159
asl::ApplicationParametersManager::load
void load(int argc, char *argv[])
asl::Block
Definition: aslBlocks.h:57
asl::Parameter< double >
asl::Parameter::v
const T & v() const
Definition: aslParametersManager.h:179
asl::ParametersManager::getDir
std::string getDir()
asl::Timer
Definition: aslTimer.h:34
asl::Timer::realTime
const double realTime() const
Definition: aslTimer.h:45
asl::Timer::stop
void stop()
Definition: aslTimer.h:44
asl::Timer::processorTime
const double processorTime() const
Definition: aslTimer.h:46
asl::Timer::start
void start()
Definition: aslTimer.h:43
asl::Timer::processorLoad
const double processorLoad() const
Definition: aslTimer.h:47
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::UValue::v
const T & v() const
Definition: aslUValue.h:43
asl::Writer::addVector
void addVector(std::string name, AbstractData &data)
asl::Writer::addScalars
void addScalars(std::string name, AbstractData &data)
asl::WriterVTKXML
Definition: aslVTKFormatWriters.h:42
asl::WriterVTKXML::write
void write()
asl::X0
@ X0
Definition: aslBCond.h:309
asl::dx
acl::VectorOfElements dx(const TemplateVE &a)
differential operator
asl::generateBCZeroStress
SPNumMethod generateBCZeroStress(SPElasticityCommonA nm, SPAbstractDataWithGhostNodes map)
Bondary condition set given values to displacement/velocity.
asl::generateBCConstantValue
SPBCond generateBCConstantValue(SPAbstractDataWithGhostNodes d, double v, const std::vector< SlicesNames > &sl)
Bondary condition that puts fixed value in each point.
asl::generateDFCylinder
SPDistanceFunction generateDFCylinder(double r, const AVec< double > &l, const AVec< double > &c)
generates cylinder
asl::normalize
SPDistanceFunction normalize(SPDistanceFunction a, double dx)
asl::generateDFCylinderInf
SPDistanceFunction generateDFCylinderInf(double r, const AVec< double > &l, const AVec< double > &c)
generates infinite cylinder
asl::SPDistanceFunction
std::shared_ptr< DistanceFunction > SPDistanceFunction
Definition: aslGeomInc.h:44
acl::elementOperators::sqrt
Element sqrt(Element e)
acl::elementOperators::cos
Element cos(Element e)
asl::d3q19
const VectorTemplate & d3q19()
Vector template.
acl::generateVEConstant
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
asl::makeAVec
AVec< T > makeAVec(T a1)
Definition: aslVectorsDynamicLength.h:176
asl::initAll
void initAll(std::vector< T * > &v)
Definition: aslNumMethod.h:67
asl::initData
void initData(SPAbstractData d, double a)
asl::generateFDElasticityRelax
SPFDElasticityRelaxation generateFDElasticityRelax(SPDataWithGhostNodesACLData d, double bM, double sM, double dt, const VectorTemplate *vT)
asl::executeAll
void executeAll(std::vector< T * > &v)
Definition: aslNumMethod.h:55
cl::flush
cl_int flush(void)
Definition: cl.hpp:7042