void MovingMeshFB::readDomain(const std::string& filename) { int i, j, k, l, l0, l1; double d; readData(filename); index.resize(n_geometry(0)); n_interior_node = 0; n_boundary_node = 0; for (i = 0;i < n_geometry(0);i ++) { Assert(geometry(0,i).vertex(0) == i, ExcInternalError()); if (geometry(0, i).boundaryMark() != 0) index[i] = n_boundary_node ++; else index[i] = n_interior_node ++; } interior_node_index.resize(n_interior_node); boundary_node_index.resize(n_boundary_node); for (i = 0,j = 0, k = 0;i < n_geometry(0);i ++) { if (geometry(0, i).boundaryMark() != 0) boundary_node_index[j ++] = i; else interior_node_index[k ++] = i; } logical_node.resize(n_geometry(0)); move_direction.resize(n_geometry(0)); logical_move_direction.resize(n_geometry(0)); monitor().resize(n_geometry(2)); std::vector<int> n_coupling_node(n_geometry(0), 0); for (i = 0;i < n_geometry(1);i ++) { n_coupling_node[geometry(1,i).vertex(0)] ++; n_coupling_node[geometry(1,i).vertex(1)] ++; } int n_max_coupling_node = *std::max_element(n_coupling_node.begin(), n_coupling_node.end()); n_max_coupling_node ++; spM.reinit(n_interior_node, n_interior_node, n_max_coupling_node); spN.reinit(n_interior_node, n_boundary_node, n_max_coupling_node); for (i = 0;i < n_geometry(2);i ++) { for (j = 0;j < 3;j ++) { l0 = geometry(2,i).vertex(j); if (geometry(0,l0).boundaryMark() == 0) { for (k = 0;k < 3;k ++) { l1 = geometry(2,i).vertex(k); if (geometry(0,l1).boundaryMark()) spN.add(index[l0], index[l1]); else spM.add(index[l0], index[l1]); } } } } spM.compress(); spN.compress(); getLogicalMesh(); }
double Kou_Density<dim>::value(const Point<dim> &p_, const unsigned int component) const { Assert (component == 0, ExcInternalError()); if (p_[ax]>0) return p*lambda*lambda_plus*exp(-lambda_plus*p_[ax]); else return (1-p)*lambda*lambda_minus*exp(lambda_minus*p_[ax]); }
double armijo( const Functional& f, const double theta, const double alpha, const double beta ) { Assert(alpha < 1.0, ExcInternalError()); Assert(beta < 1.0, ExcInternalError()); std::map<int, double> fs; // Make a function that memoizes values of the objective functional so // that we avoid repeating expensive computations. const auto F = [&](const int k) { if (fs.find(k) != fs.end()) return fs[k]; fs[k] = f(std::pow(beta, k)); return fs[k]; }; int k = 1; const double f0 = f(0); while (true) { bool decreasing = F(k) - f0 <= std::pow(beta, k) * alpha * theta; bool curvature = F(k - 1) - f0 > std::pow(beta, k - 1) * alpha * theta; if (decreasing and curvature) return std::pow(beta, k); if (decreasing) k -= 1; if (curvature) k += 1; } return 0; }
void Kou_Density<dim>::value_list(const std::vector<Point<dim> > &points, std::vector<double> &values, const unsigned int component) const { Assert (values.size() == points.size(), ExcDimensionMismatch (values.size(), points.size())); Assert (component == 0, ExcInternalError()); const unsigned int n_points=points.size(); for (unsigned int i=0;i<n_points;++i) if (points[i][ax]>0) values[i]=p*lambda*lambda_plus*exp(-lambda_plus*points[i][ax]); else values[i]=(1-p)*lambda*lambda_minus*exp(lambda_minus*points[i][ax]); }
void FEMFunction<value_type, DIM>::writeEasyMeshData(const std::string& filename) { femSpace().mesh().writeEasyMesh(filename); std::ofstream os((filename + ".dat").c_str()); os.precision(12); os.setf(std::ios::fixed, std::ios::floatfield); FEMSpace<value_type,DIM>& fem_space = femSpace(); Mesh<DIM,DIM>& mesh = fem_space.mesh(); int n_node = mesh.n_point(); std::vector<int> count(n_node, 0); std::vector<value_type> val(n_node, vector_zero); int i, j, k; FEMSpace<value_type,DIM>::ElementIterator the_element = fem_space.beginElement(); FEMSpace<value_type,DIM>::ElementIterator end_element = fem_space.endElement(); for (; the_element != end_element; the_element ++) { GeometryBM& geo = the_element->geometry(); for (i = 0; i < geo.n_vertex(); i ++) { k = mesh.geometry(0, geo.vertex(i)).vertex(0); count[k] += 1; value_type v = value(mesh.point(k), *the_element); for (j = 0; j < vector_length; j ++) val[geo.vertex(i)][j] += v[j]; } } for (i = 0; i < n_node; i ++) { Assert(count[i] > 0, ExcInternalError()); for (j = 0; j < vector_length; j ++) val[i][j] /= count[i]; } for (i = 0; i < n_node; i ++) { for (j = 0; j < vector_length; j ++) { os << val[i][j] << "\t"; } os << "\n"; } os.close(); };
void FEMFunction<value_type, DIM>::writeOpenDXData(const std::string& filename, int flag) const { std::ofstream os(filename.c_str()); os.precision(12); os.setf(std::ios::fixed, std::ios::floatfield); const FEMSpace<value_type,DIM>& fem_space = femSpace(); const Mesh<DIM,DIM>& mesh = fem_space.mesh(); int n_node = mesh.n_point(); std::vector<int> count(n_node, 0); std::vector<value_type> val(n_node, vector_zero); int i, j, k; FEMSpace<value_type,DIM>::ConstElementIterator the_element = fem_space.beginElement(); FEMSpace<value_type,DIM>::ConstElementIterator end_element = fem_space.endElement(); for (; the_element != end_element; the_element ++) { const GeometryBM& geo = the_element->geometry(); for (i = 0; i < geo.n_vertex(); i ++) { k = mesh.geometry(0, geo.vertex(i)).vertex(0); count[k] += 1; value_type v = value(mesh.point(k), *the_element); for (j = 0; j < vector_length; j ++) val[geo.vertex(i)][j] += v[j]; } } for (i = 0; i < n_node; i ++) { Assert(count[i] > 0, ExcInternalError()); for (j = 0; j < vector_length; j ++) val[i][j] /= count[i]; } os << "object 1 class array type float rank 1 shape 2 item " << n_node << " data follows\n"; for (i = 0; i < n_node; i ++) { os << mesh.point(i) << "\n"; } int n_element = mesh.n_geometry(2); for (i = 0, j = 0; i < n_element; i ++) { switch (mesh.geometry(DIM,i).n_vertex()) { case 3: j += 1; break; case 4: j += 2; break; default: Assert(false, ExcInternalError()); } } os << "\nobject 2 class array type int rank 1 shape 3 item " << j << " data follows\n"; for (i = 0; i < n_element; i ++) { switch (mesh.geometry(DIM,i).n_vertex()) { case 3: os << mesh.geometry(0, mesh.geometry(2,i).vertex(0)).vertex(0) << "\t" << mesh.geometry(0, mesh.geometry(2,i).vertex(1)).vertex(0) << "\t" << mesh.geometry(0, mesh.geometry(2,i).vertex(2)).vertex(0) << "\t\n"; break; case 4: os << mesh.geometry(0, mesh.geometry(2,i).vertex(0)).vertex(0) << "\t" << mesh.geometry(0, mesh.geometry(2,i).vertex(1)).vertex(0) << "\t" << mesh.geometry(0, mesh.geometry(2,i).vertex(2)).vertex(0) << "\t\n"; os << mesh.geometry(0, mesh.geometry(2,i).vertex(0)).vertex(0) << "\t" << mesh.geometry(0, mesh.geometry(2,i).vertex(2)).vertex(0) << "\t" << mesh.geometry(0, mesh.geometry(2,i).vertex(3)).vertex(0) << "\t\n"; break; default: Assert(false, ExcInternalError()); } } os << "attribute \"element type\" string \"triangles\"\n" << "attribute \"ref\" string \"positions\"\n\n"; os << "object 3 class array type float rank 1 shape " << vector_length << " item " << n_node << " data follows\n"; for (i = 0; i < n_node; i ++) { for (j = 0; j < vector_length; j ++) { os << val[i][j] << "\t"; } os << "\n"; } os << "attribute \"dep\" string \"positions\"\n\n"; os << "object \"FEMFunction-2d\" class field\n" << "component \"positions\" value 1\n" << "component \"connections\" value 2\n" << "component \"data\" value 3\n" << "end\n"; os.close(); };