Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "CutMeshByPlaneGenerator.h" 11 : 12 : // C++ includes 13 : #include <cmath> 14 : 15 : registerMooseObject("MooseApp", CutMeshByPlaneGenerator); 16 : 17 : InputParameters 18 14393 : CutMeshByPlaneGenerator::validParams() 19 : { 20 14393 : InputParameters params = CutMeshByLevelSetGeneratorBase::validParams(); 21 : 22 14393 : params.addRequiredParam<Point>("plane_point", "A point on the plane."); 23 14393 : params.addRequiredParam<Point>("plane_normal", "The normal vector of the plane."); 24 : 25 14393 : params.addClassDescription( 26 : "This CutMeshByPlaneGenerator object is designed to trim the input mesh by removing all the " 27 : "elements on one side of a given plane with special processing on the elements crossed by " 28 : "the cutting plane to ensure a smooth cross-section. The output mesh only consists of TET4 " 29 : "elements."); 30 : 31 14393 : return params; 32 0 : } 33 : 34 64 : CutMeshByPlaneGenerator::CutMeshByPlaneGenerator(const InputParameters & parameters) 35 : : CutMeshByLevelSetGeneratorBase(parameters), 36 64 : _plane_point(getParam<Point>("plane_point")), 37 128 : _plane_normal(getParam<Point>("plane_normal").unit()) 38 : { 39 : // Translate the plane point and plane normal to the form of the level set function 40 64 : _func_level_set = std::make_shared<SymFunction>(); 41 : // set FParser internal feature flags 42 64 : setParserFeatureFlags(_func_level_set); 43 : // The plane is (x - x0) * n_x + (y - y0) * n_y + (z - z0) * n_z = 0 44 64 : std::stringstream level_set_ss; 45 : // Let's be conservative about precision here 46 64 : level_set_ss << std::fixed << std::setprecision(15) << _plane_normal(0) << "*(x-" 47 64 : << _plane_point(0) << ") + " << _plane_normal(1) << "*(y-" << _plane_point(1) 48 64 : << ") + " << _plane_normal(2) << "*(z-" << _plane_point(2) << ")"; 49 : 50 : // VERY unlikely to reach this point because we know what we are doing 51 : // But just in case 52 64 : if (_func_level_set->Parse(level_set_ss.str(), "x,y,z") >= 0) 53 0 : mooseError("The given plane_point and plane_normal lead to invalid level set.\n", 54 0 : _func_level_set, 55 : "\nin CutMeshByPlaneGenerator ", 56 0 : name(), 57 : ".\n", 58 0 : _func_level_set->ErrorMsg()); 59 64 : _func_params.resize(3); 60 64 : }