MFEM  v4.6.0
Finite element discretization library
transformation.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details
11 
12 #include "transformation.hpp"
13 #include <cmath>
14 #include <functional>
15 
16 namespace mfem
17 {
18 namespace spde
19 {
20 
21 // ---------------------------------------------------------------------------
22 // Functions for TransformedCoefficient interface
23 // ---------------------------------------------------------------------------
24 
25 /// This function effectively implements equation 19 of the paper (see header).
26 /// `\Phi [y(x)]`
27 double TransformToUniform(double x) { return std::erfc(-x / std::sqrt(2)) / 2; }
28 
29 double ApplyLevelSetAtZero(double x) { return x >= 0 ? 1 : 0; }
30 
31 // ---------------------------------------------------------------------------
32 // Member functions for GFTransformer class
33 // ---------------------------------------------------------------------------
34 
36 {
37  GridFunctionCoefficient gf_coeff(&x);
38  ConstantCoefficient factor(max_ - min_);
39  ConstantCoefficient summand(min_);
40  TransformedCoefficient transformation_coeff(&gf_coeff, TransformToUniform);
41  ProductCoefficient product_coeff(transformation_coeff, factor);
42  SumCoefficient sum_coeff(product_coeff, summand);
43  ParGridFunction xx(x);
44  xx.ProjectCoefficient(sum_coeff);
45  x = xx;
46 }
47 
49 {
50  ConstantCoefficient offset(offset_);
51  ParGridFunction xx(x);
52  xx.ProjectCoefficient(offset);
53  x += xx;
54 }
55 
56 void ScaleTransformer::Transform(ParGridFunction &x) const { x *= scale_; }
57 
59 {
60  GridFunctionCoefficient gf_coeff(&x);
61  ConstantCoefficient threshold(-threshold_);
62  SumCoefficient sum_coeff(gf_coeff, threshold);
63  TransformedCoefficient transformation_coeff(&sum_coeff, ApplyLevelSetAtZero);
64  ParGridFunction xx(x);
65  xx.ProjectCoefficient(transformation_coeff);
66  x = xx;
67 }
68 
69 } // namespace spde
70 } // namespace mfem
A coefficient that depends on 1 or 2 parent coefficients and a transformation rule represented by a C...
A coefficient that is constant across space and time.
Definition: coefficient.hpp:84
Scalar coefficient defined as the product of two scalar coefficients or a scalar and a scalar coeffic...
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Definition: pgridfunc.cpp:561
void Transform(ParGridFunction &x) const override
Offsets a grid function by an constant offset.
void Transform(ParGridFunction &x) const override
double TransformToUniform(double x)
double ApplyLevelSetAtZero(double x)
void Transform(ParGridFunction &x) const override
Scales a grid function by an constant factor.
Class for parallel grid function.
Definition: pgridfunc.hpp:32
Scalar coefficient defined as the linear combination of two scalar coefficients or a scalar and a sca...
void Transform(ParGridFunction &x) const override
Applies a level set to the GridFunction.