LCOV - code coverage report
Current view: top level - coupling/configurations - BoundaryForceConfiguration.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 38 63.2 %
Date: 2025-06-25 11:26:37 Functions: 2 6 33.3 %

          Line data    Source code
       1             : // Copyright (C) 2015 Technische Universitaet Muenchen
       2             : // This file is part of the Mamico project. For conditions of distribution
       3             : // and use, please see the copyright notice in Mamico's main folder, or at
       4             : // www5.in.tum.de/mamico
       5             : #ifndef _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_BOUNDARYFORCECONFIGURATION_H_
       6             : #define _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_BOUNDARYFORCECONFIGURATION_H_
       7             : 
       8             : #include "coupling/NoBoundaryForce.h"
       9             : #include "coupling/ZhouBoundaryForceController.h"
      10             : #include "coupling/interface/MDSolverInterface.h"
      11             : #include "tarch/configuration/Configuration.h"
      12             : #include "tarch/configuration/ParseConfiguration.h"
      13             : #include "tarch/la/Vector.h"
      14             : #include <iostream>
      15             : 
      16             : namespace coupling {
      17             : namespace configurations {
      18             : template <unsigned int dim> class BoundaryForceConfiguration;
      19             : }
      20             : } // namespace coupling
      21             : 
      22             : /** boundary force configuration
      23             :  *      @brief reads boundary force tag
      24             :  *      @tparam dim Number of dimensions; it can be 1, 2 or 3
      25             :  *  @author Philipp Neumann
      26             :  */
      27             : template <unsigned int dim> class coupling::configurations::BoundaryForceConfiguration : public tarch::configuration::Configuration {
      28             : public:
      29             :   /** boundary force types that are implemented.
      30             :    *    @enum BoundaryForceType
      31             :    */
      32             :   enum BoundaryForceType {
      33             :     ZHOU = 0 /**< ZHOU*/,
      34             :     NO_BOUNDARYFORCE = 1 /**< NO_BOUNDARYFORCE*/
      35             :   };
      36             : 
      37             :   /** Constructor, initializes the class  */
      38         336 :   BoundaryForceConfiguration() : _insertionType(NO_BOUNDARYFORCE), _density(0.0), _temperature(0.0), _isValid(true) {}
      39             : 
      40             :   /** Destructor */
      41         340 :   virtual ~BoundaryForceConfiguration() {}
      42             : 
      43             :   /** parseSubtag
      44             :    *    @param node
      45             :    */
      46           4 :   void parseSubtag(tinyxml2::XMLElement* node) {
      47           4 :     std::string value;
      48           4 :     tarch::configuration::ParseConfiguration::readStringMandatory(value, node, "type");
      49          28 :     const std::string boundaries[6] = {"west", "east", "south", "north", "bottom", "top"};
      50             : 
      51           4 :     if (value == "zhou-boundary-force") {
      52           4 :       _insertionType = ZHOU;
      53           0 :     } else if (value == "none") {
      54           0 :       _insertionType = NO_BOUNDARYFORCE;
      55             :     } else {
      56           0 :       std::cout << "ERROR coupling::BoundaryForceConfiguration: Wrong insertion type!" << std::endl;
      57           0 :       _isValid = false;
      58           0 :       exit(EXIT_FAILURE);
      59             :     }
      60             : 
      61             :     // for all boundary force types: read the sides at which boundary force
      62             :     // shall be applied this may not be useful for NO_BOUNDARYFORCE; however,
      63             :     // once read, the user can still use the flags, even in the NO_BOUNDARYFORCE
      64             :     // case, to e.g. determine a setup with boundary forcing using external
      65             :     // implementations
      66          28 :     for (unsigned int d = 0; d < 2 * dim; d++) {
      67          48 :       tarch::configuration::ParseConfiguration::readBoolMandatory(_boundary[d], node, boundaries[d]);
      68             :     }
      69             : 
      70           4 :     if (_insertionType == ZHOU) {
      71           4 :       tarch::configuration::ParseConfiguration::readDoubleMandatory(_density, node, "density");
      72           4 :       if (_density <= 0.0) {
      73           0 :         std::cout << "ERROR coupling::BoundaryForceConfiguration: density is "
      74             :                      "smaller than zero! Density="
      75           0 :                   << _density;
      76           0 :         _isValid = false;
      77           0 :         exit(EXIT_FAILURE);
      78             :       }
      79             : 
      80           4 :       tarch::configuration::ParseConfiguration::readDoubleMandatory(_temperature, node, "temperature");
      81           4 :       if (_temperature <= 0.0) {
      82           0 :         std::cout << "ERROR coupling::BoundaryForceConfiguration: temperature "
      83             :                      "is smaller than zero! Temperature="
      84           0 :                   << _temperature;
      85           0 :         _isValid = false;
      86           0 :         exit(EXIT_FAILURE);
      87             :       }
      88             :     }
      89          28 :   }
      90             : 
      91             :   /** Returns name of xml tag that is associated to the configuration.
      92             :    *    @return name of xml tag that is associated to the configuration
      93             :    */
      94           8 :   std::string getTag() const { return "boundary-force"; }
      95             : 
      96             :   /** checks if the configuration is valid. This operation usually fails, if
      97             :    *e.g.
      98             :    *    1. parseSubtag() hasn't been called, i.e. configuration has not been
      99             :    *used, or
     100             :    *  2. parseSubtag() failed due to a wrong file.
     101             :    *  3. If a tag ain't optional and parseSubtag() was not called (first case)
     102             :    *    @return _isValid
     103             :    */
     104           4 :   bool isValid() const { return _isValid; }
     105             : 
     106             :   /** Returns boundary force type.
     107             :    *    @return _insertionType
     108             :    */
     109             :   const BoundaryForceType& getBoundaryForceType() const { return _insertionType; }
     110             : 
     111             :   /** Returns boundary ??
     112             :    *    @return _boundary
     113             :    */
     114             :   const tarch::la::Vector<2 * dim, bool>& getBoundary() const { return _boundary; }
     115             : 
     116             :   /** Returns boundary force configuration.
     117             :    *    @tparam LinkedCell type of the cell
     118             :    *    @param mdSolverInterface
     119             :    *    @return boundary force config
     120             :    */
     121             :   template <class LinkedCell>
     122             :   coupling::BoundaryForceController<LinkedCell, dim>*
     123           4 :   interpreteConfiguration(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) const {
     124           4 :     if (_insertionType == ZHOU) {
     125             :       if (dim != 3) {
     126             :         std::cout << "ERROR "
     127             :                      "coupling::configurations::BoundaryForceConfiguration::"
     128             :                      "interpreteConfiguration(): Zhou boundary force only "
     129             :                      "valid in 3D!"
     130             :                   << std::endl;
     131             :         exit(EXIT_FAILURE);
     132             :       }
     133           0 :       return new coupling::ZhouBoundaryForceController<LinkedCell, dim>(_density, _temperature, _boundary, mdSolverInterface);
     134           4 :     } else if (_insertionType == NO_BOUNDARYFORCE) {
     135           4 :       return new coupling::NoBoundaryForce<LinkedCell, dim>(mdSolverInterface);
     136             :     }
     137             :     return NULL;
     138             :   }
     139             : 
     140             : protected:
     141           4 :   BoundaryForceConfiguration(BoundaryForceType insertionType, double density, double temperature, tarch::la::Vector<2 * dim, bool> boundary)
     142           4 :       : _insertionType(insertionType), _density(density), _temperature(temperature), _isValid(true) {}
     143             : 
     144             : private:
     145             :   BoundaryForceType _insertionType;
     146             :   double _density;
     147             :   double _temperature;
     148             :   tarch::la::Vector<2 * dim, bool> _boundary;
     149             :   bool _isValid;
     150             : };
     151             : 
     152             : #endif // _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_BOUNDARYFORCECONFIGURATION_H_

Generated by: LCOV version 1.14