| 1 |
/* |
| 2 |
* Advanced Simulation Library <http://asl.org.il> |
| 3 |
* |
| 4 |
* Copyright 2015 Avtech Scientific <http://avtechscientific.com> |
| 5 |
* |
| 6 |
* |
| 7 |
* This file is part of Advanced Simulation Library (ASL). |
| 8 |
* |
| 9 |
* ASL is free software: you can redistribute it and/or modify it |
| 10 |
* under the terms of the GNU Affero General Public License as |
| 11 |
* published by the Free Software Foundation, version 3 of the License. |
| 12 |
* |
| 13 |
* ASL 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 Affero General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Affero General Public License |
| 19 |
* along with ASL. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
/** |
| 25 |
\example poroelastic.cc |
| 26 |
Required input file: [brain.vti](http://asl.org.il/input_data/brain.vti) |
| 27 |
*/ |
| 28 |
|
| 29 |
#include <aslDataInc.h> |
| 30 |
#include <acl/aclGenerators.h> |
| 31 |
#include <num/aslFDPoroElasticity.h> |
| 32 |
#include <num/aslFDElasticityBC.h> |
| 33 |
#include <num/aslFDPoroElasticityBC.h> |
| 34 |
#include <utilities/aslTimer.h> |
| 35 |
#include <utilities/aslParametersManager.h> |
| 36 |
#include <math/aslTemplates.h> |
| 37 |
#include <aslGeomInc.h> |
| 38 |
#include <math/aslDistanceFunction.h> |
| 39 |
#include <acl/aclMath/aclVectorOfElements.h> |
| 40 |
#include <acl/aclUtilities.h> |
| 41 |
#include <math/aslIndex2Position.h> |
| 42 |
#include <readers/aslVTKFormatReaders.h> |
| 43 |
#include <writers/aslVTKFormatWriters.h> |
| 44 |
|
| 45 |
|
| 46 |
typedef float FlT; |
| 47 |
//typedef double FlT; |
| 48 |
typedef asl::UValue<FlT> Param; |
| 49 |
|
| 50 |
|
| 51 |
int main(int argc, char* argv[]) |
| 52 |
{ |
| 53 |
asl::ApplicationParametersManager appParamsManager("poroelastic", "1.0"); |
| 54 |
asl::Parameter<asl::AVec<int> > size(asl::makeAVec<int>(50, 50, 50), "size", "3D size"); |
| 55 |
asl::Parameter<cl_float> dx(4e-3, "dx", "dx"); |
| 56 |
asl::Parameter<cl_float> dt(0.0001, "dt", "dt"); |
| 57 |
asl::Parameter<cl_float> bulkModulus(1000.0, "bulk_modulus", "bulk modulus"); |
| 58 |
asl::Parameter<cl_float> shearModulus(30.0, "shear_modulus", "shear modulus"); |
| 59 |
asl::Parameter<cl_float> hydraulicConductivity(1e-10, "hydraulic_conductivity", "hydraulic conductivity"); |
| 60 |
asl::Parameter<cl_float> rho(1e3, "rho", "density"); |
| 61 |
asl::Parameter<asl::AVec<FlT> > g(asl::makeAVec<FlT>(-9.8, 0.0, 0.0), "g", "gravity vector"); |
| 62 |
asl::Parameter<string> input("input", "path to the brain geometry input file"); |
| 63 |
asl::Parameter<unsigned int> tsim(20000, "num_iterations", "number of iterations"); |
| 64 |
asl::Parameter<unsigned int> tout(500, "num_it_out", "number of iterations between outputs"); |
| 65 |
|
| 66 |
appParamsManager.load(argc, argv); |
| 67 |
|
| 68 |
std::cout << "Data initialization... " << flush; |
| 69 |
|
| 70 |
asl::SPDataWithGhostNodesACLData map0(asl::read(input.v(), 0)); |
| 71 |
// asl::Block block(size.v(), dx.v()); |
| 72 |
asl::Block block(map0->getInternalBlock()); |
| 73 |
dx.v() = block.dx*1e-3; |
| 74 |
|
| 75 |
dt.v() = 0.0001f; |
| 76 |
Param bulkModulusNum(bulkModulus.v()/rho.v()/dx.v()/dx.v()); |
| 77 |
Param shearModulusNum(shearModulus.v()/rho.v()/dx.v()/dx.v()); |
| 78 |
asl::AVec<FlT> gNum(g.v()/dx.v()); |
| 79 |
Param hydraulicConductivityNum(hydraulicConductivity.v()/dx.v()/dx.v()/dx.v()); |
| 80 |
|
| 81 |
cout << gNum << "; " << bulkModulusNum.v() << "; " << hydraulicConductivityNum.v() << endl; |
| 82 |
|
| 83 |
|
| 84 |
auto displacement(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u)); |
| 85 |
auto pressure(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 86 |
acl::initData(displacement->getEContainer(), acl::generateVEConstantN(3,0)); |
| 87 |
acl::initData(pressure->getEContainer(), acl::generateVEConstant(0)); |
| 88 |
|
| 89 |
// auto mapDF(asl::generateDFInBlock(block, 0)); |
| 90 |
// auto map(asl::generateDataContainer_SP(block, mapDF, 1u, acl::typeToTypeID<FlT>())); |
| 91 |
auto mapX(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 92 |
// initData(mapX->getEContainer(), map->getEContainer()); |
| 93 |
initData(mapX->getEContainer(), map0->getEContainer()*2.-1., acl::KERNEL_BASIC); |
| 94 |
|
| 95 |
asl::WriterVTKXML writer(appParamsManager.getDir() + "poroelastic"); |
| 96 |
writer.addVector("displacement", *displacement); |
| 97 |
writer.addScalars("pressure", *pressure); |
| 98 |
writer.addScalars("map", *mapX); |
| 99 |
// writer.write(); |
| 100 |
|
| 101 |
std::cout << "Finished" << endl; |
| 102 |
|
| 103 |
std::cout << "Numerics initialization... " << flush; |
| 104 |
|
| 105 |
auto elasticity(make_shared<asl::FDPoroElasticity>(displacement, |
| 106 |
pressure, |
| 107 |
acl::generateVEConstant(bulkModulusNum.v()), |
| 108 |
acl::generateVEConstant(shearModulusNum.v()), |
| 109 |
acl::generateVEConstant(hydraulicConductivityNum.v()), |
| 110 |
&asl::d3q15())); |
| 111 |
|
| 112 |
asl::Index2PositionACL i2p(displacement->getBlock(),acl::typeToTypeID<FlT>()); |
| 113 |
asl::AVec<> center(asl::AVec<>(displacement->getBlock().getSize())*.5 * |
| 114 |
displacement->getBlock().dx + |
| 115 |
displacement->getBlock().position); |
| 116 |
asl::SPDistanceFunction scf(asl::generateDFPlane(asl::AVec<>(g.v()),center)); |
| 117 |
|
| 118 |
auto force((1.-acl::sign(scf->getDistance(i2p.positionWithInit)))/2.* |
| 119 |
acl::generateVEConstant(gNum)); |
| 120 |
auto forceField(asl::generateDataContainer_SP(block, force, 1u)); |
| 121 |
|
| 122 |
elasticity->setForce(forceField->getSubContainer()); |
| 123 |
elasticity->init(); |
| 124 |
|
| 125 |
vector<asl::SPNumMethod> bcl; |
| 126 |
bcl.push_back(asl::generateBCZeroStress(elasticity, mapX)); |
| 127 |
asl::addBCRigidWall(bcl, elasticity, {asl::X0}); |
| 128 |
|
| 129 |
//!!!!!! addSliceZ(*bcRigidWall, block.getSize()[0]/2 + 1); return |
| 130 |
|
| 131 |
initAll(bcl); |
| 132 |
|
| 133 |
std::cout << "Finished" << endl; |
| 134 |
std::cout << "Computing..." << flush; |
| 135 |
asl::Timer timer; |
| 136 |
|
| 137 |
executeAll(bcl); |
| 138 |
|
| 139 |
writer.write(); |
| 140 |
|
| 141 |
timer.start(); |
| 142 |
for (unsigned int i(0); i < tsim.v(); ++i) |
| 143 |
{ |
| 144 |
elasticity->execute(); |
| 145 |
executeAll(bcl); |
| 146 |
if (!(i % tout.v())) |
| 147 |
writer.write(); |
| 148 |
} |
| 149 |
timer.stop(); |
| 150 |
|
| 151 |
cout << "Finished" << endl; |
| 152 |
|
| 153 |
cout << "Computation statistic:" << endl; |
| 154 |
cout << "Real Time = " << timer.realTime() << "; Processor Time = " |
| 155 |
<< timer.processorTime() << "; Processor Load = " |
| 156 |
<< timer.processorLoad() * 100 << "%" << endl; |
| 157 |
|
| 158 |
return 0; |
| 159 |
} |