inline typename array_nd<T, S>::create_new cat( size_t dim, const array<array_nd<T, S> >& a) { for (size_t i = 0; i < a.length() - 1; i++) { CHECK (a[i].ndims() == a[i + 1].ndims(), eshape()); for (size_t j = 0; j < a[i].ndims(); j++) if (j != dim) { CHECK(a[i].size_nd()[j] == a[i + 1].size_nd()[j], eshape()); } } CHECK(dim < a[0].ndims(), edims()); CHECK(dim >= 0, edims()); size_array sz(a[0].ndims()); for (size_t i = 0; i < a[0].ndims(); i++) sz[i] = a[0].size_nd()[i]; sz[dim] = 0; for (size_t j = 0; j < a.length(); j++) sz[dim] += a[j].size_nd()[dim]; typename array_nd<T, S>::create_new c(sz); size_t offs = 0; for (size_t j = 0; j < a.length(); j++) { array<index_array> indx(a[j].ndims()); for (size_t i = 0; i < a[j].ndims(); i++) indx[i] = size_range((i == dim) ? offs : 0, a[j].size_nd()[i] - 1 + ((i == dim) ? offs : 0)); offs += a[j].size_nd()[dim]; c(indx) = a[j]; } return c; }
inline array_nd<T> cat(size_t dim, const array_nd<T, S1>& a1, const array_nd<T, S2>& a2, const array_nd<T, S3>& a3) { CHECK(dim < a1.ndims(), edims()); CHECK(dim >= 0, edims()); CHECK (a1.ndims() == a2.ndims(), eshape()); CHECK (a2.ndims() == a3.ndims(), eshape()); for (size_t j = 0; j < a1.ndims(); j++) if (j != dim) { CHECK(a1.size_nd()[j] == a2.size_nd()[j], eshape()); CHECK(a2.size_nd()[j] == a3.size_nd()[j], eshape()); } size_array sz(a1.size()); sz[dim] = a1.size_nd(dim); sz[dim] += a2.size_nd(dim); sz[dim] += a3.size_nd(dim); array_nd<T> c(sz); array<index_array> indx(a1.ndims(), index_all()); indx[dim] = size_range(0, a1.size_nd(dim) - 1); c(indx) = a1; indx[dim] = size_range(indx[dim].last + 1, indx[dim].last + a2.size_nd(dim)); c(indx) = a2; indx[dim] = size_range(indx[dim].last + 1, indx[dim].last + a3.size_nd(dim)); c(indx) = a3; return c; }
typename array_nd<T, S>::create_new reshape( const array_nd<T, S>& src, const array<size_t, D>& sz) { CHECK (src.length() == prod(sz), eshape()); return typename array_nd<T, S>::create_new(sz, src); }
derived_type& assign_array(const ret<A>& o) { CHECK(to_array().length() == o.length(), eshape()); // users guide: is you have a compiler error here it probably means that // you are calling assign_array with something that is not an ivl array. to_array().derived().swap(o.ret_base()); return to_array().derived(); }
derived_type& assign_array(const A& o) { CHECK(to_array().length() == o.length(), eshape()); // users guide: is you have a compiler error here it probably means that // you are calling assign_array with something that is not an ivl array. loop_on<loops::assign_copy_class>(to_array().derived(), o); return to_array().derived(); }
array_nd<T> repmat(const array_nd<T>& a, const size_array& sz) { CHECK (sz.length() <= a.ndims(), eshape()); array_nd<T> c(a); for (size_t i = 0; i < sz.length(); i++) { array_nd<T> tmp(c); for (size_t j = 0; j < sz[i]; j++) c = cat<T>(i, c, tmp); } return c; }
typename array_nd<T, S>::create_new permute( const array_nd<T, S>& a, const array<size_t, D>& sz) { CHECK (a.ndims() == sz.length(), eshape()); array<size_t, stack<3> > newsz(a.ndims()); for (size_t i = 0; i < a.ndims(); i++) newsz[i] = a.size_nd()[sz[i] - 1]; return reshape(a, newsz); }
void TraceTraceBoundary<D> :: T_CalcElementMatrix (const FiniteElement & base_fel, const ElementTransformation & eltrans, FlatMatrix<SCAL> elmat, LocalHeap & lh) const { const CompoundFiniteElement & cfel // product space = dynamic_cast<const CompoundFiniteElement&> (base_fel); // get surface elements const ScalarFiniteElement<D-1> & fel_u = // u space dynamic_cast<const ScalarFiniteElement<D-1>&> (cfel[GetInd1()]); const ScalarFiniteElement<D-1> & fel_e = // u space dynamic_cast<const ScalarFiniteElement<D-1>&> (cfel[GetInd2()]); elmat = SCAL(0.0); IntRange ru = cfel.GetRange(GetInd1()); IntRange re = cfel.GetRange(GetInd2()); int ndofu = ru.Size(); int ndofe = re.Size(); FlatMatrix<SCAL> submat(ndofe, ndofu, lh); submat = SCAL(0.0); FlatVector<> ushape(fel_u.GetNDof(), lh); FlatVector<> eshape(fel_e.GetNDof(), lh); const IntegrationRule ir(fel_u.ElementType(), fel_u.Order() + fel_e.Order()); for (int i = 0 ; i < ir.GetNIP(); i++) { MappedIntegrationPoint<D-1,D> mip(ir[i], eltrans); SCAL cc = coeff_c -> T_Evaluate<SCAL>(mip); fel_u.CalcShape (ir[i], ushape); fel_e.CalcShape (ir[i], eshape); // [ndofe x 1] [1 x ndofu] submat += (cc*mip.GetWeight()) * eshape * Trans(ushape); } elmat.Rows(re).Cols(ru) += submat; if (GetInd1() != GetInd2()) elmat.Rows(ru).Cols(re) += Conj(Trans(submat)); }
void EyeEye<D>::T_CalcElementMatrix (const FiniteElement & base_fel, const ElementTransformation & eltrans, FlatMatrix<SCAL> elmat, LocalHeap & lh) const { const CompoundFiniteElement & cfel // product space = dynamic_cast<const CompoundFiniteElement&> (base_fel); const ScalarFiniteElement<D> & fel_u = // u space dynamic_cast<const ScalarFiniteElement<D>&> (cfel[GetInd1()]); const ScalarFiniteElement<D> & fel_e = // e space dynamic_cast<const ScalarFiniteElement<D>&> (cfel[GetInd2()]); elmat = SCAL(0.0); IntRange ru = cfel.GetRange(GetInd1()); IntRange re = cfel.GetRange(GetInd2()); int ndofe = re.Size(); int ndofu = ru.Size(); Vector<> ushape(ndofu); Vector<> eshape(ndofe); ELEMENT_TYPE eltype = fel_u.ElementType(); const IntegrationRule & ir = SelectIntegrationRule(eltype, fel_u.Order()+fel_e.Order()); FlatMatrix<SCAL> submat(ndofe,ndofu,lh); submat = SCAL(0.0); for(int k=0; k<ir.GetNIP(); k++) { MappedIntegrationPoint<D,D> mip (ir[k],eltrans); fel_u.CalcShape( ir[k], ushape ); fel_e.CalcShape( ir[k], eshape ); SCAL fac = (coeff_a -> T_Evaluate<SCAL>(mip))* mip.GetWeight() ; // [ndofe x D] * [D x ndofu] submat += fac * eshape * Trans(ushape) ; } elmat.Rows(re).Cols(ru) += submat; if (GetInd1() != GetInd2()) elmat.Rows(ru).Cols(re) += Conj(Trans(submat)); }
void RobinVolume<D> :: T_CalcElementMatrix (const FiniteElement & base_fel, const ElementTransformation & eltrans, FlatMatrix<SCAL> elmat, LocalHeap & lh) const { ELEMENT_TYPE eltype = base_fel.ElementType(); const CompoundFiniteElement & cfel // product space = dynamic_cast<const CompoundFiniteElement&> (base_fel); // note how we do NOT refer to D-1 elements here: const ScalarFiniteElement<D> & fel_u = // u space dynamic_cast<const ScalarFiniteElement<D>&> (cfel[GetInd1()]); const ScalarFiniteElement<D> & fel_e = // e space dynamic_cast<const ScalarFiniteElement<D>&> (cfel[GetInd2()]); elmat = SCAL(0); IntRange ru = cfel.GetRange(GetInd1()); IntRange re = cfel.GetRange(GetInd2()); int ndofe = re.Size(); int ndofu = ru.Size(); FlatVector<> ushape(fel_u.GetNDof(), lh); FlatVector<> eshape(fel_e.GetNDof(), lh); FlatMatrix<SCAL> submat(ndofe,ndofu,lh); submat = SCAL(0); int nfacet = ElementTopology::GetNFacets(eltype); Facet2ElementTrafo transform(eltype); FlatVector< Vec<D> > normals = ElementTopology::GetNormals<D>(eltype); const MeshAccess & ma = *(const MeshAccess*)eltrans.GetMesh(); Array<int> fnums, sels; ma.GetElFacets (eltrans.GetElementNr(), fnums); for (int k = 0; k < nfacet; k++) { ma.GetFacetSurfaceElements (fnums[k], sels); // if interior element, then do nothing: if (sels.Size() == 0) continue; // else: Vec<D> normal_ref = normals[k]; ELEMENT_TYPE etfacet=ElementTopology::GetFacetType(eltype, k); IntegrationRule ir_facet(etfacet, fel_e.Order()+fel_u.Order()); // map the facet integration points to volume reference elt ipts IntegrationRule & ir_facet_vol = transform(k, ir_facet, lh); // ... and further to the physical element MappedIntegrationRule<D,D> mir(ir_facet_vol, eltrans, lh); for (int i = 0 ; i < ir_facet_vol.GetNIP(); i++) { SCAL val = coeff_c->T_Evaluate<SCAL> (mir[i]); // this is contrived to get the surface measure in "len" Mat<D> inv_jac = mir[i].GetJacobianInverse(); double det = mir[i].GetMeasure(); Vec<D> normal = det * Trans (inv_jac) * normal_ref; double len = L2Norm (normal); val *= len * ir_facet[i].Weight(); fel_u.CalcShape (ir_facet_vol[i], ushape); fel_e.CalcShape (ir_facet_vol[i], eshape); submat += val * eshape * Trans(ushape); } } elmat.Rows(re).Cols(ru) += submat; if (GetInd1() != GetInd2()) elmat.Rows(ru).Cols(re) += Conj(Trans(submat)); }