00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "VoltageInterpolaterOntoMechanicsMesh.hpp"
00030
00031 template<unsigned DIM>
00032 VoltageInterpolaterOntoMechanicsMesh<DIM>::VoltageInterpolaterOntoMechanicsMesh(
00033 TetrahedralMesh<DIM,DIM>& rElectricsMesh,
00034 QuadraticMesh<DIM>& rMechanicsMesh,
00035 std::string directory,
00036 std::string inputFileNamePrefix)
00037 {
00038
00039 Hdf5DataReader reader(directory,inputFileNamePrefix);
00040
00041 unsigned num_timesteps = reader.GetUnlimitedDimensionValues().size();
00042
00043
00044 FineCoarseMeshPair<DIM> mesh_pair(rElectricsMesh, rMechanicsMesh);
00045 mesh_pair.SetUpBoxesOnFineMesh();
00046 mesh_pair.ComputeFineElementsAndWeightsForCoarseNodes(true);
00047 assert(mesh_pair.rGetElementsAndWeights().size()==rMechanicsMesh.GetNumNodes());
00048
00049
00050 Hdf5DataWriter* p_writer = new Hdf5DataWriter(*rMechanicsMesh.GetDistributedVectorFactory(),
00051 directory,
00052 "voltage_mechanics_mesh",
00053 false,
00054 false);
00055
00056 p_writer->DefineFixedDimension( rMechanicsMesh.GetNumNodes() );
00057 int voltage_column_id = p_writer->DefineVariable("V","mV");
00058 p_writer->DefineUnlimitedDimension("Time","msecs");
00059 p_writer->EndDefineMode();
00060
00061
00062 DistributedVectorFactory factory(rElectricsMesh.GetNumNodes());
00063 Vec voltage = factory.CreateVec();
00064 std::vector<double> interpolated_voltages(rMechanicsMesh.GetNumNodes());
00065 Vec voltage_coarse = NULL;
00066
00067 for(unsigned time_step=0; time_step<num_timesteps; time_step++)
00068 {
00069
00070 reader.GetVariableOverNodes(voltage, "V", time_step);
00071 ReplicatableVector voltage_repl(voltage);
00072
00073
00074 for(unsigned i=0; i<mesh_pair.rGetElementsAndWeights().size(); i++)
00075 {
00076 double interpolated_voltage = 0;
00077
00078 Element<DIM,DIM>& element = *(rElectricsMesh.GetElement(mesh_pair.rGetElementsAndWeights()[i].ElementNum));
00079 for(unsigned node_index = 0; node_index<element.GetNumNodes(); node_index++)
00080 {
00081 unsigned global_node_index = element.GetNodeGlobalIndex(node_index);
00082 interpolated_voltage += voltage_repl[global_node_index]*mesh_pair.rGetElementsAndWeights()[i].Weights(node_index);
00083 }
00084
00085 interpolated_voltages[i] = interpolated_voltage;
00086 }
00087
00088 if(voltage_coarse!=NULL)
00089 {
00090 VecDestroy(voltage_coarse);
00091 }
00092 voltage_coarse = PetscTools::CreateVec(interpolated_voltages);
00093
00094
00095 p_writer->PutUnlimitedVariable(time_step);
00096 p_writer->PutVector(voltage_column_id, voltage_coarse);
00097 p_writer->AdvanceAlongUnlimitedDimension();
00098 }
00099
00100 if(voltage_coarse!=NULL)
00101 {
00102 VecDestroy(voltage);
00103 VecDestroy(voltage_coarse);
00104 }
00105
00106
00107 delete p_writer;
00108
00109
00110
00111
00112 std::string config_directory = HeartConfig::Instance()->GetOutputDirectory();
00113 HeartConfig::Instance()->SetOutputDirectory(directory);
00114 Hdf5ToCmguiConverter<DIM,DIM> converter(directory,
00115 "voltage_mechanics_mesh",
00116 &rMechanicsMesh,
00117 false);
00118 HeartConfig::Instance()->SetOutputDirectory(config_directory);
00119 }
00120
00122
00124
00125 template class VoltageInterpolaterOntoMechanicsMesh<1>;
00126 template class VoltageInterpolaterOntoMechanicsMesh<2>;
00127 template class VoltageInterpolaterOntoMechanicsMesh<3>;