//====================================================================== // Function: dist_to_edge // Description: return the distance from the point to this edge // Author: sjowen // Date: 2/01 // Corrected by JFowler 5/03 //====================================================================== double CubitFacetEdge::dist_to_edge( const CubitVector &this_point, CubitVector &close_point, CubitBoolean &outside_edge ) { double dist = 0.0; CubitVector p0 = point(0)->coordinates(); CubitVector p1 = point(1)->coordinates(); CubitVector edge_vec( p1, p0 ); CubitVector point_vec( this_point, p0 ); double edge_length; edge_length = edge_vec.normalize(); double dist_on_edge = edge_vec % point_vec; if (dist_on_edge < 0.0e0) { close_point = p0; outside_edge = CUBIT_TRUE; } else if (dist_on_edge > edge_length) { close_point = p1; outside_edge = CUBIT_TRUE; } else { close_point = p0 - edge_vec * dist_on_edge; outside_edge = CUBIT_FALSE; } dist = close_point.distance_between( this_point ); return dist; }
void MultiAppVariableValueSamplePostprocessorTransfer::execute() { _console << "Beginning VariableValueSamplePostprocessorTransfer " << name() << std::endl; switch (_direction) { case TO_MULTIAPP: { FEProblemBase & from_problem = _multi_app->problemBase(); MooseVariable & from_var = from_problem.getVariable(0, _from_var_name); SystemBase & from_system_base = from_var.sys(); SubProblem & from_sub_problem = from_system_base.subproblem(); MooseMesh & from_mesh = from_problem.mesh(); std::unique_ptr<PointLocatorBase> pl = from_mesh.getPointLocator(); pl->enable_out_of_mesh_mode(); for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) { Real value = -std::numeric_limits<Real>::max(); { // Get the value of the variable at the point where this multiapp is in the master domain Point multi_app_position = _multi_app->position(i); std::vector<Point> point_vec(1, multi_app_position); // First find the element the hit lands in const Elem * elem = (*pl)(multi_app_position); if (elem && elem->processor_id() == from_mesh.processor_id()) { from_sub_problem.reinitElemPhys(elem, point_vec, 0); mooseAssert(from_var.sln().size() == 1, "No values in u!"); value = from_var.sln()[0]; } _communicator.max(value); } if (_multi_app->hasLocalApp(i)) _multi_app->appProblemBase(i).getPostprocessorValue(_postprocessor_name) = value; } break; } case FROM_MULTIAPP: { mooseError( "Can't transfer a variable value from a MultiApp to a Postprocessor in the Master."); break; } } _console << "Finished VariableValueSamplePostprocessorTransfer " << name() << std::endl; }
NumericType PostProcessedQuantities<NumericType>::component( const libMesh::FEMContext& context, unsigned int component, const libMesh::Point& p, libMesh::Real /*time*/ ) { // Check if the Elem is the same between the incoming context and the cached one. // If not, reinit the cached MultiphysicsSystem context if( &(context.get_elem()) != &(_multiphysics_context->get_elem()) ) { _multiphysics_context->pre_fe_reinit(*_multiphysics_sys,&context.get_elem()); _multiphysics_context->elem_fe_reinit(); } /* Optimization since we expect this function to be called many times with the same point. _prev_point initialized to something absurd so this should always be false the first time. */ if( _prev_point != p ) { _prev_point = p; std::vector<libMesh::Point> point_vec(1,p); this->_cache.clear(); _multiphysics_sys->compute_element_cache( *(this->_multiphysics_context), point_vec, this->_cache ); } return this->compute_quantities( component ); }
//====================================================================== // Function: proj_to_line // Description: project the point to a line defined by the edge // Author: sjowen // Date: 2/01 //====================================================================== CubitStatus CubitFacetEdge::proj_to_line( const CubitVector &this_point, CubitVector &proj_point ) { CubitStatus stat = CUBIT_SUCCESS; CubitVector p0 = point(0)->coordinates(); CubitVector p1 = point(1)->coordinates(); CubitVector edge_vec( p0,p1 ); CubitVector point_vec( p0, this_point ); edge_vec.normalize(); double dist_on_edge = edge_vec % point_vec; proj_point = p0 + (edge_vec * dist_on_edge); return stat; }
// Testing input vector with single point. TEST_F(PointVecTest, TestPointVecPushBack) { ps_ptr->push_back(new GeoLib::Point(0,0,0)); ps_ptr->push_back(new GeoLib::Point(1,0,0)); ps_ptr->push_back(new GeoLib::Point(0,1,0)); ps_ptr->push_back(new GeoLib::Point(0,0,1)); GeoLib::PointVec point_vec(name, ps_ptr); // Adding a new point with same coordinates changes nothing. point_vec.push_back(new GeoLib::Point(0,0,0)); point_vec.push_back(new GeoLib::Point(1,0,0)); point_vec.push_back(new GeoLib::Point(0,1,0)); point_vec.push_back(new GeoLib::Point(0,0,1)); ASSERT_EQ(std::size_t(4), point_vec.size()); }
int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); logog_cout->SetFormatter(*custom_format); TCLAP::CmdLine cmd("Converts TIN file into VTU file.", ' ', BaseLib::BuildInfo::git_describe); TCLAP::ValueArg<std::string> inArg("i", "input-tin-file", "the name of the file containing the input TIN", true, "", "string"); cmd.add(inArg); TCLAP::ValueArg<std::string> outArg("o", "output-vtu-file", "the name of the file the mesh will be written to", true, "", "string"); cmd.add(outArg); cmd.parse(argc, argv); INFO("reading the TIN file..."); const std::string tinFileName(inArg.getValue()); auto pnt_vec = std::unique_ptr<std::vector<GeoLib::Point*>>( new std::vector<GeoLib::Point*>); GeoLib::PointVec point_vec("SurfacePoints", std::move(pnt_vec)); std::unique_ptr<GeoLib::Surface> sfc(FileIO::TINInterface::readTIN(tinFileName, point_vec)); if (!sfc) return 1; INFO("TIN read: %d points, %d triangles", pnt_vec->size(), sfc->getNTriangles()); INFO("converting to mesh data"); std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::convertSurfaceToMesh(*sfc, BaseLib::extractBaseNameWithoutExtension(tinFileName), std::numeric_limits<double>::epsilon())); INFO("Mesh created: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); INFO("Write it into VTU"); FileIO::VtuInterface writer(mesh.get()); writer.writeToFile(outArg.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 0; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd( "Converts TIN file into VTU file.\n\n" "OpenGeoSys-6 software, version " + BaseLib::BuildInfo::git_describe + ".\n" "Copyright (c) 2012-2018, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', BaseLib::BuildInfo::git_describe); TCLAP::ValueArg<std::string> inArg("i", "input-tin-file", "the name of the file containing the input TIN", true, "", "string"); cmd.add(inArg); TCLAP::ValueArg<std::string> outArg("o", "output-vtu-file", "the name of the file the mesh will be written to", true, "", "string"); cmd.add(outArg); cmd.parse(argc, argv); INFO("reading the TIN file..."); const std::string tinFileName(inArg.getValue()); auto pnt_vec = std::make_unique<std::vector<GeoLib::Point*>>(); GeoLib::PointVec point_vec("SurfacePoints", std::move(pnt_vec)); std::unique_ptr<GeoLib::Surface> sfc( GeoLib::IO::TINInterface::readTIN(tinFileName, point_vec)); if (!sfc) return EXIT_FAILURE; INFO("TIN read: %d points, %d triangles", pnt_vec->size(), sfc->getNumberOfTriangles()); INFO("converting to mesh data"); std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::convertSurfaceToMesh(*sfc, BaseLib::extractBaseNameWithoutExtension(tinFileName), std::numeric_limits<double>::epsilon())); INFO("Mesh created: %d nodes, %d elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); INFO("Write it into VTU"); MeshLib::IO::VtuInterface writer(mesh.get()); writer.writeToFile(outArg.getValue()); return EXIT_SUCCESS; }
void MultiAppVariableValueSampleTransfer::execute() { _console << "Beginning VariableValueSampleTransfer " << name() << std::endl; switch (_direction) { case TO_MULTIAPP: { FEProblem & from_problem = _multi_app->problem(); MooseVariable & from_var = from_problem.getVariable(0, _from_var_name); SystemBase & from_system_base = from_var.sys(); SubProblem & from_sub_problem = from_system_base.subproblem(); MooseMesh & from_mesh = from_problem.mesh(); std::unique_ptr<PointLocatorBase> pl = from_mesh.getPointLocator(); for (unsigned int i=0; i<_multi_app->numGlobalApps(); i++) { Real value = -std::numeric_limits<Real>::max(); { // Get the value of the variable at the point where this multiapp is in the master domain Point multi_app_position = _multi_app->position(i); std::vector<Point> point_vec(1, multi_app_position); // First find the element the hit lands in const Elem * elem = (*pl)(multi_app_position); if (elem && elem->processor_id() == from_mesh.processor_id()) { from_sub_problem.reinitElemPhys(elem, point_vec, 0); mooseAssert(from_var.sln().size() == 1, "No values in u!"); value = from_var.sln()[0]; } _communicator.max(value); if (value == -std::numeric_limits<Real>::max()) mooseError("Transfer failed to sample point value at point: " << multi_app_position); } if (_multi_app->hasLocalApp(i)) { MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm()); // Loop over the master nodes and set the value of the variable System * to_sys = find_sys(_multi_app->appProblem(i).es(), _to_var_name); unsigned int sys_num = to_sys->number(); unsigned int var_num = to_sys->variable_number(_to_var_name); NumericVector<Real> & solution = _multi_app->appTransferVector(i, _to_var_name); MooseMesh & mesh = _multi_app->appProblem(i).mesh(); MeshBase::const_node_iterator node_it = mesh.localNodesBegin(); MeshBase::const_node_iterator node_end = mesh.localNodesEnd(); for (; node_it != node_end; ++node_it) { Node * node = *node_it; if (node->n_dofs(sys_num, var_num) > 0) // If this variable has dofs at this node { // The zero only works for LAGRANGE! dof_id_type dof = node->dof_number(sys_num, var_num, 0); solution.set(dof, value); } } solution.close(); _multi_app->appProblem(i).es().update(); // Swap back Moose::swapLibMeshComm(swapped); } } break; } case FROM_MULTIAPP: { mooseError("Doesn't make sense to transfer a sampled variable's value from a MultiApp!!"); break; } } _console << "Finished VariableValueSampleTransfer " << name() << std::endl; }