00001 #include "vecincbc.h"
00002 #include "sfunctions.h"
00003
00004
00005 void VecIncBC::reinit(unsigned nBC,unsigned vectors_size)
00006 {
00007 _vectors_size=vectors_size;
00008 m_v.clear();
00009 m_v.reserve(nBC*vectors_size);
00010 this->reserve(nBC);
00011 }
00012
00013
00014
00015
00016 void VecIncBC::add_bc(Index faceIndex,Index nearCell,const VecDouble &bc)
00017 {
00018 for (Index i=0;i<_vectors_size;i++)
00019 m_v.push_back(bc(i));
00020 this->push_back(faceIndex,VecIncBCData(&(m_v.back())-_vectors_size +1,nearCell));
00021 }
00022
00023
00024
00025 void VecIncBC::set_bc_from_function(OrthoMesh &mesh,Function3D &f)
00026 {
00027 OrthoMesh::Face_It face = mesh.begin_face();
00028 OrthoMesh::Face_It end = mesh.end_face();
00029 Point3D P;
00030 VecDouble v(f.getImageDim());
00031 unsigned nBC=0;
00032 for (;face!=end;face++)
00033 {
00034 if (face->at_boundary())
00035 {
00036 face->barycenter(P);
00037 if (!f.isInDomain(P))
00038 continue;
00039 else
00040 nBC++;
00041 }
00042 }
00043 printf("Reinit BC to %u\n",nBC);
00044 reinit(nBC,f.getImageDim());
00045
00046 for (face=mesh.begin_face();face!=end;face++)
00047 {
00048 if (face->at_boundary())
00049 {
00050 face->barycenter(P);
00051 if (!f.isInDomain(P))
00052 continue;
00053 else
00054 {
00055 unsigned dim = f.getImageDim();
00056 for (unsigned j=0;j<dim;j++)
00057 v(j)=f(P,j);
00058 unsigned c1,c2;
00059 face->getValidCellIndices(c1,c2);
00060 add_bc(face->index(),c1,v);
00061 }
00062 }
00063 }
00064 }
00065
00066
00067 void VecIncBC::rewind()
00068 {
00069 assert(!m_v.empty());
00070 it=begin();
00071 }
00072
00073
00074
00075 bool VecIncBC::get_ref_bc(Index index, VecDoubleRef &vSw)
00076 {
00077 assert(vSw.size() == _vectors_size);
00078 VecIncBCData *data = it.inc_search(index);
00079 if (data)
00080 {
00081 vSw.setData(data->p);
00082 return true;
00083 }
00084 else
00085 return false;
00086
00087 }
00088
00089 bool VecIncBC::copy_bc(Index index, VecDouble &vSw)
00090 {
00091 assert(vSw.size() == _vectors_size);
00092 assert(vSw.is_owner());
00093 VecIncBCData *data = it.inc_search(index);
00094 if (data)
00095 {
00096 const double *pd=data->p;
00097 for (unsigned i=0;i<_vectors_size;i++)
00098 vSw(i)=pd[i];
00099 return true;
00100 }
00101 else
00102 return false;
00103
00104
00105 }
00106
00107
00108
00109 bool VecIncBC::has_bc(Index index)
00110 {
00111 return it.inc_search(index)!=NULL;
00112 }
00113
00114
00115 std::ostream& operator<< (std::ostream& out,VecIncBC &vbc)
00116 {
00117
00118 std::vector<VecIncBC::Node >::const_iterator it = vbc.m_list.begin();
00119 std::vector<VecIncBC::Node >::const_iterator itlast = vbc.m_list.end();
00120 itlast--;
00121 while(it != itlast)
00122 {
00123 out << it->index <<") " << "Near Cell" << it->data.nearCell << " Add: " << it->data.p << ": ";
00124 for (unsigned i=0;i<vbc._vectors_size;i++)
00125 {
00126 out << it->data.p[i] << " ";
00127 }
00128 out << std::endl;
00129 it++;
00130 }
00131 return out;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141 double* VecIncBC::get_bc_ptr(Index index)
00142 {
00143 VecIncBCData *data = it.inc_search(index);
00144 return (data) ? data->p : NULL;
00145 }