ANSYS-Maxwell2D coaxial cable electromagnetic field simulation report complete and detailed version

The electromagnetic field course is abstract in theory and complicated in mathematical calculations. Introducing ANSYS software into the teaching, using finite element analysis method, through the simulation design of typical electromagnetic fields, and simulating the characteristics of electromagnetic fields, effectively combining theory and practice, can strengthen our understanding of electromagnetic fields And application. This paper selects the typical electromagnetic field of the coaxial cable for analysis, uses ANSYS-Maxwell software to carry out 2D modeling and finite element analysis, and obtains the distribution characteristics and laws of its stable magnetic field and electric field.

File: n459.com/file/25127180-478939902

The following are irrelevant:

-------------------------------------------Dividing line----- ----------------------------------------

JAVA enumeration is more useful than you think!

I often find myself using enumerations in Java to represent a set of potential values ​​for an object.

The ability to determine what values ​​a type can have at compile time is a powerful ability that provides structure and meaning to the code.

When I first learned about enumerations, I thought they were just a tool for naming constants and could easily be replaced by the static constant string ENUM_VAL_NAME.

Then I found out that I was wrong. Facts have proved that Java enumeration has quite advanced features, which can make the code clean, not prone to errors, and powerful.

Let us take a look at some of the advanced enumeration features in Java and how to use these features to make the code simpler and more readable.

Enumerations are classes!
In Java, enumeration is a subclass of Object. Let's look at the base class of all enums, Enum (modified for brevity).

public abstract class Enum<E extends Enum>
implements Constable, Comparable, Serializable {
private final String name;

public final String name() {
return name;
}

private final int ordinal;

public final int ordinal() {
return ordinal;
}

protected Enum(String name, int ordinal) {
this.name = name;
this.ordinal = ordinal;
}

public String toString() {
return name;
}

public final boolean equals(Object other) {
return this==other;
}

public final int hashCode() {
return super.hashCode();
}

public final int compareTo(E o) {
Enum<?> other = (Enum<?>)o;
Enum self = this;
if (self.getClass() != other.getClass() && // optimization
self.getDeclaringClass() != other.getDeclaringClass())
throw new ClassCastException();
return self.ordinal - other.ordinal;
}
}

As we can see, this is basically just a regular abstract class with two fields, name and ordinal.

So enumerations are all classes, so they have many characteristics of regular classes.

We can provide instance methods, constructors, and fields for enumerations. We can override toString(), but not hashCode() or equals(Object other).

Next we look at our enumeration example, Operation

enum Operation {
ADD,
SUBTRACT,
MULTIPLY
}

This enumeration indicates that an Operation can be performed on two values ​​and will produce a result. Regarding how to implement this feature, your initial idea may be to use the switch statement as follows:

public int apply(Operation operation, int arg1, int arg2) {
switch(operation) {
case ADD:
return arg1 + arg2;
case SUBTRACT:
return arg1 - arg2;
case MULTIPLY:
return arg1 * arg2;
default:
throw new UnsupportedOperationException();
}
}

Of course, there will be some problems in this way.

The first problem is that if we add a new operation to our enum Operation, the compiler will not notify us that the switch cannot handle the new operation correctly.

To make matters worse, if a lazy developer copies or rewrites the code in another class, we may not be able to update it.

The second problem is the default default, which is necessary in every program, although we know that it will never happen in the correct code.

This is because the Java compiler knows the first problem above and wants to make sure that we can deal with adding new enumerations to Operation without knowing it.

Fortunately, Java 8 uses functional programming to provide us with a clean solution.

Function enumeration implementation
Because enumeration is a class, we can create an enumeration field to store the function that performs the operation.

But before we find a solution, let's take a look at some refactorings.

First, let's put the switch in the enum class.

enum Operation {
ADD,
SUBTRACT,
MULTIPLY;

public static int apply(Operation operation, int arg1, int arg2) {
switch(operation) {
case ADD:
return arg1 + arg2;
case SUBTRACT:
return arg1 - arg2;
case MULTIPLY:
return arg1 * arg2;
default:
throw new UnsupportedOperationException();
}
}
}

We can do this: Operation.apply(Operation.ADD, 2, 3);

Because we are now calling the method from Operation, we can change it to an instance method and use this instead of using Operation.apply() to implement it as follows:

public int apply(int arg1, int arg2) {
switch(this) {
case ADD:
return arg1 + arg2;
case SUBTRACT:
return arg1 - arg2;
case MULTIPLY:
return arg1 * arg2;
default:
throw new UnsupportedOperationException();
}
}

Use it like this: Operation.ADD.apply(2, 3);

It looks better. Now let us go one step further and completely eliminate the switch statement by using functional programming.

enum Operation {
ADD((x, y) -> x + y),
SUBTRACT((x, y) -> x - y),
MULTIPLY((x, y) -> x * y);

          Operation(BiFunction<Integer, Integer, Integer> operation) {
                  this.operation = operation;
          }

          private final BiFunction<Integer, Integer, Integer> operation;

          public int apply(int x, int y) {
                  return operation.apply(x, y);
          }

}

What I did here is:

A field BiFunction<Integer, Integer, Integer> is added. Operation
uses BiFunction to create a constructor for Operation.
Call the constructor in the enumeration definition and specify BiFunction<Integer, Integer, Integer> with lambda.
The java.util.function.BiFunction operation field is a reference to a function (method) that takes two parameters.

In our example, both parameters are of type int, and the return value is also of type int. Unfortunately, Java parameterized types do not support primitives, so we must use Integer.

Because BiFunction is annotated with @functioninterface, we can define one using Lambda notation.

Because our function accepts two parameters, we can use (x, y) to specify them.

Then we defined a one-line method that uses ->x+y to return a value. This is equivalent to the following method, but it is more concise.

class Adder implements BiFunction<Integer, Integer, Integer> { @Override public Integer apply(Integer x, Integer y) { return x + y; } } Our new Operation implementation uses the same approach: Operation.ADD.apply(2, 3);.





However, this implementation is better, because the compiler will tell us when a new Operation is added, which requires us to update the new function. Without this, if we do not remember to update the switch statement when adding a new Operation, we may get UnsupportedOperationException().

The key points
Enum enumeration is an extended class of Enum.

Enum enumeration can have fields, constructors, and instance methods.

Enum enumeration fields can store functions. Used in conjunction with lambdas, you can create clean and safe enum-specific function implementations and enforce them at compile time (instead of using switches).

Guess you like

Origin blog.csdn.net/gumenghua_com1/article/details/112555438